<template>
  <div>
    <Modal v-model="showModal" v-drag width="1050" class="modal-footer-none zIndex-1100">
      <p slot="header">项目试验项目编制</p>
      <div>
        <Row>
          <!--查询-->
          <Col span="24">
            <Form id="search-contract-record" :label-width="70" inline onsubmit="return false">
              <label class="label-sign"></label>
              <Form-item label="项目名称:">
                <Input v-model="formObj.expName" name="expName" placeholder="请输入项目名称" style="width: 200px"
                       clearable @on-enter="_search"/>
              </Form-item>
              <Form-item class="search-btn">
                <Button type="primary" @click="_search">搜索</Button>
              </Form-item>
            </Form>
          </Col>
          <Col span="24">
            <btn-list :msg="btn" :open="searchOpen" show-search-btn="true" @on-result-change="_btnClick" />
          </Col>
          <!-- 表格 -->
          <Col span="24">
            <PTVXETable ref="pageTable" :table-height="tableHeight"
                        :get-page="getPage"  show-check-box @on-result-change="_tableResultChange">
              <vxe-table-column
                v-for="item in pageColumns"
                :key="item.key"
                :field="item.key"
                :title="item.title"
                :min-width="item.width?item.width:200"
                :fixed="item.fixed?item.fixed:undefined">
                <template slot-scope="scope">
                <span v-if="item.key==='status'">
                  {{scope.row[item.key].display}}
                </span>
                  <span v-else-if="item.key==='ctime'">{{scope.row[item.key]?$dateformat(scope.row[item.key],'yyyy-mm-dd HH:MM:ss'):''}}</span>
                  <span v-else>{{scope.row[item.key]}}</span>
                </template>
              </vxe-table-column>
            </PTVXETable>
          </Col>
        </Row>
      </div>
    </Modal>

  </div>
</template>
<script>
/**
 * 操作日志-委托
 */
import { meterEntrust, soilStatistics } from '../../../api'
export default {
  data() {
    return {
      showModal: false,
      getPage: {},
      searchOpen: false,
      selectIds: [],
      pageColumns: [
        { title: '项目名称', key: 'expName' },
        { title: '检测科室', key: 'groupName' },
        { title: '状态', key: 'status' },
        { title: '备注', key: 'remark' },
        { title: '创建人', key: 'uname' },
        { title: '创建时间', key: 'ctime', dateTime: true }
      ],
      btn: [{ id: '', type: 'primary', name: '提交至审核' }],
      formObj: {
        entrustId: undefined,
        expName: undefined,
        groupId: undefined
      }
    }
  },
  computed: {
    tableHeight: function() {
      return this.$tableHeight('tableModal')
    }
  },
  methods: {
    _open(data) {
      this.showModal = true
      this.formObj.entrustId = data.id
      this.formObj.groupId = data.groupId
      this._page()
    },
    _btnClick(msg, data) {
      switch (msg) {
        case '提交至审核':
          this._submitExpReportMake()
          break
        case 'search':
          this.searchOpen = !this.searchOpen
          break
      }
    },

    _submitExpReportMake() {
      const ids = this.selectIds
      if (ids.length === 0) {
        this.$Message.warning('请至少选择一条数据!')
      } else {
        this._submitExpReportMakeConfirm(
          ids,
          `确认要提交 ${ids.length} 条数据吗?`
        )
      }
    },
    _submitExpReportMakeConfirm(ids, content) {
      this.$Modal.confirm({
        title: '提示',
        content: content || `确定要处理该条数据吗?`,
        onOk: () => {
          this._submitExpReportMakeOk(ids)
        }
      })
    },
    async _submitExpReportMakeOk(ids) {
      const result = await soilStatistics.expReportCheckApprove(ids)
      if (result) {
        this._resultChange('提交成功!')
      }
    },
    _resultChange(msg) {
      this.$Message.success(msg)
      this._page()
      this.$emit('on-result-change')
    },
    _page: async function() {
      Object.assign(this.formObj, this.$refs.pageTable._searchParams())
      const result = await meterEntrust.pageGroupExpReportMake(this.formObj)
      console.log(result)
      if (result) {
        this.getPage = result
        this.$refs.pageTable._hideLoading()
      }
    },
    _tableResultChange(msg, data) {
      switch (msg) {
        case 'changeSize':
          this._page()
          break
        case 'selectIds':
          this.selectIds = data
          break
      }
    },
    _search() {
      this._page()
    }
  }
}
</script>
