src/views/basicData/customerFile/index.vue
@@ -1,6 +1,6 @@
<template>
  <div class="app-container">
    <div class="search_form">
    <div class="search_form" style="margin-bottom: 20px;">
      <div>
        <span class="search_title">客户名称:</span>
        <el-input v-model="searchForm.customerName"
@@ -15,10 +15,14 @@
                   style="width: 240px"
                   clearable
                   @change="handleQuery">
          <el-option label="零售客户"
                     value="零售客户" />
          <el-option label="进销商客户"
                     value="进销商客户" />
          <el-option label="核心"
                     value="核心" />
          <el-option label="重要"
                     value="重要" />
          <el-option label="普通"
                     value="普通" />
          <el-option label="一般"
                     value="一般" />
        </el-select>
        <el-button type="primary"
                   @click="handleQuery"
@@ -27,7 +31,11 @@
      <div>
        <el-button type="primary"
                   @click="openForm('add')">新增客户</el-button>
        <el-button type="primary"
                   plain
                   @click="back">流入公海</el-button>
        <el-button @click="handleOut">导出</el-button>
            <el-button type="primary" @click="handleOutFollowUpList">导出跟进记录</el-button>
        <el-button type="info"
                   plain
                   icon="Upload"
@@ -125,10 +133,14 @@
              <el-select v-model="form.customerType"
                         placeholder="请选择"
                         clearable>
                <el-option label="零售客户"
                           value="零售客户" />
                <el-option label="进销商客户"
                           value="进销商客户" />
                <el-option label="核心"
                           value="核心" />
                <el-option label="重要"
                           value="重要" />
                <el-option label="普通"
                           value="普通" />
                <el-option label="一般"
                           value="一般" />
              </el-select>
            </el-form-item>
          </el-col>
@@ -211,7 +223,8 @@
                 :limit="1"
                 accept=".xlsx, .xls"
                 :headers="upload.headers"
                 :action="upload.url + '?updateSupport=' + upload.updateSupport"
                 :action="upload.url"
                 :data="upload.data"
                 :disabled="upload.isUploading"
                 :before-upload="upload.beforeUpload"
                 :on-progress="upload.onProgress"
@@ -605,6 +618,39 @@
        </div>
      </template>
    </el-dialog>
    <!-- 交接对话框 -->
    <el-dialog v-model="handoverDialogVisible"
               title="客户交接"
               width="400px"
               @close="closeHandoverDialog">
      <el-form :model="handoverForm"
               :rules="handoverRules"
               ref="handoverFormRef"
               label-width="100px">
        <el-form-item label="当前维护人">
          <span>{{ handoverForm.oldMaintainer }}</span>
        </el-form-item>
        <el-form-item label="新维护人"
                      prop="maintainer">
          <el-select v-model="handoverForm.maintainerId"
                     placeholder="请选择新维护人"
                     style="width: 100%"
                     filterable
                     @change="handleHandoverUserChange">
            <el-option v-for="item in userList"
                       :key="item.userId || item.nickName"
                       :label="item.nickName"
                       :value="item.userId" />
          </el-select>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitHandoverForm">确认</el-button>
          <el-button @click="closeHandoverDialog">取消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>
@@ -612,19 +658,13 @@
  import { onMounted, ref, reactive, getCurrentInstance, toRefs } from "vue";
  import { Search, Paperclip, Upload } from "@element-plus/icons-vue";
  import {
    addCustomerPrivate,
    delCustomerPrivate,
    getCustomer,
    getCustomerPrivatePoolById,
    getCustomerPrivatePoolInfo,
    listCustomerPrivatePool,
    updateCustomerPrivatePool,
    addCustomerFollow,
    updateCustomerFollow,
    delCustomerFollow,
    addReturnVisit,
    getReturnVisit,
  } from "@/api/basicData/customerFile.js";
  import {listCustomer, getCustomer, addCustomer, updateCustomer, delCustomer, backCustomer, handoverCustomer} from "@/api/basicData/customer.js";
  import { ElMessageBox } from "element-plus";
  import { userListNoPage } from "@/api/system/user.js";
  import useUserStore from "@/store/modules/user";
@@ -656,7 +696,7 @@
  const negotiationFormRef = ref();
  const negotiationForm = reactive({
    customerName: "",
      customerPrivatePoolId: "",
      customerId: "",
    followUpMethod: "",
    followUpLevel: "",
    followUpTime: "",
@@ -714,11 +754,23 @@
    {
      label: "客户分类",
      prop: "customerType",
         fixed: "left",
      dataType: "tag",
      width: 120,
      formatType: value => {
        switch (value) {
          case "核心": return "danger";
          case "重要": return "warning";
          case "普通": return "primary";
          case "一般": return "info";
          default: return "info";
        }
      },
    },
    {
      label: "客户名称",
      prop: "customerName",
         fixed: "left",
      width: 220,
    },
    {
@@ -797,13 +849,20 @@
      label: "操作",
      align: "center",
      fixed: "right",
      width: 290,
      width: 340,
      operation: [
        {
          name: "编辑",
          type: "text",
          clickFun: row => {
            openForm("edit", row);
          },
        },
        {
          name: "交接",
          type: "text",
          clickFun: row => {
            openHandoverDialog(row);
          },
        },
            {
@@ -844,6 +903,19 @@
  // 用户信息表单弹框数据
  const operationType = ref("");
  const dialogFormVisible = ref(false);
  // 交接对话框
  const handoverDialogVisible = ref(false);
  const handoverFormRef = ref();
  const handoverForm = reactive({
    id: undefined,
    oldMaintainer: "",
    maintainer: "",
    maintainerId: undefined,
  });
  const handoverRules = {
    maintainer: [{ required: true, message: "请选择新维护人", trigger: "change" }],
  };
  const formYYs = ref({
    // 其他字段...
    contactList: [
@@ -857,6 +929,7 @@
    searchForm: {
      customerName: "",
      customerType: "",
      type: 0
    },
    form: {
      customerName: "",
@@ -871,6 +944,7 @@
      bankAccount: "",
      bankCode: "",
      customerType: "",
      type: 0
    },
    rules: {
      customerName: [{ required: true, message: "请输入", trigger: "blur" }],
@@ -901,7 +975,10 @@
    // 设置上传的请求头部
    headers: { Authorization: "Bearer " + getToken() },
    // 上传的地址
    url: import.meta.env.VITE_APP_BASE_API + "/customerPrivate/importData",
    url: import.meta.env.VITE_APP_BASE_API + "/basic/customer/importData",
    data: {
      type: 0
    },
    // 文件上传前的回调
    beforeUpload: file => {
      console.log("文件即将上传", file);
@@ -972,7 +1049,7 @@
  };
  const getList = () => {
    tableLoading.value = true;
    listCustomerPrivatePool({ ...searchForm.value, ...page }).then(res => {
    listCustomer({ ...searchForm.value, ...page }).then(res => {
      tableLoading.value = false;
      tableData.value = res.data.records;
      page.total = res.data.total;
@@ -994,7 +1071,7 @@
  }
  /** 下载模板 */
  function importTemplate() {
    proxy.download("/customerPrivate/downloadTemplate", {}, "客户导入模板.xlsx");
    proxy.download("/basic/customer/downloadTemplate", {}, "客户导入模板.xlsx");
  }
  // 打开弹框
  const openForm = (type, row) => {
@@ -1007,12 +1084,13 @@
        contactPhone: "",
      },
    ];
    form.value.type = 0;
    form.value.maintenanceTime = getCurrentDate();
    userListNoPage().then(res => {
      userList.value = res.data;
    });
    if (type === "edit") {
      getCustomerPrivatePoolById(row.id).then(res => {
      getCustomer(row.id).then(res => {
        form.value = { ...res.data };
        formYYs.value.contactList = res.data.contactPerson
          .split(",")
@@ -1049,7 +1127,7 @@
    form.value.contactPhone = formYYs.value.contactList
      .map(item => item.contactPhone)
      .join(",");
    addCustomerPrivate(form.value).then(res => {
    addCustomer(form.value).then(res => {
      proxy.$modal.msgSuccess("提交成功");
      closeDia();
      getList();
@@ -1063,7 +1141,7 @@
    form.value.contactPhone = formYYs.value.contactList
      .map(item => item.contactPhone)
      .join(",");
    updateCustomerPrivatePool(form.value).then(res => {
    updateCustomer(form.value).then(res => {
      proxy.$modal.msgSuccess("提交成功");
      closeDia();
      getList();
@@ -1074,6 +1152,44 @@
    proxy.resetForm("formRef");
    dialogFormVisible.value = false;
  };
  // 交接
  const handleHandoverUserChange = userId => {
    const user = userList.value.find(item => (item.userId || item.nickName) === userId);
    handoverForm.maintainer = user ? user.nickName : "";
  };
  const openHandoverDialog = row => {
    handoverForm.id = row.id;
    handoverForm.oldMaintainer = row.maintainer;
    handoverForm.maintainer = "";
    handoverForm.maintainerId = undefined;
    userListNoPage().then(res => {
      userList.value = res.data;
      handoverDialogVisible.value = true;
    });
  };
  const closeHandoverDialog = () => {
    proxy.resetForm("handoverFormRef");
    handoverForm.id = undefined;
    handoverForm.oldMaintainer = "";
    handoverForm.maintainer = "";
    handoverForm.maintainerId = undefined;
    handoverDialogVisible.value = false;
  };
  const submitHandoverForm = () => {
    proxy.$refs.handoverFormRef.validate(valid => {
      if (valid) {
        handoverCustomer({
          id: handoverForm.id,
          maintainer: handoverForm.maintainer,
          maintainerId: handoverForm.maintainerId,
        }).then(() => {
          proxy.$modal.msgSuccess("交接成功");
          closeHandoverDialog();
          getList();
        });
      }
    });
  };
  // 导出
  const handleOut = () => {
    ElMessageBox.confirm("选中的内容将被导出,是否确认导出?", "导出", {
@@ -1082,12 +1198,26 @@
      type: "warning",
    })
      .then(() => {
        proxy.download("/customerPrivate/export", {}, "客户档案.xlsx");
        proxy.download("/basic/customer/export", {type: 0}, "客户档案.xlsx");
      })
      .catch(() => {
        proxy.$modal.msg("已取消");
      });
  };
   // 导出跟进记录
   const handleOutFollowUpList = () => {
      ElMessageBox.confirm("选中的内容将被导出,是否确认导出?", "导出", {
         confirmButtonText: "确认",
         cancelButtonText: "取消",
         type: "warning",
      })
         .then(() => {
            proxy.download("basic/customer-follow/export", {}, "客户跟进记录.xlsx");
         })
         .catch(() => {
            proxy.$modal.msg("已取消");
         });
   };
  // 删除
  const handleDelete = () => {
    let ids = [];
@@ -1111,7 +1241,7 @@
    })
      .then(() => {
        tableLoading.value = true;
        delCustomerPrivate(ids)
        delCustomer(ids)
          .then(() => {
            proxy.$modal.msgSuccess("删除成功");
            getList();
@@ -1122,6 +1252,36 @@
      })
      .catch(() => {
        proxy.$modal.msg("已取消");
      });
  };
  const back = () => {
    if (selectedRows.value.length === 0) {
      proxy.$modal.msgWarning("请选择数据");
      return;
    }
    const ids = selectedRows.value.map(item => item.id);
    ElMessageBox.confirm("选中的客户将流入公海,是否确认?", "流入公海提示", {
      confirmButtonText: "确认",
      cancelButtonText: "取消",
      type: "warning",
    })
      .then(() => {
        tableLoading.value = true;
        return Promise.all(ids.map(id => backCustomer(id)))
          .then(() => {
            proxy.$modal.msgSuccess("流入公海成功");
            selectedRows.value = [];
            getList();
          })
          .finally(() => {
            tableLoading.value = false;
          });
      })
      .catch(error => {
        if (error === "cancel" || error === "close") {
          proxy.$modal.msg("已取消");
        }
      });
  };
@@ -1165,8 +1325,7 @@
        if (reminderForm.id) {
          submitvalue.value = {
            id: reminderForm.id,
                  customerPrivatePoolId: reminderForm.id,
                  customerPrivatePoolId: currentCustomerId.value,
                  customerId: currentCustomerId.value,
            isEnabled: reminderForm.reminderSwitch ? 1 : 0,
            content: reminderForm.reminderContent,
            reminderTime: reminderForm.reminderTime,
@@ -1174,7 +1333,7 @@
          };
        } else {
          submitvalue.value = {
                  customerPrivatePoolId: currentCustomerId.value,
            customerId: currentCustomerId.value,
            isEnabled: reminderForm.reminderSwitch ? 1 : 0,
            content: reminderForm.reminderContent,
            reminderTime: reminderForm.reminderTime,
@@ -1203,7 +1362,7 @@
  // 打开洽谈进度弹窗
  const openNegotiationDialog = row => {
    negotiationForm.customerName = row.customerName;
    negotiationForm.customerPrivatePoolId = row.id;
    negotiationForm.customerId = row.id;
    negotiationForm.followUpMethod = "";
    negotiationForm.followUpLevel = "";
    negotiationForm.followUpTime = "";
@@ -1232,7 +1391,7 @@
          // 修改操作
          updateCustomerFollow(negotiationForm).then(res => {
            // 更新本地数据
            getCustomer(negotiationForm.customerPrivatePoolId).then(res => {
            getCustomer(negotiationForm.customerId).then(res => {
              // 更新本地数据
              negotiationRecords.value = res.data.followUpList || [];
            });
@@ -1264,7 +1423,7 @@
  // 打开详情弹窗
  const openDetailDialog = row => {
    getCustomerPrivatePoolInfo(row.id).then(res => {
    getCustomer(row.id).then(res => {
      // 填充客户基本信息
      Object.assign(detailForm, res.data);
@@ -1285,7 +1444,7 @@
    // 将当前记录数据填充到表单
    Object.assign(negotiationForm, {
      customerName: row.customerName,
         customerPrivatePoolId: row.customerPrivatePoolId,
         customerId: row.customerId,
      followUpMethod: row.followUpMethod,
      followUpLevel: row.followUpLevel,
      followUpTime: row.followUpTime,
@@ -1313,7 +1472,7 @@
        // });
        delCustomerFollow(row.id).then(() => {
          // 删除成功后更新本地数据
          getCustomer(row.customerPrivatePoolId).then(res => {
          getCustomer(row.customerId).then(res => {
            // 更新本地数据
            negotiationRecords.value = res.data.followUpList || [];
          });
@@ -1413,7 +1572,7 @@
  const downloadAttachment = row => {
    if (row.url) {
      // proxy.download(row.url, {}, row.name);
      proxy.$download.name(row.url);
         proxy.$download.byUrl(row.url, row.originalFilename);
    } else {
      proxy.$modal.msgError("下载链接不存在");
    }