<template xmlns:v-slot="http://www.w3.org/1999/XSL/Transform">
  <div>
    <el-dialog
      :title="title"
      :close-on-click-modal="false"
      v-dialogDrag
      width="1200px"
      @close="close(),closeXTable()"
      @keyup.enter.native="doSubmit"
      :visible.sync="visible">
      <el-form size="middle" :model="inputForm" ref="inputForm" 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" :rules="[
                  {required: true, message:'请输入客户名称', trigger:'blur'}
                ]">
              <el-input 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
                  :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>

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

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

            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="归属区域" prop="workClientInfo.areaId"
                          :rules="[
                   {required: true, message:'请选择归属区域', trigger:'blur'}
                 ]">
              <SelectTree
                ref="areaTree"
                :props="{
                      value: 'id',             // ID字段名
                      label: 'name',         // 显示名称
                      children: 'children'    // 子级字段名
                    }"
                url="/sys/area/treeData"
                :value="inputForm.workClientInfo.areaId"
                :clearable="true"
                :accordion="true"
                v-if="visible"
                @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">
            <el-form-item label="统一社会信用代码" prop="workClientInfo.uscCode" v-if="inputForm.workClientInfo.hasUscc === '1'"
                          :rules="[
                   {required: true, message:'请输入统一社会信用代码', trigger:'blur'}
                 ]">
              <el-input 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 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 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 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: this.validatorXG.isMobile, 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 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 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 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="mini" @click="insertEvent('bank')">新增</vxe-button>
            </template>
          </vxe-toolbar>
        </el-form-item>

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

          <vxe-table-column field="ourBank" title="开户银行" :edit-render="{}">
            <template v-slot:edit="scope" >
              <el-input v-model="scope.row.ourBank" ></el-input>
            </template>
          </vxe-table-column>
          <vxe-table-column field="bankNumber" title="开户账号" :edit-render="{}">
            <template v-slot:edit="scope" >
              <el-input v-model="scope.row.bankNumber" ></el-input>
            </template>
          </vxe-table-column>
          <vxe-table-column field="remarks" title="备注信息" :edit-render="{}">
            <template v-slot:edit="scope" >
              <el-input v-model="scope.row.remarks" ></el-input>
            </template>
          </vxe-table-column>
          <vxe-table-column title="操作" width="100">
            <template v-slot="scope">
              <el-button size="mini" 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="mini" @click="insertEvent('linkman')">新增</vxe-button>
            </template>
          </vxe-toolbar>
        </el-form-item>

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

        <vxe-table-column field="name" title="联系人姓名" :edit-render="{}">
          <template v-slot:edit="scope">
            <el-input v-model="scope.row.name" ></el-input>
          </template>
        </vxe-table-column>
        <vxe-table-column field="office" title="部门" :edit-render="{}">
          <template v-slot:edit="scope">
            <el-input v-model="scope.row.office" ></el-input>
          </template>
        </vxe-table-column>
        <vxe-table-column field="position" title="职务" :edit-render="{}">
          <template v-slot:edit="scope">
            <el-input v-model="scope.row.position" ></el-input>
          </template>
        </vxe-table-column>
        <vxe-table-column field="qq" title="QQ" :edit-render="{}">
          <template v-slot:edit="scope">
            <el-input v-model="scope.row.qq" ></el-input>
          </template>
        </vxe-table-column>
        <vxe-table-column field="linkPhone" title="联系方式1" :edit-render="{}">
          <template v-slot:edit="scope">
            <el-input v-model="scope.row.linkPhone" ></el-input>
          </template>
        </vxe-table-column>
        <vxe-table-column field="linkMobile" title="联系方式2" :edit-render="{}">
          <template v-slot:edit="scope">
            <el-input v-model="scope.row.linkMobile" ></el-input>
          </template>
        </vxe-table-column>
        <vxe-table-column field="email" title="E-mail" :edit-render="{}">
          <template v-slot:edit="scope">
            <el-input v-model="scope.row.email" ></el-input>
          </template>
        </vxe-table-column>
        <vxe-table-column title="操作" width="100">
          <template v-slot="scope">
            <el-button size="mini" type="danger" @click="removeEvent(scope.row,scope.$rowIndex,'linkman')">删除</el-button>
          </template>
        </vxe-table-column>
        </vxe-table>
        <el-divider content-position="left"><i class="el-icon-document"></i> 附件信息</el-divider>
        <el-upload  ref="upload" style="display: inline-block; margin-left: 5em; :show-header='status' ;" action=""
                   :limit="999" :http-request="httpRequest"
                   multiple
                   :on-exceed="(files, fileList) =>{
                    $message.warning(`当前限制选择 999 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`)
                   }"
                   :on-remove="handleRemove"
                   :show-file-list="false"
                   :on-change="changes"
                   :file-list="filesArra2">
          <el-button type="info" size="mini" v-if="inputForm.permissionFlag&&showVi">点击上传</el-button>
          </el-upload>
          <div style="height: calc(100% - 80px);margin-top: 10px">
          <vxe-table
            style="margin-left: 5em"
            border="inner"
            auto-resize
            resizable
            height="200px"
            :loading="loading"
            size="small"
            ref="projectTable"
            show-header-overflow
            show-overflow
            highlight-hover-row
            :menu-config="{}"
            :print-config="{}"
            @sort-change="sortChangeHandle"
            :sort-config="{remote:true}"
            :data="dataListNew"
            :checkbox-config="{}">
            <vxe-column type="seq" width="40"></vxe-column>
            <vxe-column title="文件名称" field="name">
              <template slot-scope="scope">
                <el-link  type="primary" :underline="false" @click="showFile(scope.row)">{{scope.row.name}}</el-link>
              </template>
            </vxe-column>
            <vxe-column title="创建人" field="createBy"></vxe-column>
            <vxe-column title="创建时间" field="createDate"></vxe-column>
            <vxe-column title="操作" width="200px" fixed="right" align="center">
              <template  slot-scope="scope">
                <el-button type="text"  icon="el-icon-delete" size="small" v-if="inputForm.permissionFlag&&showVi" @click="deleteMsgById(scope.row, scope.$rowIndex)">删除</el-button>
                <el-button type="text"  icon="el-icon-edit" size="small" @click="toHref(scope.row)">下载</el-button>
              </template>
            </vxe-column>
          </vxe-table>
          </div>
      </el-form>

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

<script>
  import WorkClientService from '@/api/sys/WorkClientService'
  import SelectTree from '@/components/treeSelect/treeSelect.vue'
  import OSSSerive, {
    httpRequest,
    handleRemove,
    fileName
  } from '@/api/sys/OSSService'
  import moment from 'moment'
  import ElImageViewer from 'element-ui/packages/image/src/image-viewer'
  export default {
    data () {
      return {
        visable: false,
        gridData: [],
        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: ''
      }
    },
    components: {
      ElImageViewer,
      SelectTree
    },
    ossService: null,
    workClientService: null,
    created () {
      this.ossService = new OSSSerive()
      this.workClientService = new WorkClientService()
    },
    methods: {
      async toHref (row) {
        const link = document.createElement('a')
        if (row.id === null || row.id === undefined || row.id === '') {
          await this.ossService.getTemporaryUrl(row.raw.url).then((data) => {
            const url = data.data // 完整的url则直接使用
            // 这里是将url转成blob地址，
            fetch(url).then(res => res.blob()).then(blob => { // 将链接地址字符内容转变成blob地址
              link.href = URL.createObjectURL(blob)
              console.log(link.href)
              link.download = row.name || '' // 下载文件的名字
              // a.download = url.split('/')[url.split('/').length -1] //  // 下载文件的名字
              document.body.appendChild(link)
              link.click()
              // 在资源下载完成后 清除 占用的缓存资源
              window.URL.revokeObjectURL(link.href)
              document.body.removeChild(link)
            })
          })
        } else {
          const url = row.temporaryUrl // 完整的url则直接使用
          // 这里是将url转成blob地址，
          fetch(url).then(res => res.blob()).then(blob => { // 将链接地址字符内容转变成blob地址
            link.href = URL.createObjectURL(blob)
            console.log(link.href)
            link.download = row.name || '' // 下载文件的名字
            // a.download = url.split('/')[url.split('/').length -1] //  // 下载文件的名字
            document.body.appendChild(link)
            link.click()
            // 在资源下载完成后 清除 占用的缓存资源
            window.URL.revokeObjectURL(link.href)
            document.body.removeChild(link)
          })
        }
      },
      onPreview (url) {
        this.url = url
        this.showViewer = true
      },
      // 关闭查看器
      closeViewer () {
        this.url = ''
        this.showViewer = false
      },
      init (method, id) {
        this.dataList = []
        this.dataListNew = []
        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)
              })
              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.loading = false
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.inputForm.workAttachments = []
            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
              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
              this.inputForm.workClientBank.forEach(item => {
                if (item.ourBank === null || item.ourBank === undefined || item.ourBank === '') {
                  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.isMobile(item.linkPhone)) {
                  this.$message.error('联系人联系方式1填写不正确')
                  this.loading = false
                  flag = false
                  return
                }
                if (!this.validateXG.isMobile(item.linkMobile)) {
                  this.$message.error('联系人联系方式2填写不正确')
                  this.loading = false
                  flag = false
                }
              })
              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
            })
          }
        })
      },
      close () {
        this.$refs.inputForm.resetFields()
        this.visible = false
        this.showVi = true
      },
      httpRequest (file) {
        httpRequest(file, fileName(file), 'projectRecords')
      },
      handleRemove () {
        this.fileList = handleRemove()
      },
      changes (file, fileList) {
        console.log('file', file)
        console.log('22', fileList)
        this.dataListNew = []
        this.dataList.forEach((item) => {
          this.dataListNew.push(item)
        })
        fileList.forEach((item) => {
          item.createDate = moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
          item.createBy = this.$store.state.user.name
          this.dataListNew.push(item)
        })
        console.log('11', this.dataList)
        console.log('33', this.dataListNew)
        const isLt2M = file.size / 1024 / 1024 < 300
        if (isLt2M === false) {
          this.$message.error('文件大小不能超过 ' + 300 + 'M !')
          this.fileList = []
          this.filesArra2 = []
        }
      },
      async showFile (row) {
        console.log('row', row)
        let suffix = row.name.substring(row.name.lastIndexOf('.') + 1)
        if (suffix === 'jpg' || suffix === 'png' || suffix === 'gif' || suffix === 'bmp' || suffix === 'jpeg') {
          if (row.url !== null && row.url !== undefined && row.url !== '') {
            this.onPreview(row.url)
            return
          } else {
            await this.ossService.getTemporaryUrl(row.raw.url).then((data) => {
              this.onPreview(data.data)
            })
            return
          }
        }
        if (row.url !== null && row.url !== undefined && row.url !== '') {
          if (suffix === 'pdf') {
            window.open('https://view.xdocin.com/xdoc?_xdoc=' + row.url, '_blank')
          } else if (suffix === 'rar' || suffix === 'zip' || suffix === 'jar' || suffix === '7z') {
            window.open('http://ow365.cn/?i=25008&furl=' + row.url, '_blank')
          } else {
            window.open('https://view.officeapps.live.com/op/view.aspx?src=' + row.url, '_blank')
          }
        } else if (row.raw.url !== null && row.raw.url !== undefined && row.raw.url !== '') {
          await this.ossService.getTemporaryUrl(row.raw.url).then((data) => {
            this.rowurl = data.data
          })
          if (suffix === 'pdf') {
            window.open('https://view.xdocin.com/xdoc?_xdoc=' + this.rowurl, '_blank')
          } else if (suffix === 'rar' || suffix === 'zip' || suffix === 'jar' || suffix === '7z') {
            window.open('http://ow365.cn/?i=25008&furl=' + this.rowurl, '_blank')
          } else {
            window.open('https://view.officeapps.live.com/op/view.aspx?src=' + this.rowurl, '_blank')
          }
        }
      },
      // 排序
      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) {
        console.log(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) => {
            this.bankInfos.push(data)
          })
        }
        if (type === 'linkman') {
          await this.$refs.xTable2.insert().then((data) => {
            this.linkmanInfos.push(data)
          })
        }
      },
      // 关闭窗口时调用
      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) => {
          console.log(data)
          this.inputForm.workClientInfo.name = data.data.ENTNAME
          this.inputForm.workClientInfo.uscCode = data.data.UNCID
          this.inputForm.workClientInfo.registerAddress = data.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>
