<template>
  <section>
    <nav-bar title="报修任务查询"></nav-bar>
    <section class="content mgt186" v-infinite-scroll="loadMore" infinite-scroll-disabled="busy" infinite-scroll-distance="0" infinite-scroll-immediate-check="false">
      <div class="filter-wraper">
        <div class="bottom-filter-tip">
          <div class="filter-label txtjustify">部门</div>
          <div class="fxcol mgl20 visible" >
            <dropdown-menu
              :option="option"
              :active="active"
              :open="open"
              :cancleShow="true"
              @toggleItem="toggleItem"
              @dropdownMenu="dropdownMenu"
              @cancleDropdown="cancleDropdown">
            </dropdown-menu>
          </div>
        </div>
      </div>
      <div class="grid-wraper">
        <div class="left_fixed">
          <table class="layout-t left_layout_t">
            <tr>
              <th>生成时间</th>
            </tr>
            <tr v-for="(e, i) in dataList" :key="i">
              <td>{{e.device_code}}</td>
            </tr>
          </table>
        </div>
        <div class="slide">
          <table class="layout-t">
            <tr>
              <th>设备名称</th>
              <th>设备编号</th>
              <th>所属部门</th>
              <th>保修内容</th>
              <th>开始时间</th>
            </tr>
            <tr v-for="(e, i) in dataList" :key="i">
              <td>{{e.device_name}}</td>
              <td>{{e.device_code}}</td>
              <td>{{e.name}}</td>
              <td>{{e.fault_desc}}</td>
              <td>{{e.process_time}}</td>
            </tr>
          </table>
        </div>
      </div>
      <div class="loading-tips">{{desc}}</div>
    </section>
    <section class="submit-bar">
      <button class="btn submit-button" @click="_repairRequest">查询</button>
    </section>
  </section>
</template>

<script>
import NavBar from '@components/NavBar.vue'
import DropdownMenu from '@components/DropdownMenu.vue'
import {deptList, repairRequest} from '@config/getData2.js'
export default {
  name: 'SearchRepairTask',
  components: {
    NavBar,
    DropdownMenu
  },
  data () {
    return {
      dataList: [],
      option: [],
      active: '',
      open: false,
      page: 1,
      size: '10',
      busy: false,
      desc: '',
      pkId: '',
      pkObj: {}
    }
  },
  created () {
    this._deptList()
  },
  methods: {
    toggleItem () {
      if (!this.open) {
        this.open = true
      } else {
        this.open = false
      }
    },
    dropdownMenu (i) {
      this.active = i + ''
      this.open = false
    },
    cancleDropdown () {
      this.active = ''
    },
    async _deptList () {
      let res = await deptList()
      if (res.code === '1') {
        this.option = [...res.rows]
      } else {
        this.Dialog(res.desc)
      }
    },
    async _repairRequest () {
      let id = ''
      if (this.active) {
        id = this.option[this.active].value
      }
      this.page = 1
      this.busy = false
      this.desc = ''
      let res = await repairRequest(id)
      if (res.code === '1') {
        this.dataList = []
        this.checkArr = []
        this.allcheckActive = false
        // res.rows.map(el => {
        //   this.$set(el, 'checked', false)
        // })
        this.dataList = [...res.rows]
        if (res.rows.length < 10) {
          this.busy = true
          this.desc = '已加载全部数据'
        }
      } else {
        this.Dialog(res.desc)
        this.desc = res.desc
      }
    },
    async loadMore () {
      this.busy = true
      this.page++
      let id = ''
      if (this.active) {
        id = this.option[this.active].value
      }
      let res = await repairRequest(id)
      if (res.code === '1') {
        // res.rows.map(el => {
        //   this.$set(el, 'checked', false)
        // })
        this.dataList = [...this.dataList, ...res.rows]
        if (res.rows.length < 10) {
          this.busy = true
          this.desc = '已加载全部数据'
        } else {
          this.busy = false
        }
      } else {
        this.Dialog(res.desc)
        this.desc = res.desc
      }
    }
  }
}
</script>

<style lang="stylus" scoped>
>>>.content
  height calc(100% - 1.96rem)
  overflow-y auto
</style>
