<template>
  <div class="customerTransfer flexOne">
    <div class="query-box" style="border: none;">
      <ul style="overflow: initial!important">
        <li>
          <span>
            <em>{{$t('visaT.sale')}}</em>
          </span>
          <el-select v-model="msg.CreateBy" class="w150" filterable remote reserve-keyword
            :placeholder="$t('pub.PleaseKeyWords')" :remote-method="GetClientAccountListByKeyWord">
            <el-option :label="$t('pub.unlimitedSel')" value="-1"></el-option>
            <el-option v-for="item in employeeList" :label="item.name" :value="item.empId" :key="item.empId">
              <div>
                <span>{{`${item.name}`}}</span>
                <span style="margin-left: 15px;">
                  <el-tag size="mini" v-if="item.isLeave==1">{{$t('pub.noJobSel')}}</el-tag>
                </span>
              </div>
            </el-option>
          </el-select>
        </li>
        <li>
          <span>
            <em>{{$t('salesModule.keyWords')}}</em>
          </span>
          <el-input v-model="msg.CustomerName" :placeholder="$t('salesModule.InputPhone')"></el-input>
        </li>
        <li>
          <span>
            <em>{{$t('salesModule.Belongbrand')}}</em>
          </span>
          <el-select filterable class='multiple_input' v-model='msg.Brand' :placeholder="$t('pub.pleaseSel')">
            <el-option :label="$t('pub.unlimitedSel')" :value="-1"></el-option>
            <el-option v-for='item in CustomerBrandList' :label='item.name' :value='item.id' :key='item.id'>
            </el-option>
          </el-select>
        </li>
        <li>
          <span>
            <em>{{$t('objFill.v101.Rest.guanlianztai')}}</em>
          </span>
          <el-select filterable class='multiple_input' v-model='msg.OperationStatus  '
            :placeholder="$t('pub.pleaseSel')">
            <el-option :label="$t('pub.unlimitedSel')" value=""></el-option>
            <el-option :label="$t('pub.normalSel')" :value="1"></el-option>
            <el-option label="释放" :value="2"></el-option>
          </el-select>
        </li>
        <li>
          <span>
            <em>{{$t('salesModule.CustomerStatus')}}</em>
          </span>
          <el-select filterable class='multiple_input' v-model='msg.CustomerStatus' :placeholder="$t('pub.pleaseSel')">
            <el-option :label="$t('pub.unlimitedSel')" value=""></el-option>
            <el-option :label="$t('fnc.a_wshenhe')" :value="1"></el-option>
            <el-option :label="$t('fnc.a_yshenhe')" :value="2"></el-option>
            <el-option :label="$t('salesModule.HasRefused')" :value="3"></el-option>
            <el-option :label="$t('objFill.v101.activity.heimindan')" :value="4"></el-option>
          </el-select>
        </li>
        <li>
          <span>
            <em>{{$t('objFill.v101.Rest.shifouyichan')}}</em>
          </span>
          <el-select filterable class='multiple_input' v-model='msg.ExceptionCount' :placeholder="$t('pub.pleaseSel')">
            <el-option :label="$t('pub.unlimitedSel')" :value="0"></el-option>
            <el-option :label="$t('pub.yes')" :value="1"></el-option>
            <el-option :label="$t('pub.no')" :value="2"></el-option>
          </el-select>
        </li>
        <li >
          <span >
            <em class="fl" style="margin-top: 10px !important">{{$t('admin.admin_Department')}}</em>
            <treeselect class="w200 fl" :options="departmentList" @select="getEmployeeList" v-model="DepartmentId"
              :placeholder="$t('pub.unlimitedSel')" :normalizer="normalizer" />
          </span>
        </li>
        <li>
          <span>
            <em>
              {{$t('objFill.v101.Rest.tehuizankehu')}}
            </em>
          </span>
          <el-select filterable class='multiple_input' v-model='msg.fanYong' :placeholder="$t('pub.pleaseSel')">
            <el-option :label="$t('pub.unlimitedSel')" :value="-1"></el-option>
            <el-option :label="$t('pub.yes')" :value="1"></el-option>
            <el-option :label="$t('pub.no')" :value="2"></el-option>
          </el-select>
        </li>
        <li>
          <span>
            <em>
              {{$t('scen.sc_ftTime')}}
            </em>
          </span>
          <el-date-picker class="h34" v-model="missionDate" @change="timeAdd()" type="daterange"
                  value-format="yyyy-MM-dd">
                </el-date-picker>
        </li>
        <li style="float:right;padding-top:10px;color:#111111">{{$t('salesModule.JYETJ')}}:{{datainfo.sumMoney}}</li>
        <li>
          <input type="button" class="hollowFixedBtn" :value="$t('ground.kehuditu')" @click="getMap()">
          <input type="button" class="hollowFixedBtn" :value="$t('pub.searchBtn')" @click="resetPageIndex(),getList()">
          <el-popover width="280" v-model="layerShow" popper-class="pd20" trigger="click" @show="employeeMsg.KeyWord=''"
            @hide="employeeMsg.KeyWord=''">
            <div>
              <p class="fz12 fbold mt10 color333">{{$t('fnc.zhuanjiao')}}</p>
              <p class="fz12 mt30 color666">
                <span>{{$t('salesModule.Recipient')}}</span>&nbsp;
                <el-select v-model="RecipientMsg.NewEmployeeId" class="w180" filterable remote reserve-keyword
                  :placeholder="$t('pub.PleaseKeyWords')" :remote-method="GetClientAccountListByKeyWord1">
                  <el-option v-for="item in employeeList1" :label="item.name" :value="item.empId" :key="item.empId">
                    <div>
                      <span>{{`${item.name}`}}</span>
                      <span style="margin-left: 15px;">
                        <el-tag size="mini" v-if="item.isLeave==1">{{$t('pub.noJobSel')}}</el-tag>
                      </span>
                    </div>
                  </el-option>
                </el-select>
              </p>
              <p class="fz12 mt30 color666">
                <span class="fl">{{$t('pub.pubRemark')}}</span>&nbsp;&nbsp;&nbsp;&nbsp;
                <el-input type="textarea" v-model="RecipientMsg.Remarks" class="w180"></el-input>
              </p>
              <p>
                <input type="button" @click="save()" class="normalBtn mt30" :value="$t('salesModule.MassTransfer')">
              </p>
            </div>
            <input slot="reference" type="button" class="normalBtn" :value="$t('salesModule.MassTransfer')"
              @click="RecipientMsg.NewEmployeeId='',RecipientMsg.Remarks=''">
          </el-popover>
        </li>
      </ul>
    </div>
    <div class="clearfix"></div>
    <div class="_customerTransferTable" :class="addShow==true?'_edHeight':''">
      <table class="customerTransferTable customerTransferTable2 mt20" border="0" cellspacing="0" cellpadding="0"
        v-loading="loading">
        <tr>
          <th width="14%">{{$t('salesModule.storeName')}}
            <!--<label><input type="checkbox"  v-model="isCkedAll"  @click='checkedAll()'  style="vertical-align: middle;"/>{{$t('salesModule.storeName')}}</label>-->
          </th>
          <th width="7%">{{$t('hotel.suplier_contact')}}</th>
          <th width="8%">{{$t('restaurant.res_ContactNumber')}}</th>
          <th width="10%">{{$t('admin.admin_address')}}</th>
          <th width="7%">{{$t('salesModule.belongUnion')}}</th>
          <th width="8%">{{$t('salesModule.SuoSales')}}</th>
          <th width="8%">{{$t('salesModule.CustomerStatus')}}</th>
          <th width="5%" class="cursorpointer" @click="changeSort(1, 'TradeMoney')">
            <div class="sort-th">
              <div>
                {{$t('fnc.jiaoyie')}}
              </div>
              <div class="width15 ">
                <p class=" _bold el-icon-caret-top sort-icon-top" :class="{sortActive: msg.jySort === 'asc'}"></p>
                <p class=" _bold el-icon-caret-bottom sort-icon-bottom" :class="{sortActive: msg.jySort === 'desc'}">
                </p>
              </div>
            </div>
          </th>
          <th width="5%" class="cursorpointer" @click="changeSort(2, 'TotalGuestNum')">
            <div class="sort-th">
              <div>
                {{$t('fnc.retoushu')}}
              </div>
              <div class="width15 cursorpointer">
                <p class=" _bold el-icon-caret-top sort-icon-top" :class="{sortActive: msg.rtsSort === 'asc'}"></p>
                <p class=" _bold el-icon-caret-bottom sort-icon-bottom" :class="{sortActive: msg.rtsSort === 'desc'}">
                </p>
              </div>
            </div>
          </th>
          <th width="5%">{{$t('salesModule.HappinessPassbook')}}</th>
          <th width="4%">{{$t('active.ad_yhq')}}</th>
          <th width="8%">{{$t('pub.pubRemark')}}</th>
          <th width="14%">{{$t('system.table_operation')}}</th>
        </tr>
        <tr>
          <td colspan="13" align="center" v-show="list.length==0">{{$t('system.content_noData')}}</td>
        </tr>
        <tr v-for="(item,index) in list">
          <td>
            <label>
              <input :disabled="item.disabled" type="checkbox" :value="item.CustomerId" v-model="customerList"
                @change="ckeckedOne" style="vertical-align: middle;">
              {{item.CustomerName}}<i class="iconfont icon-shimingrenzheng"
                :class="{'_class_b': item.RealNameAuthentication===1}"></i>
            </label>
            <el-popover width="280" popper-class="pd20" trigger="click">
              <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr class="_color_666">
                  <th>{{$t('objFill.v101.Rest.yichangminc')}}</th>
                  <th>{{$t('active.cl_addPp')}}</th>
                  <th>{{$t('fnc.cjshijian')}}</th>
                </tr>
                <tr v-for="(unionItem,x) in CustomerException">
                  <td>{{unionItem.ExceptionName}}</td>
                  <td>{{unionItem.CreateByName}}</td>
                  <td>{{unionItem.CreateTimestr}}</td>
                </tr>
              </table>
              <span v-if="item.ExceptionCount > 0" slot="reference" class="yichangde" @click="yichangde(item)">异</span>
            </el-popover>
          </td>
          <td>{{item.Contact}}</td>
          <td>
            <i class="iconfont icon-img_dianhua fz14" style="color:#09D49D;margin-right: 5px;"></i>
            {{item.ContactNumber}}
          </td>
          <td>{{item.Address}}</td>
          <td>{{item.AllianceName}}</td>
          <td>{{item.EmName}}{{item.IsSys==1?$t('objFill.v101.Rest.daoru'):""}}</td>
          <td>{{valueToWord(item.CustomerStatus)}}</td>
          <td>{{item.TotalPrice}}</td>
          <td>{{item.TotalGuestNum}}</td>
          <td>{{item.CL_Balance}}</td>
          <td>
            <span style="cursor: pointer;text-decoration: underline;"
              @click.stop="goUrC('CouponsList',item.CustomerAccountId)">
              {{item.CouponNum}}
            </span>
          </td>

          <td>{{item.Remark}}</td>

          <td>
            <el-button-group>
              <el-tooltip effect="dark" :content="$t('fnc.zhuanjiao')" placement="top-start">
                <el-popover width="280" popper-class="pd20" trigger="click" @show="employeeMsg.KeyWord=''"
                  @hide="employeeMsg.KeyWord=''">
                  <div>
                    <p class="fz12 fbold mt10 color333">{{$t('fnc.zhuanjiao')}}</p>
                    <p class="fz12 mt30 color666">
                      <span>{{$t('salesModule.Recipient')}}</span>&nbsp;
                      <!-- <el-select
                        filterable
                        class="w180"
                        v-model="RecipientMsg.NewEmployeeId"
                        :placeholder="$t('pub.pleaseSel')"
                      > -->
                      <el-select v-model="RecipientMsg.NewEmployeeId" class="w150" filterable remote reserve-keyword
                        :placeholder="$t('pub.PleaseKeyWords')" :remote-method="GetClientAccountListByKeyWord1">
                        <el-option v-for="item in employeeList1" :label="item.name" :value="item.empId"
                          :key="item.empId">
                          <div>
                            <span>{{`${item.name}`}}</span>
                            <span style="margin-left: 15px;">
                              <el-tag size="mini" v-if="item.isLeave==1">{{$t('pub.noJobSel')}}</el-tag>
                            </span>
                          </div>
                        </el-option>
                      </el-select>
                    </p>
                    <p class="fz12 mt30 color666">
                      <span class="fl">{{$t('pub.pubRemark')}}</span>&nbsp;&nbsp;&nbsp;&nbsp;
                      <el-input type="textarea" v-model="RecipientMsg.Remarks" class="w180"></el-input>
                    </p>
                    <p>
                      <input type="button" class="normalBtn mt30" @click="save" :value="$t('fnc.zhuanjiao')">
                    </p>
                  </div>
                  <el-button slot="reference" @click="singeleCked(item)" type="success"
                    class="iconfont icon-zhuanjiao1 fist-bottom"></el-button>
                </el-popover>
              </el-tooltip>
              <el-tooltip class="item" effect="dark" :content="$t('system.table_edit')" placement="top-start">
                <el-button v-if="bossID===1 || bossID===5" type="primary" class icon="el-icon-edit" circle
                  @click="updateData(item)"></el-button>
              </el-tooltip>
              <el-tooltip class="item" effect="dark" :content="$t('system.table_delete')" placement="top-start">
                <el-button v-if="bossID===1 || bossID===5" type="danger" class icon="el-icon-delete" circle
                  @click="deletelist(item)"></el-button>
              </el-tooltip>

              <el-tooltip class="item" effect="dark" :content="$t('salesModule.BlackList')" placement="top-start">
                <el-button v-if="item.CustomerStatus == 2" type="warning" class icon="iconfont icon-jiaruheimingdan"
                  circle @click="getBlacklist(item)">
                </el-button>
              </el-tooltip>

              <el-tooltip class="item" effect="dark" :content="$t('salesModule.RemoveBlackList')" placement="top-start">
                <el-button v-if="item.CustomerStatus == 4" type="info" class icon="iconfont icon-yichuheimingdan" circle
                  @click="getBlacklist(item)">
                </el-button>
              </el-tooltip>
              <el-tooltip class="item" effect="dark" :content="$t('fnc.xiangqing')" placement="top-start">
                <el-button @click="getUrl(item)" style="padding: 5px;" type="success" icon="iconfont icon-nav-xiaoshou">
                </el-button>
              </el-tooltip>
            </el-button-group>
          </td>
        </tr>
      </table>
      <el-pagination background @current-change="handleCurrentChange" :current-page.sync="currentPage"
        layout="total,prev, pager, next, jumper" :page-size="msg.pageSize" :total="total"></el-pagination>
    </div>
    <div class="_mc_edit _scrollbar" :class="addShow==true?'edHeightOne':''">
      <p class="_tit">
        {{$t('salesModule.addCustomer')}}
        <span class="fr">
          <button class="hollowFixedBtn" type="button" @click="cancelEdit()">{{$t('pub.cancelBtn')}}</button>
          <button type="button" class="normalBtn" v-if="allowAdd" @click="saveVisa()">{{$t('pub.saveBtn')}}</button>
        </span>
      </p>
      <el-form class="_info_box clearfix" :model="addMsg" :rules="rules" ref="addMsg" label-width="120px">
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item :label="$t('restaurant.res_ContactNumber')" prop="ContactNumber">
              <el-input :disabled="isOldPerson" v-model="addMsg.ContactNumber"
                @input="searchHistory(addMsg.ContactNumber)" :placeholder="$t('pub.pleaseImport')"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="$t('salesModule.storeName')" prop="CustomerName">
              <el-input :disabled="isOldPerson" v-model="addMsg.CustomerName" :placeholder="$t('pub.pleaseImport')"
                maxlength="20"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="$t('hotel.suplier_contact')" prop="Contact">
              <el-input :disabled="isOldPerson" v-model="addMsg.Contact" :placeholder="$t('pub.pleaseImport')"
                maxlength="20"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6"></el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item :label="$t('pub.area')">
              <el-select filterable v-model="addMsg.Province" @change="getCity">
                <el-option v-for="item in provinceList" :label="item.Name" :value="item.ID" :key="item.ID"></el-option>
              </el-select>
              <el-select filterable v-model="addMsg.City" @change="getRegion">
                <el-option v-for="item in cityList" :label="item.Name" :value="item.ID" :key="item.ID"></el-option>
              </el-select>
              <el-select filterable v-model="addMsg.District">
                <el-option v-for="item in regionList" :label="item.Name" :value="item.ID" :key="item.ID"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="$t('hotel.hotel_detailinfo')" prop="Address">
              <el-input v-model="addMsg.Address" :placeholder="$t('salesModule.HouseNumber')" maxlength="50"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <!--<el-col :span="6">-->
          <!--<el-form-item  label="所属品牌:" prop="brandIds">-->
          <!--<el-select filterable  class='multiple_input' multiple   v-model='addMsg.brandIds' :placeholder="$t('pub.pleaseSel')">-->
          <!--<el-option v-for='item in CustomerBrandList'-->
          <!--:label='item.name'-->
          <!--:value='item.id'-->
          <!--:key='item.id'>-->
          <!--</el-option>-->
          <!--</el-select>-->
          <!--</el-form-item>-->
          <!--</el-col>-->
          <el-col :span="6">
            <el-form-item :label="$t('visaT.post')" prop="Duty">
              <el-select filterable v-model="addMsg.Duty" :placeholder="$t('pub.pleaseSel')">
                <el-option v-for="item in zw" :label="item.Name" :value="item.ID" :key="item.ID"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="$t('salesModule.premises')" prop="Premises">
              <el-select filterable v-model="addMsg.Premises" :placeholder="$t('pub.pleaseSel')">
                <el-option v-for="item in jycs" :label="item.Name" :value="item.ID" :key="item.ID"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="$t('salesModule.CustomerSource')" prop="CustomerSourceType">
              <el-select filterable v-model="addMsg.CustomerSourceType" :placeholder="$t('pub.pleaseSel')">
                <el-option v-for="item in khly" :label="item.Name" :value="item.ID" :key="item.ID"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="18">
            <el-form-item :label="$t('pub.pubRemark')" prop="Remark">
              <el-input v-model="addMsg.Remark" type="textarea" maxlength="500"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="$t('salesModule.CustomerInfo')" prop="remark" v-show="addMsg.CustomerSourceType==6">
              <el-input v-model="addMsg.CustomerSource" maxlength="20"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item :label="$t('salesModule.BusinessPhoto')">
              <el-upload class="avatar-uploader" action :http-request="UploadAttachment"
                accept="image/jpeg, image/gif, image/png, image/bmp" :show-file-list="false">
                <img v-if="BusinessCardPhotos" :src="BusinessCardPhotos" class="avatar">
                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
              </el-upload>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="$t('salesModule.doorPhoto')">
              <el-upload class="avatar-uploader" action :http-request="UploadAttachment1"
                accept="image/jpeg, image/gif, image/png, image/bmp" :show-file-list="false">
                <img v-if="HousePhotos" :src="HousePhotos" class="avatar">
                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
              </el-upload>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="$t('salesModule.businessPhoto')">
              <el-upload class="avatar-uploader" action :http-request="UploadAttachment2"
                accept="image/jpeg, image/gif, image/png, image/bmp" :show-file-list="false">
                <img v-if="Images" :src="Images" class="avatar">
                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
              </el-upload>
            </el-form-item>
          </el-col>
          <el-col :span="6"></el-col>
        </el-row>
      </el-form>
    </div>
  </div>
</template>

<script>
  import Treeselect from "@riophae/vue-treeselect";
  import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  export default {
    components: {
      Treeselect
    },
    data() {
      return {
        normalizer(node) {
          return {
            id: node.DepartmentId,
            label: node.DepartmentName,
            children: node.ChildList
          };
        },
        CustomerException: [],
        datainfo: {},
        CustomerBrandList: [],
        missionDate: [],
        DepartmentId: null,
        isSelLayer: false,
        layerShow: false,
        msg: {
          pageIndex: 1,
          pageSize: 15,
          CustomerName: "",
          CreateBy: "-1",
          DepartmentId: "-1",
          Brand: -1,
          allDepartment: 0,
          CustomerStatus: '',
          OperationStatus: '',
          jySort: 'desc',
          rtsSort: '',
          orderBy: 'TradeMoney desc',
          ExceptionCount: 0,
          fanYong: -1,
          STime: '',
          ETime: ''
        },
        RecipientMsg: {
          CustomerIdArr: [],
          NewEmployeeId: "",
          Remarks: ""
        },
        departmentMsg: {
          RB_Group_Id: "0",
          RB_Branch_Id: "0",
          Status: "0",
          ParentId: "-1",
          Tier: "0"
        },
        employeeMsg: {
          RB_Group_id: "0",
          RB_Branch_id: "-1",
          departmentId: "0",
          IsLeave: "0",
          KeyWord: '',
        },
        isCkedAll: false,
        addShow: false,
        customerListAll: [],
        customerList: [],
        allLength: 0,
        loading: false,
        currentPage: 1,
        total: 0,
        list: [],
        CreateByInfoList: [],
        RecipientInfoList: [],
        departmentList: [],
        allowAdd: true,
        employeeList: [],
        addMsg: {
          CustomerId: 0,
          CustomerName: "",
          Contact: "",
          ContactNumber: "",
          Address: "",
          brandIds: [],
          remark: "",
          Duty: "",
          Premises: "",
          CustomerId: "0",
          BusinessCardPhotos: [],
          HousePhotos: [],
          Images: [],
          CustomerSourceType: "",
          CustomerSource: "",
          Country: "2",
          Province: "",
          City: "",
          District: ""
        },
        defaultImg: 'this.src="' + require("../../assets/img/litheader.png") + '"',
        BusinessCardPhotos: "",
        HousePhotos: "",
        Images: "",
        isOldPerson: false,
        provinceList: [],
        cityList: [],
        regionList: [],
        jycs: [], //经营场所
        zw: [], //职务
        khly: [],
        addMsgS: {
          isPreFilled: true,
          customerInfo: {},
          customerVisit: {
            remark: "",
            expectVisitDateTime: "",
            expectHour: 0
          }
        },
        bossID: "",
        rules: {
          Contact: [{
            required: true,
            message: this.$t('rule.EnterContratPerson'),
            trigger: "blur"
          }],
          CustomerName: [{
            required: true,
            message: this.$t('rule.EnterCusName'),
            trigger: "blur"
          }],
          ContactNumber: [{
              required: true,
              message: this.$t('rule.EnterPNum'),
              trigger: "blur"
            },
            {
              pattern: this.$commonUtils.Regex.el_ISphone,
              message: this.$t('rule.EnterRightNum')
            }
          ],
          brandIds: [{
            required: true,
            message: this.$t('rule.ChoiceBrand'),
            trigger: "change"
          }],
          Duty: [{
            required: true,
            message: this.$t('rule.ChoiceJob'),
            trigger: "change"
          }],
          remark: [{
            required: false,
            message: this.$t('rule.ChoiceJob'),
            trigger: "change"
          }],
          Premises: [{
            required: true,
            message: this.$t('rule.ChoiceJYCS'),
            trigger: "change"
          }],
          CustomerSourceType: [{
            required: true,
            message: this.$t('rule.ChoiceCusFrom'),
            trigger: "change"
          }],
          CustomerName: [{
            required: true,
            message: this.$t('rule.EnterCusName'),
            trigger: "blur"
          }],
          Address: [{
            required: true,
            message: this.$t('visaT.qsradder'),
            trigger: "blur"
          }]
        },
        employeeList1: [],
        employeeList2: [],
        HightUnitPrice: '2',
        departState: false,
      };
    },
    methods: {
      timeAdd(t) { // 日期格式
          if (!this.missionDate) {
            this.msg.STime = '';
            this.msg.ETime = '';
            return
          }
          this.msg.STime = this.missionDate[0];
          this.msg.ETime = this.missionDate[1];
      },
      changeSort(type, name) {
        if (type == 1) {
          this.msg.jySort = this.msg.jySort === '' ? 'desc' : this.msg.jySort === 'desc' ? 'asc' : ''
          this.msg.rtsSort = ''
          this.msg.orderBy = this.msg.jySort == '' ? '' : name + ' ' + this.msg.jySort
        } else {
          this.msg.jySort = ''
          this.msg.rtsSort = this.msg.rtsSort = this.msg.rtsSort === '' ? 'desc' : this.msg.rtsSort === 'desc' ? 'asc' :
            ''
          this.msg.orderBy = this.msg.rtsSort == '' ? '' : name + ' ' + this.msg.rtsSort
        }
        this.getList();
      },
      getCustomerBrandList() { // 获取品牌
        this.apipost('app_get_customer_brand', {}, res => {
          if (res.data.resultCode == 1) {
            this.CustomerBrandList = res.data.data;
          } else {
            this.$message.error(res.data.message)
          }
        }, err => {})
      },
      goUrC(path, customerId) {
        this.$router.push({
          name: path,
          query: {
            "customerId": customerId,
            blank: 'y'
          }
        })
      },
      getUrl(item) {
        this.$router.push({
          name: "CustomerAnalysis",
          query: {
            "customerId": item.CustomerIdS,
            blank: 'y'
          }
        })
      },
      getMap() {
        this.$router.push({
          name: "customerMap",
          query: {
            departState: this.departState,
            blank: 'y'
          }
        })
      },
      updateData: function (obj) {
        this.apipost(
          "app_customer_GetLeaderCustomerInfo", {
            customerId: obj.CustomerIdS
          },
          res => {
            if (res.data.resultCode == 1) {
              let data = res.data.data;
              let Address = data.Address.split(",");
              this.addMsg = data;
              this.addMsg.Address = Address[1];
              this.$message.success(res.data.message);
              this.addShow = true;
              this.getCity1();
              this.getRegion1();
            } else {
              this.$message.success(res.data.message);
            }
          },
          null
        );
      },
      deletelist: function (obj) {
        this.$Confirm(this.$t('tips.shifoushanchu'), this.$t('tips.tips'), {
            confirmButtonText: this.$t('pub.sureBtn'),
            cancelButtonText: this.$t('pub.cancelBtn'),
            type: "warning"
          })
          .then(() => {
            this.apipost(
              "app_customer_LeaderRemove", {
                ID: obj.CustomerIdS,
                saleID: obj.EmployeeId
              },
              res => {
                if (res.data.resultCode == 1) {
                  this.$message.Success(this.$t('tips.shanchuchenggong'));
                  this.getList();
                }
              },
              err => {}
            );
          })
          .catch(() => {
            this.$message.info(this.$t('tips.cancleDelete'));
          });
      },
      yichangde(obj) {
        this.apipost("app_get_GetCustomerException", {
          customerId: obj.CustomerIdS
        }, res => {
          if (res.data.resultCode == 1) {
            this.CustomerException = res.data.data
          }
        })
      },
      saveVisa() {
        // 保存
        if (this.addMsg.District == "") {
          this.addMsg.District = 0;
        }
        this.addMsgS.customerInfo = this.addMsg;
        if (this.BusinessCardPhotos) {
          this.addMsg.BusinessCardPhotos = [];
          this.addMsg.BusinessCardPhotos.push(this.BusinessCardPhotos);
        }
        if (this.HousePhotos) {
          this.addMsg.HousePhotos = [];
          this.addMsg.HousePhotos.push(this.HousePhotos);
        }
        if (this.Images) {
          this.addMsg.Images = [];
          this.addMsg.Images.push(this.Images);
        }
        let sheng = "";
        let shi = "";
        let qu = "";
        if (this.addMsg.District == "") {
          this.addMsg.District = 0;
        }
        if (this.addMsg.City == "") {
          this.addMsg.City = 0;
        }
        this.provinceList.forEach(item => {
          if (this.addMsg.Province == item.ID) {
            sheng = item.Name;
          }
        });
        this.cityList.forEach(item => {
          if (this.addMsg.City == item.ID) {
            shi = item.Name;
          }
        });
        this.regionList.forEach(item => {
          if (this.addMsg.District == item.ID) {
            qu = item.Name;
          }
        });
        let AreaName = sheng + shi + qu;
        this.addMsg.address = AreaName + "," + this.addMsg.Address;
        this.apipost(
          "app_customer_LeaderUpdateCustomer",
          this.addMsgS,
          res => {
            if (res.data.resultCode == 1) {
              this.addMsg = {
                CustomerName: "",
                Contact: "",
                ContactNumber: "",
                Address: "",
                brandIds: [],
                remark: "",
                Duty: "",
                Premises: "",
                CustomerId: "0",
                BusinessCardPhotos: [],
                HousePhotos: [],
                Images: [],
                CustomerSourceType: "",
                CustomerSource: "",
                Country: "2",
                Province: "",
                City: "",
                District: ""
              };
              this.addMsgS.customerVisit.expectVisitDateTime = "";
              this.$message.success(res.data.message);
              this.addShow = false;
              this.getList();
            } else {
              this.$message.error(res.data.message);
            }
          },
          err => {}
        );
      },
      UploadAttachment(file) {
        //上传
        let newArr = [];
        newArr.push(file.file);
        let path = "/Upload/Temporary/";
        this.UploadSelfFileT(path, newArr, x => {
          this.BusinessCardPhotos = this.domainManager().ViittoFileUrl + x.data.FilePath;
        });
      },
      UploadAttachment1(file) {
        //上传
        let newArr = [];
        newArr.push(file.file);
        let path = "/Upload/Temporary/";
        this.UploadSelfFileT(path, newArr, x => {
          this.HousePhotos = this.domainManager().ViittoFileUrl + x.data.FilePath;
        });
      },
      UploadAttachment2(file) {
        //上传
        let newArr = [];
        newArr.push(file.file);
        let path = "/Upload/Temporary/";
        this.UploadSelfFileT(path, newArr, x => {
          this.Images = this.domainManager().ViittoFileUrl + x.data.FilePath;
        });
      },
      getJycs() {
        this.apipost(
          "app_today_visit_GetCustomerPremisesEnum", {},
          res => {
            if (res.data.resultCode == 1) {
              this.jycs = res.data.data;
            }
          },
          err => {}
        );
      },
      getZw() {
        this.apipost(
          "app_today_visit_GetCustomerDutyEnum", {},
          res => {
            if (res.data.resultCode == 1) {
              this.zw = res.data.data;
            }
          },
          err => {}
        );
      },
      getKhly() {
        this.apipost(
          "app_customer_GetCustomerSourceEnum", {},
          res => {
            if (res.data.resultCode == 1) {
              this.khly = res.data.data;
            }
          },
          err => {}
        );
      },
      getProvince() {
        this.apipost(
          "app_customer_GetAreaChildList", {
            Id: 2,
            level: 1
          },
          res => {
            if (res.data.resultCode == 1) {
              this.provinceList = res.data.data;
            }
          },
          err => {}
        );
      },
      getCity() {
        this.apipost(
          "app_customer_GetAreaChildList", {
            Id: this.addMsg.Province,
            level: 2
          },
          res => {
            if (res.data.resultCode == 1) {
              this.cityList = res.data.data;
              this.regionList = [];
              this.addMsg.City = "";
              this.addMsg.District = "";
            }
          },
          err => {}
        );
      },
      getRegion() {
        this.apipost(
          "app_customer_GetAreaChildList", {
            Id: this.addMsg.City,
            level: 3
          },
          res => {
            if (res.data.resultCode == 1) {
              this.regionList = res.data.data;
              this.addMsg.District = "";
            }
          },
          err => {}
        );
      },
      getCity1() {
        this.apipost(
          "app_customer_GetAreaChildList", {
            Id: this.addMsg.Province,
            level: 2
          },
          res => {
            if (res.data.resultCode == 1) {
              this.cityList = res.data.data;
            }
          },
          err => {}
        );
      },
      getRegion1() {
        this.apipost(
          "app_customer_GetAreaChildList", {
            Id: this.addMsg.City,
            level: 3
          },
          res => {
            if (res.data.resultCode == 1) {
              this.regionList = res.data.data;
            }
          },
          err => {}
        );
      },
      searchHistory(val) {
        if (val.length == 11) {
          this.apipost(
            "app_customer_GetCustomerByContactNumber", {
              ContactNumber: val
            },
            res => {
              if (res.data.resultCode == 1) {
                if (res.data.data.customerInfo.customerId > 0) {
                  this.isOldPerson = true;
                  let x = res.data.data.customerInfo;
                  this.addMsg = x;
                  this.addMsg.Province = x.province;
                  this.addMsg.customerId = x.customerId;
                  this.getCity1();
                  this.addMsg.City = x.city;
                  this.getRegion1();
                  this.addMsg.District = x.district;
                  this.addMsg.Duty = x.duty;
                  this.addMsg.Premises = x.premises;
                  this.addMsg.CustomerSourceType = x.customerSourceType;
                  let dictid = [];
                  res.data.data.brandList.forEach(x => {
                    dictid.push(x.dictId);
                  });
                  this.addMsg.brandIds = dictid;

                  if (x.businessCardPhotos && x.businessCardPhotos.length > 0) {
                    this.BusinessCardPhotos = x.businessCardPhotos[0];
                  }
                  if (x.images && x.images.length > 0) {
                    this.Images = x.images[0];
                  }
                  if (x.housePhotos && x.housePhotos.length > 0) {
                    this.HousePhotos = x.housePhotos[0];
                  }
                }
                this.allowAdd = true;
              } else {
                if (res.data.message.indexOf("已注册客户信息") != -1) {
                  this.allowAdd = false;
                }
                this.$message.error(res.data.message);
              }
            },
            err => {}
          );
        } else {}
      },
      valueToWord(val) {
        if (val == 0) return this.$t('objFill.v101.Rest.weibaifang');
        if (val == 1) return this.$t('salesModule.haveGoutong');
        if (val == 2) return this.$t('objFill.shenhetongguo');
        if (val == 3) return this.$t('objFill.v101.dmc.shenhejj');
      },
      checkedAll() {
        //全选
        if (this.isCkedAll == true) {
          this.customerList = [];
        } else {
          this.customerListAll.forEach(item => {
            this.customerList.push(item);
          });
        }
      },
      ckeckedOne() {
        //单选
        this.employeeMsg.KeyWord = ''
        if (this.customerList.length > 0) {
          let dpId = this.customerList[0].split("|")[2];
          this.employeeMsg.departmentId = dpId;
          this.isSelLayer = true;
          this.getEmployee();
          this.list.forEach(item => {
            if (item.RB_Department_Id != dpId) {
              item.disabled = true;
            }
          });
        } else {
          this.isSelLayer = false;
          this.employeeList1 = [];
          this.employeeList2 = [];
          this.list.forEach(item => {
            item.disabled = false;
          });
        }
      },
      singeleCked(obj) {
        this.isSelLayer = true;
        this.customerList = [];
        this.customerList.push(obj.CustomerId);
        this.employeeMsg.departmentId = obj.RB_Department_Id;
        this.getEmployee();
        this.ckeckedOne();
        this.RecipientMsg.NewEmployeeId = "";
        this.RecipientMsg.Remarks = "";
      },
      save() {
        this.RecipientMsg.CustomerIdArr = [];
        this.customerList.forEach(item => {
          this.RecipientMsg.CustomerIdArr.push(item);
        });
        if (this.RecipientMsg.NewEmployeeId == "") {
          this.$message.Error(this.$t('rule.qxzzjiaoren'));
          return;
        }
        this.apipost(
          "app_customer_SetCustomerCareOfBatch",
          this.RecipientMsg,
          res => {
            if (res.data.resultCode == 1) {
              this.$message.success(res.data.message);
              this.getList();
              this.RecipientMsg.NewEmployeeId = "";
              this.RecipientMsg.Remarks = "";
              this.layerShow = false;
              this.customerList = [];
            } else {
              this.$message.error(res.data.message);
            }
          },
          err => {}
        );
      },
      getList() {
        this.loading = true;
        if (this.departState) {
          this.msg.allDepartment = 1
        }
        this.apipost(
          "app_customer_GetCustomerListForCareOf",
          this.msg,
          res => {
            if (res.data.resultCode == 1) {
              this.loading = false;
              this.allLength = res.data.data.pages.pageData.length;
              this.customerListAll = [];
              res.data.data.pages.pageData.forEach(item => {
                this.customerListAll.push(item.CustomerId);
                item.CustomerIdS = item.CustomerId;
                item.CustomerId =
                  item.CustomerId +
                  "|" +
                  item.EmployeeId +
                  "|" +
                  item.RB_Department_Id;
                item["disabled"] = false;
                item.Address = item.Address.split(",").join("");
              });
              this.datainfo = res.data.data;
              this.list = res.data.data.pages.pageData;
              this.total = res.data.data.pages.count;
            } else {
              this.$message.error(res.data.message);
              this.loading = false;
            }
          },
          err => {}
        );
      },
      getDepartment() {
        let msg = {};
        if (this.departState) {
          msg = {
            allDepartment: 1
          };
          this.msg.allDepartment = 1
        }
        this.apipost(
          "Advertising_get_GetNowDepartmentAndSubordinate", msg,
          res => {
            if (res.data.resultCode == 1) {
              this.departmentList = res.data.data;
            } else {
              this.$message.error(res.data.message);
            }
          },
          err => {}
        );
      },
      getEmployeeList(node, id) {
        this.isSelLayer = false;
        this.msg.CreateBy = "-1";
        this.msg.DepartmentId = this.employeeMsg.departmentId = node.DepartmentId;
        this.getEmployee();
      },
      getEmployee() {
        this.employeeMsg.departmentId = 0;
        this.employeeMsg.RB_Group_id = this.getLocalStorage().RB_Group_id;
        this.employeeMsg.RB_Branch_id = -1;
        this.employeeList2 = [];
        this.employeeMsg.IsLeave = -1;
        if (this.employeeMsg.KeyWord == '') {
          return
        }
        this.apipost(
          "app_get_company_employee",
          this.employeeMsg,
          res => {
            if (res.data.resultCode == 1) {
              if (!this.isSelLayer) {
                this.employeeList = res.data.data;
                this.employeeList.forEach(item => {
                  if (item.isLeave == 0) {
                    this.employeeList2.push(item);
                  }
                });
              } else {
                this.employeeList1 = res.data.data;
                this.employeeList1.forEach(item => {
                  if (item.isLeave == 0) {
                    this.employeeList2.push(item);
                  }
                });
              }
            }
          },
          err => {}
        );
      },
      GetClientAccountListByKeyWord(query) {
        if (query !== '') {
          this.employeeMsg.departmentId = 0;
          this.employeeMsg.RB_Group_id = this.getLocalStorage().RB_Group_id;
          this.employeeMsg.RB_Branch_id = -1;
          this.employeeList2 = [];
          this.employeeMsg.IsLeave = -1;
          this.employeeMsg.KeyWord = query;
          this.apipost(
            "app_get_company_employee",
            this.employeeMsg,
            res => {
              if (res.data.resultCode == 1) {
                this.employeeList = res.data.data;
              }
            },
            err => {}
          );
        }
      },
      GetClientAccountListByKeyWord1(query) {
        if (query !== '') {
          this.employeeMsg.departmentId = 0;
          this.employeeMsg.RB_Group_id = this.getLocalStorage().RB_Group_id;
          this.employeeMsg.RB_Branch_id = -1;
          this.employeeMsg.IsLeave = 0;
          this.employeeMsg.KeyWord = query;
          this.apipost(
            "app_get_company_employee",
            this.employeeMsg,
            res => {
              if (res.data.resultCode == 1) {
                this.employeeList1 = res.data.data;
              }
            },
            err => {}
          );
        }
      },
      getCreateByInfoList() {
        this.apipost(
          "app_customer_GetDepartmentEmployee",
          this.msg,
          res => {
            if (res.data.resultCode == 1) {
              this.CreateByInfoList = res.data.data.leaveList;
              this.RecipientInfoList = res.data.data.noLeaveList;
            } else {
              this.$message.error(res.data.message);
            }
          },
          err => {}
        );
      },
      handleCurrentChange(val) {
        this.msg.pageIndex = val;
        this.getList();
      },
      resetPageIndex() {
        this.msg.pageIndex = 1;
        this.currentPage = 1;
      },
      cancelEdit() {
        // 取消新增
        this.addShow = false;
        this.addMsg = {
          CustomerName: "",
          Contact: "",
          ContactNumber: "",
          Address: "",
          remark: "",
          Brand: []
        };
        (this.BusinessCardPhotos = ""),
        (this.HousePhotos = ""),
        (this.Images = ""),
        (this.addMsgS.customerVisit.expectVisitDateTime = "");
        this.resetForm("addMsg");
      },
      resetForm(formName) {
        // 重置表单
        this.$refs[formName].resetFields();
      },
      getBlacklist(item) {
        let DisabledType
        let CustomerId = item.CustomerId.split('|')[0]
        if (item.CustomerStatus == 2) {
          DisabledType = 1
          this.$confirm(this.$t('objFill.v101.Rest.shifoujruhmdan'), this.$t('tips.tips'), {
              confirmButtonText: this.$t('pub.sureBtn'),
              cancelButtonText: this.$t('pub.cancelBtn'),
              type: "warning"
            })
            .then(() => {
              this.apipost(
                "app_customer_DisabledCustomer", {
                  CustomerId: CustomerId,
                  DisabledType: DisabledType
                },
                res => {
                  if (res.data.resultCode == 1) {
                    this.$message.success(this.$t('objFill.v101.Rest.jiaruhemindcgo'));
                    this.getList();
                  }
                },
                err => {}
              );
            })
            .catch(() => {
              this.$message.info(this.$t('objFill.v101.Rest.yiquxiaojiaru'));
            });
        } else if (item.CustomerStatus == 4) {
          DisabledType = 2
          this.$confirm(this.$t('objFill.v101.Rest.shifouyichmdan'), this.$t('tips.tips'), {
              confirmButtonText: this.$t('pub.sureBtn'),
              cancelButtonText: this.$t('pub.cancelBtn'),
              type: "warning"
            })
            .then(() => {
              this.apipost(
                "app_customer_DisabledCustomer", {
                  CustomerId: CustomerId,
                  DisabledType: DisabledType
                },
                res => {
                  if (res.data.resultCode == 1) {
                    this.$message.success(this.$t('objFill.v101.Rest.yiquheimdancgo'));
                    this.getList();
                  }
                },
                err => {}
              );
            })
            .catch(() => {
              this.$message.info(this.$t('objFill.v101.Rest.yiquxiaoyichu'));
            });
        }
      }
    },

    mounted() {
      let userInfo = this.getLocalStorage();
      let ActionMenuCode = userInfo.ActionMenuCode;
      if (ActionMenuCode.indexOf('Select_AllCustomer') != -1) {
        this.departState = true;
      }
      this.bossID = userInfo.EmployeeId;
      this.departmentMsg.RB_Group_Id = userInfo.RB_Group_id; //集团
      this.getDepartment();
      // this.getEmployee();
      this.getList();
      this.getCreateByInfoList();
      this.getProvince();
      this.getJycs();
      this.getZw();
      this.getKhly();
      this.getCustomerBrandList();
    }
  };

</script>

<style>
  .customerTransferTable {
    width: 100%;
    font-size: 14px;
    color: #333;
    border: 1px solid #dcdcdc;
    box-sizing: border-box;
    border-bottom: none;
    border-right: none;
  }

  .customerTransferTable ._class_b {
    color: #257BF1 !important
  }

  .customerTransferTable.customerTransferTable2 tr th {
    background: #dcdcdc;
    height: 30px;
    font-size: 12px;
    text-align: left;
    text-indent: 0 !important;
  }

  .customerTransferTable tr {
    text-align: left;
  }

  .customerTransferTable tr:nth-child(2n) {
    background: #f2f2f2;
  }

  .customerTransferTable tr:nth-child(2n + 1) {
    background: #ffffff;
  }

  .customerTransferTable tr:hover {
    background: #d0d2d9;
  }

  .customerTransferTable tr td {
    height: 40px;
    padding-left: 25px;
    border-bottom: 1px solid #dcdcdc;
    font-size: 14px;
    color: #333;
    border-right: 1px solid #dcdcdc;
  }

  .pd20 {
    padding: 12px 20px !important;
  }

  .el-popper[x-placement^="bottom"] {
    margin-top: 0px !important;
  }

  .el-popper[x-placement^="top"] {
    margin-bottom: 0px !important;
  }

  .customerTransferTable .el-button {
    position: relative;
    top: -5px;
  }

  .customerTransferTable .el-button+.el-button {}

  .customerTransfer ._mc_edit {
    overflow: auto;
    display: none;
    position: absolute;
    z-index: 50;
    bottom: 0;
    left: 0;
    border-top: 3px solid #38425d;
    background-color: #f9f9f9;
    padding: 10px;
    width: 100%;
    min-width: 1146px;
  }

  .customerTransfer ._mc_edit ._tit {
    padding-left: 10px;
    border-left: 3px solid #e95252;
    font-size: 16px;
    font-family: "PingFangSc-Fine";
    color: #000000;
  }

  .customerTransfer ._mc_edit ._info_box ul._form li {
    float: left;
  }

  .customerTransfer .edHeightOne {
    display: block !important;
    height: 450px;
  }

  .customerTransfer ._edHeight {
    height: 340px;
  }

  .customerTransfer ._remark textarea {
    resize: none;
    width: 646px;
    height: 100px;
  }

  .customerTransfer .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }

  .customerTransfer .avatar-uploader .el-upload:hover {
    border-color: #409eff;
  }

  .customerTransfer .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 148px;
    height: 148px;
    line-height: 148px;
    text-align: center;
  }

  .customerTransfer .avatar {
    width: 148px;
    height: 148px;
    display: block;
  }

  .width15 {
    width: 15px;
  }

  .sort-th {
    display: flex;
    align-items: center;
  }

  .sortActive {
    color: #E95252;
  }

  .sort-icon-top {
    position: relative;
    top: 4px;
    /* left: -45px; */
  }

  .sort-icon-bottom {
    position: relative;
    bottom: 4px;
    /* left: -20px; */
  }

  .customerTransfer .fist-bottom {
    color: rgb(255, 255, 255);
    font-size: 14px;
    padding: 5px;
    cursor: pointer;
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    border-top-left-radius: 4px;
    border-bottom-left-radius: 4px;
  }

  .customerTransfer .el-button-group {
    padding-top: 10px;
  }

  .yichangde {
    display: inline-block;
    border-radius: 50%;
    color: red;
    border: 1px solid red;
    font-size: 12px;
    width: 18px;
    height: 18px;
    text-align: center;
    cursor: pointer;
  }

</style>