<template>
  <div class="app-container">
    <div>
      <div class="tab-header webtop">
        <div v-if="stateId === '0'">【新增】客户信息</div>
        <div v-else>【修改】客户信息</div>
        <div>
          <el-button type="primary" size="small" icon="" @click="handleJUBuCun()">保存</el-button>
          <el-button type="info" size="small" icon="el-icon-close" @click="handleReturn()">关闭</el-button>
        </div>
      </div>
      <div class="listconadd">
        <el-form ref="dataForm" :model="temp" label-position="top" label-width="190px" class="formadd " :rules="rules">
          <div class="titwu">客户信息</div>
          <div class="title" style="display: flex;align-items: center;justify-content: space-between;height:40px">
            <div>基础信息</div>
          </div>
          <el-row>
            <el-col :span="4" class="trightb">
              <el-form-item>
                <span slot="label">客户名称</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item prop="name">
                <el-input v-model="temp.name" maxlength="20" placeholder="请输入客户名称" style="width:50%" class="addinputw" clearable/>
              </el-form-item>
            </el-col>
            <el-col :span="4" class="trightb">
              <el-form-item>
                <span slot="label">客户类型</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item prop="weChatID">
                <span>{{ temp.customerType }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="4" class="trightb">
              <el-form-item>
                <span slot="label">联系电话</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item prop="mobile">
                <el-input v-model="temp.mobile" maxlength="20" placeholder="请输入联系电话" style="width:50%" class="addinputw" clearable/>
              </el-form-item>
            </el-col>
            <el-col :span="4" class="trightb">
              <el-form-item>
                <span slot="label">微信号</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item prop="weixin">
                <el-input v-model="temp.weixin" maxlength="20" placeholder="请输入微信号" style="width:50%" class="addinputw" clearable/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row v-show="temp.customerType==='个人'">
            <el-col :span="4" class="trightb">
              <el-form-item>
                <span slot="label">公司名称</span>
              </el-form-item>
            </el-col>
            <el-col :span="20">
              <el-form-item prop="company">
                <el-input v-model="temp.companyName" maxlength="20" placeholder="请输入公司名称" style="width:81%" class="addinputw" clearable/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="4" class="trightb">
              <el-form-item>
                <span slot="label">客户地址</span>
              </el-form-item>
            </el-col>
            <el-col :span="20">
              <el-form-item>
                <el-select v-model="temp.province" filterable placeholder="请选择省" class="addinputw" style="width:160px" @change="getShen">
                  <el-option v-for="item in inputProvinceList" :key="item.sid" :label="item.name" :value="item.sid"/>
                </el-select>
                <el-select v-model="temp.city" filterable placeholder="请选择市" class="addinputw" style="width:160px" @change="getShi">
                  <el-option v-for="item in inputCityList" :key="item.sid" :label="item.name" :value="item.sid"/>
                </el-select>
                <el-select v-model="temp.county" filterable placeholder="请选择县" class="addinputw" style="width:160px" @change="getQu">
                  <el-option v-for="item in inputCountyList" :key="item.sid" :label="item.name" :value="item.sid"/>
                </el-select>
                <el-input v-model="temp.address" style="width:46%" clearable/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="4" class="trightb">
              <el-form-item>
                <span slot="label">客户级别</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item prop="level">
                <el-select v-model="temp.level" class="addinputw" placeholder="请选择客户级别" style="width:50%" @change="getJiBie">
                  <el-option v-for="(item, index) in induslevel" :key="index.dictKey" :label="item.dictValue" :value="item.dictKey"/>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="4" class="trightb">
              <el-form-item v-show="isOnRemind == '是'">
                <span slot="label">是否开启提醒</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item v-show="isOnRemind == '是'">
                <el-radio :disabled="editState" v-model="temp.isOnRemind" label="是">是</el-radio>
                <el-radio :disabled="editState" v-model="temp.isOnRemind" label="否">否</el-radio>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row v-show="temp.isOnRemind=='是' && isOnRemind == '是'">
            <el-col :span="4" class="trightb">
              <el-form-item>
                <span slot="label">提醒日期</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item>
                <el-date-picker v-model="temp.remind_day" type="date" style="width:50%"
                                value-format="yyyy-MM-dd"
                                placeholder="选择日期"
                                :picker-options="pickerOptions">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="4" class="trightb">
              <el-form-item>
                <span slot="label">提醒备注</span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item>
                <el-input v-model="temp.remind_remark" maxlength="20" style="width:50%" placeholder="请输入提醒备注" class="addinputw" clearable/>
              </el-form-item>
            </el-col>
          </el-row>
          <!--更多信息-->
          <el-collapse v-model="activeNames">
            <el-collapse-item title="更多信息" name="2">
              <el-row v-show="temp.customerType==='个人'">
                <el-col :span="4" class="trightb">
                  <el-form-item>
                    <span slot="label">客户生日</span>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item>
<!--                    <el-date-picker v-model="temp.endDate" style="width:50%" type="date" format="yyyy-MM-dd" class="addinputw" value-format="yyyy-MM-dd" placeholder="请选择"/>-->
                    <el-date-picker v-model="temp.birthday" style="width:50%" type="date" format="yyyy-MM-dd"
                                    class="addinputw" value-format="yyyy-MM-dd" placeholder="请选择"/>
                  </el-form-item>
                </el-col>
                <el-col :span="4" class="trightb">
                  <el-form-item>
                    <span slot="label">性别</span>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item>
                    <el-radio v-model="temp.sex" label="男">男</el-radio>
                    <el-radio v-model="temp.sex" label="女">女</el-radio>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="4" class="trightb">
                  <el-form-item>
                    <span slot="label">证件类型</span>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item>
                    <!-- <el-select v-model="temp.certificateType" class="addinputw" placeholder="请选择证件类型" @change="getZhengJian">
                      <el-option v-for="(item, index) in cateType" :key="index.dictKey" :label="item.dictValue" :value="item.dictKey"/>
                    </el-select> -->
                    <el-input v-model="temp.certificateType" style="width:50%" maxlength="20" :readonly="true" class="addinputw" clearable/>
                  </el-form-item>
                </el-col>
                <el-col :span="4" class="trightb">
                  <el-form-item>
                    <span slot="label">证件号码</span>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item prop="idnumber">
                    <el-input v-model="temp.idnumber" style="width:50%" maxlength="18 || 9" placeholder="请输入证件号码"
                              class="addinputw" clearable
                              @keyup.native="temp.idnumber = oninput(temp.idnumber)"/>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="4" class="trightb">
                  <el-form-item>
                    <span slot="label">证件有效期</span>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item>
                    <el-date-picker v-model="temp.endDate" style="width:50%" type="date" format="yyyy-MM-dd" class="addinputw" value-format="yyyy-MM-dd" placeholder="请选择"/>
                  </el-form-item>
                </el-col>
                <el-col :span="4" class="trightb">
                  <el-form-item>
                    <span slot="label">电子邮箱</span>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item prop="e_mail">
                    <el-input v-model="temp.e_mail" maxlength="20" style="width:50%" placeholder="请输入电子邮箱"
                              class="addinputw" clearable/>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="4" class="trightb">
                  <el-form-item>
                    <span slot="label">紧急联系人</span>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item>
                    <el-input v-model="temp.emergencyContact" maxlength="20" style="width:50%" placeholder="请输入紧急联系人" class="addinputw" clearable/>
                  </el-form-item>
                </el-col>
                <el-col :span="4" class="trightb">
                  <el-form-item>
                    <span slot="label">紧急联系电话</span>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item prop="emergencyMobile">
                    <el-input v-model="temp.emergencyMobile" maxlength="20" style="width:50%" placeholder="请输入紧急联系电话" class="addinputw" clearable/>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="4" class="trightb">
                  <el-form-item>
                    <span slot="label">客户来源</span>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item>
                    <el-select v-model="temp.source" class="addinputw" style="width:50%" placeholder="请选择客户来源" @change="getKeHuLaiYUan">
                      <el-option v-for="(item, index) in sourceLisst" :key="index.dictKey" :label="item.dictValue" :value="item.dictKey"/>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="4" class="trightb">
                  <el-form-item>
                    <span slot="label">客户分类</span>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item>
                    <el-select v-model="temp.customerClass" style="width:50%" class="addinputw" placeholder="请选择客户分类" @change="getFenLei">
                      <el-option v-for="(item, index) in merClass" :key="index.dictKey" :label="item.dictValue" :value="item.dictKey"/>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="4" class="trightb">
                  <el-form-item>
                    <span slot="label">备注</span>
                  </el-form-item>
                </el-col>
                <el-col :span="20">
                  <el-form-item>
                    <el-input v-model="temp.remarks" style="width:81%" maxlength="20" placeholder="请输入备注" class="addinputw" clearable/>
                  </el-form-item>
                </el-col>
              </el-row>
              <!--              </el-form>-->
            </el-collapse-item>
          </el-collapse>
          <!--运营情况-->
          <el-collapse v-model="activeNames">
            <el-collapse-item title="运营情况" name="3">
              <el-form ref="datufrom" :model="templooke" label-position="top" label-width="190px" class="formadd03">
                <!--  <div class="titleleft">运营情况</div>-->
                <el-row>
                  <el-col :span="4" class="trightb">
                    <el-form-item>
                      <span slot="label">承运货物类型</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item>
                      <el-select v-model="templooke.consignmentType" style="width:50%" class="addinputw" placeholder="请选择承运货物类型" @change="getHuoWuLeiXing">
                        <el-option v-for="(item, index) in signmentT" :key="index.dictKey" :label="item.dictValue" :value="item.dictKey"/>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="4" class="trightb">
                    <el-form-item>
                      <span slot="label">承运货物</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item>
                      <el-select v-model="templooke.consignment" style="width:50%" class="addinputw" placeholder="请选择承运货物" @change="getHuoWu">
                        <el-option v-for="(item, index) in consign" :key="index.dictKey" :label="item.dictValue" :value="item.dictKey"/>
                      </el-select>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="4" class="trightb">
                    <el-form-item>
                      <span slot="label">运输路线</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item>
                      <el-input v-model="templooke.hallway_state" style="width:50%" maxlength="20" placeholder="请输入运输路线" class="addinputw" clearable/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="4" class="trightb">
                    <el-form-item>
                      <span slot="label">购车状态</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item>
                      <div class="yihang">
                        <el-checkbox-group v-if="aseType.length>0" v-model="aseTypeBox" @change="changexuanze">
                          <el-checkbox v-for="item in aseType" :key="item.divtkey" :label="item.divtkey">
                            {{ item.dictValue }}
                          </el-checkbox>
                        </el-checkbox-group><!--  -->
                        <div class="mw">第
                          <el-input v-model="templooke.purchase_num" :disabled="templooke.purchase_time == '0'"
                                    maxlength="10" class="addinputwduan" clearable/>
                          辆
                        </div>
                      </div>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="4" class="trightb">
                    <el-form-item>
                      <span slot="label">现有车辆</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item>
                      <el-input style="width:50%" v-model="templooke.existing_vehicles" maxlength="20" placeholder="请输入现有车辆" class="addinputw" clearable/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="4" class="trightb">
                    <el-form-item>
                      <span slot="label">现有车辆品牌</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item>
                      <el-input style="width:50%" v-model="templooke.existing_vehiclesBrand" maxlength="20" placeholder="请输入现有车辆品牌" class="addinputw" clearable/>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="4" class="trightb">
                    <el-form-item>
                      <span slot="label">备注</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="20">
                    <el-form-item>
                      <el-input style="width:81%" v-model="templooke.remarks" maxlength="20" placeholder="请输入备注" class="addinputw" clearable/>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-form>
            </el-collapse-item>
          </el-collapse>
          <!--见证材料-->
          <el-collapse v-model="activeNames" v-show="stateId=='0'">
            <el-collapse-item title="见证材料" name="4">
              <el-form ref="datufrom" :model="templooke" label-position="right" label-width="190px" class="formadd03">
                <el-row>
                  <el-col :span="24">
                    <span slot="label">文件</span>
                    <Upload ref="uploadImg" v-model="list1" bucket="map" :upload-data="{type:'0001'}"/>
                  </el-col>
                </el-row>
              </el-form>
            </el-collapse-item>
          </el-collapse>
        </el-form>
      </div>
    </div>
    <!-- 弹框提示 -->
    <el-dialog :visible.sync="dialogFormVisible" width="300px" :close-on-click-modal="false">
      <div class="result-cont">
        是否更新用户
      </div>
      <div slot="footer" v-loading="FormLoading" class="dialog-footer">
        <el-button @click="dialogFormVisibl()">否</el-button>
        <el-button type="primary" @click="dialogStatus()">是</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {getPcCustomerInfoBySid, savePcCustomerInfo, updatePcCustomerInfo,} from '@/api/jichuxinxi/crmcustomer'
import {getCity, getCounty, getProvince} from '@/api/portal/areaPicker' // 省市区
import {typeValues} from '@/api/dictcommons/shujuzidian'
import {loginDetails} from '@/api/dictcommons/basemanufacturer'
import {getStorage} from '@/utils/auth'
import Pagination from '@/components/pagination'
import pageye from '@/components/pagination/pageye'
import {getPcBusinessInfoBySid} from '@/api/jichuxinxi/crmbusiness'
import Upload from '@/components/uploadFile/ManyImageUpload.vue' // 上传文件

export default {
  name: 'KehudanganAdd',
  components: {Pagination, pageye, Upload},
  data() {
    var checkSubmit = (rule, value, callback) => {
      const Submit =
        /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/
      if (value) {
        if (!Submit.test(value)) {
          callback(new Error('请输入手机号'))
        }
        callback()
      }
      callback()
      // if (Submit.test(value)) {
      //   return callback()
      // }
      // callback(new Error('请输入手机号'))
    }
    var validatePass2 = (rule, value, callback) => {
      const WeiXin = /^[a-zA-Z][a-zA-Z\d_-]{5,19}$/;
      const phone = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
      if (value) {
        // 如果没有通过验证！！
        if (!WeiXin.test(value) && !phone.test(value)) {
          callback(new Error("请输入正确的微信号码"));
        }
        callback();
      } else {
        callback();
      }
    };
    var identitycard = (rules, value, callback) => {
      const card =
        /[^0-9.]/
        // /^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/
      if (value) {
        if (!card.test(value)) {
          callback(new Error('请输入身份证号码'))
        }
        callback()
      }
      callback()
      // if (card.test(value)) {
      //   return callback()
      // }
      // callback(new Error('请输入身份证号码'))
    }
    var validateE_mail = (rules, value, callback) => {
      const mail =
        /^[a-zA-Z0-9_-]+@([a-zA-Z0-9]+\.)+(com|cn|net|org)$/
      if (value) {
        if (!mail.test(value)) {
          callback(new Error('请输入正确的电子邮箱'))
        }
        callback()
      }
      callback()
      // if (card.test(value)) {
      //   return callback()
      // }
      // callback(new Error('请输入身份证号码'))
    }
    return {
      // 限制日期不可选择当天之前的
      pickerOptions: {
        disabledDate(time) {
          let oneDay = 60 * 60 * 24 * 1000;
          return time.getTime() < Date.now() - oneDay;
        },
      },
      editState: false,
      isOnRemind: '是',
      // ---见证材料
      list1: [],
      list2: [],
      list3: [],
      province: [],
      city: [],
      county: [],
      inputProvinceList: [],
      inputCityList: [],
      inputCountyList: [],
      list: [],
      activeNames: ['1'],
      // --按钮菜单-------
      customerClass: 'customerClass',
      merClass: [],
      customerSource: 'customerSource',
      sourceLisst: [],
      customerLevel: 'customerLevel',
      induslevel: [],
      visitWay: 'visitWay',
      industway: [],
      documenttype: 'documenttype',
      cateType: [],
      customerType: 'customerType',
      merType: [],
      ncySid: [],
      edOrgSid: [],
      consignmentType: 'consignmentType',
      signmentT: [],
      consignment: 'consignment',
      consign: [],
      industrytype: 'industrytype',
      industry_type: [],
      customerType_list: [],
      sex_list: [],
      aseTypeBox: [],
      aseType: [
        {
          dictValue: '首次购车',
          divtkey: 0
        },
        {
          dictValue: '续购',
          divtkey: 1
        },
      ],
      Customeryou: '',
      checkin: '', //登记状态
      kehusid: '',
      YongHuid: [],
      stateId: 0,
      FormLoading: false,
      listLoading: false,
      tempdaat: {},
      crmVisitAppendixDtoList: [],
      temp: {
        crmBusinessDto: {},
        crmVisitAppendixDtoList: [],
        customerType: '', // 客户类型
        visitWay: '', // 见面方式
        visitWayKey: '',
        userSid: '',
        orgSid: ''
      }, // 添加和修改
      templooke: {},
      tempmore: {},
      textMap: {
        update: '修改',
        create: '创建',
      },
      dialogFormVisible: false,
      client: '',
      clientphone: '',
      sids: [],
      listQuery: {
        current: 1,
        size: 20,
        params: {
          distributorName: ''
        }
      },
      clientSid: '',
      rules: {
        name: [
          {
            required: true,
            message: '请填写客户名称',
            trigger: 'blur'
          }
        ],
        address: [
          {
            required: true,
            message: '请填写客户地址',
            trigger: 'blur'
          }
        ],
        mobile: [
          {
            required: true,
            validator: checkSubmit,
            trigger: 'blur',
          },
        ],
        weixin: [
          {
            required: true,
            validator: validatePass2,
            trigger: 'blur',
          },
        ],
        idnumber: [
          {
            required: true,
            // validator: identitycard,
            trigger: 'blur',
          },
        ],
        e_mail: [
          {
            required: true,
            validator: validateE_mail,
            trigger: 'blur',
          },
        ],
        emergencyMobile: [
          {
            required: true,
            validator: checkSubmit,
            trigger: 'blur',
          },
        ],
      }
    }
  },
  created() {
    // 初始化变量
  },
  methods: {
    oninput(val, limit = 0) {
      val = val.replace(/[^\d.]/g, '') //保留数字
      val = val.replace(/^00/, '0.') //开头不能有两个0
      // val = val.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.'); //只保留一个小数点
      // /^0\d+/.test(val) ? val = val.slice(1) : '' //两位以上数字开头不能为0
      // const str = '^(\\d+)\\.(\\d{' + limit + '}).*$'
      // const reg = new RegExp(str)
      // if (limit === 0) {
      //   // 不需要小数点
      //   val = val.replace(reg, '$1')
      // } else {
      //   // 通过正则保留小数点后指定的位数
      //   val = val.replace(reg, '$1.$2')
      // }
      return val
    },
    // 初始
    init() {
      this.getShuJUZiDian()
      this.postHuoquyonghu()
    },
    // 修改回显
    openUpdate(sid) {
      this.clientSid = sid
      this.stateId = sid
      this.isOnRemind = '否'
      this.editState = true
      if (this.stateId !== '0') {
        getPcCustomerInfoBySid(this.stateId).then((response) => {
          console.log(response.data)
          if (response.code === '200') {
            // this.$refs['dataForm'].clearValidate()
            this.temp = response.data
            if (this.temp.birthday == 'NaN-NaN-NaN NaN:NaN:NaN'){
              this.temp.birthday = ''
            }
            if (this.temp.customerType !== '') {
              if (this.temp.customerType === '个人') {
                this.temp.certificateType = '身份证'
                this.temp.certificateTypeKey = '01'
              } else {
                this.temp.certificateType = '营业执照'
                this.temp.certificateTypeKey = '02'
              }
              typeValues({type: 'customerType'}).then((res) => {
                if (res.code === '200') {
                  this.customerType_list = res.data
                  this.customerType_list.forEach((e) => {
                    if (e.dictValue == this.temp.customerType) {
                      typeValues({psid: e.sid, type: this.customerClass}).then((res) => {
                        if (res.code === '200') {
                          this.merClass = res.data
                        }
                      })
                    }
                  })
                }
              })
            }
          }
        })
        getPcBusinessInfoBySid(this.stateId).then((response) => {
          if (response.code === '200') {
            this.templooke = response.data
            const Arry = []
            Arry.push(parseInt(response.data.purchase_time))
            this.aseTypeBox = Arry
          }
        })
      }
      this.init()
      this.huoquSheng() //获取省
    },
    // 新增
    openCreate(customerTypeList) {
      this.resetTemp()
      this.temp.customerType = customerTypeList.customerType
      this.temp.customerTypeKey = customerTypeList.customerTypeKey
      this.temp.visitWay = customerTypeList.visitWay
      this.temp.visitWayKey = customerTypeList.visitWayKey
      this.$refs['dataForm'].clearValidate()
      this.stateId = '0'
      if (this.temp.customerType !== '') {
        if (this.temp.customerType === '个人') {
          this.temp.certificateType = '身份证'
          this.temp.certificateTypeKey = '01'
        } else {
          this.temp.certificateType = '营业执照'
          this.temp.certificateTypeKey = '02'
        }
        typeValues({psid: customerTypeList.psid, type: this.customerClass}).then((res) => {
          if (res.code === '200') {
            this.merClass = res.data
          }
        })
      }
      this.init()
      this.huoquSheng() //获取省
    },
    // 下拉卡框 数据字典
    getShuJUZiDian() {
      typeValues({ type: this.documenttype }).then((res) => {
        if (res.code === '200') {
          this.cateType = res.data
        }
      })
      typeValues({ type: this.customerType }).then((res) => {
        if (res.code === '200') {
          this.merType = res.data
        }
      })
      //
      typeValues({ type: this.customerSource }).then((res) => {
        if (res.code === '200') {
          this.sourceLisst = res.data
        }
      })
      //
      typeValues({ type: this.customerLevel }).then((res) => {
        if (res.code === '200') {
          this.induslevel = res.data
        }
      })
      //
      typeValues({ type: this.visitWay }).then((res) => {
        if (res.code === '200') {
          this.industway = res.data
        }
      })
      //
      typeValues({ type: this.industrytype }).then((res) => {
        if (res.code === '200') {
          this.industry_type = res.data
        }
      })
      //
      typeValues({ type: this.consignmentType }).then((res) => {
        if (res.code === '200') {
          this.signmentT = res.data
        }
      })
      //
      typeValues({ type: this.consignment }).then((res) => {
        if (res.code === '200') {
          this.consign = res.data
        }
      })
      //
      typeValues({ type: 'sex' }).then((res) => {
        if (res.code === '200') {
          this.sex_list = res.data
        }
      })
    },
    // // 客户分类
    // getKeHufenlei(kehusid) {
    //   typeValues({psid: kehusid, type: this.customerClass}).then((res) => {
    //     console.log('9988888', res)
    //     if (res.code === '200') {
    //       this.merClass = res.data
    //     }
    //   })
    // },
    // 挂靠单位
    // getGuaKao() {
    //   namesDown({ name: this.temp.affiliatedOrgSid }).then((response) => {
    //     if (response.code === '200') {
    //       this.edOrgSid = response.data
    //     }
    //   })
    // },
    // -------------------------获取省市县方法-------------------------
    huoquSheng() {
      console.log(123456)
      getProvince().then((res) => {
        console.log('11111省：', res)
        if (res.code === '200') {
          this.inputProvinceList = res.data
        }

      })
    },
    getShen(value) {
      let bb = ''
      this.inputProvinceList.forEach((e) => {
        if (e.sid === value) {
          bb = {
            name: e.name,
            districtCode: e.districtCode,
            sid: e.sid
          }
        }
      })
      // 这里是把code的值赋给province省字段
      this.temp.province = bb.name
      this.huoquShi(bb.sid)
    },
    huoquShi(sid1) {
      var sid = {
        sid: sid1
      }
      getCity(sid).then((res) => {
        console.log('2222市', res)
        if (res.code === '200') {
          this.inputCityList = res.data
        }
      })
    },
    getShi(value) {
      let bb = ''
      this.inputCityList.forEach((e) => {
        if (e.sid === value) {
          bb = {
            name: e.name,
            districtCode: e.districtCode,
            sid: e.sid
          }
        }
      })
      this.temp.city = bb.name
      this.huoquXian(bb.sid)
    },
    huoquXian(sid1) {
      var sid = {
        sid: sid1
      }
      getCounty(sid).then((res) => {
        console.log('333县', res)
        if (res.code === '200') {
          this.inputCountyList = res.data
        }
      })
    },
    getQu(value) {
      let bb = ''
      this.inputCountyList.forEach((e) => {
        if (e.sid === value) {
          bb = {
            name: e.name,
            districtCode: e.districtCode,
            sid: e.sid
          }
        }
      })
      this.temp.county = bb.name
      // this.temp.address=this.temp.province+this.temp.city+this.temp.county
      // this.deCode.push(bb.districtCode)
      console.log('6666677777777', this.deCode)
    },
    // ----------------------------------方法--------------------
    // 组件返回
    handleReturn() {
      this.isOnRemind = '是'
      this.editState = false
      this.activeNames = ['1']
      this.$emit('handleReturn')
    },
    // 添加前数据初始化
    resetTemp() {
      this.temp = {}
      this.templooke = {}
      this.aseTypeBox = []
      this.list1 = []
    },
    // 获取用户信息
    postHuoquyonghu() {
      var token = getStorage()
      loginDetails(token).then((response) => {
        if (response.code === '200') {
          this.YongHuid = response.data
        }
      })
    },

    findselect(list, value) {
      var item = null
      for (var i = 0; i < list.length; i++) {
        if (list[i].divtkey === value) {
          item = list[i]
          break
        }
      }
      return item
    },
    // 首次 续购
    changexuanze() {
      this.aseTypeBox = [this.aseTypeBox[this.aseTypeBox.length - 1]]
      var item = this.findselect(this.aseType, this.aseTypeBox[0])
      this.templooke.purchase_time = item.divtkey
    },
    // 保存客户运营数据
    handleJUBuCun() {
      this.$refs['dataForm'].validate((valid) => {
        if (this.templooke.purchase_time == '0') {
          this.templooke.purchase_num = ''
        }
        if (valid) {
          this.FormLoading = true
          if (this.temp.sex !== '') {
            this.sex_list.forEach((e) => {
              if (e.dictValue == this.temp.sex) {
                this.temp.sexKey = e.dictKey
              }
            })
          }
          if (this.temp.isOnRemind !== '' && this.temp.isOnRemind == '是') {
            this.temp.isOnRemindkey = 1
          } else {
            this.temp.isOnRemindkey = 0
          }
          if (this.temp.customerType !== '') {
            let bb = ''
            this.merType.forEach((e) => {
              if (e.dictValue == this.temp.customerType) {
                bb = {
                  type: 'customerType',
                  name: e.dictValue,
                  value: e.dictKey,
                  sid: e.sid,
                }
              }
            })
            this.temp.customerTypeKey = bb.value
          }
          if (!this.temp.birthday){
            this.temp.birthday = ''
          }
          if (this.stateId === '0') {
            this.temp.dto1 = this.templooke // this.templooke这个是运营的数据源
            this.temp.userSid = this.YongHuid.sid
            this.temp.staffSid = this.YongHuid.staffSid
            this.temp.orgSid = this.YongHuid.organizationSid
            this.temp.crmBusinessDto = this.templooke
            this.getUrl()
            this.temp.crmVisitAppendixDtoList = this.crmVisitAppendixDtoList
            savePcCustomerInfo(this.temp).then((response) => {
              this.FormLoading = false
              if (response.code === '200') {
                // this.clientSid = response.data
                this.$notify({
                  title: '提示',
                  message: '添加成功',
                  type: 'success',
                  duration: 2000
                })
                this.templooke = {}
                this.activeNames = ['1']
                this.list1 = []
                this.$emit('handleReturn')
              } else if (response.code === '511' || response.code === '513') {
                this.FormLoading = false
                this.dialogFormVisible = true
                this.stateId = response.data
              } else {
                alert(200)
              }
            }).catch(function(reson, data) {

            })
          } else {
            this.temp.crmBusinessDto = this.templooke // this.templooke这个是运营的数据源
            this.temp.userSid = this.YongHuid.sid
            this.temp.staffSid = this.YongHuid.staffSid
            this.temp.orgSid = this.YongHuid.organizationSid
            updatePcCustomerInfo(this.temp).then((response) => {
              this.FormLoading = false
              if (response.code === '200') {
                // this.clientSid = response.data
                this.$notify({
                  title: '提示',
                  message: '修改成功',
                  type: 'success',
                  duration: 2000,
                })
                this.templooke = {}
                this.activeNames = ['1']
                this.$emit('handleReturn')
              } else {
                this.$notify({
                  title: '提示',
                  message: '修改失败',
                  type: 'error',
                  duration: 2000,
                })
              }
            })
          }
        }
      })
    },
    dialogStatus() {
      this.dialogFormVisible = false
      this.openUpdate(this.stateId)
    },
    dialogFormVisibl() {
      this.$notify({
        title: '提示',
        message: '用户名手机号重复',
        type: 'error',
        duration: 2000,
      })
      this.dialogFormVisible = false
      return
    },
    // 中介单位
    // getZhongJie() {
    //   getPcDistributorList().then((response) => {
    //     if (response.code === '200') {
    //       this.ncySid = response.data
    //     }
    //   })
    // },
    // 中介单位处理
    // getZongjieDanwei(value) {
    //   let bb = null
    //   this.ncySid.forEach((e) => {
    //     if (e.sid == value) {
    //       bb = {
    //         name: e.distributorName,
    //       }
    //     }
    //   })
    //   this.temp.agencyName = bb.name
    // },
    // ---------------------------------------------------------------------------------
    // ---------------------------数据字典的处理------------------------------------------------------
    // ---------------------------------------------------------------------------------
    // 证件类型
    getZhengJian(value) {
      let bb = null
      this.cateType.forEach((e) => {
        if (e.dictKey == value) {
          bb = {
            type: 'documenttype',
            name: e.dictValue,
            vaule: e.dictKey,
          }
        }
      })
      this.temp.certificateType = bb.name
      this.temp.certificateTypeKey = bb.vaule
    },
    // 客户类型
    // getKeHu(value) {
    //   let bb = null
    //   this.merType.forEach((e) => {
    //     if (e.dictKey == value) {
    //       bb = {
    //         type: 'customerType',
    //         name: e.dictValue,
    //         vaule: e.dictKey,
    //         sid: e.sid,
    //       }
    //     }
    //   })
    //   this.temp.customerType = bb.name
    //   console.log('value值', this.temp.customerType)
    //   this.temp.customerTypeKey = bb.vaule
    //   console.log('key值', this.temp.customerTypeKey)
    //   this.kehusid = bb.sid
    //   console.log('sid值', this.kehusid)
    //   this.getKeHufenlei(this.kehusid)
    // },
    // 客户分类
    getFenLei(value) {
      let bb = null
      this.merClass.forEach((e) => {
        if (e.dictKey == value) {
          bb = {
            type: 'customerClass',
            name: e.dictValue,
            vaule: e.dictKey
          }
        }
      })
      this.temp.customerClass = bb.name
      this.temp.customerClassKey = bb.vaule
    },
    // 客户来源
    getKeHuLaiYUan(value) {
      let bb = null
      this.sourceLisst.forEach((e) => {
        if (e.dictKey == value) {
          bb = {
            type: 'customerSource',
            name: e.dictValue,
            vaule: e.dictKey
          }
        }
      })
      this.temp.source = bb.name
      this.temp.sourceKey = bb.vaule
    },
    // 客户级别
    getJiBie(value) {
      let bb = null
      this.induslevel.forEach((e) => {
        if (e.dictKey == value) {
          bb = {
            type: 'customerLevel',
            name: e.dictValue,
            vaule: e.dictKey
          }
        }
      })
      this.temp.level = bb.name
      this.temp.levelKey = bb.vaule
    },
    // 来访
    getLaiFang(value) {
      let bb = null
      this.industway.forEach((e) => {
        if (e.dictKey == value) {
          bb = {
            type: 'visitWay',
            name: e.dictValue,
            vaule: e.dictKey
          }
        }
      })
      this.temp.visit_way = bb.name
      this.temp.visit_way_key = bb.vaule
    },
    // 客户行业
    getHangYe(value) {
      let bb = null
      this.industry_type.forEach((e) => {
        if (e.dictKey == value) {
          bb = {
            type: 'industrytype',
            name: e.dictValue,
            vaule: e.dictKey
          }
        }
      })
      this.templooke.customer_industry_type = bb.name
      this.templooke.customer_industry_type_key = bb.vaule
    },
    // 货物类别
    getHuoWuLeiXing(value) {
      let bb = null
      this.signmentT.forEach((e) => {
        if (e.dictKey == value) {
          bb = {
            type: 'consignmentType',
            name: e.dictValue,
            vaule: e.dictKey
          }
        }
      })
      this.templooke.consignmentType = bb.name
      this.templooke.consignmentTypeKey = bb.vaule
    },
    // 货物
    getHuoWu(value) {
      let bb = null
      this.consign.forEach((e) => {
        if (e.dictKey == value) {
          bb = {
            type: 'consignment',
            name: e.dictValue,
            vaule: e.dictKey
          }
        }
      })
      this.templooke.consignment = bb.name
      this.templooke.consignmentKey = bb.vaule
    },
    getUrl() {
      for (var i = 0; i < this.list1.length; i++) {
        var namese = this.list1[i].name
        var nameArr = namese.split('.')
        this.crmVisitAppendixDtoList.push({
          // attachType: '0001',
          fileName: this.list1[i].name,
          filePath: this.list1[i].url,
          fileSize: this.list1[i].size,
          // linkSid: this.temp.customerSid,
          createBySid: this.YongHuid.sid,
          fileType: nameArr[nameArr.length - 1],
        })
        console.log('11223344', this.crmVisitAppendixDtoList)
      }
    }
  }
}
</script>
<style scoped>
.yulan {
  text-align: right;
  margin-top: 15px;
}

.tleftb {
  text-align: left;
}

.trightb {
  text-align: right;
}

.hang {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  padding: 20px 10px;
}

.addinputwduan {
  width: 80px;
  margin: 0 5px;
}

/deep/ .el-collapse-item__header {
  height: 40px;
  padding: 10px;
  font-weight: bold;
  font-size: 20px;
  text-align: left;
  color: #ffffff;
  background-color: #0294d7;
}

/deep/ .el-collapse-item__content {
  padding-bottom: 0;
}
</style>
