<template>
  <div>



    <Modal v-model="showModal" :mask-closable="false" width="1200">
      <p slot="header">{{modalTitle}}</p>
      <div>
        <Form id="MeterSendTestEdit" ref="formObj" :model="formObj" :label-width="90" inline>
          <Form-item  label="委托商" prop="client" class="width-48">
            <AutoComplete ref="autoInput" v-model="formObj.client" :down-data="customerData"
                          @on-result-change="_cusNameChange" name="client" placeholder="请输入或选择委托单位"
            ></AutoComplete>
          </Form-item>
          <Form-item label="委托日期：" prop="entrustDate" class="width-48">
            <Date-picker v-model="formObj.entrustDate" @on-change="_ctimeChange" type="date" split-panels style="width:100%;"
                         placeholder="请选择委托日期" name="entrustDate"></Date-picker>
          </Form-item>
          <Form-item label="钻孔名称" prop="boreholeName" class="width-48">
            <Input v-model="formObj.boreholeName" name="boreholeName" placeholder="请输入名称"/>
          </Form-item>
          <Form-item label="钻孔位置" prop="boreholeLocation" class="width-48">
            <Input v-model="formObj.boreholeLocation" name="boreholeLocation" placeholder="请输入名称"/>
          </Form-item>
          <Form-item label="纬度" prop="latitude" class="width-48">
            <Input v-model="formObj.latitude" name="latitude" placeholder="请输入纬度"/>
          </Form-item>
          <Form-item label="经度" prop="longitude" class="width-48">
            <Input v-model="formObj.longitude" name="longitude" placeholder="请输入经度"/>
          </Form-item>
          <Form-item label="水深（米）" prop="waterDepth" class="width-48">
            <Input v-model="formObj.waterDepth" name="waterDepth" placeholder="请输入深度"/>
          </Form-item>
          <Form-item label="平均容重" prop="projectNo" class="width-48">
            <Input v-model="formObj.projectNo" name="projectNo" placeholder="请输入平均容重"/>
          </Form-item>
          <Form-item label="制单日期：" prop="tabulateDate" class="width-48">
            <Date-picker v-model="formObj.tabulateDate" @on-change="_tabulateChange" name="tabulateDate" type="date" split-panels style="width:100%;"
                         placeholder="请选择委托日期"></Date-picker>
          </Form-item>
          <Form-item @click.native="_selectPerson" label="制表人" prop="tabulater" class="width-48">
            <Input v-model="formObj.tabulater" name="tabulater" placeholder="请输入名称"/>
          </Form-item>
<!--          <Form-item label="检验类别" prop="testType" class="width-48">-->
<!--            <Input v-model="formObj.testType" name="testType" placeholder="请输入名称"/>-->
<!--          </Form-item>-->
          <Form-item label="检验类别：" prop="testType" class="width-48">
            <el-select @change="typeChange" v-model="formObj.testType" name="testType" placeholder="请选择"
                       size="small"
                       style="width:100%"
                       clearable>
              <el-option
                v-for="item in typeoptions"
                :key="item.name"
                :label="item.name"
                :value="item.key">
              </el-option>
            </el-select>
          </Form-item>
        </Form>
      </div>
      <div style="margin-bottom: 10px;">
        <btn-list :msg="edit?btnEdit:btn" :open="searchOpen" @on-result-change="_btnClick"
                  class="contHide"></btn-list>
      </div>
      <div>
        <PTVXETable
          ref="pageTable"
          :form-id="formId"
          :table-height="500"
          :get-page="getPage"
          :icon-msg="iconMsg"
          :hidePage = true
          @on-result-change="_tableResultChange">
          <vxe-table-column
            v-for="item in pageColumns"
            :key="item.key"
            :field="item.key"
            :title="item.title"
            :width="item.width"
            :min-width="200"
            :fixed="item.fixed?item.fixed:undefined"
            sortable
          >
            <template slot-scope="scope">
<!--              <div v-if="item.key==='sampleCode'" @click.stop="_handleRow(scope)">-->
<!--                <el-input v-model="scope.row.name"  blur placeholder="请输入或选择样品名称" style="width: 150px;"-->
<!--                ></el-input>-->
<!--                <a @on-result-change="_judgeBasisChange" @click="_selectjudgeBasis(scope.$rowIndex)" style="font-size: 18px;" class="">+</a>-->
<!--              </div>-->
              <div v-if="item.key==='siteNo'" @click.stop="_handleRow(scope)">
                <el-input v-model="scope.row.siteNo" blur placeholder="请输入现场编号"
                ></el-input>
              </div>
              <div v-if="item.key==='sampleDepth'" @click.stop="_handleRow(scope)">
                <el-input v-model="scope.row.sampleDepth" blur placeholder="请输入试样深度"
                ></el-input>
              </div>
              <div v-if="item.key==='samplePack'"  @click.stop="_handleRow(scope)">
                <AutoComplete v-model="scope.row.samplePack" :downData="packList"
                              @on-result-change="_packChange" name="samplePack"  placeholder="请输入或选择包装类型"
                ></AutoComplete>
              </div>
              <div v-if="item.key==='sampleDescribe'" @click.stop="_handleRow(scope)">
<!--                <el-input v-model="scope.row.sampleDescribe" blur placeholder="请输入土质描述"-->
<!--                ></el-input>-->
                <AutoComplete v-model="scope.row.sampleDescribe" :downData="soilList"
                              @on-result-change="_soilChange" name="sampleDescribe" placeholder="请输入或选择土质描述"
                ></AutoComplete>
              </div>
              <span v-else> {{ scope.row[item.key] }}</span>
            </template>
          </vxe-table-column>
        </PTVXETable>
      </div>
      <div slot="footer">
        <modal-footer ref="footerModal" :footer="footerList" @on-result-change="_footerResult"></modal-footer>
      </div>
    </Modal>
    <importModal ref="importModal" @on-result-change="_inputBack"   aptitude-item></importModal>
    <SampleItemSelect ref="sampleItemSelectModal" @on-result-change="_itemImportBack" is-change />
    <assignPerson ref="userModal" @on-result-change="_userResult"></assignPerson>
  </div>
</template>
<script>
/**
 * 添加编辑分包商
 */
import { meterEntrust, meterSample, soilEntrust } from '../../../api'
import importModal from '../../../components/import/DownloadTemplateImport'
import AutoComplete from '../../../components/base/AutoCompletes'
import SampleItemSelect from '../../meter-aptitude/standard-manage/SampleItemSelect'
import assignPerson from '../../../components/user-info-single/assignPerson'
import Global from '../../../api/config'
export default {
  components: {
    AutoComplete,
    importModal,
    SampleItemSelect,
    assignPerson
  },
  data() {
    const validatefee = (rule, value, callback) => {
      if (this.formObj.operation.fee === '') {
        callback(new Error('内容不能为空'))
      } else {
        callback()
      }
    }
    const validwaterdepth = (rule, value, callback) => {
      if (this.formObj.waterDepth === '') {
        callback(new Error('水深不能为空'))
      } else {
        callback()
      }
    }
    const validboreholeLocation = (rule, value, callback) => {
      if (this.formObj.boreholeLocation === '') {
        callback(new Error('钻孔位置不能为空'))
      } else {
        callback()
      }
    }
    const validboreholeName = (rule, value, callback) => {
      if (this.formObj.boreholeName === '') {
        callback(new Error('钻孔名称不能为空'))
      } else {
        callback()
      }
    }
    const validateRemark = (rule, value, callback) => {
      if (this.testedCityData.length === 0) {
        callback(new Error('内容不能为空'))
      } else {
        callback()
      }
    }
    const validateClient = (rule, value, callback) => {
      if (this.formObj.client === '') {
        callback(new Error('内容不能为空'))
      } else {
        callback()
      }
    }
    const validateEdate = (rule, value, callback) => {
      if (this.formObj.entrustDate === '') {
        callback(new Error('内容不能为空'))
      } else {
        callback()
      }
    }
    const validateOdate = (rule, value, callback) => {
      if (this.formObj.odate === '') {
        callback(new Error('内容不能为空'))
      } else {
        callback()
      }
    }
    return {
      formId: 'meterSendTestEditFormId',
      getPage: {
        records: []
      },
      showBtn: true,
      customerData: [],
      edit: false,
      cityData: [],
      selectData: [],
      searchOpen: true,
      testedCityData: [],
      judgeType: [{ value: 1, name: '是' }, { value: 0, name: '否' }],
      iconMsg: [
        {
          type: 'md-trash',
          id: '',
          name: '删除'
        }
      ],
      pageColumns: [
        { title: '试样编号', key: 'sampleCode', width: 140 },
        { title: '现场编号', key: 'siteNo', width: 140 },
        { title: '试验项目', key: 'experiments', width: 140 },
        { title: '试样深度', key: 'sampleDepth', width: 140 },
        { title: '样品包装类型', key: 'samplePack', width: 150 },
        { title: '土质描述', key: 'sampleDescribe' }
      ],
      btn: [
        {
          type: 'success',
          id: '',
          name: '添加'
        },
        {
          type: 'success',
          id: '',
          name: '导入试验项目'
        }
        // ,
        // {
        //   type: 'success',
        //   id: '',
        //   name: '导入'
        // }
      ],
      btnEdit: [
        {
          type: 'success',
          id: '',
          name: '添加'
        },
        {
          type: 'success',
          id: '',
          name: '导入样品'
        },
        {
          type: 'success',
          id: '',
          name: '导入试验项目'
        }
        // ,
        // {
        //   type: 'success',
        //   id: '',
        //   name: '导入'
        // }
      ],
      options: [
        {
          name: '检定'
        },
        {
          name: '校准'
        },
        {
          name: '外观检查'
        }
      ],
      typeoptions: [],
      packList: [],
      soilList: [],
      currentIndex: -1,
      id: '',
      modalTitle: '',
      subcontractorId: '',
      formObj: {},
      selectIds: [],
      indexList: [],
      itemList: [],
      ruleValidate: {
        client: [
          {
            required: true,
            message: '委托单位不能为空',
            validator: validateClient,
            trigger: ['blur', 'change']
          }
        ],
        boreholeName: [
          {
            required: true,
            validator: validboreholeName,
            message: '钻孔名称不能为空',
            trigger: 'blur'
          }
        ],
        boreholeLocation: [
          {
            required: true,
            validator: validboreholeLocation,
            message: '钻孔位置不能为空',
            trigger: 'blur'
          }
        ],
        waterDepth: [
          {
            required: true,
            validator: validwaterdepth,
            message: '水深不能为空',
            trigger: 'blur'
          }
        ],
        entrustDate: [
          {
            required: true,
            validator: validateEdate,
            message: '委托日期不能为空',
            trigger: 'blur'
          }
        ],
        odate: [
          {
            required: true,
            validator: validateOdate,
            message: '要求完成时间不能为空',
            trigger: 'blur'
          }
        ],
        'operation.person': [
          { required: true, message: '联系人不能为空', trigger: 'blur' }
        ],
        'operation.fee': [
          {
            required: true,
            validator: validatefee,
            message: '委托费用不能为空',
            trigger: 'blur'
          }
        ],
        'operation.tel': [
          { required: true, message: '联系电话不能为空', trigger: 'blur' }
        ],
        testedCityData: [
          {
            required: true,
            message: '省市区不能为空',
            validator: validateRemark,
            trigger: 'blur'
          }
        ]
      },

      clearingWayList: ['款到后测试', '先测试后付款', '其他情况（）'],
      clearingWayListTemp: ['款到后测试', '先测试后付款', '其他情况（）'],
      showModal: false,
      footerList: [
        { id: '', name: '取消', type: '' },
        { id: '', name: '保存', type: 'primary' }
      ],
      aptitudeData: []
    }
  },
  methods: {
    typeChange(data) {
      this.$forceUpdate()
      this.formObj.testType = data
    },
    _itemImportBack(data) {
      this.$forceUpdate()
      console.log('传过来的数据', data)
      for (let i = 0; i < data.length; i++) {
        data[i].id = undefined
      }
      const info = data
      console.log('去掉id后的data', info)
      for (let i = 0; i < this.indexList.length; i++) {
        const index = this.indexList[i]
        if (this.getPage.records[index].experimentList !== undefined) {
          const name = []
          this.itemList = this.getPage.records[index].experimentList
          name.push(this.getPage.records[index].experiments)
          for (let i = 0; i < info.length; i++) {
            console.log(this.getPage.records[index].experiments[i])
            this.itemList.push(info[i])
            name.push(info[i].name)
          }
          this.getPage.records[index].experiments = name.join('、')
          this.getPage.records[index].experimentList = this.itemList
          this.$set(this.getPage.records, index, this.getPage.records[index])
        } else {
          const name = []
          this.itemList = []
          for (let i = 0; i < info.length; i++) {
            this.itemList.push(info[i])
            name.push(info[i].name)
          }
          this.getPage.records[index].experiments = name.join('、')
          this.getPage.records[index].experimentList = this.itemList
          this.$set(this.getPage.records, index, this.getPage.records[index])
        }
      }
      console.log(this.getPage.records)
    },
    _selectPerson() {
      this.$refs.userModal._openOrg('选择制表人', 'itemTree')
    },
    _userResult(data, msg) {
      this.$forceUpdate()
      console.log(data, msg)
      this.formObj.tabulater = data.realname
      console.log(this.formObj.tabulater)
    },
    _packChange(msg, data) {
      switch (msg) {
        case 'select':
          this.getPage.records[this.currentIndex].samplePack = data
          break
        case 'query':
          this.getPage.records[this.currentIndex].samplePack = data
          break
      }
    },
    _soilChange(msg, data) {
      switch (msg) {
        case 'select':
          this.getPage.records[this.currentIndex].sampleDescribe = data
          break
        case 'query':
          this.getPage.records[this.currentIndex].sampleDescribe = data
          break
      }
    },
    _cusNameChange(msg, data) {
      console.log(msg, data)
      console.log('选择')
      // this.financeObj = {} // 清空维护发票信息的数据
      if (this.$string(this.id).isEmpty()) {
        // 添加的时候选择单位
        switch (msg) {
          case 'select':
            this._customerMatch(data)
            break
          case 'query':
            this._cusNameQuery(data)
            break
        }
      } else if (this.customerData.indexOf(data) !== -1) {
        this._getQueryList(data)
        // 编辑的时候选择单位(互不影响)
        // this.cusName = data
        // this.formObj.customer.cname = data
      } else {
      }
    },
    _customerMatch(data) {
      this._getQueryList(data)
    },
    _cusNameQuery(query) {
      this.formObj.client = query
    },

    _btnClick(msg) {
      this.$nextTick(function() {
        switch (msg) {
          case '添加':
            this._add()
            break
          case '导入试验项目':
            this._importItem()
            break
          case '导入样品':
            this._importSample()
            break
          case 'search':
            this.searchOpen = !this.searchOpen
            break
        }
      })
    },
    _importItem() {
      if (this.selectIds.length === 0) {
        this.$Message.warning('请选择至少一条数据！')
      } else {
        this.$refs.sampleItemSelectModal._open()
        this.allSelect(this.selectData)
      }
    },
    _getByEntrustId: async function(id) {
      const result = await soilEntrust.getVOById(id)
      if (result) {
        this.$forceUpdate()
        const sampleList = Object.assign(
          this.getPage.records,
          result.sampleList
        )
        this.$set(this.getPage.records, sampleList)
      }
    },
    _inputBack(data) {
      console.log(data)
      if (data) {
        this._getByEntrustId(this.id)
      }
      // if (undefined !== data) {
      //   if (this.getPage.records.length > 0) {
      //     const j = this.getPage.records.length
      //     for (let i = j; i < data.length + j; i++) {
      //       console.log(i)
      //       this.getPage.records.push(data[i - j])
      //       if (data[i - j].lastTime !== undefined) {
      //         this.getPage.records[i].lastTime = new Date(data[i - j].lastTime)
      //       }
      //       console.log(this.getPage.records)
      //       // this.getPage.records[i].lastTime = new Date(data[0].lastTime)
      //     }
      //   } else {
      //     for (let i = 0; i < data.length; i++) {
      //       // if (this.getPage.records[i].lastTime !== undefined) {
      //       //   const t = this.getPage.records[i].lastTime
      //       //   const d = t.valueOf(t)
      //       //   console.log('时间戳', d)
      //       //   this.getPage.records[i].lastTime = d
      //       //   this.getPage.records = []
      //       // }
      //       this.getPage.records.push(data[i])
      //       if (data[i].lastTime !== undefined) {
      //         this.getPage.records[i].lastTime = new Date(data[i].lastTime)
      //       }
      //       console.log(data[i].lastTime)
      //     }
      //   }
      // }
    },
    _ctimeChange(data) {
      this.formObj.entrustDate = data
    },
    _tabulateChange(data) {
      this.formObj.tabulateDate = data
    },
    _odateChange(data) {
      this.formObj.odate = data
    },
    _judgeBasisChange(msg, data) {
      switch (msg) {
        case 'select':
          this.formObj.stdId = data.id
          this.formObj.code = data.stdNum
          this.formObj.name = data.name
          this.$refs.formObj.validateField('code')
          break
        case 'query':
          this.formObj.stdId = ''
          this.formObj.code = data.stdNum
          this.formObj.name = ''
          this._getJudgeBasisList(data.stdNum)
          break
        case 'focus':
          this._getJudgeBasisList()
          break
        case 'blur':
          if (this.formObj.stdId === '') {
            this.formObj.code = ''
            this._getJudgeBasisList()
          }
          this.$refs.formObj.validateField('code')
      }
    },
    _selectjudgeBasis(index) {
      console.log(index)
      this.index = index
      this.$refs.EditModal._open()
    },
    _selectverification(index) {
      console.log(index)
      this.index = index
      this.$refs.VerificationModal._open()
    },
    _selectcontractCode() {
      this.$refs.ContractModal._open()
    },
    _backData(data) {
      this.$forceUpdate()
      console.log(typeof this.index)
      this.getPage.records[this.index].name = data.name
      this.getPage.records[this.index].aptitudeId = data.id
      this.getPage.records[this.index].verification = data.code + data.basis
      this.getPage.records[this.index].price = data.price
      this.getPage.records[this.index].totalPrice =
        data.price * this.getPage.records[this.index].quantity
      console.log('返回的数据', data)
      console.log(this.getPage.records)
    },
    _backContract(data) {
      this.formObj.client = data.client
      this.formObj.operation.person = data.person
      this.formObj.operation.tel = data.tel
      this.formObj.operation.fax = data.fax
      if (data.province) {
        this.testedCityData = [data.province, data.city, data.county]
        this.formObj.province = data.province
        this.formObj.city = data.city
        this.formObj.county = data.county
      }
      this.formObj.street = data.street
      this.formObj.entrustDate = new Date(data.entrustDate)
      this.formObj.odate = new Date(data.odate)
      this.formObj.contractCode = data.salesCode
      this.formObj.operation.fee = data.discountPrice
      if (data.sampleQuoteList) {
        this.getPage.records = data.sampleQuoteList
      } else {
        this.getPage.records = []
      }
    },
    _backVerification(data) {
      this.$forceUpdate()
      this.getPage.records[this.index].verification = data.verification
    },
    _add() {
      const data = {
        sampleCode: '',
        sampleDepth: '',
        samplePack: '',
        sampleDescribe: '',
        siteNo: '',
        experiments: ''
      }
      this.getPage.records.unshift(data)
    },
    _getPackList: async function() {
      const result = await soilEntrust.testType('样品包装类型')
      if (result) {
        const pack = []
        for (let i = 0; i < result.length; i++) {
          pack.push(result[i].name)
        }
        this.packList = pack
      }
    },
    _getSoil: async function() {
      const result = await soilEntrust.testType('土质描述')
      if (result) {
        const soilRemark = []
        for (let i = 0; i < result.length; i++) {
          soilRemark.push(result[i].name)
        }
        this.soilList = soilRemark
      }
    },
    _importSample() {
      const data = {
        importUrl: '/soil/v1/entrust/edit_import_entrust/?id=' + this.id,
        downloadUrl: '/meter/v1/excel/template/MeterSampleImport',
        title: '样品导入'
      }
      this.$refs.importModal._open(data, '样品导入')
    },

    _tableResultChange(msg, data, selData) {
      switch (msg) {
        case 'selectIds':
          this.selectIds = data
          this.selectData = selData
          console.log(this.selectIds)
          break
        case 'iconClick':
          this._iconClick(data.name, data.rowData, data.rowIndex)
          break
        // case 'changeSize':
        //   this._page()
        //   break
      }
    },
    allSelect(data) {
      console.log(data)
      this.indexList = []
      for (let i = 0; i < data.length; i++) {
        this.indexList.push(data[i].index)
      }
      console.log('索引', this.indexList)
    },
    // 省 市 区
    _cascaderResult(name, data, msg) {
      switch (name) {
        case 'cus':
          this._casChange(data, msg)
          break
        case 'tested':
          this._testedChange(data, msg)
          break
      }
    },
    _emptyProvince() {
      this.cityData = []
      this.testedCityData = []
      // this.formObj.tested.testedProvince = ''
      // this.formObj.tested.testedCity = ''
      // this.formObj.tested.testedCounty = ''
      // this.formObj.testedTemp.testedProvince = ''
      // this.formObj.testedTemp.testedCity = ''
      // this.formObj.testedTemp.testedCounty = ''
    },
    _testedChange(data, msg) {
      // 省、市、区
      if (msg === 'clear') {
        // this.formObj.tested.testedProvince = ''
        // this.formObj.tested.testedCity = ''
        // this.formObj.tested.testedCounty = ''
        this.formObj.testedTemp.testedProvince = ''
        this.formObj.testedTemp.testedCity = ''
        this.formObj.testedTemp.testedCounty = ''
        this.formObj.province = ''
        this.formObj.city = ''
        this.formObj.county = ''
        this.testedCityData = []
      } else {
        // this.formObj.tested.testedProvince = data.value[0]
        // this.formObj.tested.testedCity = data.value[1]
        // this.formObj.tested.testedCounty = data.value[2]
        this.formObj.province = data.value[0]
        this.formObj.city = data.value[1]
        this.formObj.county = data.value[2]
        this.testedCityData = [data.value[0], data.value[1], data.value[2]]
      }
    },

    _iconClick(res, data, index) {
      switch (res) {
        case '编辑':
          // this._editModal(true, data.id)
          break
        case '删除':
          this.getPage.records.splice(index, 1)
          this._deleteSample(data)
          break
        case '操作日志':
          // this._record(data.id)
          break
      }
    },
    _deleteSample(data) {
      if (data.id === undefined) {
        return false
      } else {
        this._delete(data.id)
      }
    },

    _delete: async function(id) {
      const result = await meterSample.deleteById(id)
      if (result) {
        console.log(result)
      }
    },

    _selectAptitude(data) {
      console.log(data)
    },
    _handleRow(data) {
      this.currentRow = data.row
      this.currentIndex = data.rowIndex
    },
    channelInputLimit(e) {
      const key = e.key
      // 不允许输入'e'和'.'
      if (key === 'e' || key === '.') {
        e.returnValue = false
        return false
      }
      return true
    },
    /** *modal-footer */
    _footerResult(name) {
      switch (name) {
        case '取消':
          this._cancel()
          break
        case '保存':
          this._ok()
          break
      }
    },
    _hideLoading() {
      this.$refs.footerModal._hideLoading()
    },
    _resultChange(msg) {
      this.showModal = false
      this.$Message.success(msg)
      this.$emit('on-result-change')
      this._hideLoading()
    },
    _ok() {
      this.$refs.formObj.validate(valid => {
        if (valid) {
          const data = this.$serialize('MeterSendTestEdit')
          console.log(this.getPage.records)
          // Object.assign(this.formObj, data)
          if (this.$string(this.id).isEmpty()) {
            // 添加
            // const saveData = this.formObj
            data.sampleList = this.getPage.records
            console.log(data)
            this._save(data)
          } else {
            // const saveData = this.formObj
            data.id = this.id
            data.sampleList = this.getPage.records
            console.log(data)
            this._edit(data)
          }
        } else {
          this.$Message.error('表单验证失败!')
        }
      })
    },
    _wayResult(msg, data) {
      switch (msg) {
        case 'select':
          this.formObj.clearingWay = data
          break
        case 'query':
          this.formObj.clearingWay = data
          this._wayQuery(data)
          break
      }
    },
    _wayQuery(query) {
      if (query === '') {
        this.clearingWayList = this.clearingWayListTemp
      } else {
        this.clearingWayList = this.clearingWayListTemp.filter(
          item => item.indexOf(query) > -1
        )
      }
    },
    _cancel() {
      this.showModal = false
    },
    _open(formObj) {
      this.$refs.autoInput._clear()
      this.edit = false
      this._getList()
      this._getTestType()
      this._getPackList()
      this._getSoil()
      this._getUser()
      this.showBtn = true
      this.showModal = true
      this._getUser()
      this._hideLoading()
      if (this.$string(formObj).isEmpty()) {
        this.$refs.formObj.resetFields()
        this.getPage.records = []
        this.formObj.client = ''
        this.id = ''
        this.formObj.entrustDate = new Date()
        this.modalTitle = '委托单新增'
      }
    },
    _openEdit(formObj) {
      this.edit = true
      console.log(formObj)
      this._getList()
      this._getTestType()
      this._getPackList()
      this._getSoil()
      this.showBtn = false
      this.showModal = true
      this.$refs.formObj.resetFields()
      this._getUser()
      this.getPage.records = []
      this._hideLoading()
      this.id = ''
      this.modalTitle = '委托单编辑'
      this.id = formObj.id
      this.formObj = formObj
      this._showTime(formObj)
      if (formObj.sampleList) {
        this.getPage.records = formObj.sampleList
      }
      // for (let i = 0; i < formObj.sampleList.length; i++) {
      //   if (formObj.sampleList[i].lastTime !== undefined) {
      //     this.getPage.records[i].lastTime = new Date(
      //       formObj.sampleList[i].lastTime
      //     )
      //   }
      // }
    },
    _getUser() {
      const user = Global.getUserInfo()
      this.formObj.tabulater = user.realname
    },
    _getTestType: async function() {
      const result = await soilEntrust.testType('检验类别')
      console.log(result)
      if (result) {
        console.log('检验类别', result)
        this.typeoptions = result
      }
    },
    _showTime(formObj) {
      if (this.formObj.entrustDate === undefined) {
        this.formObj.entrustDate = ''
      } else {
        this.formObj.entrustDate = new Date(formObj.entrustDate)
      }
      if (this.formObj.tabulateDate === undefined) {
        this.formObj.tabulateDate = ''
      } else {
        this.formObj.tabulateDate = new Date(formObj.tabulateDate)
      }
    },
    _showAddress(formObj) {
      this.testedCityData = []
      if (
        formObj.province !== undefined &&
        formObj.city !== undefined &&
        formObj.county !== undefined
      ) {
        this.testedCityData.push(formObj.province)
        this.testedCityData.push(formObj.city)
        this.testedCityData.push(formObj.county)
      }
    },
    _getList: async function() {
      const result = await meterEntrust.pageList()
      const list = []
      if (result) {
        for (let i = 0; i < result.length; i++) {
          list.push(result[i].cname)
        }
        this.customerData = list
      }
    },
    _getQueryList: async function(data) {
      const result = await meterEntrust.pageQueryList(data)
      if (result) {
        console.log('委托商', result)
      }
    },
    _save: async function(data) {
      this._hideLoading()
      console.log(data)
      const result = await soilEntrust.save(data)
      console.log(result)
      if (result) {
        this._resultChange('添加成功!')
      }
    },
    _edit: async function(data) {
      this._hideLoading()
      const result = await soilEntrust.editDTO(data)
      if (result) {
        this._resultChange('编辑成功!')
      }
    },
    _visibleChange(data) {
      this.$forceUpdate()
      console.log('清空')
      this.formObj.client = ''
      this.formObj = {}
    }
  }
}
</script>
<style>
.vxe-table--tooltip-wrapper {
  z-index: 2147483647 !important;
}
</style>
