<template>
  <div class="bgcolor clewent" v-if="infoData">
    <!--        顶部条-->
    <div class="navBarTOP">
      <van-nav-bar class="navBar" left-arrow :title="title" @click-left="onClickLeft" />
    </div>
    <!--        主体内容-->
    <div class="lineGrey"></div>
    <div class="lineGrey"></div>
    <div class="lineGrey"></div>
    <div class="lineGrey"></div>
    <div class="lineGrey"></div>
    <clewentDetails v-if="infoData" :infoData="infoData">
      <!-- <van-button
        type="info"
        v-if="infoData.customerClueStatus == 0"
        style="
          float: right;
          background: #0057ba;
          border-color: #0057ba;
          color: #fff;
          margin-top: -36px;
          border-radius: 5px;
        "
        size="small"
        plain
        class="centerBtn"
        @click="onstopVisit"
        >转交其他组织</van-button
      > -->
    </clewentDetails>
    <p style="margin: 0 16px 8px; color: #888" v-if="infoData.userCustomerClueList">
      该客资历史跟进记录
    </p>
    <van-cell-group inset class="cardclewContentCell">
      <div style="border-radius: 6px; overflow: hidden">
        <van-cell
          is-link
          v-for="(item, index) in infoData.userCustomerClueList"
          :key="index"
          @click="viewFn(item.userCustomerClueId)">
          <template #title>
            <span class="custom-title">{{ item.nickName }}</span>
          </template>
          <div class="cardContent">
            <p class="textLeft" style="padding-bottom: 0px; margin: 0">{{ item.createTime }}</p>
          </div>
        </van-cell>
      </div>
    </van-cell-group>
    <!-- 批量采购 -->
    <template v-if="infoData && infoData.isClose != 1 && infoData.isClose != 2">
      <div class="taskGather" v-if="taskGather">
        <radioGroup :clueOptionList="taskGather"></radioGroup>
      </div>
    </template>
    <br />
    <div
      v-if="infoData && infoData.isClose != 1 && infoData.isClose != 2"
      class="tc"
      style="padding: 0 16px">
      <van-button class="submitBtn" block type="info" color="#0057ba" @click="onSubmit">
        提交
      </van-button>
    </div>
    <br />
    <br />
    <br />
    <br />
    <br />
    <van-dialog v-model="show" title="转发客资" show-cancel-button :before-close="confirm">
      <p>
        <van-notice-bar wrapable :scrollable="false" text="一旦转交出去，则无法再查看，请确认！" />
      </p>
      <van-row class="serchInput">
        <van-col span="24">
          <van-cell
            class="monthNow selectcell"
            :title="companyName"
            is-link
            arrow-direction="down"
            @click="regionClick" />
        </van-col>
        <van-col span="24">
          <van-cell
            class="monthNow selectcell"
            :title="regionName"
            is-link
            @click="SalesRegionClick"
            arrow-direction="down" />
        </van-col>
        <van-col span="24">
          <van-cell
            class="monthNow selectcell"
            :title="deptName"
            is-link
            @click="SalesDepartmentClick"
            arrow-direction="down" />
        </van-col>
      </van-row>
    </van-dialog>
    <van-dialog
      v-model="showView"
      title="客资历史"
      show-cancel-button
      cancel-button-text="关闭"
      :show-confirm-button="confirmBtn"
      class="dialogz">
      <br />
      <div
        class="container linep containertext"
        style="
          background-color: #fff;
          width: 94%;
          margin: 0px auto;
          border-radius: 6px;
          font-size: 14px;
        ">
        <van-form ref="tabstoreVal">
          <div v-for="(item, index) in customItemList" :key="index">
            <div
              class="formLabel z-cell z-cells z-celly"
              v-if="item.answerType == 'sz' || item.answerType == 'rq'">
              <van-cell>
                <template #title
                  >{{ index + 1 }}.{{ item.customerClueName }}
                  <span
                    style="
                      color: #444;
                      font-size: 12px;
                      margin: 0;
                      padding: 10px 0;
                      text-align: right;
                    "
                    >{{ item.remark }}</span
                  ></template
                >
              </van-cell>
              <p class="mg0" style="word-break: break-all">{{ item.answerValue }}</p>
            </div>
            <div class="formLabel z-cell z-cells z-celly" v-if="item.answerType == 'zp'">
              <van-cell>
                <template #title>{{ index + 1 }}.{{ item.customerClueName }}</template>
              </van-cell>
              <delete-upload-imgv :imgs="item.fileInfoList"></delete-upload-imgv>
            </div>
            <div
              class="formLabel z-cell z-cells z-celly"
              v-if="item.answerType == 'wb' && viewTextShow">
              <van-cell>
                <template #title>{{ index + 1 }}.{{ item.customerClueName }}</template>
              </van-cell>
              <div class="selesetText">
                <p class="mg0" style="word-break: break-all">{{ item.answerValue }}</p>
              </div>
              <p
                style="color: #444; font-size: 12px; margin: 0; padding: 10px 0; text-align: right">
                {{ item.remark }}
              </p>
              <delete-upload-imgv :imgs="item.fileInfoList"></delete-upload-imgv>
            </div>

            <div class="formLabel z-cell z-cells z-celly" v-if="item.answerType == 'duox'">
              <van-cell>
                <template #title>{{ index + 1 }}.{{ item.customerClueName }}</template>
              </van-cell>
              <div class="selesetText">
                <div
                  class="mg0"
                  v-for="(item1, index1) in item.customerClueOptionList"
                  :key="index1">
                  <p style="color: #0057ba" v-if="item1.checked">
                    <i
                      style="
                        border: 1px solid #0057ba;
                        margin-right: 10px;
                        border-radius: 2px;
                        padding: 2px;
                      "
                      class="van-icon van-icon-success"></i>
                    <span>{{ item1.customerClueOption }}</span>
                  </p>
                  <p v-if="!item1.checked">
                    <i
                      style="
                        border: 1px solid #ccc;
                        margin-right: 10px;
                        border-radius: 2px;
                        color: #fff;
                        padding: 2px;
                      "
                      class="van-icon van-icon-success"></i>
                    <span>{{ item1.customerClueOption }}</span>
                  </p>
                </div>
              </div>
            </div>
            <div class="formLabel z-cell z-cells z-celly" v-if="item.answerType == 'dx'">
              <van-cell>
                <template #title> {{ index + 1 }}.{{ item.customerClueName }} </template>
              </van-cell>
              <div class="selesetText">
                <div
                  class="mg0"
                  v-for="(item2, index2) in item.customerClueOptionList"
                  :key="index2">
                  <p style="color: #0057ba" v-if="item2.checked">
                    <i
                      style="
                        border: 1px solid #0057ba;
                        border-radius: 40px;
                        margin-right: 10px;
                        padding: 2px;
                      "
                      class="van-icon van-icon-success"></i>
                    <span>{{ item2.customerClueOption }}</span>
                  </p>
                  <p v-if="!item2.checked">
                    <i
                      style="
                        border: 1px solid #ccc;
                        border-radius: 40px;
                        margin-right: 10px;
                        color: #fff;
                        padding: 2px;
                      "
                      class="van-icon van-icon-success"></i>
                    <span>{{ item2.customerClueOption }}</span>
                  </p>
                </div>
              </div>
              <delete-upload-imgv :imgs="item.fileInfoList"></delete-upload-imgv>
            </div>
            <div class="formLabel z-cell z-cells z-celly" v-if="item.answerType == 'bg'">
              <van-cell>
                <template #title> {{ index + 1 }}.{{ item.customerClueName }} </template>
              </van-cell>
              <div class="selesetText">
                <el-table
                  :data="JSON.parse(item.answerValue).data"
                  style="width: 100%; position: relative; left: -10px">
                  <el-table-column
                    v-for="(item, index) in JSON.parse(item.answerValue).title"
                    :key="index"
                    :prop="item.prop"
                    :label="item.label"
                    align="center">
                    <template slot-scope="scope">
                      <template v-if="item.answerType == 'text'">
                        {{ scope.row[item.prop] }}
                      </template>
                      <template v-if="item.answerType == 'wb'">
                        <span>{{ scope.row[item.prop] }}</span>
                      </template>
                      <template v-if="item.answerType == 'sz'">
                        <span>{{ scope.row[item.prop] }}</span>
                      </template>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
            </div>
          </div>
        </van-form>
      </div>
    </van-dialog>
    <van-calendar
      v-model="showCalendar"
      @confirm="onConfirm"
      color="#0057ba"
      :min-date="minDate"
      :max-date="maxDate"
      :show-confirm="false" />
    <van-popup v-model="RegionShow" capture position="bottom">
      <van-picker
        :columns="companyList"
        show-toolbar
        value-key="deptName"
        @cancel="RegionShow = false"
        @confirm="onregionConfirm" />
    </van-popup>
    <van-popup v-model="SalesRegionShow" capture position="bottom">
      <van-picker
        :columns="regionList"
        show-toolbar
        value-key="deptName"
        @cancel="SalesRegionShow = false"
        @confirm="onSalesRegionConfirm" />
    </van-popup>
    <van-popup v-model="SalesDepartmentShow" capture position="bottom">
      <van-picker
        :columns="deptList"
        show-toolbar
        value-key="deptName"
        @cancel="SalesDepartmentShow = false"
        @confirm="onSalesDepartmentConfirm" />
    </van-popup>
    <van-popup v-model="StaffShow" capture position="bottom">
      <van-picker
        :columns="userList"
        show-toolbar
        value-key="nickName"
        @cancel="StaffShow = false"
        @confirm="onStaffConfirm" />
    </van-popup>
    <van-popup v-model="StartTimeShow" capture position="bottom">
      <van-datetime-picker
        v-model="strtcurrentDate"
        :max-date="strtmaxDate"
        :min-date="strtminDate"
        title="选择查找开始时间"
        type="date"
        @cancel="StartTimeShow = false"
        @confirm="onStartTimeConfirm" />
    </van-popup>
    <van-popup v-model="EndTimeShow" capture position="bottom">
      <van-datetime-picker
        v-model="endcurrentDate"
        :max-date="endmaxDate"
        :min-date="endminDate"
        title="选择查找结束时间"
        type="date"
        @cancel="EndTimeShow = false"
        @confirm="onEndTimeConfirm" />
    </van-popup>
  </div>
</template>

<script>
import timeico from '@/assets/Icon/datatims.png';
import zRadio from '@/components/zRadiokz';
import zCheckbox from '@/components/zCheckbox1';
import uploadImg from '@/components/uploadKTask';
import deleteUploadImg from '@/components/deleteUploadImg2';
import deleteUploadImgv from '@/components/deleteUploadImg';
import {
  getCustomerClueInfoById,
  insertCustomerClueAnswer,
  getDeptInfo,
  updateCustomerClueDept,
  getCustomerClueAnswerById,
} from '@/api/clew';
import { ImagePreview } from 'vant';
import clewentDetails from './clewentDetails';
import radioGroup from './complaintDetail/radioGroup';
import { clewMixins } from '@/mixin/clew.js';
import store from '@/store';
export default {
  name: 'MyHistoricalWeekly',
  mixins: [clewMixins],
  components: {
    zRadio,
    zCheckbox,
    uploadImg,
    deleteUploadImg,
    deleteUploadImgv,
    clewentDetails,
    radioGroup,
  },
  data() {
    return {
      timeico: timeico,
      show: false,
      RegionShow: false,
      SalesRegionShow: false,
      SalesDepartmentShow: false,
      StaffShow: false,
      StartTimeShow: false,
      confirmBtn: false,
      dateIndex: '',
      EndTimeShow: false,
      uploadid2: 'uploadid2',
      strtminDate: new Date(2022, 0, 1),
      endminDate: new Date(2022, 0, 1),
      minDate: new Date(2020, 0, 1),
      maxDate: new Date(2090, 0, 31),
      strtmaxDate: new Date(),
      endmaxDate: new Date(),
      strtcurrentDate: new Date(),
      endcurrentDate: new Date(),
      companyName: '',
      deptName: '',
      regionName: '',
      showView: false,
      viewTextShow: false,
      companyCode: '',
      deptCode: '',
      regionCode: '',
      userCode: '',
      companyList: [],
      title: '',
      deptList: [],
      regionList: [],
      userList: [],
      deptForm: { type: '', parentId: '' },
      list: [],
      loading: false,
      finished: true,
      showCalendar: false,
      formData: {
        type: '2', // 汇报类型或入口 1-下属业务员日报 2-下属销售部主管周报 3-下属大区主管半月报
        companyId: '', // 公司id，必传 Long类型
        regionId: '', // 大区id，必传  Long类型
        deptId: '', // 部门id，如果为周报或日报为必传  Long类型
        userId: '', // 业务员id，如果为日报为必传      Long类型
        startTime: '', // 开始时间，必传  格式：yyyy-MM-dd  String类型
        endTime: '', // 结束时间，必传  格式：yyyy-MM-dd  String类型
        pageNum: 1, // 当前页码  int类型
        pageSize: 10, // 当前每页条数  int类型
      },
      tableList: [],
      collectionItemList: [],
      collectionAnswerlisd: [],
      flagclick: true,
      infoData: null,
      imgList: [],
      info: {},
      showv: false,
      isClose: '',
      customItemList: [],
      followUpResult: '',
      SBshow: false,
      requ: false,
      showvnum: false,
      tipSHow: false,
      namesss: '',
      tipText: '',
      totalMoneyFlag: '', //是否显示出货总金额
      taskGather: null, //跟进任务集合
    };
  },
  activated() {
    this.getCustomerClueInfoById();
  },
  created() {
    this.formData.startTime = this.getThreeDaysAgo();
    this.strtcurrentDate = new Date(this.getThreeDaysAgo());
    this.formData.endTime = this.parseTime(new Date(), '{y}-{m}-{d}') + '';
    this.endminDate = new Date(this.GetPreMonthDay(this.parseTime(new Date(), '{y}-{m}-{d}'), 2));
    this.powerGrade = localStorage.getItem('powerGrade');
    this.id = this.$route.query.id;
    this.getDeptInfo();
    // this.getCustomerClueInfoById();
  },
  watch: {
    $route(to, from) {
      if (to.path == '/clewent') {
        this.isClose = '';
        this.showv = false;
        this.SBshow = false;
        this.tipSHow = false;
        this.followUpResult = '';
        // this.getCustomerClueInfoById();
      }
    },
  },

  methods: {
    pviewFn(val, imgVal) {
      var imgList = [];
      var photos = this.reportTarget.photos[val].photos;
      for (let i = 0; i < photos.length; i++) {
        imgList.push(photos[i].fileUrl);
      }
      ImagePreview({ images: imgList, startPosition: imgVal });
    },
    viewFn(val) {
      this.viewTextShow = false;
      this.showView = true;
      this.getDetailById(val);
    },
    getDetailById(val) {
      let loading1 = this.$toast.loading({
        duration: 0,
        message: '加载中...',
        forbidClick: true,
      });
      getCustomerClueAnswerById({ userCustomerClueId: val }).then((res) => {
        loading1.clear();
        this.reportTargetAll = res.data.reportTargetAll;
        this.info = res.data;

        this.customItemList = res.data.customerClue.customerClueItemList;
        this.type = res.data.userType;
        // if(res.data.status==3){
        //   this.successContent=res.data.successContent
        // }else{
        //   this.successContent=res.data.failContent
        // }
        for (var pl = 0; pl < this.customItemList[1].customerClueOptionList.length; pl++) {
          if (
            this.customItemList[1].customerClueOptionList[pl].customerClueOption.indexOf(
              '跟进中',
            ) != -1
          ) {
            if (this.customItemList[1].customerClueOptionList[pl].value == 'Y') {
              this.viewTextShow = true;
              if (
                this.customItemList[1].customerClueOptionList[pl].customerClueOption.indexOf(
                  '跟进',
                ) != -1
              ) {
                this.customItemList[2].customerClueName =
                  '具体合作意向反馈(拜访时间、合同方向、预估合作时间)';
              }
            }
          } else {
            if (this.customItemList[1].customerClueOptionList[pl].value == 'Y') {
              this.viewTextShow = true;
              if (
                this.customItemList[1].customerClueOptionList[pl].customerClueOption.indexOf(
                  '意向',
                ) != -1
              ) {
                this.customItemList[2].customerClueName = '没有意向原因';
                this.customItemList[2].remark = '请输入';
              }
              if (
                this.customItemList[1].customerClueOptionList[pl].customerClueOption.indexOf(
                  '开户',
                ) != -1
              ) {
                this.customItemList[2].customerClueName = '开户经销商代码(例:0110067321)';
                this.customItemList[2].remark = '请输入';
              }
              if (
                this.customItemList[1].customerClueOptionList[pl].customerClueOption.indexOf(
                  '开店',
                ) != -1
              ) {
                this.customItemList[2].customerClueName = '开户门店代码(例:0190129032)';
                this.customItemList[2].remark = '请输入';
              }
              if (
                this.customItemList[1].customerClueOptionList[pl].customerClueOption.indexOf(
                  '出货',
                ) != -1
              ) {
                this.customItemList[2].customerClueName = '填写具体的产品和数量';
              }
            }
          }
        }
        this.reportContents = res.data.reportContents;
        var imgList = [];
        if (res.data.photos != null) {
          for (var k = 0; k < res.data.photos.length; k++) {
            imgList.push(res.data.photos[k].fileUrl + '');
          }
        }
        this.imgList = imgList;
      });
    },
    confirm(action, done) {
      if (action === 'confirm') {
        if (this.deptCode != '') {
          updateCustomerClueDept({
            customerClueInfoId: this.$route.query.id,
            deptId: this.deptCode,
          }).then((require) => {
            if (require.code == 200) {
              this.$toast.success('转发成功');
              this.show = false;
              if (this.$route.query.token != undefined) {
                window.location.replace(window.location.origin + this.locationOrigin + '/clew');
              } else {
                store.dispatch('setRefreshClewPage', true);
                // 返回上一页不会刷新页面
                this.$router.go(-1);
              }
              return done(true);
            } else {
              this.$toast(res.msg);
            }
          });
        } else {
          this.$toast('请选择要转发销售部');
          return done(false);
        }
      } else {
        return done(true);
        this.show = false;
      }
    },
    onstopVisit() {
      this.deptCode = '';
      this.regionList = [];
      this.deptList = [];
      this.companyName = '请选择公司';
      this.companyCode = '';
      this.regionName = '请选择大区';
      this.regionCode = '';
      this.deptName = '请选择销售部';
      this.deptCode = '';
      this.show = true;
    },
    getCustomerClueInfoById() {
      this.id = this.$route.query.id;
      this.collectionAnswerlisd = [];
      this.collectionItemList = [];
      getCustomerClueInfoById({ customerClueInfoId: this.id }).then((response) => {
        if (response.code == 200) {
          this.infoData = response.data;
          this.title = response.data.name;
          if (response.data.customerClue != null) {
            this.collectionItemList = response.data.customerClue.customerClueItemList;
            this.taskGather = response.data.customerClue.customerClueItemList;
          } else {
            this.collectionItemList = [];
          }
        } else {
          this.$toast(res.msg);
        }
      });
    },
    showCalendarClick(val) {
      this.dateIndex = val;
      this.showCalendar = true;
    },
    formatDate(date) {
      var Month = date.getMonth() + 1;
      var Day = date.getDate();
      if (Month < 10) {
        Month = '0' + Month;
      }
      if (Day < 10) {
        Day = '0' + Day;
      }
      return `${date.getFullYear()}-${Month}-${Day}`;
    },
    onConfirm(date) {
      this.showCalendar = false;
      this.collectionItemList[this.dateIndex].answerValue = this.formatDate(date);
    },
    formatter(value) {
      return value.replace(
        /[\uD83C|\uD83D|\uD83E][\uDC00-\uDFFF][\u200D|\uFE0F]|[\uD83C|\uD83D|\uD83E][\uDC00-\uDFFF]|[0-9|*|#]\uFE0F\u20E3|[0-9|#]\u20E3|[\u203C-\u3299]\uFE0F\u200D|[\u203C-\u3299]\uFE0F|[\u2122-\u2B55]|\u303D|[\A9|\AE]\u3030|\uA9|\uAE|\u3030/gi,
        '',
      );
    },
    numberFn(val, index) {
      if (!/^[+-]?\d*\.{0,1}\d{0,1}$/.test(this.collectionItemList[index].answerValue)) {
        this.collectionItemList[index].answerValue = this.collectionItemList[
          index
        ].answerValue.replace(
          /\.\d{2,}$/,
          this.collectionItemList[index].answerValue.substr(
            this.collectionItemList[index].answerValue.indexOf('.'),
            3,
          ),
        );
      }
    },
    zSelectVal(value) {
      this.tipText = '';
      if (value.Tindex == 1) {
        this.totalMoneyFlag = false;
        if (value.customerClueOption == '已出货') {
          // 判断是否显示出货总金额
          let isFlag = this.collectionItemList.find(
            (item) => item.customerClueName == '出货总金额' && item.answerType == 'sz',
          );
          if (isFlag) {
            this.totalMoneyFlag = true;
          }
        }
        this.tipSHow = false;
        this.collectionItemList[2].answerValue = '';
        for (var iv = 0; iv < value.value.length; iv++) {
          if (value.value[iv].customerClueOption.indexOf('跟进中') != -1) {
            if (value.value[iv].value == 'Y') {
              this.showv = true;
              this.requ = false;
              this.showvnum = false;
              if (value.value[iv].customerClueOption.indexOf('跟进中') != -1) {
                this.collectionItemList[2].customerClueName =
                  '具体合作意向反馈(拜访时间、合同方向、预估合作时间)';
                this.collectionItemList[2].remark = '请输入';
              }
            } else {
              this.requ = true;
              this.showv = true;
            }
          } else {
            if (value.value[iv].value == 'Y') {
              if (value.value[iv].customerClueOption.indexOf('意向') != -1) {
                this.collectionItemList[2].customerClueName = '没有意向原因';
                this.collectionItemList[2].remark = '请输入意想原因';
                this.showvnum = false;
              }
              if (value.value[iv].customerClueOption.indexOf('开户') != -1) {
                this.collectionItemList[2].customerClueName = '开户经销商代码(例:0110067321)';
                this.collectionItemList[2].remark = '例:0110067321';
                this.tipText =
                  '若该客户正在开户流程中，请勾选为“跟进中”，待流程走完，再将客资状态更新为“已开户”，并填写开户经销商代码。';
                this.showvnum = true;
                this.tipSHow = true;
                this.showv = false;
              }
              if (value.value[iv].customerClueOption.indexOf('开店') != -1) {
                this.collectionItemList[2].customerClueName = '开户门店代码(例:0190129032)';
                this.tipText =
                  '若该客户正在开店流程中，请勾选为“跟进中”，待流程走完，再将客资状态更新为“已开店”，并填写开店编码。';
                this.collectionItemList[2].remark = '例:0190129032';
                this.showvnum = true;
                this.tipSHow = true;
                this.showv = false;
              }
              if (value.value[iv].customerClueOption.indexOf('出货') != -1) {
                this.showvnum = false;
                this.collectionItemList[2].customerClueName = '填写具体的产品和数量';
                this.collectionItemList[2].remark = '例：100桶时时丽，50包超好贴';
              }
            }
          }
        }
      } else {
        if (value.value[1].value == 'Y') {
          this.SBshow = false;
        } else {
          this.SBshow = true;
        }
      }
      var collectionAnswerlisd = this.collectionAnswerlisd;
      if (collectionAnswerlisd.length > 0) {
        var num = 0;
        for (var a = 0; a < collectionAnswerlisd.length; a++) {
          if (collectionAnswerlisd[a].id == value.id) {
            collectionAnswerlisd[a] = value;
            num = 0;
          } else {
            num = 1;
          }
        }
        if (num > 0) {
          collectionAnswerlisd.push(value);
        }
      } else {
        collectionAnswerlisd.push(value);
      }
      this.collectionAnswerlisd = collectionAnswerlisd;
    },
    imgClick(val, index) {
      this.collectionId = val.collectionId + '';
      this.indeximg = index;
      this.show = true;
    },
    newimgarr1(val) {
      if (
        this.collectionItemList[val.index].fileInfoList == null ||
        this.collectionItemList[val.index].fileInfoList == undefined
      ) {
        this.collectionItemList[val.index].fileInfoList = [];
        this.collectionItemList[val.index].fileIdList = [];
      }
      this.collectionItemList[val.index].fileInfoList.push(val);
      this.collectionItemList[val.index].fileIdList.push(val.id);
    },
    dateFn(val) {
      return val.slice(0, 4) + '-' + val.slice(4, 6) + '-' + val.slice(6, 8);
    },
    onLoad() {},
    onSubmit() {
      // Mixins
      this.purchaseSubmit((data) => {
        var form = {
          isClose: this.infoData.isClose,
          followUpResult: this.infoData.followUpResult,
          customerClueItemList: data.customerClueItemList,
        };
        this.toastLoading(0, '加载中...', true);
        insertCustomerClueAnswer(form).then((res) => {
          this.toastLoading().clear();
          if (res.code == 200) {
            if (this.$route.query.token != undefined) {
              window.location.replace(window.location.origin + this.locationOrigin + '/clew');
            } else {
              store.dispatch('setRefreshClewPage', true);
              // 返回上一页不会刷新页面
              this.$router.go(-1);
            }
          } else {
            this.$toast(res.msg);
          }
        });
      });
    },
    getThreeDaysAgo() {
      let myDate = new Date();
      let lw = new Date(myDate - 1000 * 60 * 60 * 24 * 14); //最后一个数字30可改，30天的意思
      let lastY = lw.getFullYear();
      let lastM = lw.getMonth() + 1;
      let lastD = lw.getDate();
      let startData =
        lastY + '-' + (lastM < 10 ? '0' + lastM : lastM) + '-' + (lastD < 10 ? '0' + lastD : lastD); //三十天之前日期
      return startData;
    },
    GetPreMonthDay(date, monthNum, type) {
      var dateArr = date.split('-');
      var year = dateArr[0]; //获取当前日期的年份
      var month = dateArr[1]; //获取当前日期的月份
      var day = dateArr[2]; //获取当前日期的日
      var days = new Date(year, month, 0);
      days = days.getDate(); //获取当前日期中月的天数
      var year2 = year;
      var month2 = parseInt(month) - monthNum;
      if (month2 <= 0) {
        var absM = Math.abs(month2);
        year2 = parseInt(year2) - Math.ceil(absM / 12 == 0 ? 1 : parseInt(absM) / 12);
        month2 = 12 - (absM % 12);
      }
      var day2 = day;
      var days2 = new Date(year2, month2, 0);
      days2 = days2.getDate();
      if (day2 > days2) {
        day2 = days2;
      }
      if (month2 < 10) {
        month2 = '0' + month2;
      }
      var t2 = '';
      if (monthNum > 0) {
        t2 = year2 + '-' + month2 + '-01';
      } else {
        if (type == 'end') {
          var Months = new Date().getMonth() + 1;
          var days111 = new Date().getDate();
          if (Months < 10) {
            Months = '0' + Months;
          }
          if (days111 < 10) {
            days111 = '0' + days111;
          }
          if (parseInt(month2) >= new Date().getMonth() + 1) {
            t2 = year2 + '-' + Months + '-' + days111;
          } else {
            var daysd = this.getMonthDays(year2, month2);
            t2 = year2 + '-' + month2 + '-' + daysd;
          }
        } else {
          t2 = year2 + '-' + month2 + '-' + day2;
        }
      }
      return t2;
    },
    getMonthDays(year, month) {
      var stratDate = new Date(year, month - 1, 1),
        endData = new Date(year, month, 1);
      var days = (endData - stratDate) / (1000 * 60 * 60 * 24);
      return days;
    },
    getDeptInfo(type, grade) {
      this.deptForm.type = type;
      if (grade == '1') {
        this.deptForm.parentId = this.companyCode;
      } else if (grade == '2') {
        this.deptForm.parentId = this.regionCode;
      } else {
        this.deptForm.type = '';
        this.deptForm.parentId = '';
      }
      getDeptInfo(this.deptForm).then((res) => {
        res.data.forEach((item) => {
          delete item.children;
        });
        if (grade == '1') {
          this.regionList = res.data;
        } else if (grade == '2') {
          this.deptList = res.data;
        } else {
          this.companyList = res.data;
        }
      });
    },
    onClickLeft() {
      this.$router.go(-1);
    },
    regionClick() {
      this.RegionShow = true;
    },
    SalesRegionClick(val) {
      this.SalesRegionShow = true;
    },
    SalesDepartmentClick() {
      this.SalesDepartmentShow = true;
    },
    StaffClick() {
      this.StaffShow = true;
    },
    StartTimeClick() {
      this.StartTimeShow = true;
    },
    EndTimeClick() {
      this.EndTimeShow = true;
    },
    onregionConfirm(val) {
      this.RegionShow = false;
      this.companyName = val.deptName;
      this.companyCode = val.deptId;
      this.regionName = '请选择大区';
      this.regionCode = '';
      this.deptName = '请选择销售部';
      this.deptCode = '';
      this.getDeptInfo('dept', 1);
    },
    onSalesRegionConfirm(val) {
      this.SalesRegionShow = false;
      this.regionName = val.deptName;
      this.regionCode = val.deptId;
      if (val.deptId != '') {
        this.getDeptInfo('dept', 2);
      }
      this.deptName = '全部销售部';
      this.deptCode = '';
    },
    onSalesDepartmentConfirm(val) {
      this.SalesDepartmentShow = false;
      this.deptName = val.deptName;
      if (val.deptId != '') {
        this.deptCode = val.deptId;
        this.getDeptInfo('user');
      }
      this.userName = '全部业务员';
      this.userCode = '';
    },
    onStaffConfirm(val) {
      this.StaffShow = false;
      this.userName = val.nickName;
      this.userCode = val.userId;
    },
    onStartTimeConfirm(val) {
      this.formData.startTime = this.parseTime(new Date(val), '{y}-{m}-{d}') + '';
      this.StartTimeShow = false;
      this.endminDate = new Date(val);
      this.endmaxDate = new Date(this.GetPreMonthDay(this.formData.startTime, -2, 'end'));
      if (
        new Date(this.formData.startTime).getTime() > new Date(this.formData.endTime).getTime() ||
        new Date(this.endmaxDate).getTime() < new Date(this.formData.endTime).getTime()
      ) {
        this.formData.endTime = this.parseTime(new Date(val), '{y}-{m}-{d}') + '';
        this.endcurrentDate = this.GetPreMonthDay(this.formData.startTime, -2);
      }
      this.list = [];
      this.formData.pageNum = 1;
    },
    onEndTimeConfirm(val) {
      this.formData.endTime = this.parseTime(new Date(val), '{y}-{m}-{d}');
      this.strtmaxDate = new Date(val);
      if (new Date(this.formData.startTime).getTime() > new Date(this.formData.endTime).getTime()) {
        this.formData.startTime = this.formData.endTime;
      }
      this.list = [];
      this.formData.pageNum = 1;
      this.EndTimeShow = false;
    },
  },
};
</script>
<style scoped lang="scss">
.clewent {
  .container {
    background-color: white;
  }
  .formLabel {
    margin: 0 16px;
    border-bottom: 1px solid #f1f1f1;
  }
  .formLabel .van-cell {
    padding: 10px 0;
    font-size: 14px;
  }
  .formLabel .van-cell::after {
    border: 0;
  }
  .formLabeltext .van-field {
    border: 1px solid #f1f1f1;
    padding: 6px;
    width: 100%;
    border-radius: 4px;
    overflow: hidden;
  }
  .formLabel .van-field__control {
    padding: 0 10px;
  }
  .z-checkbox .van-radio {
    padding: 6px 0;
  }
  .z-cell .van-cell__title {
    font-size: 14px;
  }
  .taskGather {
    padding-left: 20px;
    padding-bottom: 20px;
    .title {
      font-size: 15px;
      font-weight: 600;
      padding: 5px 0;
    }
  }
}
</style>
<style lang="scss">
.cardclewContentCell {
  margin: 0 10px;
}
.formLabel .van-radio__label,
.formLabel .van-checkbox__label {
  font-size: 14px;
}
.van-dialog__confirm,
.van-dialog__confirm:active {
  color: #1989fa;
}
.cardclewContent {
  background: #fff;
  box-sizing: border-box;
  padding: 10px 16px;
  margin: 6px 10px 10px;
}
.cardclewContent .info {
  font-size: 14px;
  color: #444;
  line-height: 28px;
}
.cardclewContent .title p {
  padding: 0;
  margin: 0;
}
.cardclewContent .title .textLeft {
  display: inline-block;
  padding-bottom: 10px;
}
.dialogz {
  width: 100%;
}
.dialogz .van-dialog__content {
  height: 72vh;
  overflow-y: auto;
}
.radioboxss .van-radio {
  margin-bottom: 6px;
}
.fieldNumber {
  border: 1px solid #f1f1f1;
  padding-left: 5px !important;
}
.containertext {
  .el-table {
    .el-table__cell {
      padding: 3px 0;
    }
  }
}
</style>
