<template>
  <div>
    <Modal v-model="showEquipModal" :mask-closable="false" :width="1200" class="modal-index-equip">
      <p slot="header">
        选择仪器
      </p>
      <!--内容-->
      <div>
        <Row>
          <Col span="24" />
          <Form inline onsubmit="return false" :label-width="80">
            <Form-item class="search-item" label="仪器名称:" style="margin-bottom: 0">
              <Input v-model="formObj.name" placeholder="请输入仪器名称" @on-enter="_search" /></Input>
            </Form-item>
            <Form-item class="search-btn">
              <Button type="primary" @click="_search">
                搜索
              </Button>
            </Form-item>
          </Form>
          </Col>
          <!-- 表格 -->
          <Col span="24" style="margin-bottom: 10px" />
          <element-table
            ref="pageTable"
            :page-columns="pageColumns"
            :table-height="400"
            :get-page="getPage"
            :opt-col-width="80"
            @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"
              :min-width="item.width"
              :fixed="item.fixed?item.fixed:undefined"
            >
              <template slot-scope="scope">
                <div v-if="item.detail">
                  <a @click.stop="_detailModal(scope.row.id)">{{ scope.row[item.key] }}</a>
                </div>
                <div v-else-if="item.date">
                  {{ scope.row[item.key]?$dateformat(scope.row[item.key],'yyyy-mm-dd'):'' }}
                </div>
                <div v-else>
                  {{ scope.row[item.key] }}
                </div>
              </template>
            </el-table-column>
          </element-table>
          </Col>
        </Row>
      </div>
      <div slot="footer" class="btn-width">
        <Button type="ghost" style="margin-left: 8px" @click="_cancel">
          取消
        </Button>
        <Button type="primary" @click="_ok">
          确定
        </Button>
      </div>
    </Modal>
  </div>
</template>
<script>
import { equip } from '../../../../api'
export default {
  data() {
    return {
      name: '',
      showEquipModal: false,
      currentRowObj: {},
      pageParams: {
        rows: 20
      },
      getPage: {},
      formObj: {
        name: ''
      },
      pageColumns: [
        {
          title: '仪器名称',
          key: 'name',
          sortable: true,
          ellipsis: true,
          width: 160,
          align: 'center'
        },
        {
          title: '供应商名称',
          key: 'supplierName',
          sortable: true,
          ellipsis: true,
          width: 160,
          align: 'center'
        },
        {
          title: '仪器类别',
          key: 'className',
          sortable: true,
          ellipsis: true,
          width: 160,
          align: 'center'
        },
        {
          title: '品牌',
          key: 'brand',
          sortable: true,
          ellipsis: true,
          width: 160,
          align: 'center'
        },
        {
          title: '规格型号',
          key: 'spec',
          sortable: true,
          ellipsis: true,
          width: 160,
          align: 'center'
        },
        {
          title: '单价',
          key: 'price',
          sortable: true,
          ellipsis: true,
          width: 160,
          align: 'center'
        },
        {
          title: '产地',
          key: 'productPlace',
          sortable: true,
          ellipsis: true,
          width: 160,
          align: 'center'
        },
        {
          title: '计量类别',
          key: 'meterType',
          sortable: true,
          ellipsis: true,
          width: 160,
          align: 'center'
        },
        {
          title: '精确度等级',
          key: 'uncertainty',
          sortable: true,
          ellipsis: true,
          width: 160,
          align: 'center'
        },
        {
          title: '精度',
          key: 'accuracy',
          sortable: true,
          ellipsis: true,
          width: 160,
          align: 'center'
        },
        {
          title: '使用范围',
          key: 'range',
          sortable: true,
          ellipsis: true,
          width: 160,
          align: 'center'
        },
        {
          title: '技术参数',
          key: 'techParams',
          sortable: true,
          ellipsis: true,
          width: 160,
          align: 'center'
        },
        {
          title: '描述',
          key: 'remark',
          sortable: true,
          ellipsis: true,
          width: 160,
          align: 'center'
        }
      ]
    }
  },
  methods: {
    _open() {
      this.showEquipModal = true
      this.name = ''
      this._page()
      //  this._clearCurrentRow();     //清除选中的仪器
    },
    _page: async function() {
      Object.assign(this.formObj, this.$refs.pageTable._searchParams())
      const result = await equip.page(this.$serializeForm(this.formObj))
      if (result) {
        this.getPage = result
        this.$refs.pageTable._initTable()
      }
    },
    _search() {
      this.$refs.pageTable._pageChange(1)
    },
    _tableResultChange(msg, data) {
      switch (msg) {
        case 'page':
          break
        case 'select':
          this.currentRowObj = data
          break
        case 'dbSelect':
          this._dbRowChange(data)
          break
        default:
          this._page()
      }
    },
    _cancel() {
      this.showEquipModal = false
    },
    _ok() {
      this.$emit('on-result-change', this.currentRowObj)
      this.showEquipModal = false
    },
    _dbRowChange(data, index) {
      // 双击
      this.currentRowObj = data
      this._ok()
    }
  }
}
</script>
