<template>
  <div class="bgcolor">
    <!--        顶部条-->
    <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>
    <div class="cardclewContent">
      <div class="info">
        客资线索：<span v-if="infoData.cid == 3">申请代理</span
        ><span v-if="infoData.cid == 4">开设门店</span
        ><span v-if="infoData.cid == 5">批量采购</span>
      </div>
      <div class="info">区域：{{ infoData.companyName }}</div>
      <div class="info">省：{{ infoData.provinceName }}</div>
      <div class="info">市：{{ infoData.cityName }}</div>
      <div class="info">区/县：{{ infoData.countryName }}</div>
      <div class="info">姓名：{{ infoData.name }}</div>
      <div class="info">
        来电电话：<a
          style="color: #0057ba; font-weight: bold; text-decoration: underline"
          :href="'tel:' + infoData.phone"
          >{{ infoData.phone }}<van-icon name="phone"
        /></a>
      </div>
      <div class="info">
        有无涂料从业经验：<span v-if="infoData.paintExperience == 1">有</span
        ><span v-if="infoData.paintExperience == 2">无</span>
      </div>
      <div class="info">目前经营的行业：{{ infoData.industry }}</div>
      <div class="info">目前经营的品牌：{{ infoData.brand }}</div>
      <div class="info">
        目前有无实体店：<span v-if="infoData.physicalStore == 1">有</span
        ><span v-if="infoData.physicalStore == 2">无</span>
      </div>
      <div class="info" v-if="infoData.createTime">首次接入时间：{{ infoData.createTime }}</div>
      <div class="info" v-if="infoData.latestClueTime">
        最后一次跟进时间：{{ infoData.latestClueTime }}
      </div>
      <div class="info">
        跟进状态：<span v-if="infoData.isClose == 1">跟进完成</span
        ><span v-if="infoData.isClose == 0">跟进中</span
        ><span v-if="infoData.isClose == -1">未跟进</span>
      </div>
      <div class="info" v-if="infoData.followUpResult" style="word-break: break-all">
        跟进结果：{{ infoData.followUpResult }}
      </div>
      <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
      >
    </div>
    <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>

    <div
      v-if="infoData.isClose != 1"
      class="container"
      style="width: 94%; margin: 0px auto; border-radius: 6px">
      <van-form ref="form">
        <div v-for="(item, index) in collectionItemList" :key="index">
          <div
            v-if="item.answerType == 'sz' && activTadioLabel == '已出货'"
            class="formLabel z-cell">
            <van-cell>
              <template #title>
                <span class="van-f-red">*</span>{{ item.customerClueName }}
                <!-- <span style="font-size: 12px; color: #888">{{ item.remark }}</span> -->
              </template>
            </van-cell>
            <van-field
              v-model="item.answerValue"
              :placeholder="item.remark"
              type="number"
              :border="true"
              @input="numberFn(item, index)"></van-field>
          </div>
          <div v-if="item.answerType == 'rq'" class="formLabel z-cell">
            <van-cell>
              <template #title>
                <span v-if="item.isMust == 0" class="van-f-red">*</span>{{ item.customerClueName
                }}<span style="font-size: 14px; color: #ccc">{{ item.remark }}</span>
              </template>
            </van-cell>
            <van-field
              v-model="item.answerValue"
              clickable
              name="calendar"
              placeholder="点击选择日期"
              readonly
              @click="showCalendarClick(index)" />
            <p
              style="
                color: #444;
                font-size: 12px;
                margin: 0;
                padding: 10px 0;
                text-align: right;
              "></p>
          </div>
          <div v-if="item.answerType == 'zp'" class="formLabel z-cell">
            <van-cell>
              <template #title>
                <span v-if="item.isMust == 0" class="van-f-red">*</span>{{ item.customerClueName }}
              </template>
            </van-cell>
            <van-row gutter="10" style="margin-bottom: 10px">
              <p style="margin-top: 0">
                <span style="font-size: 12px; color: #888">{{ item.remark }}</span>
              </p>
              <delete-upload-img :imgs="item.fileInfoList"></delete-upload-img>
              <upload-img
                :uploadid="uploadid2"
                @newimgarr="newimgarr1"
                imgText="上传照片"
                :indexImg="index"
                :customId="item.customerClueId"
                :summaryId="item.customerClueItemId"
                @click="imgClick(item, index)"></upload-img>
            </van-row>
          </div>
          <div v-if="item.answerType == 'wb' && showv" class="formLabel z-cell formLabeltext">
            <van-cell>
              <template #title>
                <span class="van-f-red" v-if="requ">*</span>{{ item.customerClueName }}
              </template>
            </van-cell>
            <van-field
              v-model="item.answerValue"
              :formatter="formatter"
              :placeholder="item.remark"
              rows="1"
              autosize
              type="textarea"></van-field>
            <!--            <p style="color: #444;font-size: 12px;margin: 0;padding:10px 0;text-align: right">{{ item.remark }}</p>-->
          </div>
          <div v-if="item.answerType == 'wb' && showvnum" class="formLabel z-cell formLabeltext">
            <van-cell>
              <template #title>
                <span class="van-f-red" v-if="requ">*</span>{{ item.customerClueName }}
              </template>
            </van-cell>
            <van-field
              type="digit"
              v-model="item.answerValue"
              maxlength="10"
              :formatter="formatter"
              :placeholder="item.remark"></van-field>
            <!--            <p style="color: #444;font-size: 12px;margin: 0;padding:10px 0;text-align: right">{{ item.remark }}</p>-->
          </div>
          <div v-if="item.answerType == 'duox'" class="formLabel z-cell">
            <van-cell>
              <template #title>
                <span v-if="item.isMust == 0" class="van-f-red">*</span>{{ item.customerClueName }}
              </template>
            </van-cell>
            <z-checkbox
              :answerType="item.answerType"
              :checkboxval="item.answerValue"
              :collectionType="item.customOptionList"
              :textc="item.customerClueId"
              :zCheckboxcolumns="item.customerClueOptionList"
              @zSelectVal="zSelectVal"></z-checkbox>
          </div>
          <div v-if="item.answerType == 'dx'" class="formLabel z-cell">
            <van-cell>
              <template #title>
                <span v-if="item.isMust == 0" class="van-f-red">*</span>{{ item.customerClueName }}
              </template>
            </van-cell>
            <van-field>
              <template #input>
                <z-radio
                  :answerType="item.answerType"
                  :collectionType="item.collectionType"
                  :radio="item.answerValue"
                  :textc="item.customerClueId"
                  :Tindex="index"
                  :zRadiocolumns="item.customerClueOptionList"
                  @zSelectVal="zSelectVal"></z-radio>
              </template>
            </van-field>
          </div>
          <br />
        </div>
        <div style="height: auto" v-if="tipSHow">
          <p style="color: orange; margin: 6px 16px; font-size: 14px">
            <van-icon name="info-o" />&nbsp;{{ tipText }}
          </p>
        </div>
        <br />
      </van-form>
    </div>
    <br />
    <div v-if="infoData.isClose != 1" 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>
        </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';

export default {
  name: 'MyHistoricalWeekly',
  components: { zRadio, zCheckbox, uploadImg, deleteUploadImg, deleteUploadImgv },
  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: {},
      imgList: [],
      info: {},
      showv: false,
      isClose: '',
      customItemList: [],
      followUpResult: '',
      SBshow: false,
      requ: false,
      showvnum: false,
      tipSHow: false,
      namesss: '',
      tipText: '',
      activTadioLabel: '', //当前选中跟进结果
    };
  },
  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 + '/mobile/clew');
              } else {
                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;
          } 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.activTadioLabel = value.customerClueOption;
        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() {
      for (var c = 0; c < this.collectionAnswerlisd.length; c++) {
        for (var b = 0; b < this.collectionItemList.length; b++) {
          if (this.collectionAnswerlisd[c].id == this.collectionItemList[b].customId) {
            this.collectionItemList[b].customOptionList = this.collectionAnswerlisd[c].value;
          }
        }
      }
      for (var i = 0; i < this.collectionItemList.length; i++) {
        this.collectionItemList[i].customerClueInfoId = this.infoData.customerClueInfoId;
      }
      if (
        this.collectionItemList[0].customerClueOptionList[1].value == 'N' &&
        this.collectionItemList[0].customerClueOptionList[0].value == 'N'
      ) {
        this.$toast('请选择回访电话是否接通');
        return;
      }
      var show = false;
      var textshow = false;
      for (var i1 = 0; i1 < this.collectionItemList[1].customerClueOptionList.length; i1++) {
        if (this.collectionItemList[1].customerClueOptionList[i1].value == 'Y') {
          show = true;
          if (
            this.collectionItemList[1].customerClueOptionList[i1].customerClueOption.indexOf(
              '跟进中'
            ) == -1
          ) {
            if (this.collectionItemList[2].answerValue.trim() == '') {
              textshow = true;
            }
          }
        }
      }
      if (!show) {
        this.$toast('请选择跟进结果');
        return;
      }
      if (
        this.collectionItemList[0].customerClueOptionList[1].value == 'Y' &&
        this.collectionItemList[1].customerClueOptionList[1].value == 'N' &&
        this.collectionItemList[1].customerClueOptionList[0].value == 'N'
      ) {
        this.$toast('当您的回访电话未接通，跟进结果请选择  “跟进中”或者“没有意向”');
        return;
      }

      if (textshow) {
        if (
          this.collectionItemList[1].customerClueOptionList[2].value == 'Y' ||
          this.collectionItemList[1].customerClueOptionList[3].value == 'Y'
        ) {
          this.$toast('请输入10位' + this.collectionItemList[2].customerClueName);
        } else {
          this.$toast('请输入' + this.collectionItemList[2].customerClueName);
        }
        return;
      }
      if (this.showvnum) {
        if (this.collectionItemList[2].answerValue.trim().length < 10) {
          this.$toast('请输入10位' + this.collectionItemList[2].customerClueName);
          return;
        }
      }
      var form = {
        isClose: this.isClose,
        followUpResult: this.followUpResult,
        customerClueItemList: this.collectionItemList,
      };
      if (this.flagclick) {
        this.flagclick = false;
        this.timer = null;
        this.timer = setTimeout(() => {
          this.flagclick = true;
        }, 2000);
        insertCustomerClueAnswer(form).then((res) => {
          if (res.code == 200) {
            if (this.$route.query.token != undefined) {
              window.location.replace(window.location.origin + '/mobile/clew');
            } else {
              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>
.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;
}
</style>
<style>
.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;
}
</style>
