PartInfo.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <template>
  2. <a-card :bordered="false">
  3. <div class="table-page-search-wrapper">
  4. <a-form layout="inline">
  5. <a-row :gutter="48">
  6. <a-col :md="8" :sm="24">
  7. <a-form-item label="关键字">
  8. <a-input v-model.trim="queryParam.keyword" placeholder="请输入名称/编码"/>
  9. </a-form-item>
  10. </a-col>
  11. <a-col :md="8 || 24" :sm="24">
  12. <span class="table-page-search-submitButtons">
  13. <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
  14. <a-button style="margin-left: 8px" @click="resetSearchForm">重置</a-button>
  15. </span>
  16. </a-col>
  17. </a-row>
  18. </a-form>
  19. </div>
  20. <div class="table-operator" style="margin-bottom: 8px;">
  21. <a-button v-if="$auth('part-infos-add')" type="primary" icon="plus" @click="handleAdd">新增</a-button>
  22. <a-button style="margin-left: 8px" v-if="$auth('part-infos-export')" type="primary" icon="download" @click="doExport">导出</a-button>
  23. <a-dropdown v-action:edit v-if="selectedRowKeys.length > 0 && $auth('part-infos-del')">
  24. <a-menu slot="overlay">
  25. <a-popconfirm title="是否要删除所选数据?" @confirm="batchDelete()">
  26. <a-menu-item key="1"><a-icon type="delete" /><a>删除</a></a-menu-item>
  27. </a-popconfirm>
  28. </a-menu>
  29. <a-button style="margin-left: 8px">
  30. 批量操作 <a-icon type="down" />
  31. </a-button>
  32. </a-dropdown>
  33. </div>
  34. <s-table
  35. ref="table"
  36. size="default"
  37. rowKey="id"
  38. :columns="columns"
  39. :data="loadData"
  40. :alert="options.alert"
  41. :rowSelection="options.rowSelection"
  42. showPagination="auto"
  43. >
  44. <span slot="action" slot-scope="record">
  45. <a @click="handleView(record)">查看</a>
  46. <operation-button
  47. v-if="$auth('part-infos-edit')"
  48. @click="handleEdit(record)" >修改</operation-button>
  49. <operation-button
  50. v-if="$auth('part-infos-del')"
  51. :type="2"
  52. title="是否要删除该条数据?"
  53. @confirm="batchDelete(record.id)" >删除</operation-button>
  54. <operation-button
  55. @click="handleCopy(record)" >复制</operation-button>
  56. <operation-button
  57. v-if="$auth('repair-forms-spare-part-used')"
  58. @click="sparePartUsedList(record)" >备件列表</operation-button>
  59. </span>
  60. <span slot="status" slot-scope="text">
  61. <badge
  62. :status="DictCache.COLOR.PART_STATUS[text]"
  63. :text="statusMap[text]" />
  64. </span>
  65. </s-table>
  66. <base-form ref="baseModal" @ok="handleOk"/>
  67. <detail ref="detailModal"/>
  68. <spare-part-used-modal ref="sparePartUsedModal" />
  69. </a-card>
  70. </template>
  71. <script>
  72. import { STable, Ellipsis } from '@/components'
  73. import BaseForm from './modules/BaseForm'
  74. import Detail from './modules/Detail'
  75. import SparePartUsedModal from '@/views/sqarepartmanage/sparepartused/modules/SparePartUsedModal'
  76. import { getPartInfoPage, deletePartInfos, fetchPartInfo, exportPartInfo } from '@/api/part/info'
  77. export default {
  78. name: 'PartInfoList',
  79. components: {
  80. STable,
  81. Ellipsis,
  82. BaseForm,
  83. Detail,
  84. SparePartUsedModal
  85. },
  86. data () {
  87. return {
  88. // 查询参数
  89. queryParam: {
  90. sbId: this.$route.query.id
  91. },
  92. statusMap: {},
  93. unitMap: {},
  94. levelMap: {},
  95. sourceTypeMap: {},
  96. // 表头
  97. columns: [
  98. {
  99. title: '序号',
  100. dataIndex: 'index',
  101. customRender: (text, record, index) => {
  102. return `${(this.$refs.table.localPagination.current - 1) * this.$refs.table.localPagination.pageSize + index + 1}`
  103. }
  104. },
  105. {
  106. title: '部件编号',
  107. dataIndex: 'no'
  108. },
  109. {
  110. title: '部件名称',
  111. dataIndex: 'name'
  112. },
  113. {
  114. title: '部件类别',
  115. dataIndex: 'typeId',
  116. customRender: (text, record, index) => {
  117. return record.typeName
  118. }
  119. },
  120. {
  121. title: '部件等级',
  122. dataIndex: 'level',
  123. customRender: (text, record, index) => {
  124. return this.BaseTool.Object.getField(this.levelMap, text)
  125. }
  126. },
  127. {
  128. title: '所属设备',
  129. dataIndex: 'sbId',
  130. customRender: (text, record, index) => {
  131. return record.sbName
  132. }
  133. },
  134. {
  135. title: '备注',
  136. dataIndex: 'remark'
  137. },
  138. {
  139. title: '操作',
  140. key: 'action',
  141. width: '300px',
  142. align: 'center',
  143. fixed: 'right',
  144. scopedSlots: { customRender: 'action' }
  145. }
  146. ],
  147. // 加载数据方法 必须为 Promise 对象
  148. loadData: parameter => {
  149. this.sbId = this.queryParam.sbId
  150. parameter = {
  151. ...parameter,
  152. ...this.queryParam,
  153. dataScope: {
  154. sortBy: 'desc',
  155. sortName: 'update_time'
  156. }
  157. }
  158. return getPartInfoPage(Object.assign(parameter, this.queryParam))
  159. .then(res => {
  160. return res.data
  161. })
  162. },
  163. selectedRowKeys: [],
  164. selectedRows: [],
  165. options: {
  166. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  167. rowSelection: {
  168. selectedRowKeys: this.selectedRowKeys,
  169. onChange: this.onSelectChange
  170. }
  171. },
  172. optionAlertShow: false
  173. }
  174. },
  175. created () {
  176. this.tableOption()
  177. this.statusMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.PART_STATUS)
  178. this.unitMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SBINFO_UNIT)
  179. this.levelMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.PART_LEVEL)
  180. this.sourceTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SBTYPE_SOURCETYPE)
  181. },
  182. methods: {
  183. tableOption () {
  184. if (!this.optionAlertShow) {
  185. this.options = {
  186. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  187. rowSelection: {
  188. selectedRowKeys: this.selectedRowKeys,
  189. onChange: this.onSelectChange,
  190. getCheckboxProps: record => ({
  191. props: {
  192. disabled: false,
  193. name: record.id
  194. }
  195. })
  196. }
  197. }
  198. this.optionAlertShow = true
  199. } else {
  200. this.options = {
  201. alert: false,
  202. rowSelection: null
  203. }
  204. this.optionAlertShow = false
  205. }
  206. },
  207. handleAdd () {
  208. const param = { sbId: this.sbId }
  209. this.$refs.baseModal.base(param)
  210. },
  211. batchDelete (id) {
  212. let ids = []
  213. if (this.BaseTool.String.isBlank(id)) {
  214. const length = this.selectedRows.length
  215. if (length === 0) {
  216. this.$message.info('请选择要删除的记录')
  217. return
  218. }
  219. ids = this.selectedRows.map(item => item.id)
  220. } else {
  221. ids = [id]
  222. }
  223. deletePartInfos(ids).then(res => {
  224. this.$message.info('删除成功')
  225. this.handleOk()
  226. this.$refs.table.clearSelected()
  227. })
  228. },
  229. handleEdit (record) {
  230. fetchPartInfo({ id: record.id }).then(res => {
  231. const modal = this.$refs.baseModal
  232. modal.base(res.data)
  233. })
  234. },
  235. handleView (record) {
  236. fetchPartInfo({ id: record.id }).then(res => {
  237. const modal = this.$refs.detailModal
  238. modal.base(res.data)
  239. })
  240. },
  241. handleCopy (record) {
  242. fetchPartInfo({ id: record.id }).then(res => {
  243. const modal = this.$refs.baseModal
  244. res.data.id = null
  245. modal.base(res.data)
  246. })
  247. },
  248. sparePartUsedList (record) {
  249. const modal = this.$refs.sparePartUsedModal
  250. modal.base({}, { partId: record.id })
  251. },
  252. handleOk () {
  253. this.$refs.table.refresh()
  254. },
  255. onSelectChange (selectedRowKeys, selectedRows) {
  256. this.selectedRowKeys = selectedRowKeys
  257. this.selectedRows = selectedRows
  258. },
  259. resetSearchForm () {
  260. this.queryParam = {
  261. }
  262. this.$refs.table.refresh(true)
  263. },
  264. doExport () {
  265. const parameter = {
  266. ...this.queryParam
  267. }
  268. exportPartInfo(parameter).then(file => {
  269. this.BaseTool.UPLOAD.downLoadExportExcel(file)
  270. })
  271. }
  272. }
  273. }
  274. </script>