business.vue 6.3 KB

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