<template>
  <div>
    <div class="layout-content-padding">
      <div class="layout-content-main">
        <Row style="margin-top: 10px;">
          <Form id="search-form-sample-progress" :label-width="80" inline onsubmit="return false">
          <Form-item label="试验名称:" class="search-item">
            <Input @on-enter="_search" v-model="formObj.name" name="name" placeholder="请输入试验名称" style="width:100%" clearable></Input>
          </Form-item>
            <Form-item label="钻孔名称:" class="search-item">
              <Input @on-enter="_search" v-model="formObj.boreholeName" 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 span="24">-->
          <!--<SampleSteps :info="sampleInfo" ref="stepsModal"></SampleSteps>-->
          <!--</Col>-->
          <Col style="height: 300px;" span="24">
            <VScrollFull ref="myscrollfull" @load="_loadData" :pageSize="rows">
              <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 { soilStatistics } from '../../../api'
import SampleSteps from './SampleSteps'

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 }]
    }
  },
  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 soilStatistics.listExperimentProgress(
        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)
      }
      // 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>
