<template>
  <div>
    <Card style="width:100%;">
    <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 v-model="formObj.name" name="name" placeholder="请输入试验名称" style="width:100%" clearable @on-enter="_search"></Input>
          </Form-item>
            <Form-item label="钻孔名称:" class="search-item">
              <Input v-model="formObj.boreholeName" name="boreholeName" placeholder="请输入钻孔名称" style="width:100%" clearable @on-enter="_search"></Input>
            </Form-item>
          <Form-item class="search-item">
            <Button type="primary" class="width-80" @click="_search">搜索</Button>
          </Form-item>

            <Form-item class="search-item">
              <Button class="width-80"  @click="_more">查看更多</Button>
            </Form-item>
            </Form>
          <!--查询条件-->
          <!--样品进度-->
          <!--<Col span="24">-->
          <!--<SampleSteps :info="sampleInfo" ref="stepsModal"></SampleSteps>-->
          <!--</Col>-->
          <Col style="height: 300px;" 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>
    </Card>
  </div>
</template>

<script>
import VScrollFull from '../../../components/base/VScrollFull'
import { soilStatistics } from '../../../api'
// import Global from '../../../api/config'
import SampleSteps from './SampleSteps'

export default {
  components: {
    SampleSteps,
    VScrollFull
  },
  data() {
    return {
      dateList: [],
      sampleProgressList: ['已分配', '检测完成', '复核', '校核'],
      // 样品信息
      sampleInfo: [],
      testTypeList: [],
      // 合同id
      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()
    },

    _more() {
      window.open('/soil/statistics/experiment_progress', '_blank')
    },

    _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 = 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>
