<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" 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" :tableHeight="tableHeight"
                        @on-result-change="_tableResultChange" :getPage="getPage" hide-checkbox>
              <vxe-table-column
                :field="item.key"
                :title="item.title"
                :min-width="item.width?item.width:200"
                :fixed="item.fixed?item.fixed:undefined"
                v-for="item in pageColumns" :key="item.key">
                <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: {
        origin: '',
        entrustId: ''
      }
    }
  },
  computed: {
    tableHeight: function() {
      return this.$tableHeight('tableModal')
    }
  },
  methods: {
    _open(contractId) {
      this.showModal = true
      this.formObj.entrustId = contractId
      this.formObj.origin = undefined
      this._page()
    },
    _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)
      // )
    },

    _tableResultChange(msg, data) {
      switch (msg) {
        case 'page':
          this.getPage = this.$store.state.FoodContractRecord.page
          break
        case 'changeSize':
          this._page()
          break
      }
    },
    _search() {
      this.$refs.pageTable._pageChange(1)
    }
  }
}
</script>
