index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <template>
  2. <div class="table-box">
  3. <ProTable ref="proTable" :columns="columns" row-key="id" :request-api="listSparePartsApi">
  4. <!-- 表格 header 按钮 -->
  5. <template #tableHeader="scope">
  6. <el-button type="primary" v-auth="['als:spareParts:add']" icon="CirclePlus" @click="openDialog(1, '部件新增')"> 新增 </el-button>
  7. <el-button type="primary" v-auth="['als:spareParts:import']" icon="Upload" plain @click="batchAdd"> 导入 </el-button>
  8. <el-button type="primary" v-auth="['als:spareParts:export']" icon="Download" plain @click="downloadFile"> 导出 </el-button>
  9. <el-button
  10. type="danger"
  11. v-auth="['als:spareParts:remove']"
  12. icon="Delete"
  13. plain
  14. :disabled="!scope.isSelected"
  15. @click="batchDelete(scope.selectedListIds)"
  16. >
  17. 批量删除
  18. </el-button>
  19. </template>
  20. <!-- 表格操作 -->
  21. <template #operation="scope">
  22. <el-button type="primary" link icon="View" v-auth="['als:spareParts:query']" @click="openDialog(3, '部件查看', scope.row)"> 查看 </el-button>
  23. <el-button type="primary" link icon="EditPen" v-auth="['als:spareParts:edit']" @click="openDialog(2, '部件编辑', scope.row)">
  24. 编辑
  25. </el-button>
  26. <el-button type="primary" link icon="Delete" v-auth="['als:spareParts:remove']" @click="deleteSpareParts(scope.row)"> 删除 </el-button>
  27. </template>
  28. </ProTable>
  29. <FormDialog ref="formDialogRef" :items-options="itemsOptions" :model="model" />
  30. <ImportExcel ref="dialogRef" />
  31. <TaskDialog ref="taskDialogRef" />
  32. </div>
  33. </template>
  34. <script setup lang="tsx" name="SpareParts">
  35. import { useHandleData } from '@/hooks/useHandleData'
  36. import { ElMessageBox } from 'element-plus'
  37. import ImportExcel from '@/components/ImportExcel/index.vue'
  38. import TaskDialog from '@/components/TaskDialog/index.vue'
  39. import FormDialog from '@/components/FormDialog/index.vue'
  40. import { ProTableInstance, ColumnProps } from '@/components/ProTable/interface'
  41. import {
  42. listSparePartsApi,
  43. delSparePartsApi,
  44. addSparePartsApi,
  45. updateSparePartsApi,
  46. importTemplateApi,
  47. importSparePartsDataApi,
  48. exportSparePartsApi,
  49. getSparePartsApi
  50. } from '@/api/modules/als/spareParts'
  51. // ProTable 实例
  52. const proTable = ref<ProTableInstance>()
  53. // 表单model
  54. const model = ref({})
  55. // 删除部件信息
  56. const deleteSpareParts = async (params: any) => {
  57. await useHandleData(delSparePartsApi, params.id, '删除【' + params.id + '】部件')
  58. proTable.value?.getTableList()
  59. }
  60. // 批量删除部件信息
  61. const batchDelete = async (ids: string[]) => {
  62. await useHandleData(delSparePartsApi, ids, '删除所选部件信息')
  63. proTable.value?.clearSelection()
  64. proTable.value?.getTableList()
  65. }
  66. const taskDialogRef = ref<InstanceType<typeof TaskDialog> | null>(null)
  67. // 导出部件列表
  68. const downloadFile = async () => {
  69. ElMessageBox.confirm('确认导出部件数据?', '温馨提示', { type: 'warning' }).then(async () => {
  70. exportSparePartsApi(proTable.value?.searchParam)
  71. taskDialogRef.value?.openExportDialog()
  72. })
  73. }
  74. // 批量添加部件
  75. const dialogRef = ref<InstanceType<typeof ImportExcel> | null>(null)
  76. const batchAdd = () => {
  77. const params = {
  78. title: '部件',
  79. tempApi: importTemplateApi,
  80. importApi: importSparePartsDataApi,
  81. getTableList: proTable.value?.getTableList
  82. }
  83. dialogRef.value?.acceptParams(params)
  84. }
  85. const formDialogRef = ref<InstanceType<typeof FormDialog> | null>(null)
  86. // 打开弹框的功能
  87. const openDialog = async (type: number, title: string, row?: any) => {
  88. let res = { data: {} }
  89. if (row?.id) {
  90. res = await getSparePartsApi(row?.id || null)
  91. }
  92. model.value = type == 1 ? {} : res.data
  93. // 重置表单
  94. setItemsOptions()
  95. const params = {
  96. title,
  97. width: 580,
  98. isEdit: type !== 3,
  99. api: type == 1 ? addSparePartsApi : updateSparePartsApi,
  100. getTableList: proTable.value?.getTableList
  101. }
  102. formDialogRef.value?.openDialog(params)
  103. }
  104. // 表格配置项
  105. const columns = reactive<ColumnProps<any>[]>([
  106. { type: 'selection', fixed: 'left', width: 70 },
  107. { prop: 'id', label: '编号' },
  108. {
  109. prop: 'name',
  110. label: '部件名称',
  111. search: {
  112. el: 'input'
  113. },
  114. width: 120
  115. },
  116. {
  117. prop: 'model',
  118. label: '型号',
  119. search: {
  120. el: 'input'
  121. },
  122. width: 120
  123. },
  124. {
  125. prop: 'systemName',
  126. label: '所属系统',
  127. search: {
  128. el: 'input'
  129. },
  130. width: 120
  131. },
  132. {
  133. prop: 'factory',
  134. label: '制造厂',
  135. search: {
  136. el: 'input'
  137. },
  138. width: 120
  139. },
  140. {
  141. prop: 'quantity',
  142. label: '数量',
  143. search: {
  144. el: 'input'
  145. },
  146. width: 120
  147. },
  148. {
  149. prop: 'createBy',
  150. label: '创建人',
  151. width: 120
  152. },
  153. {
  154. prop: 'createTime',
  155. label: '创建时间',
  156. width: 120
  157. },
  158. {
  159. prop: 'updateBy',
  160. label: '更新人',
  161. width: 120
  162. },
  163. {
  164. prop: 'updateTime',
  165. label: '更新时间',
  166. width: 120
  167. },
  168. { prop: 'operation', label: '操作', width: 230, fixed: 'right' }
  169. ])
  170. // 表单配置项
  171. let itemsOptions = reactive<ProForm.ItemsOptions[]>([])
  172. const setItemsOptions = () => {
  173. itemsOptions = [
  174. {
  175. label: '部件名称',
  176. prop: 'name',
  177. rules: [{ required: true, message: '部件名称不能为空', trigger: 'blur' }],
  178. compOptions: {
  179. placeholder: '请输入部件名称'
  180. }
  181. },
  182. {
  183. label: '型号',
  184. prop: 'model',
  185. rules: [{ required: true, message: '型号不能为空', trigger: 'blur' }],
  186. compOptions: {
  187. placeholder: '请输入型号'
  188. }
  189. },
  190. {
  191. label: '所属系统',
  192. prop: 'systemName',
  193. rules: [{ required: true, message: '所属系统不能为空', trigger: 'blur' }],
  194. compOptions: {
  195. placeholder: '请输入所属系统'
  196. }
  197. },
  198. {
  199. label: '制造厂',
  200. prop: 'factory',
  201. rules: [{ required: true, message: '制造厂不能为空', trigger: 'blur' }],
  202. compOptions: {
  203. placeholder: '请输入制造厂'
  204. }
  205. },
  206. {
  207. label: '数量',
  208. prop: 'quantity',
  209. rules: [{ required: true, message: '数量不能为空', trigger: 'blur' }],
  210. compOptions: {
  211. placeholder: '请输入数量'
  212. }
  213. }
  214. ]
  215. }
  216. </script>