SparePartUsedSelectModal.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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. <a-button v-if="$auth('sqarepartmanage-spare-part-used-add')" type="primary" icon="plus" @click="handleAdd()">新增</a-button>
  30. <a-dropdown v-action:edit v-if="selectedRowKeys.length > 0 && $auth('sqarepartmanage-spare-part-used-del')">
  31. <a-menu slot="overlay">
  32. <a-popconfirm title="是否要删除所选数据?" @confirm="batchDelete()">
  33. <a-menu-item key="1"><a-icon type="delete" /><a>删除</a></a-menu-item>
  34. </a-popconfirm>
  35. </a-menu>
  36. <a-button style="margin-left: 8px">
  37. 批量操作 <a-icon type="down" />
  38. </a-button>
  39. </a-dropdown>
  40. </div>
  41. <s-table
  42. ref="table"
  43. size="default"
  44. rowKey="id"
  45. :columns="columns"
  46. :data="loadData"
  47. :alert="options.alert"
  48. :customRow="options.customRow"
  49. :rowSelection="options.rowSelection"
  50. showPagination="auto"
  51. >
  52. <span slot="action" slot-scope="record1">
  53. <template>
  54. <a @click="handleView(record1)">查看</a>
  55. <a-divider type="vertical" />
  56. <a @click="handleEdit(record1)">修改</a>
  57. <a-divider type="vertical" />
  58. <a-popconfirm v-if="record1.status==1" @confirm="handleFeiqi(record1.id)">
  59. <a>废弃</a>
  60. </a-popconfirm>
  61. </template>
  62. </span>
  63. <span slot="status" slot-scope="text">
  64. <badge
  65. :status="DictCache.COLOR.SPARE_PART_USED_STATUS[text]"
  66. :text="statusMap[text]" />
  67. </span>
  68. </s-table>
  69. <base-form ref="baseModal" @ok="handleOk"/>
  70. <detail ref="detailModal"/>
  71. </a-card>
  72. <template slot="footer">
  73. <a-button :loading="confirmLoading" type="primary" @click="handleCancel()">取消</a-button>
  74. <a-button :loading="confirmLoading" type="primary" @click="handleSelect()">选择</a-button>
  75. </template>
  76. </a-modal>
  77. </template>
  78. <script>
  79. import { STable, Ellipsis } from '@/components'
  80. import BaseForm from './BaseForm'
  81. import Detail from './Detail'
  82. import { getSparePartUsedPage, deleteSparePartUseds, updateSparePartUsed, fetchSparePartUsed, exportSparePartUsed } from '@/api/sqarepartmanage/sparepartused'
  83. export default {
  84. name: 'SparePartUsedSelectModal',
  85. components: {
  86. STable,
  87. Ellipsis,
  88. BaseForm,
  89. Detail
  90. },
  91. props: {
  92. type: {
  93. type: String,
  94. default: 'radio'
  95. },
  96. selectedRowKey: {
  97. type: Array,
  98. default: () => {
  99. return []
  100. }
  101. },
  102. selectedRow: {
  103. type: Array,
  104. default: () => {
  105. return []
  106. }
  107. }
  108. },
  109. data () {
  110. return {
  111. confirmLoading: false,
  112. mdl: {},
  113. modalTitle: null,
  114. visible: false,
  115. record: null,
  116. // 查询参数
  117. queryParam: {
  118. },
  119. // 表头
  120. columns: [
  121. {
  122. title: '序号',
  123. dataIndex: 'index',
  124. customRender: (text, record, index) => {
  125. return `${(this.$refs.table.localPagination.current - 1) * this.$refs.table.localPagination.pageSize + index + 1}`
  126. }
  127. },
  128. {
  129. title: '设备名称',
  130. dataIndex: 'sbId',
  131. customRender: (text, record, index) => {
  132. return record.sbName
  133. }
  134. },
  135. {
  136. title: '部位名称',
  137. dataIndex: 'partId',
  138. customRender: (text, record, index) => {
  139. return record.partName
  140. }
  141. },
  142. {
  143. title: '备件名称',
  144. dataIndex: 'spareId',
  145. customRender: (text, record, index) => {
  146. return record.spareName
  147. }
  148. },
  149. {
  150. title: '投用日期',
  151. dataIndex: 'startDate'
  152. },
  153. {
  154. title: '预计报废日期',
  155. dataIndex: 'changeDate'
  156. },
  157. {
  158. title: '实际更换日期',
  159. dataIndex: 'realChangeDate'
  160. },
  161. {
  162. title: '使用状态',
  163. dataIndex: 'status',
  164. scopedSlots: { customRender: 'status' }
  165. },
  166. {
  167. title: '操作',
  168. key: 'action',
  169. width: '200px',
  170. align: 'center',
  171. scopedSlots: { customRender: 'action' }
  172. }
  173. ],
  174. // 下拉框map
  175. delFlagMap: {},
  176. // 加载数据方法 必须为 Promise 对象
  177. loadData: parameter => {
  178. parameter = {
  179. ...parameter,
  180. ...this.queryParam,
  181. dataScope: {
  182. sortBy: 'desc',
  183. sortName: 'update_time'
  184. }
  185. }
  186. return getSparePartUsedPage(Object.assign(parameter, this.queryParam))
  187. .then(res => {
  188. return res.data
  189. })
  190. },
  191. selectedRowKeys: [],
  192. selectedRows: [],
  193. options: {
  194. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  195. rowSelection: {
  196. selectedRowKeys: this.selectedRowKeys,
  197. onChange: this.onSelectChange
  198. }
  199. },
  200. optionAlertShow: false,
  201. isCreated: false
  202. }
  203. },
  204. created () {
  205. // 下拉框map
  206. this.statusMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SPARE_PART_USED_STATUS)
  207. // this.tableOption()
  208. },
  209. methods: {
  210. tableOption () {
  211. if (!this.optionAlertShow) {
  212. this.options = {
  213. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  214. rowSelection: {
  215. selectedRowKeys: this.selectedRowKeys,
  216. onChange: this.onSelectChange,
  217. type: this.type,
  218. getCheckboxProps: record => ({
  219. props: {
  220. disabled: false,
  221. name: record.id
  222. }
  223. })
  224. },
  225. customRow: (record) => {
  226. return {
  227. on: { // 事件
  228. click: (event) => { // 点击行
  229. // 选择对象
  230. this.mySelect([record.id], [record])
  231. },
  232. dblclick: (event) => {
  233. this.mySelect([record.id], [record])
  234. this.handleSelect()
  235. }
  236. }
  237. }
  238. }
  239. }
  240. this.optionAlertShow = true
  241. } else {
  242. this.options = {
  243. alert: false,
  244. rowSelection: null
  245. }
  246. this.optionAlertShow = false
  247. }
  248. },
  249. handleView (record) {
  250. fetchSparePartUsed({ id: record.id }).then(res => {
  251. const modal = this.$refs.detailModal
  252. modal.base(res.data)
  253. })
  254. },
  255. batchDelete (id) {
  256. let ids = []
  257. if (this.BaseTool.String.isBlank(id)) {
  258. const length = this.selectedRows.length
  259. if (length === 0) {
  260. this.$message.info('请选择要删除的记录')
  261. return
  262. }
  263. ids = this.selectedRows.map(item => item.id)
  264. } else {
  265. ids = [id]
  266. }
  267. deleteSparePartUseds(ids).then(res => {
  268. this.$message.info('删除成功')
  269. this.handleOk()
  270. this.$refs.table.clearSelected()
  271. })
  272. },
  273. handleEdit (record) {
  274. fetchSparePartUsed({ id: record.id }).then(res => {
  275. const modal = this.$refs.baseModal
  276. modal.base(res.data, { sbId: this.repaireRecord.id, modelId: this.repaireRecord.modelId })
  277. })
  278. },
  279. handleFeiqi (id) {
  280. updateSparePartUsed({ id: id, status: 2 }).then(res => {
  281. this.$message.info('废弃成功')
  282. this.handleOk()
  283. this.$refs.table.clearSelected()
  284. })
  285. },
  286. handleOk () {
  287. this.$refs.table.refresh()
  288. },
  289. onSelectChange (selectedRowKeys, selectedRows) {
  290. this.selectedRowKeys = selectedRowKeys
  291. this.selectedRows = selectedRows
  292. },
  293. resetSearchForm () {
  294. this.queryParam = {
  295. }
  296. this.$refs.table.refresh(true)
  297. },
  298. base (record, queryParam = {}) {
  299. this.visible = true
  300. this.modalTitle = '选择信息'
  301. this.queryParam = queryParam
  302. // console.log(333, this.queryParam)
  303. this.repaireRecord = record
  304. if (this.isCreated) {
  305. this.$refs.table.clearSelected()
  306. // this.options.rowSelection.type = this.type
  307. this.handleOk()
  308. } else {
  309. this.tableOption()
  310. this.isCreated = true
  311. }
  312. },
  313. handleAdd () {
  314. this.$refs.baseModal.base(null, { sbId: this.repaireRecord.sbId, modelId: this.repaireRecord.modelId })
  315. },
  316. handleCancel () {
  317. this.visible = false
  318. this.confirmLoading = false
  319. },
  320. handleSelect () {
  321. if (this.selectedRowKeys.length === 0) {
  322. this.$message.warn('请至少选择一项信息')
  323. } else {
  324. this.confirmLoading = true
  325. this.$emit('selected', this.record, this.selectedRowKeys, this.selectedRows)
  326. this.confirmLoading = false
  327. this.visible = false
  328. }
  329. },
  330. mySelect (selectedRowKeys, selectedRows) {
  331. this.$refs.table.updateSelect(selectedRowKeys, selectedRows)
  332. this.$refs.table.rowSelection.onChange(selectedRowKeys, selectedRows)
  333. }
  334. }
  335. }
  336. </script>