<template>
  <div>
    <Modal v-model="showModal" width="900" class="modal-footer-none zIndex-1100">
      <p slot="header">
        操作日志
      </p>
      <div>
        <Row>
          <!--查询-->
          <Col span="24">
          <Form inline onsubmit="return false" :label-width="70">
            <label class="label-sign" />
            <Form-item label="操作阶段:">
              <Input
                v-model="formObj.origin"
                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">
          <element-table
            ref="pageTable"
            :table-height="tableHeight"
            :get-page="getPage"
            hide-checkbox
            @on-result-change="_tableResultChange"
          >
            <el-table-column
              v-for="item in pageColumns"
              :key="item.key"
              show-overflow-tooltip
              :prop="item.key"
              :label="item.title"
              :min-width="item.width"
              :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>
            </el-table-column>
          </element-table>
          </Col>
        </Row>
      </div>
    </Modal>
  </div>
</template>
<script>
/**
 * 操作日志-委托
 */
import { drugRecord } from '../../api'
export default {
  data() {
    return {
      showModal: false,
      getPage: {},
      pageColumns: [
        { title: '操作类型', key: 'type', width: 80 },
        { title: '操作阶段', key: 'origin', width: 100 },
        { title: '目标阶段', key: 'target', width: 100 },
        { title: '操作人', key: 'operator', width: 80 },
        { title: '操作时间', key: 'ctime', width: 150 },
        { title: '操作原因', key: 'remark', width: 200 },
        { title: '责任人', key: 'liable', width: 80 }
      ],
      formObj: {
        origin: '',
        itemId: ''
      }
    }
  },
  computed: {
    tableHeight: function() {
      return this.$tableHeight('tableModal')
    }
  },
  methods: {
    _open(itemId) {
      this.showModal = true
      this.formObj.itemId = itemId
      this.formObj.origin = ''
      this._page()
    },
    _page: async function() {
      Object.assign(this.formObj, this.$refs.pageTable._searchParams())
      const database = this.$serializeForm(this.formObj)
      console.log(database)
      const result = await drugRecord.pageItemRecord(
        this.$serializeForm(this.formObj)
      )
      if (result) {
        this.getPage = result
        this.$refs.pageTable._initTable()
      }
    },
    _searchParams(formId) {
      return this.$refs.pageTable._searchParams(formId)
    },
    _tableResultChange(msg, data) {
      switch (msg) {
        case 'page':
          this._page()
          break
        // case 'iconClick':
        //   this._iconClick(data.name, data.rowData)
        //   break
        // case 'selectIds':
        //   this.selectIds = data
        //   break
      }
    },
    _search() {
      this.$refs.pageTable._pageChange(1)
    }
  }
}
</script>
