<template xmlns:v-slot="http://www.w3.org/1999/XSL/Transform">
  <div>
    <el-dialog
      :title="title"
      :close-on-click-modal="false"
	  draggable
      width="1200px"
      @close="close(),closeXTable()"
      @keyup.enter.native="doSubmit"
	  v-model="visible">
      <el-form size="large" :model="inputForm" ref="inputForm" :rules="rules" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
               label-width="150px">
        <el-row  :gutter="0">
          <el-col :span="10">
            <el-form-item label="客户名称" prop="workClientInfo.name">
              <el-input maxlength="64" v-model="inputForm.workClientInfo.name" placeholder="请输入客户名称"></el-input>
            </el-form-item>
          </el-col>
            <el-col :span="2">
              <el-popover
                v-model="visable"
                placement="left"
                width="400"
                height="800"
                trigger="click"
                :popper-options="{ boundariesElement: 'viewport', removeOnDestroy: true }"
                ref="pops">
                <vxe-table
                  border="inner"
                  auto-resize
                  resizable
				  keep-source
                  :row-config="{isHover: true}"
                  :data="gridData"
                  :checkbox-config="{}"
                  :row-style="rowStyle"
                  @cell-click="rowClick"
                  :show-header="false"
                >
                  <vxe-column title="" field="entname" ></vxe-column>
                </vxe-table>

				  <template #reference>
					  <el-button type="info" @click="getPopTable" style="width: 100%" plain>查询</el-button>
				  </template>

              </el-popover>
            <el-form-item>

            </el-form-item>
          </el-col>
          <el-col :span="12" >
            <el-form-item style="margin-left: 8px" label="归属区域" prop="workClientInfo.areaId"
                          :rules="[
                   {required: true, message:'请选择归属区域', trigger:'blur'}
                 ]">
              <SelectTree
                ref="areaTree"
                :props="{
                      value: 'id',             // ID字段名
                      label: 'name',         // 显示名称
                      children: 'children'    // 子级字段名
                    }"
                url="/system-server/sys/area/treeData"
                :value="inputForm.workClientInfo.areaId"
                :clearable="true"
                :accordion="true"
                v-if="visible"
				size="large"
                @getValue="(value) => {inputForm.workClientInfo.areaId=value}"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row  :gutter="15">

          <el-col :span="12">

            <el-form-item label="是否拥有信用代码" prop="workClientInfo.hasUscc"
                 :rules="[
                  {required: true, message:'请选择是否拥有信用代码', trigger:'blur'}
                 ]">
              <el-radio-group v-model="inputForm.workClientInfo.hasUscc">
                  <el-radio v-for="item in $dictUtils.getDictList('yes_no')" :label="item.value" >{{item.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>

          <el-col :span="12" v-if="inputForm.workClientInfo.hasUscc === '1'">
            <el-form-item label="统一社会信用代码"
						  prop="workClientInfo.uscCode">
              <el-input maxlength="64" v-model="inputForm.workClientInfo.uscCode" placeholder="请输入统一社会信用代码"></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="客户性质" prop="workClientInfo.companyType"
                :rules="[
                  {required: true, message:'请选择客户性质', trigger:'blur'}
                ]">
              <el-select v-model="inputForm.workClientInfo.companyType" placeholder="请选择" style="width:100%;">
                <el-option
                  v-for="item in $dictUtils.getDictList('customer_nature')"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="所在行业" prop="workClientInfo.companyIndustry"
                :rules="[
                  {required: true, message:'请选择所在行业', trigger:'blur'}
                ]">
              <el-select v-model="inputForm.workClientInfo.companyIndustry" placeholder="请选择" style="width:100%;">
                <el-option
                  v-for="item in $dictUtils.getDictList('industry')"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="客户类型" prop="workClientInfo.clientType"
                 :rules="[
                    {required: true, message:'请选择客户类型', trigger:'blur'}
                 ]">
              <el-select v-model="inputForm.workClientInfo.clientType" placeholder="请选择" style="width:100%;">
                <el-option
                  v-for="item in $dictUtils.getDictList('customer_type')"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

<!--          <el-col :span="12">-->
<!--            <el-form-item label="代表方" prop="workClientInfo.deputyList"-->
<!--                          :rules="[-->
<!--                    {required: true, message:'请选择代表方', trigger:'blur'}-->
<!--                 ]">-->
<!--              <el-select v-model="inputForm.workClientInfo.deputyList" placeholder="请选择" multiple style="width:100%;">-->
<!--                <el-option-->
<!--                  v-for="item in $dictUtils.getDictList('representative')"-->
<!--                  :key="item.value"-->
<!--                  :label="item.label"-->
<!--                  :value="item.value">-->
<!--                </el-option>-->
<!--              </el-select>-->
<!--            </el-form-item>-->
<!--          </el-col>-->

          <el-col :span="12">
            <el-form-item label="法人代表" prop="workClientInfo.lawerPresint">
              <el-input maxlength="64" v-model="inputForm.workClientInfo.lawerPresint" placeholder="请填写法人代表"></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="邮政编码" prop="workClientInfo.zipCode">
              <el-input maxlength="64" v-model="inputForm.workClientInfo.zipCode" placeholder="请填写邮政编码"></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="传真" prop="workClientInfo.fax">
              <el-input maxlength="64" v-model="inputForm.workClientInfo.fax" placeholder="请填写传真"></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="公司电话" prop="workClientInfo.telephone"
                          :rules="[
                   {validator: validatorXG.isPhoneOrMobile, trigger: 'change'},
                   {validator: validatorXG.isPhoneOrMobile, trigger: 'blur'}
                 ]">
              <el-input v-model="inputForm.workClientInfo.telephone" placeholder="请填写公司电话"></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="公司网址" prop="workClientInfo.companyUrl">
              <el-input maxlength="64" v-model="inputForm.workClientInfo.companyUrl" placeholder="请填写公司网址"></el-input>
            </el-form-item>
          </el-col>



          <el-col :span="24">
            <el-form-item label="注册地址" prop="workClientInfo.registerAddress">
              <el-input maxlength="128" v-model="inputForm.workClientInfo.registerAddress" placeholder="请填写注册地址"></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="24">
            <el-form-item label="详细地址" prop="workClientInfo.address">
              <el-input maxlength="128" v-model="inputForm.workClientInfo.address" placeholder="请填写详细地址"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="单位简介" prop="workClientInfo.remarks">
          <el-input v-model="inputForm.workClientInfo.remarks"
                    type="textarea"
                    :rows="5"
                    maxlength="500"
                    placeholder="请输入单位简介"
                    show-word-limit>
          </el-input>
        </el-form-item>

        <el-form-item label="开票信息" prop="bankInfos">
          <vxe-toolbar>
            <template #buttons>
              <vxe-button status="primary" :disabled="method==='view'" size="small" @click="insertEvent('bank')">新增</vxe-button>
            </template>
          </vxe-toolbar>
        </el-form-item>

        <vxe-table
			:key="tableKey"
          border
          show-overflow
          ref="xTable1"
          class="vxe-table-element"
          :data="bankInfos"
		  keep-source
          style="margin-left: 5em"
          @cell-click="dbclickFun"
          @edit-closed=""
          :edit-config="{trigger: 'click', mode: 'row', showStatus: false, autoClear: true, icon: '#'}"
        >

          <vxe-table-column field="ourBank" title="开票银行" :edit-render="{}" show-overflow="title">
            <template #edit="scope" >
              <el-input maxlength="64" v-model="scope.row.ourBank" ></el-input>
            </template>
          </vxe-table-column>
          <vxe-table-column field="bankNumber" title="开票账号" :edit-render="{}" show-overflow="title">
            <template #edit="scope" >
              <el-input v-model="scope.row.bankNumber" @blur="checkBankNumber(scope.row)" maxlength="30"></el-input>
            </template>
          </vxe-table-column>
          <vxe-table-column field="remarks" title="备注信息" :edit-render="{}" show-overflow="title">
            <template #edit="scope" >
              <el-input maxlength="64" v-model="scope.row.remarks" ></el-input>
            </template>
          </vxe-table-column>
          <vxe-table-column title="操作" width="100">
            <template #default="scope">
              <el-button size="small" type="danger" @click="removeEvent(scope.row,scope.$rowIndex,'bank')">删除</el-button>
            </template>
          </vxe-table-column>
        </vxe-table>

        <el-form-item style="margin-top: 20px" label="联系人信息" prop="linkmanInfos">
          <vxe-toolbar >
            <template #buttons>
              <vxe-button status="primary" :disabled="method==='view'" size="small" @click="insertEvent('linkman')">新增</vxe-button>
            </template>
          </vxe-toolbar>
        </el-form-item>

        <vxe-table
			:key="tableKey"
          border
          show-overflow
          ref="xTable2"
          class="vxe-table-element"
          :data="linkmanInfos"
          style="margin-left: 5em"
		  keep-source
          @cell-click="dbclickFun"
          @edit-closed=""
          :edit-config="{trigger: 'click', mode: 'row', showStatus: false, autoClear: true, icon: '#'}"
        >

        <vxe-table-column field="name" title="联系人姓名" :edit-render="{}" show-overflow="title">
          <template #edit="scope">
            <el-input maxlength="10" v-model="scope.row.name" ></el-input>
          </template>
        </vxe-table-column>
        <vxe-table-column field="office" title="部门" :edit-render="{}" show-overflow="title">
          <template #edit="scope">
            <el-input maxlength="10" v-model="scope.row.office" ></el-input>
          </template>
        </vxe-table-column>
        <vxe-table-column field="position" title="职务" :edit-render="{}" show-overflow="title">
          <template #edit="scope">
            <el-input maxlength="10" v-model="scope.row.position" ></el-input>
          </template>
        </vxe-table-column>
        <vxe-table-column field="qq" title="QQ" :edit-render="{}" show-overflow="title">
          <template #edit="scope">
            <el-input v-model="scope.row.qq" ></el-input>
          </template>
        </vxe-table-column>
        <vxe-table-column field="linkPhone" title="联系方式1" :edit-render="{}" show-overflow="title">
          <template #edit="scope">
            <el-input v-model="scope.row.linkPhone"  maxlength="20"></el-input>
          </template>
        </vxe-table-column>
        <vxe-table-column field="linkMobile" title="联系方式2" :edit-render="{}" show-overflow="title">
          <template #edit="scope">
            <el-input v-model="scope.row.linkMobile"  maxlength="20"></el-input>
          </template>
        </vxe-table-column>
        <vxe-table-column field="email" title="E-mail" :edit-render="{}" show-overflow="title">
          <template #edit="scope">
            <el-input v-model="scope.row.email"  maxlength="64"></el-input>
          </template>
        </vxe-table-column>
        <vxe-table-column title="操作" width="100">
          <template #default="scope">
            <el-button size="small" type="danger" @click="removeEvent(scope.row,scope.$rowIndex,'linkman')">删除</el-button>
          </template>
        </vxe-table-column>
        </vxe-table>
        <!--        附件-->
        <UpLoadComponent ref="uploadComponent"></UpLoadComponent>
      </el-form>

<!--      <el-image-viewer-->
<!--        v-if="showViewer"-->
<!--        :on-close="closeViewer"-->
<!--        :url-list="[url]"-->
<!--        zIndex="9999"/>-->
		<template #footer>
			<span class="dialog-footer">
      <el-button  @click="close(),closeXTable()" icon="el-icon-circle-close">关闭</el-button>
      <el-button  type="primary" v-if="method != 'view'" @click="doSubmit()" icon="el-icon-circle-check" v-noMoreClick >确定</el-button>
			</span>
		</template>
    </el-dialog>
  </div>
</template>

<script>
  import WorkClientService from '@/api/sys/WorkClientService'
  import SelectTree from '@/components/treeSelect/treeSelect.vue'
  import UpLoadComponent from '@/views/common/UpLoadComponent'
  import OSSSerive from '@/api/sys/OSSService'
  // import ElImageViewer from 'element-ui/packages/image/src/image-viewer'
  export default {
    data () {
      let checkUscCode = (rule, value, callback) => {
			this.haveUscCode(value, callback)
      }
      let checkWorkClient = (rule, value, callback) => {
        this.haveWorkClient(value, callback)
      }
      return {
        visable: false,
        gridData: [],
		tableKey: '',
        radio: 0,
        tableData: [],
        dataList: [],
        dataListNew: [],
        title: '',
        method: '',
        visible: false,
        loading: false,
        returnForm: {
          workClientInfo: {
            name: '',
            lawerPresintnamename: '',
            lawerPresint: '',
            orUnicode: '',
            companyType: '',
            companyIndustry: '',
            clientType: '',
            creditRank: '',
            areaId: '',
            zipCode: '',
            fax: '',
            taxId: '',
            email: '',
            address: '',
            registerAddress: '',
            companyUrl: '',
            remarks: '',
            companyId: '',
            officeId: '',
            areaParentIds: '',
            telephone: '',
            hasUscc: '',
            uscCode: '',
            number: '',
            deputy: '',
            deputyList: []
          }
        },
        inputForm: {
          workClientInfo: {
            name: '',
            lawerPresintnamename: '',
            lawerPresint: '',
            orUnicode: '',
            companyType: '',
            companyIndustry: '',
            clientType: '',
            creditRank: '',
            areaId: '',
            zipCode: '',
            fax: '',
            taxId: '',
            email: '',
            address: '',
            registerAddress: '',
            companyUrl: '',
            remarks: '',
            companyId: '',
            officeId: '',
            areaParentIds: '',
            telephone: '',
            hasUscc: '',
            uscCode: '',
            number: '',
            deputy: '',
            deputyList: []
          },
          deputyList: [],
          permissionFlag: '', // 判断是否为当前登录人参数
          name: '',
          hasUscc: '',
          uscCode: '',
          companyType: '',
          companyIndustry: '',
          clientType: '',
          deputy: '',
          lawerPresint: '',
          zipCode: '',
          fax: '',
          telephone: '',
          companyUrl: '',
          areaId: '',
          registerAddress: '',
          address: '',
          remarks: ''
        },
        bankInfos: [],
        bankInfo: {
          ourBank: '',
          bankNumber: '',
          remarks: ''
        },
        linkmanInfos: [],
        linkmanInfo: {
          name: '',
          office: '',
          position: '',
          qq: '',
          linkPhone: '',
          linkMobile: '',
          email: ''
        },
        filesArra2: [],
        fileList: [],
        isFlag: true,
        showViewer: false, // 显示查看器
        url: '',
        rowurl: '',
        src: '',
        showVi: true,
        onedit: false,
        type: '',
        loadProgress: 0, // 动态显示进度条
        progressFlag: false, // 关闭进度条
        rules: {
          'workClientInfo.uscCode': [
            {required: true, validator: checkUscCode, trigger: 'blur'},
            {required: true, validator: checkUscCode, trigger: 'change'}
          ],
          'workClientInfo.name': [
            {required: true, validator: checkWorkClient, trigger: 'blur'},
            {required: true, validator: checkWorkClient, trigger: 'change'}
          ]
        }
      }
    },
    components: {
      // ElImageViewer,
      SelectTree,
      UpLoadComponent
    },
    ossService: null,
    workClientService: null,
    created () {
      this.ossService = new OSSSerive()
      this.workClientService = new WorkClientService()
    },
    mounted () {
    },
    methods: {
      isExistByName () {
        let value = this.inputForm.workClientInfo.name
        if (value !== null && value !== undefined && value !== '') {
          this.workClientService.isExist(value).then((data) => {
            if (data !== 0) {
              this.$message.error('该客户名称已存在')
            }
          })
        }
      },
      isExistByUscCode () {
        let value = this.inputForm.workClientInfo.uscCode
        if (value !== null && value !== undefined && value !== '') {
          this.workClientService.isExist(value).then((data) => {
            if (data !== 0) {
              this.$message.error('该统一社会信用代码已存在')
            }
          })
        }
      },
      haveUscCode (value, callback) {
        if (!this.commonJS.isEmpty(value)) {
          this.workClientService.haveUscCode(this.inputForm.id, value).then((data) => {
            if (!data) {
              callback(new Error('该统一社会信用代码已存在'))
            } else {
              callback()
            }
          })
        } else {
          callback(new Error('统一社会信用代码不可以为空'))
        }
      },
      haveWorkClient (value, callback) {
        if (!this.commonJS.isEmpty(value)) {
          this.workClientService.haveWorkClient(this.inputForm.id, value).then((data) => {
            if (!data) {
              callback(new Error('该客户名称已存在'))
            } else {
              callback()
            }
          })
        } else {
          callback(new Error('客户名称不可以为空'))
        }
      },
      // 关闭查看器
      closeViewer () {
        this.url = ''
        this.showViewer = false
      },
      async init (method, id) {
        this.dataList = []
        this.dataListNew = []
        await this.ossService.findFileList(id).then((data) => {
          data.forEach((item) => {
            item.name = item.attachmentName
            this.dataList.push(item)
            this.dataListNew.push(item)
          })
        })
        this.method = method
        this.inputForm = {
          deputyList: [],
          name: '',
          hasUscc: '',
          uscCode: '',
          companyType: '',
          companyIndustry: '',
          clientType: '',
          deputy: '',
          lawerPresint: '',
          zipCode: '',
          fax: '',
          telephone: '',
          companyUrl: '',
          areaId: '',
          registerAddress: '',
          address: '',
          remarks: '',
          bankInfos: [],
          bankInfo: {
            ourBank: '',
            bankNumber: '',
            remarks: ''
          },
          linkmanInfos: [],
          linkmanInfo: {
            name: '',
            office: '',
            position: '',
            qq: '',
            linkPhone: '',
            linkMobile: '',
            email: ''
          },
          filesArra2: [],
          fileList: [],
          isFlag: true,
          showViewer: false, // 显示查看器
          url: '',
          rowurl: '',
          src: '',
          showVi: true,
          type: '',
          workClientInfo: {
            name: '',
            lawerPresintnamename: '',
            lawerPresint: '',
            orUnicode: '',
            companyType: '',
            companyIndustry: '',
            clientType: '',
            creditRank: '',
            areaId: '',
            zipCode: '',
            fax: '',
            taxId: '',
            email: '',
            address: '',
            registerAddress: '',
            companyUrl: '',
            remarks: '',
            companyId: '',
            officeId: '',
            areaParentIds: '',
            telephone: '',
            hasUscc: '',
            uscCode: '',
            number: '',
            deputy: '',
            deputyList: []
          }
        }
        this.inputForm.id = id
        if (method === 'add') {
          this.inputForm.workClientInfo.hasUscc = '1'
          this.inputForm.permissionFlag = true
          this.title = `新建客户信息`
        } else if (method === 'edit') {
          this.title = '修改客户信息'
        } else if (method === 'view') {
          this.showVi = false
          this.title = '查看客户详情'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          // this.$refs.upload.clearFiles()
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.workClientService.findById(this.inputForm.id).then((data) => {
              // this.inputForm = this.recover(this.inputForm, data)
              data.workClientBank.forEach(i => {
                this.bankInfos.push(i)
              })
              data.workClientLinkman.forEach(i => {
                this.linkmanInfos.push(i)
              })
				this.tableKey = Math.random()
              const deputyList = []
              if (data.workClientInfo.deputy !== null && data.workClientInfo.deputy !== undefined && data.workClientInfo.deputy !== '') {
                data.workClientInfo.deputy.split(',').forEach(item => {
                  if (item !== null && item !== undefined && item !== '') {
                    deputyList.push(item)
                  }
                })
              }
              this.inputForm.workClientInfo = JSON.parse(JSON.stringify(data.workClientInfo))
              this.inputForm.permissionFlag = true
              this.inputForm.workClientInfo.deputyList = deputyList
              this.inputForm.workClientInfo = JSON.parse(JSON.stringify(this.inputForm.workClientInfo))
              this.inputForm.workClientInfo.hasUscc = JSON.stringify(this.inputForm.workClientInfo.hasUscc)
              this.$refs.uploadComponent.newUpload(method, this.dataListNew, 'workClient', 300)
            })
          }
          if (method !== 'edit' && method !== 'view') {
            this.$refs.uploadComponent.newUpload(method, [], 'workClient', 300)
          }
          this.loading = false
        })
      },
      // 表单提交
      doSubmit () {
      	if (this.inputForm.workClientInfo.hasUscc === '1'){
			if (!this.commonJS.isEmpty(this.inputForm.workClientInfo.uscCode)) {
				this.workClientService.haveUscCode(this.inputForm.id, this.inputForm.workClientInfo.uscCode).then((data) => {
					if (!data) {
						this.$message.error('该统一社会信用代码已存在')
					}
				})
			} else {
				this.$message.error('统一社会信用代码为空')
				return
			}
		}
        if (!this.commonJS.isEmpty(this.inputForm.workClientInfo.name)) {
          this.workClientService.haveWorkClient(this.inputForm.id, this.inputForm.workClientInfo.name).then((data) => {
            if (!data) {
              this.$message.error('该客户名称已存在')
            }
          })
        } else {
          this.$message.error('客户名称为空')
          return
        }
        if (this.$refs.uploadComponent.checkProgress()) {
          this.loading = false
          return
        }
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.inputForm.workAttachments = []
            this.dataListNew = this.$refs.uploadComponent.getDataList()
            this.dataListNew.forEach((item) => {
              if (item.id === null || item.id === undefined || item.id === '') {
                item.url = item.raw.url
              }
              item.attachmentFlag = 'workClient'
              item.fileSize = item.size
              item.attachmentName = item.name
              item.createBy = null
              this.inputForm.workAttachments.push(item)
            })
            this.inputForm.workClientBank = []
            this.bankInfos.forEach((item) => {
              this.inputForm.workClientBank.push(item)
            })
            this.inputForm.workClientLinkman = []
            this.linkmanInfos.forEach((item) => {
              this.inputForm.workClientLinkman.push(item)
            })
            // if (this.inputForm.workClientBank.length === 0) {
            //   this.$message.error('开户行信息至少填写一条')
            //   this.loading = false
            //   return
            // } else {
            let flag = true
			  console.log(this.inputForm.workClientBank)
            this.inputForm.workClientBank.forEach(item => {
              if (item.ourBank === null || item.ourBank === undefined || item.ourBank === '') {
              	console.log('开票银行未填写')
                this.$message.error('开票银行未填写')
                this.loading = false
                flag = false
                return
              } else if (item.bankNumber === null || item.bankNumber === undefined || item.bankNumber === '') {
                this.$message.error('开票账号未填写')
                this.loading = false
                flag = false
                return
              }
              if (!this.validateXG.isBankNumber(item.bankNumber)) {
                this.$message.error('请输入正确的开票账号')
                this.loading = false
                flag = false
              }
            })
            if (flag === false) {
              return
            }
            // }
            if (this.inputForm.workClientLinkman.length === 0) {
              this.$message.error('联系人信息至少填写一条')
              this.loading = false
              return
            } else {
              let flag = true
              this.inputForm.workClientLinkman.forEach(item => {
                if (item.name === null || item.name === undefined || item.name === '') {
                  this.$message.error('联系人姓名未填写')
                  this.loading = false
                  flag = false
                  return
                }
                if (!this.validateXG.isPhoneOrMobile(item.linkPhone)) {
                  this.$message.error('联系人联系方式1填写不正确')
                  this.loading = false
                  flag = false
                }
              })
              if (flag === false) {
                return
              }
            }
            if (this.inputForm.workClientLinkman.length !== 0) {
              let flag = true
              this.inputForm.workClientLinkman.forEach(item => {
                if (!this.commonJS.isEmpty(item.email)) {
                  if (!this.validateXG.isEmail(item.email)) {
                    this.$message.error('联系人信息-Email填写不正确')
                    this.loading = false
                    flag = false
                    return
                  }
                }
                if (!this.commonJS.isEmpty(item.qq)) {
                  if (!this.validate.isQq(item.qq)) {
                    this.$message.error('联系人信息-qq填写不正确')
                    this.loading = false
                    flag = false
                    return
                  }
                }
                flag = true
              })
              if (flag === false) {
                return
              }
            }

            this.inputForm.workClientInfo.deputy = this.inputForm.workClientInfo.deputyList.join(',')

            this.workClientService.save(this.inputForm).then((data) => {
              this.close()
              this.$message.success(data)
              this.$emit('refreshDataList')
              this.loading = false
            }).catch(() => {
              this.loading = false
            })
          }
        })
      },
      checkBankNumber (row) {
        if (!this.validateXG.isBankNumber(row.bankNumber)) {
          this.$message.error('请输入正确的开票账号')
          throw new Error('请输入正确的开票账号')
        }
      },
      close () {
        this.$refs.uploadComponent.clearUpload()
        this.$refs.inputForm.resetFields()
        this.visible = false
        this.showVi = true
      },
      // 排序
      sortChangeHandle (column) {
        this.orders = []
        if (column.order != null) {
          this.orders.push({column: this.$utils.toLine(column.prop), asc: column.order === 'ascending'})
        }
        this.refreshList()
      },
      deleteMsgById (row, index) {
        this.dataListNew.splice(index, 1)
        if (row.id !== null && row.id !== '' && row.id !== undefined) {
          this.ossService.deleteMsgById(row.id)
        }
      },
      twoDecimalPlaces (num) {
        let str = num.toString()
        var len1 = str.substr(0, 1)
        var len2 = str.substr(1, 1)
        // eslint-disable-next-line eqeqeq
        if (str.length > 1 && len1 == 0 && len2 != '.') {
          str = str.substr(1, 1)
        }
        // eslint-disable-next-line eqeqeq
        if (len1 == '.') {
          str = ''
        }
        // eslint-disable-next-line eqeqeq
        if (str.indexOf('.') != -1) {
          var str_ = str.substr(str.indexOf('.') + 1)
          // eslint-disable-next-line eqeqeq
          if (str_.indexOf('.') != -1) {
            str = str.substr(0, str.indexOf('.') + str_.indexOf('.') + 1)
          }
          if (str_.length > 4) {
            this.$message.warning(`金额小数点后只能输入四位，请正确输入！`)
            return (str = '')
          }
        }
        // eslint-disable-next-line no-useless-escape
        str = str.replace(/[^\d^\.]+/g, '') // 保留数字和小数点
        return str
      },
      positiveInteger (num) {
        let str = num.toString()
        var len1 = str.substr(0, 1)
        var len2 = str.substr(1, 1)
        // eslint-disable-next-line eqeqeq
        if (str.length > 1 && len1 == 0 && len2 != '.') {
          str = str.substr(1, 1)
        }
        // eslint-disable-next-line eqeqeq
        if (len1 == '.') {
          str = ''
        }
        // eslint-disable-next-line no-useless-escape
        str = str.replace(/[^\d^]+/g, '') // 保留数字
        return str
      },
      tableRowClassName ({row, rowIndex}) {
        row.index = rowIndex
      },
      handleRadioChange (val) {
        if (val) {
          this.radio = val.index
        }
      },
      // 点击修改
      dbclickFun (cell) {
        // this.onedit = false
      },
      // 删除
      removeEvent (row, rowIndex, type) {
        if (type === 'bank') {
          this.$refs.xTable1.remove(row)
          this.bankInfos.splice(rowIndex, 1)
        }
        if (type === 'linkman') {
          this.$refs.xTable2.remove(row)
          this.linkmanInfos.splice(rowIndex, 1)
        }
      },
      // 新增
      // eslint-disable-next-line no-dupe-keys
      async insertEvent (type) {
        if (type === 'bank') {
          await this.$refs.xTable1.insert().then((data) => {
          	console.log(data)
            this.bankInfos.push(data.row)
          })
        }
        if (type === 'linkman') {
          await this.$refs.xTable2.insert().then((data) => {
            this.linkmanInfos.push(data.row)
          })
        }
      },
      // 关闭窗口时调用
      closeXTable () {
        this.bankInfos = []
        this.linkmanInfos = []
        this.closePop()
      },
      rowStyle (event) {
        return 'cursor:pointer;'
      },
      async rowClick (event) {
        let id = this.gridData[event.rowIndex].companyid
        await this.workClientService.enterpriseTicketInfo(id).then((data) => {
          this.inputForm.workClientInfo.name = data.ENTNAME
          this.inputForm.workClientInfo.uscCode = data.UNCID
          this.inputForm.workClientInfo.registerAddress = data.OPLOC
        })
        this.visable = false
      },
      async getPopTable () {
        let name = this.inputForm.workClientInfo.name
        if (name !== null && name !== undefined && name !== '') {
          await this.workClientService.enterpriseSearchByName(name).then((data) => {
            this.gridData = data.data.items
          })
        }
        // this.$refs.pops.updatePopper()
      },
      closePop () {
        this.visable = false
      }
    }
  }
</script>

<style>
  .tid_40 .vxe-body--column .vxe-cell{
    padding: 1px;
    text-align: center;
  }
  .tid_40 .vxe-header--row .col--last{
    text-align: center;
  }
  .tid_45 .vxe-body--column .vxe-cell{
    padding: 1px;
    text-align: center;
  }
  .tid_45 .vxe-header--row .col--last{
    text-align: center;
  }
</style>

<style scoped>
  .avatar{
    height: 100px;
  }
  .el-divider__text {
    font-weight: bold;
    font-size: 16px;
  }
</style>
