<template>
  <div class="borderless">
    <div class="customer-head">
      <div class="customer-back">
        <!--        <i class="back-icon el-icon-arrow-left"></i><i style="font-style:normal">返回管理列表</i>-->
        <el-button type="danger" style="border: none;background: none;color: red" icon="el-icon-arrow-left"
          @click="backToList()">返回列表
        </el-button>
      </div>
      <div class="add-customer-btn">
        <el-button type="primary" @click="synchronization" size="small" :disabled="!form.id">同 步
        </el-button>
        <el-button type="primary" @click="openFlow" size="small" :disabled="!form.id">审 核
        </el-button>
        <el-button type="primary" :disabled="disabled" @click="editCustomer(null)" size="small">{{  form.id ? "确认修改" : "确认新增"
          }}
        </el-button>
      </div>
    </div>
    <div class="customer-main">
      <el-form :model="form" ref="form" label-width="100px" class="demo-ruleForm">
        <containerTitle title="基础资料"></containerTitle>
        <basic-container>
          <el-row>
            <el-col v-for="(item, index) in basicData.column" :key="index" :span="item.span ? item.span : 8">
              <el-form-item :label="item.label" :prop="item.prop" :rules="item.rules">
                <avue-input-tree v-if="item.prop === 'corpsTypeId'" leaf-only multiple style="width: 100%;" size="small"
                  :props="{ label: 'title' }" v-model="form[item.prop]" placeholder=" " type="tree" :dic="dic">
                </avue-input-tree>
                <el-cascader v-else-if="item.prop === 'belongtoarea'" v-model="form[item.prop]" collapse-tags
                  :options="dicArea" :props="props" size="small" style="width: 100%;" :show-all-levels="false"
                  @change="addressChange"></el-cascader>
                <!--                <avue-input-tree-->
                <!--                  v-else-if="item.prop === 'belongtoarea'"-->
                <!--                  leaf-only-->
                <!--                  multiple-->
                <!--                  tags-->
                <!--                  style="width: 100%;"-->
                <!--                  size="small"-->
                <!--                  :props="{ label: 'name', value: 'name' }"-->
                <!--                  v-model="form[item.prop]"-->
                <!--                  placeholder=" "-->
                <!--                  type="tree"-->
                <!--                  :dic="dicArea"-->
                <!--                ></avue-input-tree>-->
                <el-select v-else-if="item.prop === 'adminProfiles'" size="small" style="width: 100%;"
                  v-model="form[item.prop]" multiple placeholder="">
                  <el-option v-for="item in userList" :key="item.id" :label="item.name" :value="item.id">
                  </el-option>
                </el-select>
                <el-select v-else-if="item.prop === 'creditRating'" size="small" style="width: 100%;"
                  v-model="form[item.prop]" placeholder="">
                  <el-option v-for="item in creditRatingList" :key="item.id" :label="item.dictValue"
                    :value="item.dictValue">
                  </el-option>
                </el-select>
                <el-select v-else-if="item.prop === 'line'" size="small" style="width: 100%;"
                  v-model="form[item.prop]" clearable placeholder="请选择" multiple collapse-tags>
                  <el-option v-for="item in lineList" :key="item.id" :label="item.dictValue" :value="item.dictKey">
                  </el-option>
                </el-select>
                <crop-select v-else-if="item.prop === 'belongtocompany'" v-model="form[item.prop]"
                  @getCorpData="getCorpName" corpType="GS"></crop-select>
                <el-input type="text" v-else-if="item.prop === 'initials'" v-model="form[item.prop]" size="small"
                  autocomplete="off" :disabled="item.disabled" show-word-limit maxlength="1"></el-input>
                <el-input type="textarea" v-else-if="item.prop === 'remarks'" :rows="1" placeholder="请输入内容"
                  v-model="form[item.prop]">
                </el-input>
                <el-input type="age" v-else v-model="form[item.prop]" size="small" autocomplete="off"
                  :disabled="item.disabled"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </basic-container>
        <containerTitle title="联系方式"></containerTitle>
        <basic-container>
          <el-row>
            <el-col v-for="(item, index) in contactInformation.column" :key="index" :span="item.span ? item.span : 8">
              <el-form-item :label="item.label" :prop="item.prop" :rules="item.rules">
                <el-input type="textarea" v-if="item.prop === 'addr'" :rows="2" placeholder="请输入内容"
                  v-model="form[item.prop]">
                </el-input>
                <el-input type="textarea" v-else-if="item.prop === 'storageAddr'" :rows="2" placeholder="请输入内容"
                  v-model="form[item.prop]">
                </el-input>
                <el-input type="textarea" v-else-if="item.prop === 'subStorageAddr'" :rows="2" placeholder="请输入内容"
                  v-model="form[item.prop]">
                </el-input>
                <el-input v-else type="age" v-model="form[item.prop]" size="small" autocomplete="off"></el-input>

              </el-form-item>
            </el-col>
          </el-row>
        </basic-container>
        <containerTitle title="财务资料"></containerTitle>
        <basic-container>
          <el-row>
            <el-col v-for="(item, index) in financialInformation.column" :key="index" :span="item.span ? item.span : 8">
              <el-form-item :label="item.label" :prop="item.prop" :rules="item.rules" v-if="!item.hide">
                <el-switch v-if="item.prop === 'creditstatus'" v-model="form[item.prop]" active-value="0"
                  inactive-value="1" active-text="开启" inactive-text="关闭">
                </el-switch>
                <el-select v-else-if="item.prop === 'paymentType'" v-model="form[item.prop]" clearable filterable
                  size="small" style="width: 100%;">
                  <el-option v-for="(item, index) in paymentOption" :key="index" :label="item.dictValue"
                    :value="item.dictValue"></el-option>
                </el-select>
                <el-select v-else-if="item.prop === 'packageRemarks'" v-model="form[item.prop]" clearable filterable
                  size="small" style="width: 100%;">
                  <el-option v-for="(item, index) in packageOptions" :key="index" :label="item.dictValue"
                    :value="item.dictValue"></el-option>
                </el-select>
                <el-select v-else-if="item.prop === 'a'" v-model="form[item.prop]" clearable filterable size="small"
                  style="width: 100%;" @change="aChange">
                  <el-option v-for="(item, index) in settingOption" :key="index" :label="item.dictValue"
                    :value="item.dictValue"></el-option>
                </el-select>
                <el-select v-else-if="item.prop === 'c'" v-model="form[item.prop]" clearable filterable size="small"
                  style="width: 100%;" @change="cChange">
                  <el-option v-for="(item, index) in monthOption" :key="index" :label="item.dictValue"
                    :value="item.dictKey"></el-option>
                </el-select>
                <el-input v-else type="age" v-model="form[item.prop]" size="small" autocomplete="off"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </basic-container>
        <containerTitle title="客户联系人"></containerTitle>
        <basic-container>
          <avue-crud ref="crud" :option="customerContact" v-model="contactsForm" :data="contactsData"
            @saveColumn="saveColumn" @resetColumn="resetColumn" @row-save="rowSave" @row-update="rowUpdate"
            @row-del="rowDel">
            <template slot-scope="{ type, size, row }" slot="menu">
              <el-button icon="el-icon-check" :size="size" :type="type" @click="creatingUsers(row)">创建用户</el-button>
            </template>
          </avue-crud>
        </basic-container>
        <!-- <containerTitle title="客户优势项目"></containerTitle>
        <basic-container style="margin-bottom: 10px">
          <avue-crud
            :option="advantageProject"
            v-model="advantageProjectForm"
            :data="advantageProjectData"
            @row-save="rowSaveProject"
            @row-update="rowUpdateProject"
            @row-del="rowDelProject"
          ></avue-crud>
        </basic-container> -->
        <containerTitle title="客户开户行"></containerTitle>
        <basic-container>
          <avue-crud ref="crud2" :option="bankOfDeposit" v-model="bankOfDepositForm" :data="bankOfDepositData"
            @saveColumn="saveColumn2" @resetColumn="resetColumn2" @row-save="rowSaveBankOfDeposit"
            @row-update="rowUpdateBankOfDeposit" @row-del="rowDelBankOfDeposit"></avue-crud>
        </basic-container>
        <containerTitle title="收发货地址"></containerTitle>
        <basic-container>
          <avue-crud ref="crud3" :option="addressOption" v-model="addressForm" :data="addressData"
            @saveColumn="saveColumn3" @resetColumn="resetColumn3" @row-save="rowSaveAddress"
            @row-update="rowUpdateAddress" @row-del="rowDelAddress"></avue-crud>
        </basic-container>
      </el-form>
    </div>
    <flow-dialog :switchDialog="switchDialog" @onClose="onClose()">
      <template slot="content"> </template>
    </flow-dialog>
    <el-dialog title="同 步" :visible.sync="dialogVisible" append-to-body width="60%">
      <avue-form ref="formData" v-model="formData" :option="option">
      </avue-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="confirmSynchronization">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog title="创建用户" :visible.sync="dialogVisibleBt" append-to-body width="60%">
      <avue-form v-if="dialogVisibleBt" ref="formDataTwo" v-model="formDataTwo" :option="optionData">
      </avue-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisibleBt = false">取 消</el-button>
        <el-button type="primary" @click="confirmSynchronizationTwo">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  customerList,
  typeSave,
  detail,
  deleteDetails,
  corpstypeTree,
  corpsattn,
  corpsbank,
  corpsfiles,
  corpsitem,
  areaTypeTree,
  corpsAddrDelete,
  synchronizationCopy,
  creatingUsers
} from "@/api/basicData/customerInformation";
import customerContact from "./configuration/customerContact.json";
import advantageProject from "./configuration/advantageProject.json";
import bankOfDeposit from "./configuration/bankOfDeposit.json";
import flowDialog from "@/components/flow-dialog/main";
import { customerParameter } from "@/enums/management-type";
import { gainUser } from "@/api/basicData/customerInquiry";
import addressOption from "./configuration/addressOption.json";
import website from "@/config/website";
import { getRoleTree } from "@/api/system/role";
import { getDeptTree } from "@/api/system/dept";
import { getPostList } from "@/api/system/post";
import { contrastObj, contrastList } from "@/util/contrastData";
export default {
  name: "detailsPage",
  data() {
    return {
      userList: [],
      formData: {},
      formDataTwo: {},
      creditRatingList: [],
      lineList: [],
      optionData: {
        span: 8,
        menuBtn: false,
        column: [
          {
            label: "所属角色",
            prop: "roleId",
            multiple: true,
            type: "tree",
            dicData: [],
            props: {
              label: "title"
            },
            checkStrictly: true,
            slot: true,
            rules: [
              {
                required: true,
                message: "请选择所属角色",
                trigger: "click"
              }
            ]
          },
          {
            label: "所属部门",
            prop: "deptId",
            type: "tree",
            multiple: true,
            dicData: [],
            props: {
              label: "title"
            },
            checkStrictly: true,
            slot: true,
            rules: [
              {
                required: true,
                message: "请选择所属部门",
                trigger: "click"
              }
            ]
          },
          {
            label: "所属岗位",
            prop: "postId",
            type: "tree",
            multiple: true,
            dicData: [],
            props: {
              label: "postName",
              value: "id"
            },
            rules: [
              {
                required: true,
                message: "请选择所属岗位",
                trigger: "click"
              }
            ]
          }
        ]
      },
      dialogVisibleBt: false,
      dialogVisible: false,
      option: {
        span: 12,
        menuBtn: false,
        column: [
          {
            label: "客户类型",
            prop: "corpType",
            type: "select",
            cascader: ["corpsTypeId"],
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=corp_type",
            props: {
              label: "dictValue",
              value: "dictKey"
            },
            rules: [
              {
                required: true,
                message: "请选择客户类型",
                trigger: "blur"
              }
            ]
          },
          {
            label: "类别",
            prop: "corpsTypeId",
            type: "tree",
            dicUrl: "/api/blade-client/corpstype/tree?&corpType={{key}}",
            props: {
              label: "title",
              value: "value"
            },
            rules: [
              {
                required: true,
                message: "请选择类型",
                trigger: "blur"
              }
            ]
          }
        ]
      },
      switchDialog: false,
      form: {},

      disabled: false,
      contactsForm: {},
      advantageProjectForm: {},
      bankOfDepositForm: {},
      contactsData: [],
      advantageProjectData: [],
      bankOfDepositData: [],
      dic: [],
      dicArea: [],
      customerContact: {},
      advantageProject: advantageProject,
      bankOfDeposit: {},
      contactInformation: {
        column: [
          {
            label: "联系人",
            prop: "attn",
            rules: [
              {
                required: false,
                message: "请输入联系人",
                trigger: "blur"
              }
            ]
          },
          {
            label: "联系电话",
            prop: "tel",
            rules: [
              {
                required: false,
                message: "请输入联系电话",
                trigger: "blur"
              }
            ]
          },
          {
            label: "职位",
            prop: "position",
            rules: [
              {
                required: false,
                message: "请输入职位",
                trigger: "blur"
              }
            ]
          },
          {
            label: "单位地址",
            prop: "addr",
            rules: [
              {
                required: false,
                message: "请输入单位地址",
                trigger: "blur"
              }
            ]
          },
          {
            label: "仓库地址",
            prop: "storageAddr",
            rules: [
              {
                required: false,
                message: "请输入仓库地址",
                trigger: "blur"
              }
            ]
          },
          {
            label: "分仓地址",
            prop: "subStorageAddr",
            rules: [
              {
                required: false,
                message: "请输入分仓地址",
                trigger: "blur"
              }
            ]
          }
        ]
      },
      financialInformation: {
        column: [
          {
            label: "账户名称",
            prop: "accountName",
            span: 8,
            rules: [
              {
                required: false,
                message: " ",
                trigger: "blur"
              }
            ]
          },
          {
            label: "开户银行",
            prop: "accountBank",
            span: 8,
            rules: [
              {
                required: false,
                message: " ",
                trigger: "blur"
              }
            ]
          },
          {
            label: "银行帐号",
            prop: "accountNo",
            span: 8,
            rules: [
              {
                required: false,
                message: " ",
                trigger: "blur"
              }
            ]
          },
          {
            label: "CNAPS",
            prop: "cnaps",
            span: 8,
            rules: [
              {
                required: false,
                message: " ",
                trigger: "blur"
              }
            ]
          },
          {
            label: "银行地址",
            prop: "localBankAddress",
            span: 8,
            rules: [
              {
                required: false,
                message: " ",
                trigger: "blur"
              }
            ]
          },
          {
            label: "外币账户名称",
            prop: "accountNameFcy",
            span: 8,
            rules: [
              {
                required: false,
                message: " ",
                trigger: "blur"
              }
            ]
          },
          {
            label: "外币开户银行",
            prop: "accountBankFcy",
            span: 8,
            rules: [
              {
                required: false,
                message: " ",
                trigger: "blur"
              }
            ]
          },
          {
            label: "外币银行账号",
            prop: "accountNoFcy",
            span: 8,
            rules: [
              {
                required: false,
                message: " ",
                trigger: "blur"
              }
            ]
          },
          {
            label: "Swift Code",
            prop: "swiftCode",
            span: 8,
            rules: [
              {
                required: false,
                message: " ",
                trigger: "blur"
              }
            ]
          },
          {
            label: "外币银行地址",
            prop: "foreignBankAddress",
            span: 8,
            rules: [
              {
                required: false,
                message: " ",
                trigger: "blur"
              }
            ]
          },
          {
            label: "授信状态",
            prop: "creditstatus",
            span: 8,
            rules: [
              {
                required: false,
                message: " ",
                trigger: "blur"
              }
            ]
          },
          {
            label: "授信等级",
            prop: "creditLevel",
            span: 8,
            rules: [
              {
                required: false,
                message: " ",
                trigger: "blur"
              }
            ]
          },
          {
            label: "授信额度",
            prop: "creditGrant",
            span: 8,
            rules: [
              {
                required: false,
                message: " ",
                trigger: "blur"
              }
            ]
          },
          {
            label: "授信天数",
            prop: "creditDay",
            span: 8,
            rules: [
              {
                required: false,
                message: " ",
                trigger: "blur"
              }
            ]
          },
          {
            label: "授信利率",
            prop: "creditRate",
            span: 8,
            rules: [
              {
                required: false,
                message: " ",
                trigger: "blur"
              }
            ]
          },
          {
            label: "FOB系数",
            span: 8,
            prop: "coefficient"
          },
          {
            label: "付款方式",
            span: 8,
            prop: "paymentType"
          },
          {
            label: "纳税人识别号",
            prop: "taxpayerDifferenceCode"
          },
          {
            label: "包装要求",
            span: 8,
            prop: "packageRemarks"
          },
          {
            label: "账期设置",
            span: 8,
            prop: "a"
          },
          {
            label: "天数",
            span: 8,
            prop: "b"
          },
          {
            label: "结清月份",
            span: 8,
            prop: "c"
          },
          {
            label: "结清天数",
            span: 8,
            prop: "j"
          },
          {
            label: "日利息万分",
            span: 8,
            prop: "d"
          },
          {
            label: "最大欠款额",
            span: 8,
            prop: "e"
          },
          {
            label: "协议号",
            span: 8,
            prop: "f"
          },
          {
            label: "账期日期",
            span: 8,
            prop: "g"
          },
          {
            label: "账期备注",
            span: 24,
            prop: "h"
          }
        ]
      },
      basicData: {
        column: [
          {
            label: "编码",
            prop: "code",
            rules: [
              {
                required: true,
                message: " ",
                trigger: "blur"
              }
            ]
          },
          {
            label: "名称",
            prop: "cname",
            rules: [
              {
                required: true,
                message: " ",
                trigger: "blur"
              }
            ]
          },
          {
            label: "简称",
            prop: "shortName"
          },
          {
            label: "类别",
            prop: "corpsTypeId",
            rules: [
              {
                required: true,
                message: " ",
                trigger: "blur"
              }
            ]
          },
          {
            label: "企业类型",
            prop: "companytype",
            rules: [
              {
                required: false,
                message: " ",
                trigger: "blur"
              }
            ]
          },
          {
            label: "代理品牌",
            prop: "goodtypes",
            rules: [
              {
                required: false,
                message: " ",
                trigger: "blur"
              }
            ]
          },
          {
            label: "所属公司",
            prop: "belongtocompany",
            rules: [
              {
                required: false,
                message: " ",
                trigger: "blur"
              }
            ]
          },
          {
            label: "分管员",
            prop: "adminProfiles",
            span: 8
          },
          {
            label: "区域",
            prop: "belongtoarea",
            span: 8,
            mock: {
              type: "county"
            }
          },
          {
            label: "信用等级",
            prop: "creditRating",
            span: 8
          },
          {
            label: "代理商编码",
            prop: "agentCode",
            span: 8
          }, {
            label: "首字母",
            prop: "initials",
            span: 8
          },{
            label: "优势航线",
            prop: "line",
            span: 8
          },
          // {
          //   label: "总返利",
          //   prop: "profitReturn",
          //   disabled: true,
          //   span: 8
          // },
          // {
          //   label: "已用返利",
          //   prop: "usedProfit",
          //   disabled: true,
          //   span: 8
          // },
          // {
          //   label: "可用返利",
          //   prop: "surplusProfit",
          //   disabled: false,
          //   span: 8
          // },
          // {
          //   label: "可用返利",
          //   prop: "monthProfit",
          //   disabled: true,
          //   span: 8
          // },
          {
            label: "备注",
            prop: "remarks",
            span: 16,
            mock: {
              type: "county"
            }
          }
        ]
      },
      paymentOption: [],
      settingOption: [],
      monthOption: [],
      addressOption: {},
      addressForm: {},
      addressData: [],
      formRow: {},
      // 包装要求
      packageOptions: [],
      props: {
        value: "name",
        label: "name",
        multiple: true
      },
      addressLatLng: [],
      oldform: {
        creditstatus:'1'
      },
      oldcontactsData: [],
      oldbankOfDepositData: [],
      oldadvantageProjectData: [],
      oldaddressLatLng: [],
      oldaddressData: [],
    };
  },
  props: {
    detailData: {
      type: Object
    }
  },
  components: {
    flowDialog
  },
  async created() {
    this.customerContact = await this.getColumnData(
      this.getColumnName(143),
      customerContact
    );
    this.bankOfDeposit = await this.getColumnData(
      this.getColumnName(144),
      bankOfDeposit
    );
    this.addressOption = await this.getColumnData(
      this.getColumnName(145),
      addressOption
    );
    if (!website.tenantMode) {
      this.initData(website.tenantId);
    } else {
      this.initData();
    }
    if (this.$store.getters.userInfo.tenant_id === "096359") {
      let list = ["profitReturn", "usedProfit", "surplusProfit", "monthProfit"];
      for (let item in list) {
        for (let i in this.basicData.column) {
          if (list[item] == this.basicData.column[i].prop) {
            this.basicData.column.splice(i, 1);
          }
        }
      }
    }
    corpstypeTree({ corpType: customerParameter.code }).then(res => {
      this.dic = res.data.data;
    });
    areaTypeTree().then(res => {
      this.dicArea = res.data.data;
    });
    this.getWorkDicts("packageRemarks").then(res => {
      this.packageOptions = res.data.data;
    });
    this.getWorkDicts("payment_term").then(res => {
      this.paymentOption = res.data.data;
    });
    this.getWorkDicts("account_period").then(res => {
      this.settingOption = res.data.data;
    });
    this.getWorkDicts("month").then(res => {
      this.monthOption = res.data.data;
    });
    this.getWorkDicts("credit_rating").then(res => {
      this.creditRatingList = res.data.data;
    });
    this.getWorkDicts("dominant_route").then(res => {
      this.lineList = res.data.data;
    });
    if (this.$route.query.customerName) {
      this.returnButton = true
    } else {
      this.returnButton = true
    }
    if (this.detailData.id) {
      detail(this.detailData.id).then(res => {
        if (res.data.data.adminProfiles) {
          res.data.data.adminProfiles = res.data.data.adminProfiles.split(",");
        }
        if (res.data.data.line){
          res.data.data.line = res.data.data.line.split(",")
        }
        this.form = res.data.data;
        this.contactsData = this.form.corpsAttnList;
        this.bankOfDepositData = this.form.corpsBankList;
        this.advantageProjectData = this.form.corpsItems;
        this.addressLatLng = JSON.parse(this.form.addressLatLng);
        this.addressData = this.form.corpsAddrList;
        this.oldform = this.deepClone(res.data.data);
        this.oldcontactsData = this.deepClone(this.form.corpsAttnList);
        this.oldbankOfDepositData = this.deepClone(this.form.corpsBankList);
        this.oldadvantageProjectData = this.deepClone(this.form.corpsItems);
        this.oldaddressLatLng = this.deepClone(JSON.parse(this.form.addressLatLng));
        this.oldaddressData = this.deepClone(this.form.corpsAddrList);
        if (this.form.belongtoarea) {
          this.form.belongtoarea = this.form.belongtoarea
            .split(",")
            .map(item => item.split("/"));
        }
        delete this.form.corpsAttnList;
        delete this.form.corpsBankList;
        delete this.form.corpsItems;
        delete this.form.corpsAddrList;
      });
    } else if (this.detailData.treeDeptId) {
      this.$set(this.form, "corpsTypeId", this.detailData.treeDeptId);
      if (this.$route.query.customerName) {
        this.$set(this.form, "cname", this.$route.query.customerName);
        this.$router.$avueRouter.closeTag(window.location.hash.slice(1))
      } else if (this.$route.query) {
        this.$set(this.form, "cname", this.$route.query.corpName);
      }
    } else {
      if (this.$route.query.customerName) {
        this.$set(this.form, "cname", this.$route.query.customerName);
        this.$router.$avueRouter.closeTag(window.location.hash.slice(1))
      } else if (this.$route.query) {
        this.$set(this.form, "cname", this.$route.query.corpName);
      }
    }
    gainUser().then(res => {
      this.userList = res.data.data;
    });
    this.getWorkDicts("currency").then(res => {
      this.findObject(this.bankOfDeposit.column, "fcyno").dicData =
        res.data.data;
    });
  },
  methods: {
    initData(tenantId) {
      getRoleTree(tenantId).then(res => {
        const column = this.findObject(this.optionData.column, "roleId");
        column.dicData = res.data.data;
      });
      getDeptTree(tenantId).then(res => {
        const column = this.findObject(this.optionData.column, "deptId");
        column.dicData = res.data.data;
      });
      getPostList(tenantId).then(res => {
        const column = this.findObject(this.optionData.column, "postId");
        column.dicData = res.data.data;
      });
    },
    addressChange() {
      this.addressLatLng = [];
      this.form.belongtoarea.forEach(e => {
        if (e.length == 1) {
          this.dicArea.forEach(item1 => {
            if (item1.provinceName == e[0]) {
              this.addressLatLng.push({
                name: item1.provinceName,
                value: this.addressLatLng.length + 1,
                lng: item1.lng,
                lat: item1.lat,
                zoom: 1
              });
            }
          });
        } else if (e.length == 3) {
          this.dicArea.forEach(item1 => {
            if (item1.provinceName == e[0]) {
              if (item1.children.length > 0) {
                item1.children.forEach(item2 => {
                  if (item2.cityName == e[1]) {
                    if (e[0] == e[1]) {
                      if (item2.children.length > 0) {
                        item2.children.forEach(item3 => {
                          if (item3.districtName == e[2]) {
                            this.addressLatLng.push({
                              name: item3.districtName,
                              value: this.addressLatLng.length + 1,
                              lng: item3.lng,
                              lat: item3.lat,
                              zoom: 1
                            });
                          }
                        });
                      }
                    } else if (e[0] != e[1]) {
                      this.addressLatLng.push({
                        name: item2.cityName,
                        value: this.addressLatLng.length + 1,
                        lng: item2.lng,
                        lat: item2.lat,
                        zoom: 1
                      });
                    }
                  }
                });
              }
            }
          });
        }
      });
      this.addressLatLng = this.addressLatLng.filter(
        (currentValue, currentIndex, selfArr) => {
          return (
            selfArr.findIndex(x => x.name === currentValue.name) ===
            currentIndex
          );
        }
      );
    },
    //确认创建用户
    confirmSynchronizationTwo() {
      this.$refs["formDataTwo"].validate((valid, done) => {
        done();
        if (valid) {
          let data = JSON.parse(JSON.stringify(this.formDataTwo));
          data.deptId = data.deptId.join(",");
          data.roleId = data.roleId.join(",");
          data.postId = data.postId.join(",");
          creatingUsers({
            ...data,
            id: this.formRow.id
          }).then(res => {
            this.dialogVisibleBt = false;
            this.formDataTwo = {}
            this.$message.success(
              "创建用户成功,默认帐号：手机号。默认密码：123456"
            );
          });
        } else {
          return false;
        }
      });
    },
    aChange(row) {
      console.log(row)
      if (row == '月结') {
        this.financialInformation.column.forEach(e => {
          if (e.prop == 'b') {
            e.hide = true
          }
          if (e.prop == 'c') {
            e.hide = false
          }
          if (e.prop == 'j') {
            e.hide = false
          }
        })
      } else if (row == '业务后') {
        this.financialInformation.column.forEach(e => {
          if (e.prop == 'b') {
            e.hide = false
          }
          if (e.prop == 'c') {
            e.hide = true
          }
          if (e.prop == 'j') {
            e.hide = true
          }
        })
      } else {
        this.financialInformation.column.forEach(e => {
          if (e.prop == 'b') {
            e.hide = true
          }
          if (e.prop == 'c') {
            e.hide = true
          }
          if (e.prop == 'j') {
            e.hide = true
          }
        })
      }
    },
    creatingUsers(row) {
      if (row.id) {
        if (row.tel) {
          this.dialogVisibleBt = true;
          this.formDataTwo = {};
          this.formRow = row;
        } else {
          this.$message.error("请输入手机号");
        }
      } else {
        this.$message.error("请保存数据后再点击");
      }
    },
    //新增客户联系人保存触发
    rowSave(row, done, loading) {
      console.log(row, done, loading);
      this.contactsData.push(row);
      done();
    },
    //修改客户联系人触发
    rowUpdate(row, index, done, loading) {
      done(row);
    },
    //删除客户联系人触发
    rowDel(row, index, donerowDel) {
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        // 数据回调进行刷新
        if (row.id) {
          corpsattn(row.id).then(res => {
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.contactsData.splice(index, 1);
          });
        } else {
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          this.contactsData.splice(index, 1);
        }
      });
    },
    //新增客户优势项目保存触发
    rowSaveProject(row, done, loading) {
      console.log(row, done, loading);
      this.advantageProjectData.push(row);
      done();
    },
    //修改客户优势项目触发
    rowUpdateProject(row, index, done, loading) {
      done(row);
    },
    //删除客户优势项目触发
    rowDelProject(row, index, donerowDel) {
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        if (row.id) {
          corpsitem(row.id).then(res => {
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.advantageProjectData.splice(index, 1);
          });
        } else {
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          this.advantageProjectData.splice(index, 1);
        }
      });
    },
    //新增客户优势项目保存触发
    rowSaveBankOfDeposit(row, done, loading) {
      console.log(row, done, loading);
      this.bankOfDepositData.push(row);
      done();
    },
    //修改客户优势项目触发
    rowUpdateBankOfDeposit(row, index, done, loading) {
      done(row);
    },
    //删除客户优势项目触发
    rowDelBankOfDeposit(row, index, donerowDel) {
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        if (row.id) {
          corpsbank(row.id).then(res => {
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.bankOfDepositData.splice(index, 1);
          });
        } else {
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          this.bankOfDepositData.splice(index, 1);
        }
      });
    },
    //新增收发货地址保存触发
    rowSaveAddress(row, done, loading) {
      this.addressData.push(row);
      done();
    },
    //修改收发货地址优势项目触发
    rowUpdateAddress(row, index, done, loading) {
      done(row);
    },
    //删除收发货地址优势项目触发
    rowDelAddress(row, index, donerowDel) {
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        if (row.id) {
          corpsAddrDelete(row.id).then(res => {
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.addressData.splice(index, 1);
          });
        } else {
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          this.addressData.splice(index, 1);
        }
      });
    },
    //修改提交触发
    editCustomer(status) {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.corpsAttnList = this.contactsData;
          this.form.corpsBankList = this.bankOfDepositData;
          this.form.corpsItems = this.advantageProjectData;
          this.form.corpsAddrList = this.addressData;
          this.form.addressLatLng = JSON.stringify(this.addressLatLng);
          if (typeof this.form.corpsTypeId == "object") {
            this.form.corpsTypeId = this.form.corpsTypeId.join(",");
          }
          if (this.form.line&&typeof this.form.line == "object"){
            this.form.line = this.form.line.join(",")
          }
          this.disabled = true;

          if (this.form.belongtoarea) {
            // this.form.belongtoarea = this.form.belongtoarea.toString();
            this.form.belongtoarea = this.form.belongtoarea
              .map(e => e.join("/"))
              .join(",");
          }
          if (this.form.adminProfiles) {
            this.form.adminProfiles = this.form.adminProfiles.join(",");
          }
          this.form.corpType = customerParameter.code;
          typeSave(this.form).then(res => {
            if (res.data.data === "error") {
              this.disabled = false;
              this.$message({
                showClose: true,
                message: res.data.msg,
                type: "error"
              });
            } else {
              this.$message({
                type: "success",
                message: this.form.id ? "修改成功!" : "新增成功!"
              });
              if (res.data.data.adminProfiles) {
                res.data.data.adminProfiles = res.data.data.adminProfiles.split(",");
              }
              if (res.data.data.line){
                res.data.data.line = res.data.data.line.split(",")
              }
              this.form = res.data.data;
              this.contactsData = res.data.data.corpsAttnList;
              if (this.form.belongtoarea) {
                this.form.belongtoarea = this.form.belongtoarea
                  .split(",")
                  .map(item => item.split("/"));
              }
              this.disabled = false;
              if (status) {
                this.$emit("goBack", true);
              }
            }
          });
        } else {
          return false;
        }
      });
    },
    synchronization() {
      this.dialogVisible = true;
    },
    async saveColumn() {
      const inSave = await this.saveColumnData(
        this.getColumnName(143),
        this.customerContact
      );
      if (inSave) {
        this.$nextTick(() => {
          this.$refs.crud.doLayout();
        });
        this.$message.success("保存成功");
        //关闭窗口
        this.$refs.crud.$refs.dialogColumn.columnBox = false;
      }
    },
    async resetColumn() {
      this.customerContact = customerContact;
      const inSave = await this.delColumnData(
        this.getColumnName(143),
        customerContact
      );
      if (inSave) {
        this.$nextTick(() => {
          this.$refs.crud.doLayout();
        });
        this.$message.success("重置成功");
        this.$refs.crud.$refs.dialogColumn.columnBox = false;
      }
    },
    async saveColumn2() {
      const inSave = await this.saveColumnData(
        this.getColumnName(144),
        this.bankOfDeposit
      );
      if (inSave) {
        this.$nextTick(() => {
          this.$refs.crud2.doLayout();
        });
        this.$message.success("保存成功");
        //关闭窗口
        this.$refs.crud2.$refs.dialogColumn.columnBox = false;
      }
    },
    async resetColumn2() {
      this.bankOfDeposit = bankOfDeposit;
      const inSave = await this.delColumnData(
        this.getColumnName(144),
        bankOfDeposit
      );
      if (inSave) {
        this.$nextTick(() => {
          this.$refs.crud2.doLayout();
        });
        this.$message.success("重置成功");
        this.$refs.crud2.$refs.dialogColumn.columnBox = false;
      }
    },
    async saveColumn3() {
      const inSave = await this.saveColumnData(
        this.getColumnName(145),
        this.addressOption
      );
      if (inSave) {
        this.$nextTick(() => {
          this.$refs.crud3.doLayout();
        });
        this.$message.success("保存成功");
        //关闭窗口
        this.$refs.crud3.$refs.dialogColumn.columnBox = false;
      }
    },
    async resetColumn3() {
      this.addressOption = addressOption;
      const inSave = await this.delColumnData(
        this.getColumnName(145),
        addressOption
      );
      if (inSave) {
        this.$nextTick(() => {
          this.$refs.crud3.doLayout();
        });
        this.$message.success("重置成功");
        this.$refs.crud3.$refs.dialogColumn.columnBox = false;
      }
    },
    //确认同步
    confirmSynchronization() {
      this.$refs["formData"].validate((valid, done) => {
        if (valid) {
          synchronizationCopy({
            ...this.formData,
            id: this.form.id
          }).then(res => {
            done();
            this.$message.success("同步成功");
            this.dialogVisible = false;
          });
        } else {
          return done();
        }
      });
    },
    backToList(value) {
      if (
          contrastObj(this.form, this.oldform) ||
          contrastList(this.contactsData, this.oldcontactsData) ||
          contrastList(this.bankOfDepositData, this.oldbankOfDepositData) ||
          contrastList(this.advantageProjectData, this.oldadvantageProjectData) ||
          contrastList(this.addressLatLng || [], this.oldaddressLatLng || []) ||
          contrastList(this.addressData, this.oldaddressData)
      ) {
        this.$confirm("数据发生变化未有提交记录, 是否提交?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
            .then(() => {
              this.editCustomer("goBack");
            })
            .catch(() => {
              this.$emit("goBack", true);
            });
      }else{
        this.$emit("goBack", true);
      }
    },
    openFlow() {
      this.switchDialog = !this.switchDialog;
    },
    onClose(val) {
      this.switchDialog = val;
    },
    getCorpName(row) { }
  }
};
</script>

<style lang="scss" scoped>
::v-deep .el-form-item {
  margin-bottom: 0;
}

::v-deep .el-form-item__content {
  line-height: 32px;
}
</style>
