<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-original-record-model" inline onsubmit="return false" :label-width="70">
            <label class="label-sign" />
            <Form-item label="模板名称:">
              <Input
                name="title"
                placeholder="请输入模板名称"
                style="width: 200px"
                @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"
            :page-columns="pageColumns"
            :table-height="tableHeight"
            :get-page="getPage"
            :opt-col-width="140"
            @on-result-change="_tableResultChange"
          >
            <el-table-column
              v-for="item in pageColumns"
              :key="item.key"
              show-overflow-tooltip
              sortable
              :prop="item.key"
              :label="item.title"
              :width="item.width"
              :min-width="200"
              :fixed="item.fixed?item.fixed:undefined"
            >
              <template slot-scope="scope">
                <div v-if="item.datetime">
                  {{ scope.row[item.key]?$dateformat(scope.row[item.key],'yyyy-mm-dd HH:MM:ss'):'' }}
                </div>
                <div v-else>
                  {{ scope.row[item.key] }}
                </div>
              </template>
            </el-table-column>
          </element-table>
          </Col>
        </Row>
      </div>
    </Modal>
  </div>
</template>
<script>
/**
 * 操作日志-委托
 */
import { drugItem } from '../../../../../api/index'
export default {
  data() {
    return {
      showModal: false,
      getPage: {},
      dataSource: {},
      pageColumns: [
        { title: '模板名称', key: 'title' },
        { title: '操作时间', key: 'ctime', datetime: true }
      ],
      contractId: ''
    }
  },
  computed: {
    tableHeight: function() {
      return this.$tableHeight('tableModal')
    }
  },
  methods: {
    _open(contractId, dataSource) {
      this.dataSource = dataSource
      this.showModal = true
      this.origin = ''
      this._page()
    },
    async _page() {
      const data = {
        contractId: this.contractId
      }
      if (this.origin) {
        Object.assign(data, { origin: this.origin })
      }
      Object.assign(data, this.$refs.pageTable._searchParams())
      const result = await drugItem.originalRecordsPage(data)
      if (result) {
        this.getPage = result
        this.$refs.pageTable._hideLoading()
      }
    },
    _tableResultChange(msg, data) {
      console.log(msg)
      switch (msg) {
        case 'page':
          this._page()
          break
        case 'dbSelect':
          this.showModal = false
          this._dbSelect(data)
          break
      }
    },
    _dbSelect(data) {
      const callData = { modelId: data, dataSource: this.dataSource }
      this.$emit('on-result-change', callData)
    },
    _search() {
      this.$refs.pageTable._pageChange(1)
    }
  }
}
</script>
