business.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <template>
  2. <div class="pageWrap bgc">
  3. <div class="content-warp flex-column-page-wrap">
  4. <!-- 公用搜索组件 -->
  5. <LeSearchForm ref="searchForm" v-model:searchData="searchData" :forms="forms" :loading="tableOpts.options.loading"> </LeSearchForm>
  6. <div style="margin: 20px; font-size: 1.2em;color: red">
  7. 演示关联业务审批逻辑,对应 业务流程KEY为 purchaseOrder
  8. </div>
  9. <!-- LeTable 组件使用 -->
  10. <LeTable
  11. ref="tableRef"
  12. v-model:searchParams="tableOpts.searchParams"
  13. v-bind="tableOpts"
  14. v-model:curRow="tableOpts.curRow"
  15. v-model:checked-options="checkedColumns"
  16. :columns="activeColumns"
  17. >
  18. <template #toolLeft>
  19. <el-button type="primary" @click="addHandler">
  20. <el-icon class="btn-icon">
  21. <Plus />
  22. </el-icon>
  23. </el-button>
  24. <el-button type="danger" :disabled="curSelectionRows.length === 0" @click="batch_del">
  25. <el-icon class="btn-icon">
  26. <Delete />
  27. </el-icon>
  28. </el-button>
  29. </template>
  30. <template #statusSlot="scope">
  31. <el-tag v-if="scope.row.status === 1" type="danger">已拒绝</el-tag>
  32. <el-tag v-else-if="scope.row.status === 2" type="success">已通过</el-tag>
  33. <el-tag v-else type="info">待审批</el-tag>
  34. </template>
  35. <template #actionSlot="scope">
  36. <el-tooltip content="提交审批" placement="bottom" effect="light">
  37. <el-icon class="ibt0" @click="table_edit(scope.row)">
  38. <Promotion />
  39. </el-icon>
  40. </el-tooltip>
  41. <el-divider direction="vertical"></el-divider>
  42. <el-popconfirm title="确定删除吗?" @confirm="table_del(scope.row)">
  43. <template #reference>
  44. <el-icon class="ibt0">
  45. <Delete />
  46. </el-icon>
  47. </template>
  48. </el-popconfirm>
  49. </template>
  50. </LeTable>
  51. </div>
  52. <LeFormConfigDialog
  53. v-if="visible"
  54. ref="dialogUserRef"
  55. v-model="visible"
  56. title="新增采购订单"
  57. width="600px"
  58. :form-data="activeData"
  59. :form-options="formOptions"
  60. @submit="submitHandler"
  61. />
  62. </div>
  63. </template>
  64. <script lang="tsx" setup>
  65. import purchaseOrder from '@/api/test/purchaseOrder'
  66. import { computed, nextTick, ref, watch } from 'vue'
  67. import { ElMessage, ElMessageBox, ElTree } from 'element-plus'
  68. import { useTablePage } from '@/hooks/useTablePage'
  69. import { Plus, Delete } from '@element-plus/icons-vue'
  70. const visible = ref(false) // 弹窗显示隐藏
  71. const activeData = ref({})
  72. const formsDialog = [
  73. {
  74. prop: 'title',
  75. label: '标题',
  76. itemType: 'input',
  77. rules: [{ required: true, message: '请输入采购订单标题', trigger: 'blur' }]
  78. },
  79. {
  80. prop: 'content',
  81. label: '内容',
  82. rows: "2",
  83. type: 'textarea',
  84. rules: [{ required: true, message: '请输入采购订单内容', trigger: 'blur' }]
  85. }
  86. ]
  87. // 新增的表单 和 编辑的表单
  88. const formOptions = computed(() => {
  89. return {
  90. forms: formsDialog,
  91. labelWidth: 120,
  92. span: 30,
  93. showResetBtn: true,
  94. formConfig: {
  95. showCancelBtn: true,
  96. submitLoading: false
  97. }
  98. }
  99. })
  100. const groupFilterText = ref('')
  101. const treeRef = ref<InstanceType<typeof ElTree>>()
  102. // 表格搜索条件
  103. const forms = ref([
  104. {
  105. prop: 'keyword',
  106. label: '采购单名称:',
  107. itemType: 'input',
  108. placeholder: '请输入采购单名称'
  109. }
  110. ])
  111. // table列表数据请求
  112. const queryList = async () => {
  113. const { options, searchParams } = tableOpts
  114. options.loading = true
  115. try {
  116. const { records: list, total } = await purchaseOrder.postPageApi(searchParams)
  117. tableOpts.total = total
  118. tableOpts.list = list
  119. } catch {
  120. console.log('获取列表数据失败')
  121. tableOpts.total = 0
  122. tableOpts.list = []
  123. options.loading = false // 更改加载中的 loading值
  124. } finally {
  125. options.loading = false
  126. }
  127. }
  128. // table 参数
  129. const columns = [
  130. {
  131. prop: 'title',
  132. label: '标题',
  133. minWidth: 80
  134. },
  135. {
  136. prop: 'content',
  137. label: '内容',
  138. minWidth: 100
  139. },
  140. {
  141. prop: 'status',
  142. label: '状态',
  143. minWidth: 50,
  144. slots: {
  145. default: 'statusSlot'
  146. }
  147. },
  148. {
  149. prop: 'flwComment',
  150. label: '审批内容',
  151. minWidth: 100
  152. },
  153. {
  154. prop: 'createBy',
  155. label: '创建人',
  156. minWidth: 100
  157. },
  158. {
  159. prop: 'createTime',
  160. label: '创建时间',
  161. minWidth: 126
  162. },
  163. {
  164. prop: 'action',
  165. label: '操作',
  166. width: 100,
  167. fixed: 'right',
  168. slots: {
  169. default: 'actionSlot'
  170. }
  171. }
  172. ]
  173. const { searchData, tableOpts, checkedColumns, activeColumns, curSelectionRows, updateParams } = useTablePage(
  174. {
  175. options: {
  176. showIndex: false
  177. },
  178. // 需要展示的列
  179. columns,
  180. // 控制列配置
  181. columnsConfig: {
  182. columns
  183. }
  184. },
  185. {
  186. queryList,
  187. fetchImmediate: false
  188. }
  189. )
  190. // 删除
  191. const deleteItem = async ids => {
  192. // try {
  193. await purchaseOrder.postDeleteApi(ids)
  194. ElMessage.error(`删除成功~`)
  195. updateParams()
  196. // } catch (e) {
  197. // console.log('删除失败')
  198. // ElMessage.error(`删除失败~`)
  199. // }
  200. }
  201. // 单个删除
  202. const table_del = row => {
  203. deleteItem([row.id])
  204. }
  205. //批量删除
  206. const batch_del = () => {
  207. const ids = curSelectionRows.value.map(item => item.id) // 多选数据
  208. ElMessageBox.confirm('是否删除选中数据?', '提示', {
  209. confirmButtonText: '确认',
  210. cancelButtonText: '取消',
  211. type: 'error',
  212. buttonSize: 'default'
  213. }).then(() => {
  214. deleteItem(ids)
  215. })
  216. }
  217. // 弹窗事件
  218. const submitHandler = async params => {
  219. formOptions.value.formConfig.submitLoading = true
  220. try {
  221. params.status = params.status ? 1 : 0
  222. params.id = null
  223. await purchaseOrder.postAddOrEditSaveApi(params)
  224. ElMessage.success(`新增成功~`)
  225. visible.value = false
  226. updateParams()
  227. formOptions.value.formConfig.submitLoading = false
  228. } catch (e) {
  229. console.log(e)
  230. formOptions.value.formConfig.submitLoading = false
  231. }
  232. }
  233. const addHandler = () => {
  234. activeData.value = {}
  235. visible.value = true
  236. }
  237. nextTick(() => {
  238. queryList()
  239. })
  240. watch(groupFilterText, val => {
  241. treeRef.value!.filter(val)
  242. })
  243. </script>