<template>
  <div>
    <Modal v-model="showModal" width="900" 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.origin" @on-enter="_search" name="origin" placeholder="请输入操作阶段"
                       style="width: 200px" clearable/>
              </Form-item>
              <Form-item class="search-btn">
                <Button @click="_search" type="primary">搜索</Button>
              </Form-item>
            </Form>
          </Col>
          <!-- 表格 -->
          <Col span="24">
            <PTVXETable ref="pageTable" :table-height="tableHeight"
                        :get-page="getPage" @on-result-change="_tableResultChange" hide-checkbox>
              <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==='type'">
                  {{scope.row[item.key] === 0 ? '流转' : scope.row[item.key] === 1 ? '退回': scope.row[item.key] === 2 ?'更新' :
                  scope.row[item.key] === 3 ? '转发':'文件'}}
                </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 } from '../../api'
export default {
  data() {
    return {
      showModal: false,
      getPage: {},
      pageColumns: [
        { title: '操作类型', key: 'type', width: 80 },
        { title: '操作阶段', key: 'origin', width: 120 },
        { title: '目标阶段', key: 'target', width: 120 },
        { title: '操作人', key: 'operator', width: 80 },
        { title: '操作时间', key: 'ctime', width: 150 },
        { title: '操作原因', key: 'remark' },
        { title: '责任人', key: 'liable', width: 80 }
      ],
      formObj: {
        entrustId: undefined,
        origin: undefined,
        sampleId: undefined
      }
    }
  },
  computed: {
    tableHeight: function() {
      return this.$tableHeight('tableModal')
    }
  },
  methods: {
    _open(entrustId) {
      this.showModal = true
      this.formObj.entrustId = entrustId
      this.formObj.sampleId = undefined
      this._page()
    },
    _openTask(sampleId) {
      this.showModal = true
      this.formObj.sampleId = sampleId
      this.formObj.entrustId = undefined
      this._pageTask()
    },
    _openSurplus(samplePrepareId) {
      this.showModal = true
      this.formObj.samplePrepareId = samplePrepareId
      this._pageSurplus()
    },
    _openBcakup(sampleBackupId) {
      this.showModal = true
      this.formObj.sampleBackupId = sampleBackupId
      this._pageBackup()
    },
    _page: async function() {
      console.log('要传的参数')
      console.log(this.formObj)
      const result = await meterEntrust.pageOutTaskOperation(this.formObj)
      console.log(result)
      if (result) {
        this.getPage = result
      }
      // this.$refs.pageTable._page(
      //   'search-contract-record',
      //   'FoodContractRecord/page',
      //   this.$serializeFormSearch(this.formObj)
      // )
    },
    _pageSurplus: async function() {
      const result = await meterEntrust.prepareRecordPage(
        this.$serializeForm(this.formObj)
      )
      if (result) {
        this.getPage = result
      }
    },
    _pageBackup: async function() {
      const result = await meterEntrust.backupRecordPage(
        this.$serializeForm(this.formObj)
      )
      if (result) {
        this.getPage = result
      }
    },
    _pageTask: async function() {
      console.log('要传的参数')
      console.log(this.formObj)
      const result = await meterEntrust.pageTask(this.formObj)
      console.log(result)
      if (result) {
        this.getPage = result
      }
    },
    _tableResultChange(msg, data) {
      switch (msg) {
        case 'page':
          this.getPage = this.$store.state.FoodContractRecord.page
          break
        case 'changeSize':
          this._page()
          break
      }
    },
    _search() {
      if (this.formObj.entrustId !== undefined) {
        this._page()
      } else if (this.formObj.sampleBackupId !== undefined) {
        this._pageBackup()
      } else if (this.formObj.samplePrepareId !== undefined) {
        this._pageSurplus()
      } else {
        this._pageTask()
      }
    }
  }
}
</script>
