deteleTables.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <el-dialog v-model="deteleClueDialogVisible" width="1000" :before-close="beForeCancel" :show-close="false" top="10vh">
  3. <template #header="{ close, titleId, titleClass }">
  4. <div class="flex justify-between items-center border-b pb-3 dialog-header">
  5. <h4 :id="titleId">产品回收站</h4>
  6. <div>
  7. <el-button type="primary" @click="batchRestore()"
  8. v-loading="allLoading.batchRecoveryLoading">批量恢复</el-button>
  9. <el-button type="primary" @click="batchDeletes()"
  10. v-loading="allLoading.batchDeteleLoading">批量删除</el-button>
  11. <el-button @click="cancel()">取消</el-button>
  12. </div>
  13. </div>
  14. </template>
  15. <div class="h-[60vh] flex flex-col">
  16. <div class="flex-1 w-full overflow-hidden">
  17. <el-table ref="clueTableRef" :data="deteleClueTable" border v-loading="allLoading.tableLoading"
  18. style="width: 100%;height: 100%;">
  19. <el-table-column type="selection" width="55" />
  20. <el-table-column prop="productCode" label="产品编号" width="180"></el-table-column>
  21. <el-table-column prop="productName" label="产品名称" width="180"></el-table-column>
  22. <el-table-column prop="typeName" label="产品类别" width="180"></el-table-column>
  23. <el-table-column prop="unitName" label="单位" width="180"></el-table-column>
  24. <el-table-column prop="price" label="标准价格(元)" width="180"></el-table-column>
  25. <el-table-column prop="inventory" label="库存" width="180"></el-table-column>
  26. <el-table-column prop="status" label="状态" width="180"></el-table-column>
  27. <el-table-column prop="inchargerName" label="负责人" width="190">
  28. <template #default="scope">
  29. <TextTranslation translationTypes="userName" :translationValue="scope.row.inchargerName"></TextTranslation>
  30. </template>
  31. </el-table-column>
  32. <el-table-column prop="creatorName" label="创建人" width="180">
  33. <template #default="scope">
  34. <TextTranslation translationTypes="userName" :translationValue="scope.row.creatorName"></TextTranslation>
  35. </template>
  36. </el-table-column>
  37. <el-table-column prop="createTime" label="创建时间" width="180"></el-table-column>
  38. <el-table-column label="操作" fixed="right" width="120">
  39. <template #default="scope">
  40. <el-button link type="primary" size="large" @click="restoreItemRow([scope.row])">恢复</el-button>
  41. <el-button link type="danger" size="large" @click="deteItemRow([scope.row])">删除</el-button>
  42. </template>
  43. </el-table-column>
  44. </el-table>
  45. </div>
  46. <div class="flex justify-end pt-3">
  47. <el-pagination layout="total, prev, pager, next, sizes" :page-size="tableForm.pageSize"
  48. @size-change="handleSizeChange" @current-change="handleCurrentChange" :total="clueTotalTable"
  49. :hide-on-single-page="true" />
  50. </div>
  51. </div>
  52. </el-dialog>
  53. </template>
  54. <script lang="ts" setup>
  55. import { post } from '@/utils/request';
  56. import { ref, reactive, onMounted, watchEffect, watch, inject } from 'vue'
  57. import { DETERDETELE, RECYCLELIST, ROLLBACK } from './api';
  58. import { ElTable } from 'element-plus';
  59. import { confirmAction } from '@/utils/tools';
  60. const emits = defineEmits(['showDeteleProduct']);
  61. const globalPopup = inject<GlobalPopup>('globalPopup')
  62. const deteleClueTable = ref([])
  63. const deteleClueDialogVisible = ref(false)
  64. const clueTotalTable = ref(0)
  65. const allLoading = reactive({
  66. batchRecoveryLoading: false,
  67. batchDeteleLoading: false,
  68. tableLoading: false
  69. })
  70. const tableForm = reactive({
  71. pageIndex: 1,
  72. pageSize: 10
  73. })
  74. const clueTableRef = ref<InstanceType<typeof ElTable>>() // 产品table dom
  75. const props = defineProps<{
  76. visibles: boolean
  77. }>()
  78. watch(() => props.visibles, (newVal) => {
  79. deteleClueDialogVisible.value = newVal
  80. if (newVal) {
  81. getTableList()
  82. }
  83. })
  84. function batchRestore() {
  85. const data = clueTableRef.value && clueTableRef.value.getSelectionRows()
  86. if (!data.length) {
  87. globalPopup?.showWarning('请选择需要恢复的数据')
  88. return
  89. }
  90. restoreItemRow(data)
  91. }
  92. function batchDeletes() {
  93. const data = clueTableRef.value && clueTableRef.value.getSelectionRows()
  94. if (!data.length) {
  95. globalPopup?.showWarning('请选择需要删除的数据')
  96. return
  97. }
  98. deteItemRow(data)
  99. }
  100. function deteItemRow(items: any[]) {
  101. const ids = items.map((item: any) => item.id).join(',')
  102. const str = items.map((item: any) => item.productName).join(',')
  103. confirmAction(`确定${items.length > 1 ? '批量删除这些' : '删除'}【${str}】产品吗?`, '', 'warning').then(() => {
  104. post(DETERDETELE, { ids }).then(res => {
  105. if (res.code != 'ok') {
  106. globalPopup?.showError(res.msg)
  107. return
  108. }
  109. globalPopup?.showSuccess('删除成功')
  110. getTableList()
  111. })
  112. })
  113. }
  114. function restoreItemRow(items: any[]) {
  115. const ids = items.map((item: any) => item.id).join(',')
  116. const str = items.map((item: any) => item.productName).join(',')
  117. confirmAction(`确定${items.length > 1 ? '批量恢复这些' : '恢复'}【${str}】产品吗?`, '', 'warning').then(() => {
  118. post(ROLLBACK, { ids }).then(res => {
  119. if (res.code != 'ok') {
  120. globalPopup?.showError(res.msg)
  121. return
  122. }
  123. globalPopup?.showSuccess('恢复成功')
  124. getTableList()
  125. })
  126. })
  127. }
  128. function getTableList() {
  129. allLoading.tableLoading = true
  130. post(RECYCLELIST, { ...tableForm }).then((res) => {
  131. if (res.code == 'ok') {
  132. const { record, total } = res.data
  133. deteleClueTable.value = record
  134. clueTotalTable.value = total
  135. }
  136. }).finally(() => {
  137. allLoading.tableLoading = false
  138. })
  139. }
  140. function handleSizeChange(val: number) {
  141. tableForm.pageIndex = 1
  142. tableForm.pageSize = val
  143. getTableList()
  144. }
  145. function handleCurrentChange(val: number) {
  146. tableForm.pageIndex = val
  147. getTableList()
  148. }
  149. function cancel() {
  150. emits('showDeteleProduct', false)
  151. }
  152. function beForeCancel(done: () => void) {
  153. emits('showDeteleProduct', false)
  154. done()
  155. }
  156. onMounted(() => {
  157. })
  158. </script>
  159. <style lang="scss" scoped></style>