<template>
  <div>
    <div class="layout-content-padding">
      <div class="layout-content-main">
        <Row style="padding-top: 10px;border: 2px solid #EEEEEE;background-color: white;">
          <Form id="search-form-sample-progress" :label-width="80" inline onsubmit="return false">
            <Form-item label="委托编号:" class="search-item">
              <Input v-model="formObj.entrustCode" @on-enter="_search" name="entrustCode" placeholder="请输入委托编号" style="width:100%" clearable></Input>
            </Form-item>
            <Form-item label="钻孔名称:" class="search-item">
              <Input v-model="formObj.boreholeName" @on-enter="_search" name="boreholeName" placeholder="请输入钻孔名称" style="width:100%" clearable></Input>
            </Form-item>
            <Form-item class="search-item">
              <Button @click="_search" type="primary" class="width-80">搜索</Button>
            </Form-item>
          </Form>
          <Col style="height: 420px;width: 100%;" span="24">
            <VScrollFull ref="myscrollfull" :page-size="rows" @load="_loadData">
              <div slot="empty" style="text-align:center" class="gray-color">暂无数据</div>
              <SampleSteps ref="stepsModal" :info="sampleInfo"></SampleSteps>
            </VScrollFull>
          </Col>
        </Row>
      </div>
    </div>
  </div>
</template>

<script>
import VScrollFull from '../../components/base/VScrollFull'
import { soilEntrust } from '../../api'
import SampleSteps from './ItemFlow'

export default {
  components: {
    SampleSteps,
    VScrollFull
  },
  data() {
    return {
      dateList: [],
      sampleProgressList: ['已分配', '检测完成', '复核', '校核'],
      // 样品信息
      sampleInfo: [],
      testTypeList: [],
      // 合同id
      contractId: '',
      //
      page: 0,
      rows: 10,
      formObj: {},
      processObj: {
        height: document.documentElement.clientHeight - 300 + 'px'
      },
      typeList: [{ name: '企业', value: 0 }, { name: '政府', value: 1 }]
    }
  },
  computed: {
    tableHeight: function() {
      return this.$tableHeight('noBtn') - 200
    }
  },
  mounted() {
    // this._initData()
  },
  methods: {
    _reportDateChange(data) {
      $('input[name="reportDateBegin"]').val(data[0])
      $('input[name="reportDateEnd"]').val(data[1])
    },
    // 日期
    _ctimeChange(data) {
      $('input[name="beginDate"]').val(data[0])
      $('input[name="endDate"]').val(data[1])
    },
    _search() {
      // 超期未完成(默认的)
      // 重置
      this.$refs.myscrollfull.$_init()
    },
    _loadData: async function(pageIndex) {
      console.log('pageIndex', pageIndex)
      this.page = pageIndex
      if (pageIndex === 1) {
        this.sampleInfo = []
      }
      Object.assign(this.formObj, this._searchParams())
      const result = await soilEntrust.listSummaryQuery(
        this.$serializeForm(this.formObj)
      )
      if (result) {
        const records = result.records
        const pages = result.pages
        // for (let i = 0; i < records.length; i++) {
        //   // 获取下标
        //   if (records[i].auditTime) {
        //     records[i].progressIndex = 3
        //   } else if (records[i].checkTime) {
        //     records[i].progressIndex = 2
        //   } else if (records[i].testEndTime) {
        //     records[i].progressIndex = 1
        //   } else if (records[i].allotTime) {
        //     records[i].progressIndex = 0
        //   } else {
        //     records[i].progressIndex = -1
        //   }
        // }
        // this.sampleInfo = records
        this.sampleInfo = this.sampleInfo.concat(records)
        this.$refs.myscrollfull.endByPage(this.sampleInfo.length, pages)
        console.log('this.sampleInfo', this.sampleInfo)
      }
      // this.$store
      //   .dispatch('StbSampleProgress/list', this._searchParams())
      //   .then(() => {
      //     const result = this.$store.state.StbSampleProgress.list
      //     const records = result.records
      //     const pages = result.pages
      //     for (let i = 0; i < records.length; i++) {
      //       // 获取下标
      //       records[i].statisStatusIndex = this.sampleProgressList.indexOf(
      //         records[i].statisStatus
      //       )
      //     }
      //     this.sampleInfo = this.sampleInfo.concat(records)
      //     this.$refs.myscrollfull.endByPage(this.sampleInfo.length, pages)
      //   })
    },
    // 获取模块数量
    _statusChange(data, list) {
      const temp = []
      const blueList = list.blueList
      const redList = list.redList
      const greenList = list.greenList
      const orgList = list.orgList
      for (let i = 0; i < blueList.length; i++) {
        temp.push(blueList[i])
      }
      for (let i = 0; i < redList.length; i++) {
        temp.push(redList[i])
      }
      for (let i = 0; i < greenList.length; i++) {
        temp.push(greenList[i])
      }
      for (let i = 0; i < orgList.length; i++) {
        temp.push(orgList[i])
      }
      if (temp.length !== 0) {
        $('input[name=queryTypeList]').val(temp.join(','))
      } else {
        $('input[name=queryTypeList]').val('')
      }
      this._search()
    },
    _searchParams() {
      const data = this.$serialize('search-form-sample-progress')
      data.page = this.page
      data.rows = this.rows
      return this.$extend(data)
    }
  }
}
</script>
