<template>
  <div class="storeEdit">
    <!--        顶部条-->
    <div class="navBarTOP">
      <van-nav-bar
        class="navBar"
        title="编辑信息"
        left-arrow
        @click-left="onClickLeft"
        right-text="保存"
        @click-right="onSubmit" />
    </div>
    <!--        主体内容-->
    <div style="margin-top: 44px">
      <van-dialog v-model="show" title="门店位置">
        <mapmarker :info="fromValue"></mapmarker>
      </van-dialog>
      <van-form ref="tabstoreVal">
        <van-tabs class="myTab" v-model="tabVal" color="#1989fa">
          <van-tab title="基础信息" name="insidePlan">
            <van-field readonly v-model="fromValue.storeCode" label="编号">
              <template #left-icon>
                <span class="van-f-red"> </span>
              </template>
            </van-field>
            <van-field
              readonly
              clickable
              name="picker"
              :value="fromValue.storeCategoryName"
              label="类型"
              placeholder="点击选择类型"
              @click="showPicker = true">
              <template #left-icon>
                <span class="van-f-red">*</span>
              </template>
            </van-field>
            <van-field
              readonly
              clickable
              name="picker"
              :value="fromValue.orgName"
              label="部门名称"
              placeholder="点击选择部门名称"
              @click="PickerDept">
              <template #left-icon>
                <span class="van-f-red">*</span>
              </template>
            </van-field>
            <div
              style="background-color: white; padding: 0 14px"
              class="morelaji"
              v-if="fromValue.storeCategory != 'C917'">
              <!-- 分销店 -->
              <template
                v-if="
                  verifyStoreType(fromValue.storeCategory) &&
                  verifyStoreType(fromValue.storeCategory).type == 'fxd'
                ">
                <van-row style="border-bottom: 1px solid #ebedf0">
                  <van-col span="24">
                    <van-field label="经销商名称" @click="showPickerChainsListFn" class="TCFXList">
                      <template #left-icon>
                        <span class="van-f-red">*</span>
                      </template>
                      <template #input>
                        <template
                          v-if="sfaStoreChainsContactList && sfaStoreChainsContactList.length">
                          <div
                            class="sfaStoreChainsContactList"
                            v-for="(item, index) in sfaStoreChainsContactList"
                            :key="index">
                            {{ item.categoryDescribe }}
                            {{ item.chainCode }}
                            {{ item.chainName }}
                          </div>
                        </template>
                        <template v-else>
                          <span style="color: rgb(150, 151, 153)"> 点击选择经销商名称 </span>
                        </template>
                      </template>
                    </van-field>
                  </van-col>
                </van-row>
              </template>
              <template v-else>
                <van-row style="border-bottom: 1px solid #ebedf0">
                  <van-col span="20">
                    <van-field
                      rows="1"
                      autosize
                      type="textarea"
                      readonly
                      clickable
                      name="picker"
                      :value="fromValue.chainName"
                      label="经销商名称"
                      placeholder="点击选择经销商名称"
                      @click="showPickerChainsListFn">
                      <template #left-icon>
                        <span
                          v-if="
                            fromValue.ifJzStoreType != 1 &&
                            fromValue.storeCategory != 'C912' &&
                            fromValue.storeCategory != 'C917'
                          "
                          class="van-f-red"
                          >*</span
                        >
                      </template>
                    </van-field>
                  </van-col>
                  <van-col span="4"
                    ><van-button
                      size="small"
                      type="info"
                      style="margin-top: 6px"
                      native-type="button"
                      @click="moreTypeShowFn"
                      ><van-icon name="list-switching" />更多</van-button
                    ></van-col
                  >
                </van-row>
              </template>
            </div>
            <van-field
              v-model="fromValue.storeName"
              @blur="setStoreNameFn"
              :label="storeName"
              placeholder="请输入">
              <template #left-icon>
                <span class="van-f-red">*</span>
              </template>
            </van-field>
            <van-field
              readonly
              clickable
              name="picker"
              :value="fromValue.provinceName"
              label="省(州)"
              placeholder="点击选择省(州)"
              @click="showProvincePicker = true">
              <template #left-icon>
                <span class="van-f-red">*</span>
              </template>
            </van-field>
            <van-field
              readonly
              clickable
              name="picker"
              :value="fromValue.cityName"
              label="城市"
              placeholder="点击选择城市"
              @click="showCityPicker = true">
              <template #left-icon>
                <span class="van-f-red">*</span>
              </template>
            </van-field>
            <van-field
              readonly
              clickable
              name="picker"
              :value="fromValue.districtName"
              label="区(县)"
              placeholder="点击选择区(县)"
              @click="showDistrictPicker = true">
              <template #left-icon>
                <span class="van-f-red">*</span>
              </template>
            </van-field>
            <van-field
              readonly
              clickable
              name="picker"
              :value="fromValue.townName"
              label="街道"
              placeholder="点击选择街道"
              @click="showTownPicker = true">
              <template #left-icon>
                <span class="van-f-red">*</span>
              </template>
            </van-field>
            <van-field
              v-model="fromValue.addressLine"
              rows="1"
              autosize
              type="textarea"
              :label="address"
              placeholder="地址"
              @blur="addressFn">
              <template #left-icon>
                <span class="van-f-red">*</span>
              </template>
              <template #button>
                <van-button size="small" type="info" native-type="button" @click="fns"
                  ><van-icon name="location-o" />地图</van-button
                >
              </template>
            </van-field>
            <van-field v-model="fromValue.lat" readonly label="经度" placeholder="经度">
              <template #left-icon>
                <span class="van-f-red"> </span>
              </template>
            </van-field>
            <van-field v-model="fromValue.lon" readonly label="维度" placeholder="维度">
              <template #left-icon>
                <span class="van-f-red"> </span>
              </template>
            </van-field>
            <van-field
              readonly
              clickable
              name="picker"
              :value="fromValue.cityLevel"
              label="城市等级"
              placeholder="点击选择城市等级">
              <template #left-icon>
                <span class="van-f-red"></span>
              </template>
            </van-field>
            <div v-if="fromValue.storeCategory != 'C917'">
              <van-field
                v-if="fromValue.ifJzStoreType != 1"
                v-model="fromValue.area"
                @input="numberFn"
                type="number"
                label="面积(m²)"
                placeholder="面积">
                <template #left-icon>
                  <span class="van-f-red"> </span>
                </template>
              </van-field>
              <van-field
                v-if="fromValue.ifJzStoreType == 1"
                v-model="fromValue.area"
                @input="numberFn"
                type="number"
                label="家装展厅面积(m²)"
                placeholder="面积">
                <template #left-icon>
                  <span class="van-f-red">*</span>
                </template>
              </van-field>
            </div>
            <van-field
              v-model="fromValue.contactName"
              v-if="fromValue.ifJzStoreType != 1 && fromValue.storeCategory != 'C917'"
              label="联系人"
              placeholder="联系人">
              <template #left-icon>
                <span class="van-f-red">*</span>
              </template>
            </van-field>
            <van-field
              v-model="fromValue.contactName"
              v-if="fromValue.ifJzStoreType == 1 && fromValue.storeCategory != 'C917'"
              label="老板"
              placeholder="老板">
              <template #left-icon>
                <span class="van-f-red"> </span>
              </template>
            </van-field>
            <van-field
              v-if="fromValue.storeCategory != 'C917'"
              type="tel"
              v-model="fromValue.telephone"
              label="联系电话"
              placeholder="联系电话"
              @blur="phoneCheck">
              <template #left-icon>
                <span class="van-f-red" v-if="fromValue.ifJzStoreType != 1">*</span>
              </template>
            </van-field>
            <van-field
              readonly
              v-model="fromValue.salesmanName"
              label="销售员"
              placeholder="销售员">
              <template #left-icon>
                <span class="van-f-red"> </span>
              </template>
            </van-field>
            <div v-if="GZAttributeFormShow" style="background-color: #ffffff; padding: 10px">
              <p style="color: #666"><span class="van-f-red">*</span>潜在客户类型</p>
              <div style="padding: 4px">
                <van-radio-group v-model="fromValue.potentialCustomerType" class="typeRadioStore1">
                  <van-row gutter="20">
                    <van-col
                      span="12"
                      v-for="(item, index) in potentialCustomerTypeList"
                      :key="index"
                      style="margin-bottom: 10px">
                      <van-radio shape="square" :name="item.dictCode">{{ item.text }}</van-radio>
                    </van-col>
                  </van-row>
                </van-radio-group>
              </div>
            </div>
            <van-field label="是否车铺开店" v-if="typeABshow">
              <template #input>
                <span v-if="fromValue.carShop == 1">是</span>
                <span v-if="fromValue.carShop == 0">否</span>
              </template>
              <template #left-icon>
                <span class="van-f-red">*</span>
              </template>
            </van-field>
            <van-field label="车铺照片" v-if="fromValue.carShop == 1 && typeABshow">
              <template #left-icon>
                <span class="van-f-red">*</span>
              </template>
            </van-field>
            <div v-if="fromValue.carShop == 1 && typeABshow">
              <p
                style="
                  color: #666;
                  font-size: 14px;
                  margin: 0;
                  background-color: #fff;
                  padding: 6px 18px;
                ">
                注:店招及车铺产品拍在一张照片里
              </p>
              <viewUploadImg :imgs="fromValue.carShopImgList"></viewUploadImg>
            </div>
            <!-- 同城分销店提示 同城店铺 未结案时 -->
            <div
              v-if="fromValue.approvalStatus == 0"
              style="font-size: 16px; font-weight: 600; padding: 10px 16px 0 16px">
              该店首批铺货要求<span style="color: red">1000元</span>，请上传陈列照片
            </div>
            <div v-if="fromValue.storeCategory != 'C917'">
              <div style="padding: 0 20px 20px 20px; height: 228px; background-color: #f1f1f1">
                <div class="displayImg">
                  <div class="displayImgBox">
                    <div v-if="storeTypePOP">
                      <upload-img
                        :uploadid="uploadid2"
                        :imgArr="fromValue.img"
                        @newimgarr="newimgarr1"
                        :imgText="fromValue.ifJzStoreType != 1 ? '门头照' : '家装前台照片'"
                        :disabled="true"
                        :type="1"></upload-img>
                    </div>
                    <div v-else>
                      <upload-img
                        :uploadid="uploadid2"
                        :imgArr="fromValue.img"
                        @newimgarr="newimgarr1"
                        :imgText="fromValue.storeCategory == 'C912' ? '工地铭牌照片' : '公司照片'"
                        :type="1"></upload-img>
                    </div>
                  </div>
                  <template
                    v-if="fromValue.ifJzStoreType != 1 && storeTypePOP && displayImg.length">
                    <div class="displayImgBox" v-for="(urls, index) in displayImg" :key="index">
                      <template v-if="fromValue.storeCategory == '126565'">
                        <van-icon
                          name="close"
                          size="16"
                          @click="deleteImg(index)"
                          v-if="
                            fromValue.processApprovalStatus != 1 &&
                            fromValue.processApprovalStatus != 2
                          " />
                      </template>
                      <van-icon name="close" size="16" @click="deleteImg(index)" v-else />
                      <img :src="urls" width="99%" height="99%" @click="previewsImg(index)" />
                      <div class="title">陈列照</div>
                    </div>
                  </template>
                  <div class="displayImgBox" v-if="fromValue.ifJzStoreType != 1">
                    <div v-if="storeTypePOP">
                      <template v-if="fromValue.storeCategory == '126565'">
                        <upload-img
                          v-if="
                            fromValue.processApprovalStatus != 1 &&
                            fromValue.processApprovalStatus != 2
                          "
                          :uploadid="uploadid2"
                          imgArr=""
                          @newimgarr="newimgarr1"
                          imgText="陈列照(至少一张)"
                          :type="2"
                          :count="1"
                          :displayPhoto="fromValue.storeCategory == '126565' ? '1' : '0'"
                          :displayImg="displayImg"></upload-img>
                      </template>
                      <template v-else>
                        <upload-img
                          v-if="fromValue.ifJzStoreType != 1"
                          :uploadid="uploadid2"
                          imgArr=""
                          @newimgarr="newimgarr1"
                          imgText="陈列照(至少一张)"
                          :type="2"
                          :count="1"></upload-img>
                      </template>
                    </div>
                  </div>
                </div>
              </div>
            </div>
            <!-- 无效店铺，关闭店铺 -->
            <!-- <div class="invalid">
              <van-button type="warning" round @click="valid">无效关店</van-button>
            </div> -->
          </van-tab>
          <van-tab title="属性信息" name="Planpic">
            <!-- 同城分销店-属性信息 -->
            <div v-if="dictTypeFormShow" style="background-color: #ffffff; padding: 10px">
              <p style="color: #666; font-size: 14px"><span class="van-f-red">*</span>属性</p>
              <div style="padding: 4px">
                <van-radio-group v-model="fromValue.tcfxName" class="typeRadioStore1">
                  <van-row gutter="20">
                    <van-col
                      span="12"
                      v-for="(item, index) in TCFXList"
                      :key="index"
                      style="margin-bottom: 10px"
                      v-if="item.remark == fromValue.storeCategory">
                      <van-radio shape="square" :name="item.dictCode + ''">{{
                        item.text
                      }}</van-radio>
                    </van-col>
                  </van-row>
                </van-radio-group>
              </div>
              <!-- 主营竞品品牌 -->
              <p style="color: #666; font-size: 14px">
                <span class="van-f-red">*</span>主营竞品品牌
              </p>
              <div style="padding: 4px">
                <van-checkbox-group
                  v-model="fromValue.storeCompetitorList"
                  direction="horizontal"
                  class="typeRadioStore1">
                  <van-row gutter="24">
                    <van-col
                      span="12"
                      v-for="(item, index) in storeCompetitorlist"
                      style="margin-bottom: 10px">
                      <van-checkbox
                        v-if="item.dictLabel != '其他'"
                        :name="item.dictValue"
                        shape="square"
                        :key="index">
                        {{ item.dictValue }}
                      </van-checkbox>
                    </van-col>
                  </van-row>
                </van-checkbox-group>
                <van-field
                  v-if="fromValue.storeCategory != '126565'"
                  name="otherCompetitor"
                  class="otherCompetitor"
                  v-model="fromValue.otherCompetitor"
                  autosize
                  type="textarea"
                  label="其他"
                  maxlength="20"
                  placeholder="请输入" />
              </div>
            </div>
            <div v-if="dictTypeSJSFormShow" style="background-color: #ffffff; padding: 10px">
              <p style="color: #666"><span class="van-f-red">*</span>属性</p>
              <div style="padding: 4px">
                <van-radio-group v-model="fromValue.tcfxName" class="typeRadioStore1">
                  <van-row gutter="20">
                    <van-col
                      span="12"
                      v-for="(item, index) in SJSList"
                      :key="index"
                      style="margin-bottom: 10px">
                      <van-radio shape="square" :name="item.dictCode">{{ item.text }}</van-radio>
                    </van-col>
                  </van-row>
                </van-radio-group>
              </div>
            </div>
            <div v-if="dictTypeAFormShow" style="background-color: #ffffff; padding: 10px">
              <p style="color: #666"><span class="van-f-red">*</span>属性</p>
              <div style="padding: 4px">
                <van-radio-group
                  v-model="fromValue.attribute3"
                  class="typeRadioStore1"
                  @change="attrChange">
                  <van-row gutter="20">
                    <van-col
                      span="12"
                      v-for="(item, index) in brandst"
                      :key="index"
                      style="margin-bottom: 10px">
                      <van-radio shape="square" :name="item.dictCode">{{ item.text }}</van-radio>
                    </van-col>
                  </van-row>
                </van-radio-group>
              </div>
              <van-field
                v-if="attrShow"
                v-model="fromValue.attribute5"
                label="其他品牌"
                placeholder="其他品牌">
                <template #left-icon>
                  <span class="van-f-red">*</span>
                </template>
              </van-field>
            </div>
            <div v-if="dictTypeQGJZFormShow" style="background-color: #ffffff; padding: 10px">
              <p style="color: #666"><span class="van-f-red">*</span>属性</p>
              <div style="padding: 4px">
                <van-radio-group v-model="fromValue.tcfxName" class="typeRadioStore1">
                  <van-row gutter="20">
                    <van-col
                      span="12"
                      v-for="(item, index) in QGJZist"
                      :key="index"
                      style="margin-bottom: 10px">
                      <van-radio shape="square" :name="item.dictCode">{{ item.text }}</van-radio>
                    </van-col>
                  </van-row>
                </van-radio-group>
              </div>
            </div>
          </van-tab>
        </van-tabs>
      </van-form>
    </div>
    <!--类型-->
    <van-popup v-model="showPicker" position="bottom">
      <van-picker
        show-toolbar
        :columns="storeCategoryList"
        value-key="dictLabel"
        @confirm="onConfirm"
        @cancel="showPicker = false" />
    </van-popup>
    <!--经销商-->
    <van-popup
      v-model="showPickerChainsList"
      position="bottom"
      class="agencyBox"
      :close-on-click-overlay="false">
      <!-- 分销店 -->
      <template
        v-if="
          verifyStoreType(fromValue.storeCategory) &&
          verifyStoreType(fromValue.storeCategory).type == 'fxd'
        ">
        <div class="header_btn">
          <div class="cancel" @click="showPickerChainsList = false">取消</div>
          <div class="confirm" @click="treeSelectConfirm">确定</div>
        </div>
        <van-tree-select
          :items="treeSelect"
          :main-active-index.sync="activeIndex"
          @click-nav="clickNav">
          <template #content>
            <div
              class="treeSelectchildren"
              v-if="activeIndex == index"
              v-for="(item, index) in treeSelect"
              :key="index">
              <div
                class="item"
                v-for="(val, ind) in item.children"
                :key="ind"
                @click="treeSelectItemClick(item, index, val, ind)">
                <div
                  :class="{
                    'van-radio__icon': true,
                    'van-radio__icon--round': true,
                    'van-radio__icon--checked': val.Check,
                  }">
                  <i class="van-icon van-icon-success"></i>
                </div>
                <div class="value">{{ val.chainCode }} {{ val.chainName }}</div>
              </div>
            </div>
          </template>
        </van-tree-select>
      </template>
      <template v-else>
        <van-picker
          show-toolbar
          :columns="ChainsList"
          value-key="chainName"
          @confirm="onConfirmChainsList"
          @cancel="showPickerChainsList = false" />
      </template>
    </van-popup>
    <van-popup v-model="moreTypeShow" position="bottom" style="height: 80%; font-size: 14px">
      <van-row style="background-color: #f5f5f5">
        <van-col span="20">
          <van-field
            left-icon="search"
            style="margin-top: 2px; border-radius: 6px; overflow: hidden"
            v-model="chainName"
            label=""
            placeholder="请输入关键词"
            clearable />
        </van-col>
        <van-col
          span="4"
          style="text-align: center; line-height: 48px"
          @click="getChainsByDeptCodesearch">
          <div style="background-color: #0057ba; color: #fff">搜索</div></van-col
        >
      </van-row>
      <van-picker
        show-toolbar
        :columns="ChainsLists"
        value-key="chainName"
        @confirm="onConfirmChainsList"
        @cancel="moreTypeShow = false" />
    </van-popup>
    <van-popup v-model="showPickerDeptList" position="bottom">
      <van-picker
        show-toolbar
        :columns="deptList"
        @confirm="onDeptConfirm"
        @cancel="showPickerDeptList = false" />
    </van-popup>
    <!--同城类型-->
    <van-popup v-model="showTCFXL" position="bottom">
      <van-picker
        show-toolbar
        :columns="TCFXList"
        @confirm="onTCFXLConfirm"
        @cancel="showTCFXL = false" />
    </van-popup>
    <!--省、市、区、街道-->
    <van-popup v-model="showProvincePicker" position="bottom">
      <van-picker
        show-toolbar
        title="省(州)"
        :columns="provinceList"
        @confirm="onProvinceConfirm"
        @cancel="showProvincePicker = false" />
    </van-popup>
    <van-popup v-model="showCityPicker" position="bottom">
      <van-picker
        show-toolbar
        title="城市"
        :columns="cityList"
        @confirm="onCityConfirm"
        @cancel="showCityPicker = false" />
    </van-popup>
    <van-popup v-model="showDistrictPicker" position="bottom">
      <van-picker
        show-toolbar
        title="县区"
        :columns="districtList"
        @confirm="onDistrictConfirm"
        @cancel="showDistrictPicker = false" />
    </van-popup>
    <van-popup v-model="showTownPicker" position="bottom">
      <van-picker
        show-toolbar
        title="街道"
        :columns="townList"
        @confirm="onTownConfirm"
        @cancel="showTownPicker = false" />
    </van-popup>
    <!--    部门数据 -->
    <div id="allmap"></div>
    <div style="position: fixed; top: 0; height: 100%; z-index: 3000; width: 100%" v-if="showmap">
      <div id="allmap1" style="height: 100%; width: 100%"></div>
      <div style="position: fixed; z-index: 99999; top: 0; width: 100%; background-color: white">
        <van-search
          v-model="search"
          shape="round"
          background="#0057ba"
          @input="searchFn"
          placeholder="请输入搜索关键词" />
        <div style="height: 200px; overflow: hidden" v-if="searchSHow">
          <div style="height: 100px; min-height: 200px; overflow-y: scroll; padding: 12px">
            <div
              v-for="(itme, index) in mapsearchlist"
              style="border-bottom: 1px solid #eee"
              @click="addressFns(itme)">
              <p>{{ itme.title }}</p>
              <p>{{ itme.address }}</p>
            </div>
          </div>
        </div>
      </div>
      <div class="mapaddress">
        <div class="title">
          <span @click="showmap = false" style="float: left"
            ><van-icon name="cross" size="16"
          /></span>
          <p class="titleText">附近地址信息</p>
          <span style="float: right" @click="confirmMap">确定</span>
        </div>
        <div class="listBox">
          <van-radio-group v-model="addresssb" @change="mapselect">
            <van-radio :name="index" v-for="(item, index) in maplist" :key="index">
              <p style="margin: 4px 0; font-weight: bold">{{ item.title }}</p>
              <p style="margin: 4px 0">{{ item.address }}</p>
            </van-radio>
          </van-radio-group>
          <br />
          <br />
          <br />
          <br />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {
  updateStore,
  beforeAdd,
  streetQuery,
  getTCFXList,
  getById,
  phoneCheck,
  getChainsByDeptCode,
  addStore,
  checkVisit,
  getSJSList,
  getQGJZist,
  getbrands,
  getCustomerInfoList,
  getCustomerNatureList,
  getMainProjectList,
  getMainRelationList,
  getManagementModelList,
  getpotentialCustomerTypeList,
  getDictOption,
} from '@/api/index';
import uploadImg from '@/components/uploadImgVStore';
import uploadImgc from '@/components/uploadImgVStorec';
import viewUploadImg from '@/components/viewUploadImg';
import mapmarker from '@/components/mapMarker';
import { jsonp } from 'vue-jsonp';
import txmapimg1 from '@/assets/txmap1.svg';
import txmapimg2 from '@/assets/txmap2.svg';
import txmapimg3 from '@/assets/marker_blue.png';
import { valid } from '@/api/visitstore';
import { ImagePreview } from 'vant';
import { getPosition, getTicketFun, getMapPoi, getkeywordPoi } from '@/utils/TXApiFun';
import { listChainsByCategory } from '@/api/store';

export default {
  name: 'storeAdd',
  components: { uploadImg, mapmarker, uploadImgc, viewUploadImg },
  data() {
    return {
      searchSHow: false,
      mapsearchlist: [],
      search: '',
      showmap: false,
      showDialog: false,
      msgList: '',
      tabVal: 'insidePlan',
      typeABshow: false,
      showPickerChainsList: false,
      showDistribute: false,
      showProvincePicker: false,
      showCityPicker: false,
      showDistrictPicker: false,
      showTownPicker: false,
      showPickerDeptList: false,
      dictTypeFormShow: false,
      moreTypeShow: false,
      typeShow: false,
      dictTypeSJSFormShow: false,
      dictTypeAFormShow: false,
      dictTypeQGJZFormShow: false,
      attrShow: false,
      provinceList: [],
      showTCFXL: false,
      show: false,
      cityList: [],
      deptList: [],
      districtList: [],
      cont: 0,
      townList: [],
      uploadid2: 'uploadid2',
      storeTypePOP: false,
      storeName: '名称',
      fromValue: {
        addressLine: '',
        chainCode: '',
        telephone: '',
        storeCategoryName: '',
        provinceName: '',
        salesmanName: '',
        orgName: '',
        lat: '',
        lon: '',
        districtName: '',
        contactName: '',
        cityName: '',
        cityLevel: '',
        potentialCustomerType: '',
        storeName: '',
        storeCategory: '',
        area: '',
        img: '',
        imgSed: '',
        townName: '',
        tcfxName: '',
        tcfxCode: '',
        orgId: '',
        carShop: '',
        carShopImgList: [],
        showroom: '',
        attribute3: '',
        attribute5: '',
        customerInfoFrom: '',
        customerNature: '',
        managementModel: '',
        mainProjectType: '',
        mainRelationFrom: '',
        storeCompetitorList: [],
        otherCompetitor: '',
      },
      img: 'https://svs-test.oss-cn-shanghai.aliyuncs.com/1647398239620微信截图_20220315112921.png',
      location: {
        lat: '34.616712',
        lon: '112.440816',
      },
      checkboxGroup: [],
      radio: '',
      Radiocolumns: [
        { name: '1', text: '选项01' },
        { name: '2', text: '选项02' },
      ],
      showPicker: false,
      cityLeveList: [],
      storeTypeList: [],
      storeCategoryList: [],
      ChainsList: [],
      TCFXList: [],
      imgs: [],
      provinceCode: '',
      cityCode: '',
      countyCode: '',
      districtName: '',
      contactName: '',
      cityName: '',
      cityLevel: '',
      storeCategory: '',
      phoneNumber: true,
      sfaOrderProducts: [],
      deptShow: false,
      validFlag: '',
      QGJZist: [],
      SJSList: [],
      chainName: '',
      ChainsLists: [],
      address: '地址',
      brandst: [],
      maplist: [],
      ManagementModelList: [],
      MainRelationList: [],
      MainProjectList: [],
      CustomerNatureList: [],
      CustomerInfoList: [],
      potentialCustomerTypeList: [],
      GZAttributeFormShow: false,
      addresssb: -1,
      markers: undefined,
      markers1: undefined,
      marker: undefined,
      pageShow: false,
      map: '',
      pLat: '',
      pLot: '',
      displayImg: [],
      activeIndex: 0,
      treeSelectItemInd: 0,
      treeSelect: [],
      sfaStoreChainsContactList: [], //选中确定的经销商
      activatedTCFXList: [], //选中的经销商
      chainUser: false, //是否经销商用户 true
      storeCompetitorlist: [], //主营竞品品牌
      otherCompetitor: '', //主营竞品品牌-其他
      activatedStoreCompetitor: [],
    };
  },
  activated() {
    this.chainUser = localStorage.getItem('chainUser'); //经销商人员（包含分销、先锋）
    this.tabVal = 'insidePlan';
    this.treeSelect = [];
    // 授权
    getTicketFun(['getLocation', 'chooseImage', 'uploadImage']).then(() => {
      this.getTCFXList();
      this.getSJSList();
      this.getQGJZist();
      this.getDetail();
      this.getbrands();
      this.getStreetQuery();
      this.getCustomerInfoList();
      this.getManagementModelList();
      this.getMainRelationList();
      this.getMainProjectList();
      this.getCustomerNatureList();
      this.getpotentialCustomerTypeList();
      this.showmap = false;
    });
  },
  methods: {
    addressFns(val) {
      var that = this;
      setTimeout(() => {
        that.searchSHow = false;
        that.map.setCenter(new TMap.LatLng(val.location.lat, val.location.lng));
        that.markers1.updateGeometries([
          {
            id: 'marker',
            styleId: 'marker',
            position: new TMap.LatLng(val.location.lat, val.location.lng),
          },
        ]);
        that.maplist = [];
        // 地点搜索 获取500米范围poi点
        getMapPoi({ latitude: val.location.lat, longitude: val.location.lng }).then((res) => {
          console.log(res);
          that.maplist = res.data;
          that.marker.setGeometries([]);
          setTimeout(() => {
            for (let p = 0; p < res.data.length; p++) {
              that.marker.updateGeometries([
                {
                  id: res.data[p].id,
                  position: new TMap.LatLng(res.data[p].location.lat, res.data[p].location.lng),
                },
              ]);
            }
          });
        });
        that.addresssb = -1;
      });
    },
    searchFn(val) {
      this.searchSHow = false;
      getkeywordPoi({ latitude: this.pLat, longitude: this.pLot }, val).then((res) => {
        // 不显示下拉选择
        if (!res.data.length && !val) {
          this.searchSHow = false;
        } else {
          this.searchSHow = true;
        }
        // 联想下拉选
        this.mapsearchlist = res.data;
      });
    },
    mapselect(val) {
      this.searchSHow = false;
      if (val > -1) {
        this.markers.updateGeometries([
          {
            id: 'markers1',
            styleId: 'abc',
            position: new TMap.LatLng(
              this.maplist[val].location.lat,
              this.maplist[val].location.lng,
            ),
          },
        ]);
      }
    },
    confirmMap() {
      if (this.addresssb > -1) {
        let checkedPoint = this.maplist[this.addresssb];
        // 坐标转换
        let TXisBD = this.CJ02BD(checkedPoint.location.lat, checkedPoint.location.lng);
        this.fromValue.addressLine = checkedPoint.address;
        var location = this.CJ02BD(this.pLat, this.pLot);
        this.fromValue.lat = location.lat;
        this.fromValue.lon = location.lon;
        this.fromValue.poiAddress = checkedPoint.address;
        this.fromValue.poiLat = TXisBD.lat;
        this.fromValue.poiLon = TXisBD.lon;
        this.fromValue.poiId = checkedPoint.id;
        this.fromValue.poiName = checkedPoint.title;
      }
      this.showmap = false;
    },
    fns() {
      this.search = '';
      getPosition()
        .then((res) => {
          let { TXisBD, resData } = res;
          this.pLat = resData.latitude;
          this.pLot = resData.longitude;
          if (this.fromValue.lon == '') {
            this.fromValue.lon = TXisBD.lon;
            this.fromValue.lat = TXisBD.lat;
          }
          this.showmap = true;
          // 地点搜索 获取500米范围poi点
          getMapPoi({ latitude: this.pLat, longitude: this.pLot }).then((res) => {
            console.log(res);
            this.maplist = res.data;
            setTimeout(() => {
              this.addVisits1('1');
            });
          });
        })
        .catch((error) => {
          this.$dialog.alert({
            message: error,
          });
        });
      this.addresssb = -1;
    },
    addVisits1(val) {
      var that = this;
      var latlng = {
        lat: this.pLat,
        lon: this.pLot,
      };
      var map = new TMap.Map('allmap1', {
        zoom: 15,
        center: new TMap.LatLng(latlng.lat, latlng.lon),
      });
      var markers = new TMap.MultiMarker({
        id: 'markers',
        map: map,
        geometries: [],
        styles: {
          marker: new TMap.MarkerStyle({
            width: 32,
            height: 40,
            anchor: { x: 16, y: 32 },
            src: 'https://mapapi.qq.com/web/lbs/javascriptGL/demo/img/marker-pink.png',
          }),
        },
      });
      markers.setGeometries([]);
      var location = new TMap.LatLng(latlng.lat, latlng.lon);
      map.setCenter(location);
      markers.updateGeometries([
        {
          id: 'marker',
          styleId: 'marker',
          position: location,
        },
      ]);
      var marker = new TMap.MultiMarker({
        map: map,
        styles: {
          default: new TMap.MarkerStyle({
            width: 32,
            height: 40,
            anchor: {
              x: 17,
              y: 21,
            },
            src: 'https://mapapi.qq.com/web/lbs/javascriptGL/demo/img/marker_blue.png',
          }),
        },
        geometries: [],
      });
      marker.setGeometries([]);
      setTimeout(() => {
        for (let p = 0; p < this.maplist.length; p++) {
          marker.updateGeometries([
            {
              id: this.maplist[p].id,
              position: new TMap.LatLng(this.maplist[p].location.lat, this.maplist[p].location.lng),
            },
          ]);
        }
      });
      var markers1 = new TMap.MultiMarker({
        map: map,
        mapgeometries: [
          {
            id: 'markers1',
            position: new TMap.LatLng(0, 0),
          },
        ],
        styles: {
          abc: new TMap.MarkerStyle({
            width: 32,
            height: 40,
            anchor: { x: 16, y: 32 },
            src: txmapimg3,
          }),
        },
      });
      markers1.setGeometries([]);
      this.map = map;
      this.markers = markers1;
      this.markers1 = markers;
      this.marker = marker;
      map.removeControl(TMap.constants.DEFAULT_CONTROL_ID.SCALE);
      map.removeControl(TMap.constants.DEFAULT_CONTROL_ID.ROTATION);
      map.removeControl(TMap.constants.DEFAULT_CONTROL_ID.ZOOM);
    },
    addressFn() {
      localStorage.setItem('locationRemark', this.fromValue.addressLine);
    },
    getChainsByDeptCodesearch(chainName) {
      this.ChainsLists = [];
      getChainsByDeptCode({
        chainName: this.chainName,
        cityName: this.fromValue.cityNameOld,
        districtName: this.fromValue.districtNameOld,
        deptId: this.fromValue.deptId,
        ifJzStoreType: this.fromValue.ifJzStoreType,
        storeCategory: this.fromValue.storeCategory,
      }).then((res) => {
        this.ChainsLists = res.data.sfaChains;
        this.ChainsLists.push({});
        this.ChainsLists.pop();
      });
    },
    //
    PickerDept() {
      if (this.deptShow) {
        this.showPickerDeptList = true;
      }
    },
    handleSelectionChange(val) {
      this.fromValue.orderProductStoreList = val;
    },
    getpotentialCustomerTypeList() {
      getpotentialCustomerTypeList().then((res) => {
        var potentialCustomerTypeList = [];
        for (var t = 0; t < res.data.length; t++) {
          potentialCustomerTypeList.push({
            text: res.data[t].dictLabel,
            dictCode: res.data[t].dictValue,
          });
        }
        this.potentialCustomerTypeList = potentialCustomerTypeList;
      });
    },
    getChainsByDeptCode(deptCode, ifJzStoreType) {
      getChainsByDeptCode({
        cityName: this.fromValue.cityName,
        districtName: this.fromValue.districtName,
        deptId: deptCode,
        ifJzStoreType: ifJzStoreType,
        storeCategory: this.fromValue.storeCategory,
      }).then((res) => {
        if (res.data.deptList.length == 1) {
          this.fromValue.orgId = res.data.deptList[0].deptId;
          this.fromValue.orgName = res.data.deptList[0].deptName;
          localStorage.setItem('orgName', res.data.deptList[0].deptName);
          this.ChainsList = res.data.sfaChains;
          this.deptShow = false;
        } else {
          this.deptShow = true;
          this.ChainsList = [];
          var deptList = [];
          for (var t1 = 0; t1 < res.data.deptList.length; t1++) {
            deptList.push({
              deptId: res.data.deptList[t1].deptId,
              text: res.data.deptList[t1].deptName,
            });
          }
          this.deptList = deptList;
        }
        var arrlist = [];
        if (res.data.sfaOrderProducts != null) {
          for (var n1 = 0; n1 < this.fromValue.orderProductStoreList.length; n1++) {
            for (var n2 = 0; n2 < res.data.sfaOrderProducts.length; n2++) {
              res.data.sfaOrderProducts[n2].storeProductId =
                res.data.sfaOrderProducts[n2].orderProductId;
              if (
                res.data.sfaOrderProducts[n2].orderProductId ==
                this.fromValue.orderProductStoreList[n1].productId
              ) {
                res.data.sfaOrderProducts[n2].orderNum =
                  this.fromValue.orderProductStoreList[n1].orderNum;
                res.data.sfaOrderProducts[n2].storeProductId =
                  this.fromValue.orderProductStoreList[n1].storeProductId;
                arrlist.push(res.data.sfaOrderProducts[n2]);
              }
            }
          }
          this.sfaOrderProducts = res.data.sfaOrderProducts;
        }
      });
    },
    getCustomerInfoList() {
      getCustomerInfoList().then((res) => {
        var CustomerInfoList = [];
        for (var t = 0; t < res.data.length; t++) {
          CustomerInfoList.push({ text: res.data[t].dictLabel, dictCode: res.data[t].dictValue });
        }
        this.CustomerInfoList = CustomerInfoList;
      });
    },
    getCustomerNatureList() {
      getCustomerNatureList().then((res) => {
        var CustomerNatureList = [];
        for (var t = 0; t < res.data.length; t++) {
          CustomerNatureList.push({ text: res.data[t].dictLabel, dictCode: res.data[t].dictValue });
        }
        this.CustomerNatureList = CustomerNatureList;
      });
    },
    getMainProjectList() {
      getMainProjectList().then((res) => {
        var MainProjectList = [];
        for (var t = 0; t < res.data.length; t++) {
          MainProjectList.push({ text: res.data[t].dictLabel, dictCode: res.data[t].dictValue });
        }
        this.MainProjectList = MainProjectList;
      });
    },
    getMainRelationList() {
      getMainRelationList().then((res) => {
        var MainRelationList = [];
        for (var t = 0; t < res.data.length; t++) {
          MainRelationList.push({ text: res.data[t].dictLabel, dictCode: res.data[t].dictValue });
        }
        this.MainRelationList = MainRelationList;
      });
    },
    getManagementModelList() {
      getManagementModelList().then((res) => {
        var ManagementModelList = [];
        for (var t = 0; t < res.data.length; t++) {
          ManagementModelList.push({
            text: res.data[t].dictLabel,
            dictCode: res.data[t].dictValue,
          });
        }
        this.ManagementModelList = ManagementModelList;
      });
    },
    getChainsByDeptId(deptCode, ifJzStoreType) {
      getChainsByDeptCode({
        cityName: this.fromValue.cityName,
        districtName: this.fromValue.districtName,
        deptId: deptCode,
        ifJzStoreType: ifJzStoreType,
        storeCategory: this.fromValue.storeCategory,
      }).then((res) => {
        this.ChainsList = res.data.sfaChains;
      });
    },
    onDeptConfirm(value) {
      this.fromValue.orgName = value.text;
      localStorage.setItem('orgName', value.text);
      this.fromValue.orgId = value.deptId;
      this.fromValue.chainCode = '';
      this.fromValue.chainName = '';
      this.getChainsByDeptId(value.deptId, this.fromValue.ifJzStoreType);
      this.showPickerDeptList = false;
    },
    setStoreNameFn() {
      localStorage.setItem('chainName', this.fromValue.storeName);
    },
    attrChange(val) {
      if (val == '0') {
        this.attrShow = true;
      } else {
        this.attrShow = false;
        this.fromValue.attribute5 = '';
      }
    },
    getStreetQuery(type) {
      var provinceCode = '';
      var cityCode = '';
      var countyCode = '';
      if (type == '1') {
        provinceCode = this.fromValue.province;
        cityCode = '';
        countyCode = '';
      } else if (type == '2') {
        provinceCode = this.fromValue.province;
        cityCode = this.fromValue.city;
        countyCode = '';
      } else if (type == '3') {
        provinceCode = this.fromValue.province;
        cityCode = this.fromValue.city;
        countyCode = this.fromValue.district;
      } else {
        provinceCode = '';
        cityCode = '';
        countyCode = '';
      }
      streetQuery({ provinceCode: provinceCode, cityCode: cityCode, countyCode: countyCode }).then(
        (res) => {
          var provinceList = [];
          var cityList = [];
          var districtList = [];
          var townList = [];
          if (type == '1') {
            for (var z1 = 0; z1 < res.data.length; z1++) {
              cityList.push({ cityCode: res.data[z1].cityCode, text: res.data[z1].cityName });
            }
            this.cityList = cityList;
          } else if (type == '2') {
            for (var z2 = 0; z2 < res.data.length; z2++) {
              districtList.push({
                countyCode: res.data[z2].countyCode,
                text: res.data[z2].countyName,
                countyLevel: res.data[z2].countyLevel,
              });
            }
            this.districtList = districtList;
          } else if (type == '3') {
            for (var z3 = 0; z3 < res.data.length; z3++) {
              townList.push({ townCode: res.data[z3].townCode, text: res.data[z3].townName });
            }
            this.townList = townList;
          } else {
            for (var z = 0; z < res.data.length; z++) {
              provinceList.push({
                provinceCode: res.data[z].provinceCode,
                text: res.data[z].provinceName,
              });
            }
            this.provinceList = provinceList;
          }
        },
      );
    },
    getDetail() {
      // 获取当前定位
      this.getLocation();
      this.phoneNumber = true;
      let loading1 = this.$toast.loading({
        duration: 0,
        message: '加载中...',
        forbidClick: true,
      });
      var postType = localStorage.getItem('postType');
      if (postType == 'GZ') {
        this.typeShow = false;
      } else {
        this.typeShow = true;
      }

      getById({ storeId: this.$route.query.id }).then((res) => {
        loading1.clear();
        this.validFlag = this.$route.query.validFlag;

        if (res.code == 200) {
          this.fromValue = res.data;
          this.fromValue.storeCompetitorList = this.fromValue.storeCompetitorList || [];
          this.sfaStoreChainsContactList = this.fromValue.sfaStoreChainsContactList;
          if (this.fromValue.imgSed && this.fromValue.imgSed != '') {
            this.displayImg = this.fromValue.imgSed.split(',');
          } else {
            this.displayImg = [];
          }
          if (this.fromValue.lat != null) {
          } else {
            this.fromValue.lat = '';
            this.fromValue.lon = '';
          }
          localStorage.setItem('locationRemark', res.data.addressLine);
          localStorage.setItem('orgName', res.data.orgName);
          if (
            this.fromValue.potentialCustomerType != null &&
            this.fromValue.potentialCustomerType != undefined
          ) {
          } else {
            this.fromValue.potentialCustomerType = '';
          }
          if (this.fromValue.carShopImgList != null) {
          } else {
            this.fromValue.carShopImgList = [];
          }
          if (this.fromValue.attribute3 != null) {
          } else {
            this.fromValue.attribute3 = '';
          }
          if (this.fromValue.attribute5 != null) {
          } else {
            this.fromValue.attribute5 = '';
          }
          // this.getChainsByDeptCode(res.data.orgId)
          this.getChainsByDeptCode(null, res.data.ifJzStoreType);
          if (
            this.verifyStoreType(this.fromValue.storeCategory) &&
            this.verifyStoreType(this.fromValue.storeCategory).type == 'fxd'
          ) {
            this.typeABshow = true;
            this.dictTypeFormShow = true;
          }
          // if (this.fromValue.storeCategory == '129081') {
          //   this.dictTypeAFormShow = true;
          // }
          // if (this.fromValue.storeCategory == '10131') {
          //   this.dictTypeFormShow = true;
          // }

          if (this.fromValue.attribute3 == '0') {
            this.attrShow = true;
          }
          if (this.fromValue.storeCategory == 'sjs61') {
            this.dictTypeSJSFormShow = true;
          }
          if (this.fromValue.storeCategory == 'zyjz63') {
            this.dictTypeQGJZFormShow = true;
          } else {
            this.dictTypeQGJZFormShow = false;
          }
          if (this.fromValue.storeCategory == 'C912') {
            this.storeTypePOP = false;
            this.storeName = '铭牌上项目名称';
            this.address = '地址';
          } else if (this.fromValue.storeCategory == 'C917') {
            this.storeTypePOP = false;
            this.storeName = '名称';
            this.address = '地址';
          } else {
            this.storeTypePOP = true;
            this.storeName = '名称';
            this.address = '地址';
          }
          if (this.fromValue.storeCategory == 'C917') {
            this.GZAttributeFormShow = true;
            this.dictTypeSJSFormShow = false;
            this.dictTypeQGJZFormShow = false;
            this.dictTypeFormShow = false;
            this.dictTypeAFormShow = false;
            this.typeABshow = false;
          } else {
            this.GZAttributeFormShow = false;
          }
          localStorage.setItem('chainName', res.data.storeName);
          this.getStreetQuery();
          this.getStreetQuery('1');
          this.getStreetQuery('2');
          this.getStreetQuery('3');
          this.beforeAddFn(res.data.ifJzStoreType);
        } else {
          this.$toast.fail(res.msg);
        }
        this.getTCompetitiveProduct();
      });
    },
    newimgarr1(val) {
      if (val.type == '1') {
        this.fromValue.img = val.fileUrl;
      } else if (val.type == '2') {
        // this.fromValue.imgSed = val.fileUrl;
        this.displayImg.push(val.fileUrl);
      } else {
        this.fromValue.carShopImgList.push(val.fileUrl);
      }
    },
    // 关闭无效店铺
    valid() {
      this.$dialog
        .confirm({
          title: '系统提示',
          message: '是否确认无效关店？',
        })
        .then(() => {
          this.toastLoading();
          valid({ storeId: this.$route.query.id }).then((res) => {
            this.toastLoading().clear();
            if (res.code == 200) {
              this.$router.go(-2);
            } else {
              this.Toast({
                message: res.msg,
                duration: 3000,
              });
            }
          });
        });
    },
    beforeAddFn(ifJzStoreType) {
      beforeAdd({
        cityName: this.fromValue.cityName,
        districtName: this.fromValue.districtName,
        ifJzStoreType: ifJzStoreType,
        storeId: this.$route.query.id,
      }).then((res) => {
        this.storeCategoryList = res.data.storeCategoryList;
      });
    },
    getbrands() {
      getbrands({}).then((res) => {
        var brandst = [];
        for (var t = 0; t < res.data.length; t++) {
          brandst.push({ text: res.data[t].dictLabel, dictCode: res.data[t].dictValue });
        }
        this.brandst = brandst;
      });
    },
    addVisits2() {
      var that = this;
      var map = new TMap.Map('allmap', {
        zoom: 15,
        center: new TMap.LatLng(39.986785, 116.301012),
      });
      var geocoder = new TMap.service.Geocoder(); // 新建一个正逆地址解析类
      var markers = new TMap.MultiMarker({
        map: map,
        geometries: [],
      });
      markers.setGeometries([]);
      var latlng = this.gcj02BD(this.fromValue.lat, this.fromValue.lon);
      var location = new TMap.LatLng(latlng.lat, latlng.lon);
      map.setCenter(location);
      markers.updateGeometries([
        {
          id: 'marker',
          position: location,
        },
      ]);
      geocoder.getAddress({ location: location }).then(function (result) {
        var addresses = result.result.formatted_addresses;
        (that.cityName = result.result.ad_info.city),
          (that.districtName = result.result.ad_info.district),
          (that.provinceName = result.result.ad_info.province),
          (that.addressLine = addresses.recommend);
        localStorage.setItem('locationRemark', addresses.recommend);
        localStorage.setItem('address', addresses.recommend);
        that.beforeAddFn();
      });
    },
    getLocation() {
      getPosition()
        .then((res) => {
          let { TXisBD } = res;
          this.location = TXisBD;
          this.fromValue.lat = TXisBD.lat;
          this.fromValue.lon = TXisBD.lon;
        })
        .catch((error) => {
          this.$dialog.alert({
            message: error,
          });
        });
    },
    showPickerChainsListFn() {
      if (this.chainUser == 'true') return;
      if (this.fromValue.storeCategoryName == '') {
        this.$toast('类型未选择');
        return;
      } else if (this.fromValue.orgName == '') {
        this.$toast('部门未选择');
        return;
      } else {
        // 分销店
        if (
          this.verifyStoreType(this.fromValue.storeCategory) &&
          this.verifyStoreType(this.fromValue.storeCategory).type == 'fxd'
        ) {
          this.getStoreChainsContact();
        } else {
          this.showPickerChainsList = true;
        }
      }
    },
    // 同城分销-属性信息
    getTCFXList() {
      getTCFXList({}).then((res) => {
        var TCFXList = [];
        for (var t = 0; t < res.data.length; t++) {
          TCFXList.push({
            text: res.data[t].dictLabel,
            dictCode: res.data[t].dictValue,
            remark: res.data[t].remark,
          });
        }
        this.TCFXList = TCFXList;
      });
    },
    // 竞品品牌
    getTCompetitiveProduct() {
      let zidian =
        this.fromValue.storeCategory == '126565'
          ? 'wj_main_competitor_brands'
          : 'main_competitor_brands';
      getDictOption({}, zidian).then((res) => {
        this.storeCompetitorlist = res.data;
      });
    },
    getSJSList() {
      getSJSList({}).then((res) => {
        var SJSList = [];
        for (var t = 0; t < res.data.length; t++) {
          SJSList.push({ text: res.data[t].dictLabel, dictCode: res.data[t].dictValue });
        }
        this.SJSList = SJSList;
      });
    },
    getQGJZist() {
      getQGJZist({}).then((res) => {
        var QGJZist = [];
        for (var t = 0; t < res.data.length; t++) {
          QGJZist.push({ text: res.data[t].dictLabel, dictCode: res.data[t].dictValue });
        }
        this.QGJZist = QGJZist;
      });
    },
    onProvinceConfirm(value) {
      this.fromValue.provinceName = value.text;
      this.fromValue.province = value.provinceCode;
      this.fromValue.cityName = '';
      this.fromValue.city = '';
      this.fromValue.districtName = '';
      this.fromValue.district = '';
      this.fromValue.townName = '';
      this.fromValue.townCode = '';
      this.countyCode = '';
      this.cityCode = '';
      this.provinceCode = value.provinceCode;
      this.getStreetQuery('1');
      this.showProvincePicker = false;
    },
    onCityConfirm(value) {
      this.fromValue.cityName = value.text;
      this.fromValue.city = value.cityCode;
      this.fromValue.districtName = '';
      this.fromValue.district = '';
      this.fromValue.townName = '';
      this.fromValue.townCode = '';
      this.countyCode = '';
      this.cityCode = value.cityCode;
      this.getStreetQuery('2');
      this.showCityPicker = false;
    },
    onDistrictConfirm(value) {
      this.fromValue.districtName = value.text;
      this.fromValue.district = value.countyCode;
      this.fromValue.townName = '';
      this.fromValue.townCode = '';
      this.countyCode = value.countyCode;
      this.fromValue.cityLevel = value.countyLevel;
      this.getStreetQuery('3');
      this.showDistrictPicker = false;
    },
    onTownConfirm(value) {
      this.fromValue.townName = value.text;
      this.fromValue.townCode = value.townCode;
      this.showTownPicker = false;
    },
    onTCFXLConfirm(value) {
      this.fromValue.tcfxName = value.text;
      this.fromValue.tcfxCode = value.dictCode;
      this.showTCFXL = false;
    },
    moreTypeShowFn() {
      if (this.fromValue.storeCategoryName == '') {
        this.$toast('类型未选择');
        return;
      } else if (this.fromValue.orgName == '') {
        this.$toast('部门未选择');
        return;
      } else {
        this.ChainsLists = [];
        this.moreTypeShow = true;
      }
    },
    onConfirm(value) {
      // || value.dictValue == "129081" ||value.dictValue == "10131"
      this.fromValue.storeCategoryName = value.text;
      this.fromValue.storeCategory = value.dictValue;
      if (
        this.verifyStoreType(this.fromValue.storeCategory) &&
        this.verifyStoreType(this.fromValue.storeCategory).type == 'fxd'
      ) {
        this.typeABshow = true;
        this.dictTypeFormShow = true;
      } else {
        this.typeABshow = false;
        this.fromValue.carShop = '';
        this.fromValue.carShopImgList = [];
        this.fromValue.tcfxName = '';
        this.fromValue.tcfxCode = '';
        this.dictTypeFormShow = false;
      }

      // if (value.dictValue == '129081') {
      //   this.dictTypeAFormShow = true;
      // } else {
      //   this.fromValue.tcfxName = '';
      //   this.fromValue.tcfxCode = '';
      //   this.dictTypeAFormShow = false;
      // }
      if (value.dictValue == 'C917') {
        this.GZAttributeFormShow = true;
        this.dictTypeSJSFormShow = false;
        this.dictTypeQGJZFormShow = false;
        this.dictTypeFormShow = false;
        this.dictTypeAFormShow = false;
        this.typeABshow = false;
      } else {
        this.fromValue.tcfxName = '';
        this.fromValue.tcfxCode = '';
        this.GZAttributeFormShow = false;
      }
      // if (value.dictValue == '10131') {
      //   this.dictTypeFormShow = true;
      // } else {
      //   this.fromValue.tcfxName = '';
      //   this.fromValue.tcfxCode = '';
      //   this.dictTypeFormShow = false;
      // }
      if (value.dictValue == 'sjs61') {
        this.dictTypeSJSFormShow = true;
      } else {
        this.fromValue.tcfxName = '';
        this.fromValue.tcfxCode = '';
        this.dictTypeSJSFormShow = false;
      }
      if (value.dictValue == 'zyjz63') {
        this.dictTypeQGJZFormShow = true;
      } else {
        this.fromValue.tcfxName = '';
        this.fromValue.tcfxCode = '';
        this.dictTypeQGJZFormShow = false;
      }
      if (this.fromValue.ifJzStoreType == 1 && value.ifJzStoreType != 1) {
        this.$toast('家装公司不能变为同城店');
        return;
      } else if (this.fromValue.ifJzStoreType != 1 && value.ifJzStoreType == 1) {
        this.$toast('同城店不能变为家装公司');
        return;
      } else {
        this.fromValue.chainName = '';
        this.fromValue.chainCode = '';
        this.fromValue.orgName = '';
        this.fromValue.orgId = '';
        this.fromValue.storeCategoryName = value.dictLabel;
        this.fromValue.storeCategory = value.dictValue;
        this.fromValue.ifJzStoreType = value.ifJzStoreType;
        this.getChainsByDeptCode(null, value.ifJzStoreType);
        // 切换门店类型删除选定经销商
        // 同城分销人员禁止切换经销商
        if (this.chainUser == 'false') {
          this.treeSelect = [];
          this.sfaStoreChainsContactList = []; //选中确定的经销商
          this.activatedTCFXList = []; //选中的经销商
        }
        this.showPicker = false;
      }
      if (value.dictValue == 'C912') {
        this.storeTypePOP = false;
        this.storeName = '铭牌上项目名称';
        this.address = '地址';
      } else if (value.dictValue == 'C917') {
        this.storeTypePOP = false;
        this.storeName = '名称';
        this.address = '地址';
      } else {
        this.storeTypePOP = true;
        this.storeName = '名称';
        this.address = '地址';
      }
    },
    onConfirmChainsList(value) {
      this.fromValue.chainName = value.chainName;
      this.fromValue.chainCode = value.chainCode;
      this.showPickerChainsList = false;
      this.moreTypeShow = false;
    },
    numberFn() {
      if (Number(this.fromValue.area) < 1) {
        this.fromValue.area = '';
      } else {
        this.fromValue.area = this.fromValue.area.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1');
      }
    },
    onSubmit() {
      this.fromValue.imgSed = this.displayImg.join(',');
      for (var n1 = 0; n1 < this.fromValue.orderProductStoreList.length; n1++) {
        for (var n2 = 0; n2 < this.sfaOrderProducts.length; n2++) {
          if (
            this.sfaOrderProducts[n2].storeProductId ==
            this.fromValue.orderProductStoreList[n1].storeProductId
          ) {
            this.fromValue.orderProductStoreList[n1].orderNum = this.sfaOrderProducts[n2].orderNum;
          }
        }
      }
      var fromValue = JSON.parse(JSON.stringify(this.fromValue));
      if (fromValue.storeCompetitorList == null || fromValue.storeCompetitorList == undefined) {
        fromValue.storeCompetitorList = [];
      }
      this.activatedStoreCompetitor = [];
      var telrg = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
      if (fromValue.orgId == '') {
        this.$toast('部门未选择');
        return;
      } else if (fromValue.storeName == '') {
        if (fromValue.storeCategory == 'C912') {
          this.$toast('铭牌上项目名称未填写');
        } else if (fromValue.storeCategory == 'C917') {
          this.$toast('名称未填写');
        } else {
          this.$toast('名称未填写');
        }
        return;
      } else if (fromValue.addressLine == '') {
        if (fromValue.storeCategory == 'C912') {
          this.$toast('地址未填写');
        } else if (fromValue.storeCategory == 'C917') {
          this.$toast('地址未填写');
        } else {
          this.$toast('地址未填写');
        }
        return;
      } else if (fromValue.storeCategoryName == '') {
        this.$toast('类型未填写');
        return;
      } else if (fromValue.provinceName == '') {
        this.$toast('所在省份未填写');
        return;
      } else if (fromValue.cityName == '') {
        this.$toast('所在城市未填写');
        return;
      } else if (fromValue.districtName == '') {
        this.$toast('所在县区未填写');
        return;
      } else if (fromValue.townName == '') {
        this.$toast('所在街道未填写');
        return;
      } else if (
        fromValue.contactName == '' &&
        fromValue.ifJzStoreType != 1 &&
        fromValue.storeCategory != 'C917'
      ) {
        this.$toast('联系人未填写');
        return;
      } else if (
        fromValue.telephone.trim() == '' &&
        fromValue.ifJzStoreType != 1 &&
        fromValue.storeCategory != 'C917'
      ) {
        this.$toast('联系电话未填写');
        return;
      } else if (
        !telrg.test(fromValue.telephone) &&
        fromValue.ifJzStoreType != 1 &&
        fromValue.storeCategory != 'C917'
      ) {
        this.$toast('手机号格式错误');
        return;
      } else if (
        !this.phoneNumber &&
        fromValue.ifJzStoreType != 1 &&
        fromValue.storeCategory != 'C917'
      ) {
        this.$toast('不能填写业务员手机号');
        return;
      } else if (fromValue.img == '' && fromValue.storeCategory != 'C917') {
        if (this.storeTypePOP) {
          if (fromValue.ifJzStoreType != 1) {
            this.$toast('图片未上传');
          } else {
            this.$toast('家装前台照片未上传');
          }
        } else {
          this.$toast('照片未上传');
        }
        return;
      } else if (
        (fromValue.storeCategory == 'sjs61' || fromValue.storeCategory == 'zyjz63') &&
        fromValue.tcfxName == ''
      ) {
        this.$toast('属性未填写');
        return;
      }
      if (fromValue.area.trim() == '' && fromValue.ifJzStoreType == 1) {
        this.$toast('家装展厅面积未填写');
        return;
      }
      if (this.GZAttributeFormShow && fromValue.potentialCustomerType == '') {
        this.$toast('潜在客户类型未填写');
        return;
      }

      // 同城分销类型门店
      if (
        this.verifyStoreType(this.fromValue.storeCategory) &&
        this.verifyStoreType(this.fromValue.storeCategory).type == 'fxd'
      ) {
        // 同城分销多经销商
        fromValue.sfaStoreChainsContactList = this.sfaStoreChainsContactList;
        if (!this.sfaStoreChainsContactList || !this.sfaStoreChainsContactList.length) {
          this.$toast('经销商未填写');
          return;
        }
        if (fromValue.tcfxName == '') {
          this.$toast('属性未填写');
          return;
        }
        if (fromValue.imgSed == '') {
          this.$toast('图片未上传');
          return;
        }
        if (this.fromValue.storeCategory == '126565') {
          if (!fromValue.storeCompetitorList.length) {
            this.$toast('主营竞品品牌未填写');
            return;
          }
          this.activatedStoreCompetitor = JSON.parse(
            JSON.stringify(this.fromValue.storeCompetitorList),
          );
        } else {
          if (!fromValue.storeCompetitorList.length && !fromValue.otherCompetitor) {
            this.$toast('主营竞品品牌未填写');
            return;
          }
          this.activatedStoreCompetitor = JSON.parse(
            JSON.stringify(this.fromValue.storeCompetitorList),
          );
          if (this.fromValue.otherCompetitor) {
            if (this.fromValue.otherCompetitor.length < 2) {
              this.$toast('主营竞品品牌其他文本信息最少2个字');
              return;
            } else {
              this.activatedStoreCompetitor.push(this.fromValue.otherCompetitor);
            }
          }
        }
        fromValue.storeCompetitorList = JSON.parse(JSON.stringify(this.activatedStoreCompetitor));
      } else {
        // 非同城分销店 经销商必填校验
        if (
          fromValue.chainName == '' &&
          fromValue.ifJzStoreType != 1 &&
          fromValue.storeCategory != 'C912' &&
          fromValue.storeCategory != 'C917'
        ) {
          this.$toast('经销商未选择');
          return;
        }
      }

      let loading1 = this.$toast.loading({
        duration: 0,
        message: '加载中...',
        forbidClick: true,
      });
      // 当前定位复制
      fromValue.myLat = this.location.lat;
      fromValue.myLon = this.location.lon;
      console.log(fromValue);
      updateStore(fromValue).then((res) => {
        loading1.clear();
        if (res.code == 200) {
          this.$dialog
            .alert({
              title: '系统提示',
              message: res.msg,
            })
            .then(() => {
              this.$router.go(-1);
            });
        } else {
          this.$dialog.alert({
            message: res.msg,
            messageAlign: 'left',
          });
        }
      });
    },
    onClickLeft() {
      this.$router.go(-1);
    },
    phoneCheck() {
      if (this.fromValue.ifJzStoreType != 1) {
        var telrg = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
        if (this.fromValue.telephone.trim() == '') {
          return;
        } else if (!telrg.test(this.fromValue.telephone)) {
          this.$toast('手机号格式错误');
          return;
        } else {
          phoneCheck({ phoneNumber: this.fromValue.telephone }).then((res) => {
            if (res.code == 200) {
              this.phoneNumber = true;
            } else {
              this.phoneNumber = false;
            }
          });
        }
      }
    },
    // 陈列照 图片删除
    deleteImg(index) {
      this.displayImg.splice(index, 1);
    },
    // 预览
    previewsImg(index) {
      var arrimg = [];
      for (var imgi = 0; imgi < this.displayImg.length; imgi++) {
        arrimg.push(this.displayImg[imgi]);
      }
      ImagePreview({
        images: arrimg,
        startPosition: index,
      });
    },
    //获取经销商
    async getStoreChainsContact() {
      // 打开select，上次选中确认数据赋值给选中待确认，回显使用
      this.activatedTCFXList = JSON.parse(JSON.stringify(this.sfaStoreChainsContactList));
      if (!this.treeSelect.length) {
        this.toastLoading(0, '加载中...', true);
        listChainsByCategory({ orgId: this.fromValue.orgId }).then((res) => {
          this.toastLoading().clear();
          // 初始化数据
          res.data.forEach((val) => {
            val.dot = false;
          });
          this.showPickerChainsList = true;
          this.treeSelect = res.data;
          this.setCheckData();
        });
      } else {
        this.showPickerChainsList = true;
        this.setCheckData();
      }
    },
    setCheckData() {
      for (let x = 0; x < this.treeSelect.length; x++) {
        // 设置左侧选中图标
        let activate = this.activatedTCFXList.find((item) => {
          return item.categoryCode == this.treeSelect[x].code;
        });
        this.treeSelect[x].dot = activate ? true : false;
        // 右侧选中返现
        let children = this.treeSelect[x].children;
        if (children && this.treeSelect[x].dot) {
          for (let y = 0; y < children.length; y++) {
            let activate = this.activatedTCFXList.find((item) => {
              return (
                children[y].categoryCode == item.categoryCode &&
                children[y].chainCode == item.chainCode
              );
            });
            if (activate) {
              children[y].Check = true;
            } else {
              children[y].Check = false;
            }
          }
        }
      }
      this.$forceUpdate();
      this.activeIndex = 0;
    },
    // 左侧数据点击
    clickNav(index) {
      // this.treeSelect[index].children.forEach((val) => {
      //   // 回显右侧选中
      //   let activate = this.activatedTCFXList.find((item) => item.code == val.code);
      //   val.Check = activate ? true : false;
      // });
    },
    // 右侧数据点击
    treeSelectItemClick(itemData, index, val, ind) {
      itemData.children.forEach((item) => {
        if (val.chainCode == item.chainCode) {
          item.Check = !item.Check;
          // 设置左侧选中图标
          itemData.dot = item.Check;
        } else {
          item.Check = false;
        }
      });
      this.$forceUpdate();
    },
    // 分销店 确认
    treeSelectConfirm() {
      let treeSelectArr = [];
      this.treeSelect.forEach((item) => {
        if (item.dot) {
          let childrenData = item.children.find((val) => val.Check);
          treeSelectArr.push(childrenData);
        }
      });
      if (!treeSelectArr.length) {
        this.$toast('请选择至少选择一个经销商');
        return false;
      }
      console.log(treeSelectArr);
      this.sfaStoreChainsContactList = treeSelectArr;
      this.showPickerChainsList = false;
    },
  },
};
</script>
<style scoped lang="scss">
.myTab .van-tabs__nav--card {
  margin: 0 !important;
  border-left: 0;
  border-right: 0;
}

.myTab .van-tabs__wrap,
.myTab .van-tabs__nav--card {
  height: 40px;
}

.myTab .van-tab {
  line-height: 40px;
}

.van-f-red {
  color: red;
  width: 4px;
  display: inline-block;
}
.storeEdit {
  .invalid {
    display: flex;
    justify-content: center;
    padding-bottom: 10px;
    .van-button {
      width: 70%;
    }
  }
}
.displayImg {
  overflow: hidden;
  .displayImgBox {
    position: relative;
    width: 48%;
    padding: 20px 0;
    height: 210px;
    float: left;
    margin-right: 4%;
    .title {
      text-align: center;
      padding: 5px 0;
    }
  }
  .displayImgBox:nth-child(even) {
    margin-right: 0;
  }
  i {
    position: absolute;
    right: 4px;
    color: white;
    background: red;
    overflow: hidden;
    border-radius: 50%;
  }
}
</style>
<style lang="scss">
#allmap {
  width: 100px;
  height: 100px;
  position: fixed;
  left: -2000px;
}
.van-dialog__confirm,
.van-dialog__confirm:active {
  color: #0057ba;
}

.navBarTOP {
  position: fixed;
  width: 100%;
  z-index: 2;
  top: 0;
}
.typeRadioStore .van-radio {
  margin: 10px;
}
.typeRadioStore .van-radio__icon .van-icon {
  border: 0 !important;
}
.typeRadioStore .van-radio__icon--checked .van-icon {
  color: #1989fa;
  background-color: transparent;
  border-color: transparent;
}
.typeRadioStore .van-cell {
  padding: 0 16px;
  line-height: 40px;
}
.container .typeRadioStore .van-cell__title {
  height: 40px;
}
.typeRadioStore1 .van-radio__icon .van-icon {
  border-radius: 2px;
  border-color: #ccc !important;
}
.typeRadioStore1 .van-radio__icon--checked .van-icon {
  background-color: transparent;
  color: #1989fa;
  border-color: #1989fa !important;
}
.typeRadioStore1 .van-radio .van-radio__label {
  font-size: 14px;
}
.typeRadioStore1 .van-radio[aria-checked='true'] .van-radio__label {
  color: #1989fa;
}
.typeRadioStore1 .van-checkbox__icon .van-icon {
  border-color: #ccc !important;
}
.typeRadioStore1 .van-checkbox__icon--checked .van-icon {
  background-color: transparent;
  color: #1989fa;
  border-color: #1989fa !important;
}
.typeRadioStore1 .van-checkbox .van-checkbox__label {
  font-size: 14px;
}
.typeRadioStore1 .van-checkbox[aria-checked='true'] .van-checkbox__label {
  color: #1989fa;
}
.morelaji .van-cell {
  padding: 10px 0;
}
.storeEdit {
  .agencyBox {
    .header_btn {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 10px;
      font-size: 16px;
      border-bottom: 1px solid #ccc;
      div {
        padding: 3px;
      }
    }
    .van-sidebar {
      width: 100px;
      text-align: center;
      flex: none;
    }
    .treeSelectchildren {
      .item {
        display: flex;
        align-items: center;
        padding: 5px;
        .value {
          margin-left: 15px;
        }
      }
    }
  }
  .TCFXList {
    .van-field__control--custom {
      flex-direction: column;
      align-items: self-start;
      .sfaStoreChainsContactList {
        padding: 3px;
      }
    }
  }
  .otherCompetitor {
    padding: 10px 0px;
    border-bottom: 1px solid #b6b6b6;
    .van-cell__title {
      width: 50px;
    }
  }
}
</style>
