deteleTables.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <el-dialog v-model="deteleBusinessDialogVisible" width="1000" :before-close="beForeCancel" :show-close="false"
  3. top="10vh">
  4. <template #header="{ close, titleId, titleClass }">
  5. <div class="flex justify-between items-center border-b pb-3 dialog-header">
  6. <h4 :id="titleId">商机回收站</h4>
  7. <div>
  8. <el-button type="primary" v-loading="allLoading.batchRecoveryLoading" :disabled="batchTableData.length == 0"
  9. @click="batchOperation('恢复')">批量恢复</el-button>
  10. <el-button type="primary" v-loading="allLoading.batchDeteleLoading" :disabled="batchTableData.length == 0"
  11. @click="batchOperation('删除')">批量删除</el-button>
  12. <el-button @click="cancel()">取消</el-button>
  13. </div>
  14. </div>
  15. </template>
  16. <div class="h-[60vh] flex flex-col">
  17. <div class="flex-1 w-full overflow-hidden">
  18. <el-table ref="busiessTableRef" :data="deteleBusinessTable" border v-loading="allLoading.tableLoading"
  19. @selection-change="changeBatch" style="width: 100%;height: 100%;">
  20. <el-table-column type="selection" width="55" />
  21. <el-table-column v-for="(item, index) in tableColumn" :prop="item.prop" :label="item.label" :key="index"
  22. :width="item.width">
  23. <template #default="scope">
  24. <span>{{ scope.row[item.prop] }}</span>
  25. </template>
  26. </el-table-column>
  27. <el-table-column label="操作" fixed="right" width="120">
  28. <template #default="scope">
  29. <el-button link type="primary" size="large"
  30. @click="businessOperationItem(scope.row.id, scope.row.name, '恢复')">恢复</el-button>
  31. <el-button link type="danger" size="large"
  32. @click="businessOperationItem(scope.row.id, scope.row.name, '删除')">删除</el-button>
  33. </template>
  34. </el-table-column>
  35. </el-table>
  36. </div>
  37. <div class="flex justify-end pt-3">
  38. <el-pagination layout="total, prev, pager, next, sizes" :page-size="tableForm.pageFrom"
  39. @size-change="handleSizeChange" @current-change="handleCurrentChange" :total="businessTotalTable"
  40. :hide-on-single-page="true" />
  41. </div>
  42. </div>
  43. </el-dialog>
  44. </template>
  45. <script lang="ts" setup>
  46. import { post } from '@/utils/request';
  47. import { ref, reactive, onMounted, watchEffect, watch, inject } from 'vue'
  48. import { BUSIESS_DETELELIST, BUSIESS_PERDETELE, BUSIESS_ROWBACK, tableColumn } from '../api';
  49. import { ElTable } from 'element-plus';
  50. import { confirmAction } from '@/utils/tools';
  51. import { formatDate } from '@/utils/times';
  52. type operationType = '恢复' | '删除'
  53. const emits = defineEmits(['closeVisible']);
  54. const globalPopup = inject<GlobalPopup>('globalPopup')
  55. const deteleBusinessTable = ref([])
  56. const deteleBusinessDialogVisible = ref(false)
  57. const businessTotalTable = ref(0)
  58. const batchTableData = ref([])
  59. const allLoading = reactive({
  60. batchRecoveryLoading: false,
  61. batchDeteleLoading: false,
  62. tableLoading: false
  63. })
  64. const tableForm = reactive({
  65. pageIndex: 1,
  66. pageFrom: 10
  67. })
  68. const busiessTableRef = ref<InstanceType<typeof ElTable>>() // 线索table dom
  69. const props = defineProps<{
  70. visibles: boolean
  71. }>()
  72. watch(() => props.visibles, (newVal) => {
  73. deteleBusinessDialogVisible.value = newVal
  74. if (newVal) {
  75. getTableList()
  76. }
  77. })
  78. function batchOperation(type: operationType) {
  79. const value = batchTableData.value.map((item: any) => item.id).join(',')
  80. const label = batchTableData.value.map((item: any) => item.name).join(',')
  81. businessOperationItem(value, label, type, true)
  82. }
  83. function businessOperationItem(value: string | number, label: string, type: operationType, batch: boolean = false) {
  84. confirmAction(`确定${batch ? '批量' : ''}${type}【${label}】商机吗?`).then(() => {
  85. let url = type == '恢复' ? BUSIESS_ROWBACK : BUSIESS_PERDETELE
  86. post(url, { ids: value }).then(res => {
  87. if (res.code != 'ok') {
  88. globalPopup?.showError(res.msg)
  89. return
  90. }
  91. globalPopup?.showSuccess(`${type}成功`)
  92. getTableList()
  93. changeBatch(false)
  94. }).catch((err) => {
  95. globalPopup?.showError(err.msg)
  96. })
  97. })
  98. }
  99. function changeBatch(flag: boolean = true) {
  100. if (flag) {
  101. batchTableData.value = busiessTableRef.value && busiessTableRef.value.getSelectionRows()
  102. } else {
  103. batchTableData.value = []
  104. busiessTableRef.value && busiessTableRef.value.clearSelection()
  105. }
  106. }
  107. function getTableList() {
  108. allLoading.tableLoading = true
  109. post(BUSIESS_DETELELIST, { ...tableForm }).then((res) => {
  110. if (res.code == 'ok') {
  111. const { data, total } = res.data
  112. deteleBusinessTable.value = data.map((item: any) => {
  113. return {
  114. ...item,
  115. expectedTransactionDate: formatDate(new Date(item.expectedTransactionDate))
  116. }
  117. })
  118. businessTotalTable.value = total
  119. }
  120. }).finally(() => {
  121. allLoading.tableLoading = false
  122. })
  123. }
  124. function handleSizeChange(val: number) {
  125. tableForm.pageIndex = 1
  126. tableForm.pageFrom = val
  127. getTableList()
  128. }
  129. function handleCurrentChange(val: number) {
  130. tableForm.pageIndex = val
  131. getTableList()
  132. }
  133. function cancel() {
  134. emits('closeVisible', 'deteleBusinessVisible')
  135. }
  136. function beForeCancel(done: () => void) {
  137. emits('closeVisible', 'deteleBusinessVisible')
  138. done()
  139. }
  140. onMounted(() => {
  141. })
  142. </script>
  143. <style lang="scss" scoped></style>