Просмотр исходного кода

客户信息表新增导入重复数据下载

cgp 2 недель назад
Родитель
Сommit
13852deb4a
2 измененных файлов с 82 добавлено и 2 удалено
  1. 2 1
      package.json
  2. 80 1
      src/views/qw/companyCustomer/index.vue

+ 2 - 1
package.json

@@ -118,7 +118,8 @@
     "vue2-ace-editor": "0.0.15",
     "vue2-ace-editor": "0.0.15",
     "vuedraggable": "^2.20.0",
     "vuedraggable": "^2.20.0",
     "vuex": "3.1.0",
     "vuex": "3.1.0",
-    "wangeditor": "^4.6.13"
+    "wangeditor": "^4.6.13",
+    "xlsx": "^0.18.5"
   },
   },
   "devDependencies": {
   "devDependencies": {
     "@vue/cli-plugin-babel": "4.4.4",
     "@vue/cli-plugin-babel": "4.4.4",

+ 80 - 1
src/views/qw/companyCustomer/index.vue

@@ -1631,6 +1631,7 @@
 </template>
 </template>
 
 
 <script>
 <script>
+import * as XLSX from 'xlsx';
 import {
 import {
   listCustomer,
   listCustomer,
   getCustomer,
   getCustomer,
@@ -2173,6 +2174,23 @@ export default {
               }
               }
               // 刷新列表
               // 刷新列表
               this.getList();
               this.getList();
+              // ===== 新增:检查是否有重复数据 =====
+              if (result.duplicateList && result.duplicateList.length > 0) {
+                this.$confirm(
+                  `检测到 ${result.duplicateList.length} 条重复客户数据(手机号已存在),是否下载重复客户数据列表?`,
+                  "重复数据提示",
+                  {
+                    confirmButtonText: "下载",
+                    cancelButtonText: "取消",
+                    type: "warning",
+                  }
+                ).then(() => {
+                  // 下载重复数据 Excel
+                  this.downloadDuplicateExcel(result.duplicateList);
+                }).catch(() => {
+                  // 用户取消下载
+                });
+              }
             } else {
             } else {
               this.$message.error(response.msg || "导入失败");
               this.$message.error(response.msg || "导入失败");
             }
             }
@@ -2189,7 +2207,69 @@ export default {
       // 触发文件选择
       // 触发文件选择
       input.click();
       input.click();
     },
     },
+    // 下载重复客户数据 Excel
+    downloadDuplicateExcel(duplicateList) {
+      if (typeof XLSX === 'undefined' || !XLSX.utils) {
+        this.$message.error('XLSX 库未加载,请检查依赖安装');
+        return;
+      }
+      try {
+        // 1. 校验数据
+        if (!Array.isArray(duplicateList) || duplicateList.length === 0) {
+          this.$message.warning('没有重复数据可下载');
+          return;
+        }
+
+        // 2. 构造数据(增加空值保护)
+        const data = duplicateList.map(item => ({
+          '收件人姓名': item.customerName || '',
+          '电话': item.phone || '',
+          '地址': item.address || '',
+          '购买次数': item.buyCount || 0
+        }));
+
+        // 3. 创建工作簿
+        const wsData = [
+          ['姓名', '电话', '地址', '购买次数'],
+          ...data.map(row => [row['姓名'], row['电话'], row['地址'], row['购买次数']])
+        ];
+
+        const wb = XLSX.utils.book_new();
+        const ws = XLSX.utils.aoa_to_sheet(wsData);
+        // 可选:设置列宽
+        ws['!cols'] = [
+          { wch: 15 },
+          { wch: 15 },
+          { wch: 30 },
+          { wch: 12 }
+        ];
+        XLSX.utils.book_append_sheet(wb, ws, '重复客户');
+
+        // 4. 生成 Excel 文件数据
+        const wbout = XLSX.write(wb, { bookType: 'xlsx', type: 'array' });
+        if (!wbout || wbout.length === 0) {
+          throw new Error('生成 Excel 数据为空');
+        }
 
 
+        // 5. 创建 Blob 并下载
+        const blob = new Blob([wbout], { type: 'application/octet-stream;charset=utf-8' });
+        const link = document.createElement('a');
+        link.href = URL.createObjectURL(blob);
+        const now = new Date();
+        const dateStr = `${now.getFullYear()}-${String(now.getMonth()+1).padStart(2,'0')}-${String(now.getDate()).padStart(2,'0')} ${String(now.getHours()).padStart(2,'0')}${String(now.getMinutes()).padStart(2,'0')}${String(now.getSeconds()).padStart(2,'0')}`;
+        link.download = `重复客户数据_${dateStr}.xlsx`;
+        document.body.appendChild(link);
+        link.click();
+        // 延迟移除链接并释放内存
+        setTimeout(() => {
+          document.body.removeChild(link);
+          URL.revokeObjectURL(link.href);
+        }, 100);
+      } catch (error) {
+        console.error('下载重复数据失败:', error);
+        this.$message.error('下载失败,请查看控制台错误信息');
+      }
+    },
     handlePrescribeData(row) {
     handlePrescribeData(row) {
       // 2. 弹出确认框
       // 2. 弹出确认框
       this.$confirm("是否确认开方?", "提示", {
       this.$confirm("是否确认开方?", "提示", {
@@ -3103,7 +3183,6 @@ export default {
           }
           }
 
 
           // ========== 第三步:调用快捷认领接口(传递完整表单数据) ==========
           // ========== 第三步:调用快捷认领接口(传递完整表单数据) ==========
-          // 注意:后端 quickClaimAndImprove 需要接收完整的 FsCompanyCustomer 对象
           await quickClaimAndImprove(this.form);
           await quickClaimAndImprove(this.form);
           this.$message.success('快捷认领并完善信息成功');
           this.$message.success('快捷认领并完善信息成功');
           this.open = false;
           this.open = false;