zuozhengqing
2023-10-18 0ec635d5e432be07c3103ac2e9bd25edb941f775
src/views/client/followupRecords/AddFollowupRecordsDialog.vue
@@ -25,11 +25,7 @@
              <el-col :span="12" v-if="isUnflod">
                <el-form-item label="跟进记录编号" prop="number">
                  <WordInput
                    v-if="
                      codenumer &&
                      (explain != '' || isIdDisabled) &&
                      method == 0
                    "
                    v-if="codenumer && (explain != '' || isIdDisabled) && method == 0"
                    :codenumer="codenumer"
                    :sum="sum"
                    :disabled="this.editConfig.title !== '新建' || isIdDisabled"
@@ -37,10 +33,7 @@
                    @codeList="codeList"
                  />
                  <span v-else-if="method == 0" style="color: #f56c6c"
                    >请优先配置编码规范
                    <el-button type="text" @click="numberClick">
                      配置规范
                    </el-button></span
                    >请优先配置编码规范 <el-button type="text" @click="numberClick"> 配置规范 </el-button></span
                  >
                  <span v-else>自动生成</span>
                </el-form-item>
@@ -52,24 +45,18 @@
                      v-model="editConfig.infomation.client_name"
                      :fetch-suggestions="
                        (queryString, callback) => {
                          querySearchAsync(queryString, callback, 'client');
                          querySearchAsync(queryString, callback, 'client')
                        }
                      "
                      value-key="name"
                      @select="handleSelectClient('client', $event)"
                      style="width: 100%"
                    ></el-autocomplete>
                    <div
                      class="common-select-btn"
                      @click="selClientClick('client')"
                    >
                    <div class="common-select-btn" @click="selClientClick('client')">
                      <i class="el-icon-circle-plus-outline" title="选择"></i>
                    </div>
                    <div
                      v-if="
                        editConfig.infomation.client_name &&
                        editConfig.infomation.client_name.length > 0
                      "
                      v-if="editConfig.infomation.client_name && editConfig.infomation.client_name.length > 0"
                      class="common-select-btn"
                      @click="clearupClient('client')"
                    >
@@ -88,12 +75,7 @@
                      size="mini"
                      style="width: 100%"
                    >
                      <el-option
                        v-for="item in clientStatusOptions"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id"
                      >
                      <el-option v-for="item in clientStatusOptions" :key="item.id" :label="item.name" :value="item.id">
                      </el-option>
                    </el-select>
                    <!-- <div class="common-select-btn"><i class="el-icon-setting"></i></div> -->
@@ -107,24 +89,18 @@
                      v-model="editConfig.infomation.contact_name"
                      :fetch-suggestions="
                        (queryString, callback) => {
                          querySearchAsync(queryString, callback, 'contact');
                          querySearchAsync(queryString, callback, 'contact')
                        }
                      "
                      value-key="name"
                      @select="handleSelectClient('contact', $event)"
                      style="width: 100%"
                    ></el-autocomplete>
                    <div
                      class="common-select-btn"
                      @click="selClientClick('contact')"
                    >
                    <div class="common-select-btn" @click="selClientClick('contact')">
                      <i class="el-icon-circle-plus-outline" title="选择"></i>
                    </div>
                    <div
                      v-if="
                        editConfig.infomation.contact_name &&
                        editConfig.infomation.contact_name.length > 0
                      "
                      v-if="editConfig.infomation.contact_name && editConfig.infomation.contact_name.length > 0"
                      class="common-select-btn"
                      @click="clearupClient('contact')"
                    >
@@ -141,12 +117,7 @@
                    size="mini"
                    style="width: 100%"
                  >
                    <el-option
                      v-for="item in memberOptions"
                      :key="item.id"
                      :label="item.username"
                      :value="item.id"
                    >
                    <el-option v-for="item in memberOptions" :key="item.id" :label="item.username" :value="item.id">
                    </el-option>
                  </el-select>
                </el-form-item>
@@ -170,12 +141,7 @@
                    size="mini"
                    style="width: 100%"
                  >
                    <el-option
                      v-for="item in contactInfoOptions"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id"
                    >
                    <el-option v-for="item in contactInfoOptions" :key="item.id" :label="item.name" :value="item.id">
                    </el-option>
                  </el-select>
                </el-form-item>
@@ -187,7 +153,7 @@
                      v-model="editConfig.infomation.sale_chance_name"
                      :fetch-suggestions="
                        (queryString, callback) => {
                          querySearchAsync(queryString, callback, 'chance');
                          querySearchAsync(queryString, callback, 'chance')
                        }
                      "
                      value-key="name"
@@ -196,11 +162,7 @@
                      placeholder="请先选择客户名称"
                      :disabled="isChance"
                    ></el-autocomplete>
                    <div
                      v-if="!isChance"
                      class="common-select-btn"
                      @click="selClientClick('chance')"
                    >
                    <div v-if="!isChance" class="common-select-btn" @click="selClientClick('chance')">
                      <i class="el-icon-circle-plus-outline"></i>
                    </div>
                    <div
@@ -225,24 +187,18 @@
                      v-model="editConfig.infomation.sales_leads_name"
                      :fetch-suggestions="
                        (queryString, callback) => {
                          querySearchAsync(queryString, callback, 'lead');
                          querySearchAsync(queryString, callback, 'lead')
                        }
                      "
                      value-key="name"
                      @select="handleSelectClient('lead', $event)"
                      style="width: 100%"
                    ></el-autocomplete>
                    <div
                      class="common-select-btn"
                      @click="selClientClick('lead')"
                    >
                    <div class="common-select-btn" @click="selClientClick('lead')">
                      <i class="el-icon-circle-plus-outline"></i>
                    </div>
                    <div
                      v-if="
                        editConfig.infomation.sales_leads_name &&
                        editConfig.infomation.sales_leads_name.length > 0
                      "
                      v-if="editConfig.infomation.sales_leads_name && editConfig.infomation.sales_leads_name.length > 0"
                      class="common-select-btn"
                      @click="clearupClient('lead')"
                    >
@@ -340,23 +296,15 @@
          </div> -->
        </div>
        <!-- 展开收起 -->
        <div
          v-if="editConfig.title === '新建'"
          class="unflod-collapse"
          @click="unflodCollapseClick"
        >
        <div v-if="editConfig.title === '新建'" class="unflod-collapse" @click="unflodCollapseClick">
          <div>{{ unflodCollapseStr }}</div>
          <div v-if="isUnflod"><i class="el-icon-arrow-up"></i></div>
          <div v-else><i class="el-icon-arrow-down"></i></div>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" size="small" @click="saveClick('form')"
          >保 存</el-button
        >
        <el-button size="small" @click="editConfig.visible = false"
          >取 消</el-button
        >
        <el-button type="primary" size="small" @click="saveClick('form')">保 存</el-button>
        <el-button size="small" @click="editConfig.visible = false">取 消</el-button>
      </div>
      <!-- 选择客户 -->
      <SelectClientDialog
@@ -387,22 +335,17 @@
</template>
<script>
import { getAllData } from "@/api/client/client";
import {
  getAddFollowRecord,
  getUpdateFollowRecord,
  getContactInfoList,
} from "@/api/client/followupRecords";
import SelectClientDialog from "@/views/other/commonDialog/SelectClientDialog";
import SelectContactDialog from "@/views/other/commonDialog/SelectContactDialog";
import SelectChanceDialog from "@/views/other/commonDialog/SelectChanceDialog";
import SelectLeadDialog from "@/views/other/commonDialog/SelectLeadDialog";
import codeMixin from "./mixin/codeMixin";
import { getAllData } from "@/api/client/client"
import { getAddFollowRecord, getUpdateFollowRecord, getContactInfoList } from "@/api/client/followupRecords"
import SelectClientDialog from "@/views/other/commonDialog/SelectClientDialog"
import SelectContactDialog from "@/views/other/commonDialog/SelectContactDialog"
import SelectChanceDialog from "@/views/other/commonDialog/SelectChanceDialog"
import SelectLeadDialog from "@/views/other/commonDialog/SelectLeadDialog"
import codeMixin from "./mixin/codeMixin"
import { getContactList } from "@/api/client/contacts"
import { mapActions } from "vuex";
import { getSaleChanceList } from "@/api/sales/salesOpportunity";
import { mapActions } from "vuex"
import { getSaleChanceList } from "@/api/sales/salesOpportunity"
import { getSalesLeadsList } from "@/api/client/salesLead"
export default {
  name: "AddFollowupRecordsDialog",
@@ -414,9 +357,9 @@
        return {
          visible: false,
          title: "新建",
          infomation: {},
        };
      },
          infomation: {}
        }
      }
    },
    isDetail: {
      type: Boolean,
@@ -427,62 +370,51 @@
    SelectClientDialog,
    SelectContactDialog,
    SelectChanceDialog,
    SelectLeadDialog,
    SelectLeadDialog
  },
  computed: {
    searchCommonHeight() {
      return this.$refs.searchCommonView.offsetHeight;
      return this.$refs.searchCommonView.offsetHeight
    },
    clientList() {
      return this.$store.state.getClientName.clientList;
    },
    contactNamelist() {
      return this.$store.state.getClientName.contactNamelist;
    },
      return this.$store.state.getClientName.clientList
    }
    // contactNamelist() {
    //   return this.$store.state.getClientName.contactNamelist
    // },
    // saleChancelist() {
    //   return this.$store.state.getClientName.saleChancelist
    // },
    saleLeadlist() {
      return this.$store.state.getClientName.saleLeadlist;
    },
    // saleLeadlist() {
    //   return this.$store.state.getClientName.saleLeadlist
    // }
  },
  data() {
    return {
      dialogWidth: "50%",
      editConfig: this.editContactsConfig,
      rules: {
        number: [
          { required: true, message: "请输入跟进记录编号", trigger: "blur" },
        ],
        member_id: [
          { required: true, message: "请选择负责人", trigger: "change" },
        ],
        record: [
          { required: true, message: "请输入跟进记录", trigger: "blur" },
        ],
        client_name: [
          { required: true, message: "请选择客户名称", trigger: "change" },
        ],
        contact_name: [
          { required: true, message: "请选择联系人姓名", trigger: "change" },
        ],
        number: [{ required: true, message: "请输入跟进记录编号", trigger: "blur" }],
        member_id: [{ required: true, message: "请选择负责人", trigger: "change" }],
        record: [{ required: true, message: "请输入跟进记录", trigger: "blur" }],
        client_name: [{ required: true, validator: this.checkClient, trigger: "change" }],
        contact_name: [{ required: true, message: "请选择联系人姓名", trigger: "change" }],
        topic: [{ required: true, message: "请输入主题", trigger: "blur" }],
        // content: [{ required: true, message: "请输入内容", trigger: "blur" }],
        phoneNumber: [
          { required: false, message: "", trigger: "blur" },
          { len: 11, message: "长度在11个字符", trigger: "blur" },
          {
            pattern:
              /^1(3\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\d|9[0-35-9])\d{8}$/,
            pattern: /^1(3\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\d|9[0-35-9])\d{8}$/,
            message: "请输入正确的手机号",
            trigger: "blur",
          },
        ],
            trigger: "blur"
          }
        ]
      },
      pickerOptions: {
        disabledDate: (time) => {
          return time.getTime() > Date.now();
        },
          return time.getTime() > Date.now()
        }
      },
      clientStatusOptions: [], // 客户状态
      contactInfoOptions: [], // 联系方式
@@ -492,124 +424,124 @@
      editSelectClientConfig: {
        editVisible: false,
        title: "",
        infomation: {},
        infomation: {}
      },
      editSelectContactConfig: {
        editVisible: false,
        title: "",
        infomation: {},
        search_map:{}
        search_map: {}
      },
      editSelectChanceConfig: {
        editVisible: false,
        title: "",
        infomation: {},
        search_map:{},
        search_map: {}
      },
      editSelectLeadConfig: {
        editVisible: false,
        title: "",
        infomation: {},
        search_map:{},
        search_map: {}
      },
      clientId: this.editContactsConfig.infomation.client_id,
      contactId: this.editContactsConfig.infomation.contact_id,
      saleChanceId: this.editContactsConfig.infomation.sale_chance_id,
      saleLeadId: this.editContactsConfig.infomation.sales_leads_id,
      saleChancelist: [],
      isChance: true,
    };
      isChance: true
    }
  },
  created() {
    this.$store.dispatch("geClient");
    this.$store.dispatch("geContact");
    this.$store.dispatch("geClient")
    // this.$store.dispatch("geContact")
    // this.$store.dispatch("geChance")
    this.$store.dispatch("geLead");
    this.getCommonData();
    this.getContactInfoList();
    this.formInfo();
    // this.$store.dispatch("geLead")
    this.getCommonData()
    this.getContactInfoList()
    this.formInfo()
  },
  watch: {
    "editContactsConfig.visible"(val) {
      if (val) {
        this.formInfo();
        this.formInfo()
      }
    },
    "editContactsConfig.infomation.codeStandID"() {
      this.formInfo();
    },
      this.formInfo()
    }
  },
  methods: {
    ...mapActions(["getContactFilter","getLeadFilter"]),
    ...mapActions(["getContactFilter", "getLeadFilter"]),
    formInfo() {
      this.objCode.type = "跟进记录编码";
      this.objCode.codeStandID = "";
      this.objCode.type = "跟进记录编码"
      this.objCode.codeStandID = ""
      if (this.editConfig.infomation.codeStandID) {
        this.objCode.codeStandID = this.editConfig.infomation.codeStandID;
        this.objCode.codeStandID = this.editConfig.infomation.codeStandID
      }
      this.getRCodeStandardList();
      this.getRCodeStandardList()
    },
    getCommonData() {
      getAllData().then((res) => {
        console.log(res);
        this.clientStatusOptions = res.data.client_status;
        this.memberOptions = res.data.member;
        this.dataProcess();
      });
        console.log(res)
        this.clientStatusOptions = res.data.client_status
        this.memberOptions = res.data.member
        // this.dataProcess()
      })
    },
    async getContactInfoList() {
      await getContactInfoList().then((res) => {
        if (res.code === 200) {
          this.contactInfoOptions = res.data.list;
          this.contactInfoOptions = res.data.list
        }
      });
      })
    },
    dataProcess() {
      this.saleChancelist.map((item) => {
        if (this.saleChanceId === item.id) {
          this.editConfig.infomation.sale_chance_name = item.name;
          this.editConfig.infomation.sale_chance_name = item.name
        }
      });
      })
      this.saleLeadlist.map((item) => {
        if (this.saleLeadId === item.id) {
          this.editConfig.infomation.sales_leads_name = item.name;
          this.editConfig.infomation.sales_leads_name = item.name
        }
      });
      })
    },
    handleClose() {
      this.editConfig.visible = false;
      this.editConfig.visible = false
    },
    // 保存
    saveClick(formName) {
      this.$refs[formName].validate((valid) => {
        this.validateFormNumber()
        if (valid) {
          const params = this.saveParams();
          const params = this.saveParams()
          if (this.editConfig.title === "新建") {
            getAddFollowRecord(params).then((res) => {
              this.editConfig.visible = false;
              this.editConfig.visible = false
              if (res.code === 200) {
                this.$message.success("添加成功");
                this.$parent.getData();
                this.$message.success("添加成功")
                this.$parent.getData()
              }
            });
            })
          } else {
            getUpdateFollowRecord(params).then((res) => {
              this.editConfig.visible = false;
              this.editConfig.visible = false
              if (res.code === 200) {
                this.$message.success("编辑成功");
                this.$parent.getData();
                this.$message.success("编辑成功")
                this.$parent.getData()
              }
            });
            })
          }
        } else {
          console.log("error submit");
          return false;
          console.log("error submit")
          return false
        }
      });
      })
    },
    saveParams() {
      let data = this.editConfig.infomation;
      let data = this.editConfig.infomation
      let follow_record = {
        follow_record: {
          client_id: this.clientId || 0,
@@ -627,16 +559,16 @@
          sales_leads_id: this.saleLeadId || 0,
          topic: data.topic || "",
          codeStandID: data.ID,
          codeRule: this.codeRule,
        },
      };
      let params = {};
      if (this.editConfig.title === "新建") {
        params = { ...follow_record };
      } else {
        params = { ...follow_record, id: data.id || 0 };
          codeRule: this.codeRule
        }
      }
      return params;
      let params = {}
      if (this.editConfig.title === "新建") {
        params = { ...follow_record }
      } else {
        params = { ...follow_record, id: data.id || 0 }
      }
      return params
    },
    // 获取销售机会
    getChanceList(id) {
@@ -644,124 +576,141 @@
        page: 1,
        pageSize: 15,
        search_map: {
          client_id: id,
        },
          client_id: id
        }
      }).then((res) => {
        if (res.code == 200) {
          this.saleChancelist = res.data.list;
          this.saleChancelist = res.data.list
        }
      });
      })
    },
    // 选择客户相关方法
    querySearchAsync(queryString, cb, value) {
      var restaurants = [];
      var restaurants = []
      if (value === "client") {
        restaurants = this.clientList;
        restaurants = this.clientList
      } else if (value === "contact") {
        restaurants = this.contactNamelist;
        restaurants = this.contactNamelist
      } else if (value === "chance") {
        restaurants = this.saleChancelist;
        restaurants = this.saleChancelist
      } else {
        restaurants = this.saleLeadlist;
        restaurants = this.saleLeadlist
      }
      var results = queryString
        ? restaurants.filter(this.createStateFilter(queryString))
        : restaurants;
      cb(results);
      var results = queryString ? restaurants.filter(this.createStateFilter(queryString)) : restaurants
      cb(results)
    },
    createStateFilter(queryString) {
      return (state) => {
        return (
          state.name.toLowerCase().indexOf(queryString.toLowerCase()) === 0
        );
      };
        return state.name.toLowerCase().indexOf(queryString.toLowerCase()) === 0
      }
    },
    async handleSelectClient(value, item) {
      if (value === "client") {
        console.log(item,"item")
        this.editSelectContactConfig.search_map.client_id=item.id
        this.editSelectChanceConfig.search_map.client_id=item.id
        this.editSelectLeadConfig.search_map.name=item.name
        await getContactList({
        search_map:{
          client_id:item.id
    // 联系人列表
    async getContactList(item) {
      await getContactList({
        search_map: {
          client_id: item.id
        },
        page: 1,
        pageSize: 15
        }).then((res) => {
          if (res.code === 200) {
            this.getContactFilter(res.data.list);
          }
        });
        await getSalesLeadsList({
          search_map:{
            name:item.name
          },
        }).then((res) => {
          if (res.code === 200) {
            this.getLeadFilter(res.data.list);
          }
        });
        this.clientId = item.id;
        this.editConfig.infomation.client_name = item.name;
        this.isChance = false;
        this.getChanceList(item.id);
      }).then((res) => {
        if (res.code === 200) {
          this.contactNamelist = res.data.list
        }
      })
    },
    // 销售线索
    async getSalesLeadsList(item) {
      await getSalesLeadsList({
        search_map: {
          name: item.name
        }
      }).then((res) => {
        if (res.code === 200) {
          this.saleLeadlist = res.data.list
        }
      })
    },
    async handleSelectClient(value, item) {
      if (value === "client") {
        this.editConfig.infomation.contact_name = ""
        this.editConfig.infomation.sales_leads_name=""
        this.editConfig.infomation.sale_chance_name=""
        this.editSelectContactConfig.search_map.client_id = item.id
        this.editSelectChanceConfig.search_map.client_id = item.id
        this.editSelectLeadConfig.search_map.name = item.name
        this.getContactList(item)
        this.getSalesLeadsList(item)
        this.clientId = item.id
        this.editConfig.infomation.client_name = item.name
        this.isChance = false
        this.getChanceList(item.id)
      } else if (value === "contact") {
        this.contactId = item.id;
        this.editConfig.infomation.contact_name = item.name;
        this.contactId = item.id
        this.editConfig.infomation.contact_name = item.name
      } else if (value === "chance") {
        this.saleChanceId = item.id;
        this.editConfig.infomation.sale_chance_name = item.name;
        this.saleChanceId = item.id
        this.editConfig.infomation.sale_chance_name = item.name
      } else {
        this.saleLeadId = item.id;
        this.editConfig.infomation.sales_leads_name = item.name;
        this.saleLeadId = item.id
        this.editConfig.infomation.sales_leads_name = item.name
      }
    },
    selClientClick(value) {
      if (value === "client") {
        this.editSelectClientConfig.editVisible = true;
        this.editSelectClientConfig.editVisible = true
      } else if (value === "contact") {
        this.editSelectContactConfig.editVisible = true;
        this.editSelectContactConfig.editVisible = true
      } else if (value === "chance") {
        this.editSelectChanceConfig.editVisible = true;
        this.editSelectChanceConfig.editVisible = true
      } else {
        this.editSelectLeadConfig.editVisible = true;
        this.editSelectLeadConfig.editVisible = true
      }
    },
    selClient(row, value) {
      if (value === "contact") {
        this.editConfig.infomation.contact_name = row.name;
        this.contactId = row.id;
        this.editConfig.infomation.contact_name = row.name
        this.contactId = row.id
      } else if (value === "client") {
        this.editConfig.infomation.client_name = row.name;
        this.clientId = row.id;
        this.isChance = false;
        this.getChanceList(row.id);
        this.editConfig.infomation.contact_name = ""
        this.editConfig.infomation.sales_leads_name=""
        this.editConfig.infomation.sale_chance_name=""
        this.editSelectContactConfig.search_map.client_id = row.id
        this.editSelectChanceConfig.search_map.client_id = row.id
        this.editSelectLeadConfig.search_map.name = row.name
        this.getContactList(row)
        this.getSalesLeadsList(row)
        this.clientId = row.id
        this.editConfig.infomation.client_name = row.name
        this.isChance = false
        this.getChanceList(row.id)
      } else if (value === "chance") {
        this.editConfig.infomation.sale_chance_name = row.name;
        this.saleChanceId = row.id;
        this.editConfig.infomation.sale_chance_name = row.name
        this.saleChanceId = row.id
      } else {
        this.editConfig.infomation.sales_leads_name = row.name;
        this.saleLeadId = row.id;
        this.editConfig.infomation.sales_leads_name = row.name
        this.saleLeadId = row.id
      }
    },
    // 清除已选择用户
    clearupClient(value) {
      if (value === "client") {
        this.editConfig.infomation.client_name = "";
        this.clientId = 0;
        this.isChance = true;
        this.editConfig.infomation.sale_chance_name = "";
        this.saleChanceId = 0;
        this.editConfig.infomation.contact_name = ""
        this.editConfig.infomation.sales_leads_name=""
        this.editConfig.infomation.sale_chance_name=""
        this.editConfig.infomation.client_name = ""
        this.clientId = 0
        this.isChance = true
        this.editConfig.infomation.sale_chance_name = ""
        this.saleChanceId = 0
      } else if (value === "contact") {
        this.editConfig.infomation.contact_name = "";
        this.contactId = 0;
        this.editConfig.infomation.contact_name = ""
        this.contactId = 0
      } else if (value === "chance") {
        this.editConfig.infomation.sale_chance_name = "";
        this.saleChanceId = 0;
        this.editConfig.infomation.sale_chance_name = ""
        this.saleChanceId = 0
      } else {
        this.editConfig.infomation.sales_leads_name = "";
        this.saleLeadId = 0;
        this.editConfig.infomation.sales_leads_name = ""
        this.saleLeadId = 0
      }
    },
    // 添加附件
@@ -771,15 +720,23 @@
    // 展开收起
    unflodCollapseClick() {
      if (this.unflodCollapseStr === "收起") {
        this.unflodCollapseStr = "展开更多栏目";
        this.isUnflod = false;
        this.unflodCollapseStr = "展开更多栏目"
        this.isUnflod = false
      } else {
        this.unflodCollapseStr = "收起";
        this.isUnflod = true;
        this.unflodCollapseStr = "收起"
        this.isUnflod = true
      }
    },
  },
};
    // 客户名称单独校验
    checkClient(rule, value, callback) {
      if (this.editConfig.infomation.client_name && this.editConfig.infomation.client_name.length > 0) {
        callback()
      } else {
        callback(new Error("请选择客户名称"))
      }
    }
  }
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->