deteleTables.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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"
  9. :disabled="batchTableData.length == 0" @click="batchOperation('恢复')">批量恢复</el-button>
  10. <el-button type="primary" v-loading="allLoading.batchDeteleLoading"
  11. :disabled="batchTableData.length == 0" @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 tableColumns" :prop="item.prop" :label="item.label"
  22. :key="index" :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.orderName, '恢复')">恢复</el-button>
  31. <el-button link type="danger" size="large"
  32. @click="businessOperationItem(scope.row.id, scope.row.orderName, '删除')">删除</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.pageSize"
  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 { GETTABLELIST, paymentStatus, tableColumns, URL_BATCHDELETE, URL_RECOVER } 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. pageSize: 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.orderName).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 == '恢复' ? URL_RECOVER : URL_BATCHDELETE
  86. // let url = ''
  87. post(url, { ids: value }).then(res => {
  88. if (res.code != 'ok') {
  89. globalPopup?.showError(res.msg)
  90. return
  91. }
  92. globalPopup?.showSuccess(`${type}成功`)
  93. getTableList()
  94. changeBatch(false)
  95. }).catch((err) => {
  96. globalPopup?.showError(err.msg)
  97. })
  98. })
  99. }
  100. function changeBatch(flag: boolean = true) {
  101. if (flag) {
  102. batchTableData.value = busiessTableRef.value && busiessTableRef.value.getSelectionRows()
  103. } else {
  104. batchTableData.value = []
  105. busiessTableRef.value && busiessTableRef.value.clearSelection()
  106. }
  107. }
  108. function getTableList() {
  109. allLoading.tableLoading = true
  110. post(GETTABLELIST, { ...tableForm, isDelete: 1 }).then((res) => {
  111. if (res.code == 'ok') {
  112. const { record, total } = res.data
  113. deteleBusinessTable.value = (record || []).map((item: any) => {
  114. let val = paymentStatus.find((items: any) => items.value == item.status)
  115. return {
  116. ...item,
  117. statusValue: val ? val.label : ''
  118. }
  119. })
  120. businessTotalTable.value = total
  121. }
  122. }).finally(() => {
  123. allLoading.tableLoading = false
  124. })
  125. }
  126. function handleSizeChange(val: number) {
  127. tableForm.pageIndex = 1
  128. tableForm.pageSize = val
  129. getTableList()
  130. }
  131. function handleCurrentChange(val: number) {
  132. tableForm.pageIndex = val
  133. getTableList()
  134. }
  135. function cancel() {
  136. emits('closeVisible', 'deteleOrderVisible')
  137. }
  138. function beForeCancel(done: () => void) {
  139. emits('closeVisible', 'deteleOrderVisible')
  140. done()
  141. }
  142. onMounted(() => {
  143. })
  144. </script>
  145. <style lang="scss" scoped></style>