<template>
  <div>
    <div class="tabBox clearfix" style="position: relative;background-color: white;margin-bottom: 20px;margin-top: 20px;">
      <el-tabs v-model="activeName">
        <el-tab-pane label="不合格项目" name="first">
          <div class="saleBox" style="padding-left: 20px;float: left;background-color: lightblue">
            <p style="font-size: 14px;">
              <!--                      {{ range }}不合格数量-->
              不合格数量
            </p>
            <div id="saleImg" style="width: 660px;height: 260px;" />
          </div>
        </el-tab-pane>
      </el-tabs>
      <div class="timeBox" style="float: right;position: absolute;right: 0px;top: 0px;">
        <div style="float: left;line-height: 34px;">
          <!--        <a @click="_rangeDayChange" :class="{actived:pitch=='_rangeDayChange'}">今日</a>-->
          <!--        <a @click="_rangeWeekChange" :class="{actived:pitch=='_rangeWeekChange'}">本周</a>-->
          <!--        <a @click="_rangeMonthChange" :class="{actived:pitch=='_rangeMonthChange'}">本月</a>-->
          <!--        <a @click="_rangeYearChange" :class="{actived:pitch=='_rangeYearChange'}">本年</a>-->
          <a>今日</a>
          <a>本周</a>
          <a>本月</a>
          <a>本年</a>
        </div>
        <div class="calendar" style="overflow: hidden">
          <div class="block">
            <el-date-picker
              v-model="value1"
              type="datetimerange"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :default-time="['12:00:00']"
              style="width: 200px;margin-left: 20px;"
            />
          </div>
        </div>
      </div>
    </div>
    <div class="failTable">
      <Form
        v-show="searchOpen"
        inline
        onsubmit="return false"
        :label-width="70"
        class="search-form"
      >
        <label class="label-sign" />
        <Form-item class="search-item" label="物料类型:">
          <Input v-model="formObj.name" placeholder="请输入物料类型" clearable @on-enter="_formSearch" />
        </Form-item>
        <Form-item class="search-btn">
          <Button type="primary" @click="_formSearch">
            搜索
          </Button>
        </Form-item>
      </Form>

      <element-table
        ref="pageTable"
        :page-columns="pageColumns"
        :table-height="tableHeight"
        :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"
          :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>
            <span v-else-if="item.type" class="blue-color">
              {{ scope.row[item.key] === undefined ? '': scope.row[item.key].display }}
            </span>
            <div v-else>
              {{ scope.row[item.key] }}
            </div>
          </template>
        </el-table-column>
        <!--        <el-table-column-->
        <!--          slot="col"-->
        <!--          label="操作"-->
        <!--          align="center"-->
        <!--          :width="100"-->
        <!--          fixed="right"-->
        <!--        >-->
        <!--          <template slot-scope="scope">-->
        <!--            <icon-list-->
        <!--              :msg="iconMsg"-->
        <!--              :row-data="scope.row"-->
        <!--              @on-result-change="_iconClick"-->
        <!--            />-->
        <!--          </template>-->
        <!--        </el-table-column>-->
      </element-table>
    </div>
  </div>
</template>
<script>
import { drugStatistics } from '../../api'
import { saleImg } from '../../api/homePage'
export default {
  name: 'FailItem',
  data() {
    return {
      activeName: 'first',
      value1: '',
      pageColumns: [
        { title: '项目名称', key: 'name', width: '150' },
        { title: '样品编号', key: 'sampleCode', width: '120' },
        { title: '物料名称', key: 'sampleName', width: '130' },
        { title: '检测值', key: 'testValue', width: '100' },
        { title: '限量值', key: 'limitValue', width: '190' },
        { title: '检测依据', key: 'code', width: '350' },
        { title: '检测依据名称', key: 'standardName', width: '350' }
      ],
      formObj: {
        name: ''
      },
      getPage: {},
      iconMsg: [
        // { type: 'pt-a-edit', id: '', name: '编辑' },
        // { type: 'pt-a-trash', id: '', name: '删除' }
      ]
    }
  },
  computed: {
    tableHeight: function() {
      if (this.searchOpen) {
        return this.$tableHeight('search')
      } else {
        return this.$tableHeight('noSearch')
      }
    }
  },
  mounted() {
    this._getItemFail()
    this._page()
  },
  methods: {
    _getItemFail: async function() {
      const result = await drugStatistics.getItemFail(this.queryRange)
      if (result) {
        console.log('getItemFail', result)
        this.itemNotOk = result
        saleImg(result)
      }
    },
    _page: async function() {
      Object.assign(this.formObj, this.$refs.pageTable._searchParams())
      const result = await drugStatistics.pageItemFail(
        this.$serializeForm(this.formObj)
      )
      if (result) {
        this.getPage = result
        this.$refs.pageTable._initTable()
      }
    },

    _iconClick(res, data) {
      switch (res) {
        case '编辑':
          this._editModal(data.id)
          break
        case '删除':
          this._deleteById(data.id)
          break
      }
    },
    _tableResultChange(msg, data) {
      switch (msg) {
        case 'page':
          this._page()
          break
        case 'iconClick':
          this._iconClick(data.name, data.rowData)
          break
      }
    }
  }
}
</script>

<style scoped>
</style>
