SparePartUsedModal.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <template>
  2. <a-modal
  3. :title="modalTitle"
  4. :width="1000"
  5. :visible="visible"
  6. :confirmLoading="confirmLoading"
  7. class="ant-modal2"
  8. @cancel="handleCancel"
  9. >
  10. <a-card :bordered="false">
  11. <div class="table-page-search-wrapper">
  12. <a-form layout="inline">
  13. <a-row :gutter="48">
  14. <a-col :md="8" :sm="24">
  15. <a-form-item label="关键字">
  16. <a-input v-model.trim="queryParam.keyword" placeholder="请输入名称/类型名称"/>
  17. </a-form-item>
  18. </a-col>
  19. <a-col :md="8 || 24" :sm="24">
  20. <span class="table-page-search-submitButtons">
  21. <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
  22. <a-button style="margin-left: 8px" @click="resetSearchForm">重置</a-button>
  23. </span>
  24. </a-col>
  25. </a-row>
  26. </a-form>
  27. </div>
  28. <div class="table-operator" style="margin-bottom: 8px;">
  29. </div>
  30. <s-table
  31. ref="table"
  32. size="default"
  33. rowKey="id"
  34. :columns="columns"
  35. :data="loadData"
  36. :alert="options.alert"
  37. :customRow="options.customRow"
  38. :rowSelection="options.rowSelection"
  39. showPagination="auto"
  40. >
  41. <span slot="action" slot-scope="record1">
  42. <template>
  43. <a @click="handleView(record1)">查看</a>
  44. </template>
  45. </span>
  46. <span slot="status" slot-scope="text">
  47. <badge
  48. :status="DictCache.COLOR.SPARE_PART_USED_STATUS[text]"
  49. :text="statusMap[text]" />
  50. </span>
  51. </s-table>
  52. <detail ref="detailModal"/>
  53. </a-card>
  54. <template slot="footer">
  55. <a-button :loading="confirmLoading" type="primary" @click="handleCancel()">返回</a-button>
  56. </template>
  57. </a-modal>
  58. </template>
  59. <script>
  60. import { STable, Ellipsis } from '@/components'
  61. import Detail from './Detail'
  62. import { getSparePartUsedPage, fetchSparePartUsed } from '@/api/sqarepartmanage/sparepartused'
  63. export default {
  64. name: 'SparePartUsedSelectModal',
  65. components: {
  66. STable,
  67. Ellipsis,
  68. Detail
  69. },
  70. props: {
  71. type: {
  72. type: String,
  73. default: 'radio'
  74. },
  75. selectedRowKey: {
  76. type: Array,
  77. default: () => {
  78. return []
  79. }
  80. },
  81. selectedRow: {
  82. type: Array,
  83. default: () => {
  84. return []
  85. }
  86. }
  87. },
  88. data () {
  89. return {
  90. confirmLoading: false,
  91. mdl: {},
  92. modalTitle: null,
  93. visible: false,
  94. record: null,
  95. // 查询参数
  96. queryParam: {
  97. },
  98. // 表头
  99. columns: [
  100. {
  101. title: '序号',
  102. dataIndex: 'index',
  103. customRender: (text, record, index) => {
  104. return `${(this.$refs.table.localPagination.current - 1) * this.$refs.table.localPagination.pageSize + index + 1}`
  105. }
  106. },
  107. {
  108. title: '设备名称',
  109. dataIndex: 'sbId',
  110. customRender: (text, record, index) => {
  111. return record.sbName
  112. }
  113. },
  114. {
  115. title: '部位名称',
  116. dataIndex: 'partId',
  117. customRender: (text, record, index) => {
  118. return record.partName
  119. }
  120. },
  121. {
  122. title: '备件名称',
  123. dataIndex: 'spareId',
  124. customRender: (text, record, index) => {
  125. return record.spareName
  126. }
  127. },
  128. {
  129. title: '投用日期',
  130. dataIndex: 'startDate'
  131. },
  132. {
  133. title: '预计报废日期',
  134. dataIndex: 'changeDate'
  135. },
  136. {
  137. title: '实际更换日期',
  138. dataIndex: 'realChangeDate'
  139. },
  140. {
  141. title: '使用状态',
  142. dataIndex: 'status',
  143. scopedSlots: { customRender: 'status' }
  144. },
  145. {
  146. title: '操作',
  147. key: 'action',
  148. width: '200px',
  149. align: 'center',
  150. scopedSlots: { customRender: 'action' }
  151. }
  152. ],
  153. // 下拉框map
  154. delFlagMap: {},
  155. // 加载数据方法 必须为 Promise 对象
  156. loadData: parameter => {
  157. parameter = {
  158. ...parameter,
  159. ...this.queryParam,
  160. dataScope: {
  161. sortBy: 'desc',
  162. sortName: 'update_time'
  163. }
  164. }
  165. return getSparePartUsedPage(Object.assign(parameter, this.queryParam))
  166. .then(res => {
  167. return res.data
  168. })
  169. },
  170. selectedRowKeys: [],
  171. selectedRows: [],
  172. options: {
  173. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  174. rowSelection: {
  175. selectedRowKeys: this.selectedRowKeys,
  176. onChange: this.onSelectChange
  177. }
  178. },
  179. optionAlertShow: false,
  180. isCreated: false
  181. }
  182. },
  183. created () {
  184. // 下拉框map
  185. this.statusMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SPARE_PART_USED_STATUS)
  186. // this.tableOption()
  187. },
  188. methods: {
  189. tableOption () {
  190. if (!this.optionAlertShow) {
  191. this.options = {
  192. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  193. rowSelection: {
  194. selectedRowKeys: this.selectedRowKeys,
  195. onChange: this.onSelectChange,
  196. type: this.type,
  197. getCheckboxProps: record => ({
  198. props: {
  199. disabled: false,
  200. name: record.id
  201. }
  202. })
  203. },
  204. customRow: (record) => {
  205. return {
  206. on: { // 事件
  207. click: (event) => { // 点击行
  208. // 选择对象
  209. this.mySelect([record.id], [record])
  210. },
  211. dblclick: (event) => {
  212. this.mySelect([record.id], [record])
  213. this.handleSelect()
  214. }
  215. }
  216. }
  217. }
  218. }
  219. this.optionAlertShow = true
  220. } else {
  221. this.options = {
  222. alert: false,
  223. rowSelection: null
  224. }
  225. this.optionAlertShow = false
  226. }
  227. },
  228. handleView (record) {
  229. fetchSparePartUsed({ id: record.id }).then(res => {
  230. const modal = this.$refs.detailModal
  231. modal.base(res.data)
  232. })
  233. },
  234. handleOk () {
  235. this.$refs.table.refresh()
  236. },
  237. onSelectChange (selectedRowKeys, selectedRows) {
  238. this.selectedRowKeys = selectedRowKeys
  239. this.selectedRows = selectedRows
  240. },
  241. resetSearchForm () {
  242. this.queryParam = {
  243. }
  244. this.$refs.table.refresh(true)
  245. },
  246. base (record, queryParam = {}) {
  247. this.visible = true
  248. this.modalTitle = '备件列表'
  249. this.queryParam = queryParam
  250. this.record = record
  251. if (this.isCreated) {
  252. this.$refs.table.clearSelected()
  253. // this.options.rowSelection.type = this.type
  254. this.handleOk()
  255. } else {
  256. this.tableOption()
  257. this.isCreated = true
  258. }
  259. },
  260. handleCancel () {
  261. this.visible = false
  262. this.confirmLoading = false
  263. },
  264. handleSelect () {
  265. if (this.selectedRowKeys.length === 0) {
  266. this.$message.warn('请至少选择一项信息')
  267. } else {
  268. this.confirmLoading = true
  269. this.$emit('selected', this.record, this.selectedRowKeys, this.selectedRows)
  270. this.confirmLoading = false
  271. this.visible = false
  272. }
  273. },
  274. mySelect (selectedRowKeys, selectedRows) {
  275. this.$refs.table.updateSelect(selectedRowKeys, selectedRows)
  276. this.$refs.table.rowSelection.onChange(selectedRowKeys, selectedRows)
  277. }
  278. }
  279. }
  280. </script>