<template>
  <div>
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' class="search_area" @condition-changed='$parent.search' v-ref:cri>
        <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
          <div class="row">
            <div
              :class="{'form-group col-sm-6':$parent.$parent.$parent.showItem,'form-group col-sm-4':!$parent.$parent.$parent.showItem}"
              style="margin: 0">
              <role-selector-safe-dep
                role-name="安检员"
                role-lable="安&ensp;检&ensp;员"
                @re-res="$parent.$parent.getRes"
                @alluser="$parent.$parent.getchecker"
                :value.sync="model.f_checker_id"
                v-model="model.f_checker_id"
                condition="f_checker_name = '{}'">
              </role-selector-safe-dep>
            </div>
            <div
              :class="{'form-group col-sm-3':$parent.$parent.$parent.showItem,'form-group col-sm-2':!$parent.$parent.$parent.showItem}">
              <label class="font_normal_body">安检起始</label>
              <datepicker
                :value.sync="$parent.$parent.f_start_time"
                placeholder='安检起始' style="width:60%"
                :show-rest-button="reset">
              </datepicker>
            </div>
            <div
              :class="{'form-group col-sm-3':$parent.$parent.$parent.showItem,'form-group col-sm-2':!$parent.$parent.$parent.showItem}">
              <label class="font_normal_body">安检截止</label>
              <datepicker
                :value.sync="$parent.$parent.f_end_time"
                placeholder='安检截止' style="width:60%"
                :show-rest-button="reset">
              </datepicker>
            </div>
            <div
              :class="{'form-group col-sm-3':$parent.$parent.$parent.showItem,'form-group col-sm-2':!$parent.$parent.$parent.showItem}">
              <label class="font_normal_body">班&emsp;&emsp;组</label>
              <v-select
                class="select select_list"
                :value.sync="model.userType"
                v-model="model.userType"
                :options="$parent.$parent.depments"
                condition="f_checker_name like '{}%'"
                placeholder='请选择'
                :search="false"
                close-on-select
                value-single
              >
            </div>
            <div style="width: auto;margin-top:8px;float: right"
                 :class="{'form-group col-sm-3':$parent.$parent.$parent.showItem,'form-group col-sm-2':!$parent.$parent.$parent.showItem}">
              <export-excel-safe :data="$parent.$parent.searchData"
                                 :field="$parent.$parent.excelHeaders"
                                 progress="safeGetExportProgress"
                                 sqlurl="rs/logic/SafeExportExcel" sql-name="noplanCount"
                                 template-name='无计划安检单'></export-excel-safe>
              <button type="button" class="button_search button_spacing" @click="search()">查询</button>
<!--              <button type="button" class="button_new-1 button_spacing" data-toggle="dropdown"-->
<!--                      @click="$parent.$parent.print($parent.model.rows)">-->
<!--                打印-->
<!--              </button>-->
              <div class="button_spacing"
                   :class="{'button_shrink_left':$parent.$parent.$parent.showItem,'button_shrink_right':!$parent.$parent.$parent.showItem}"
                   @click="$parent.$parent.hiddenr()"></div>
            </div>
          </div>
        </div>
      </criteria>
      <data-grid :model="model" partial='list' v-ref:grid class="list_area table_sy">
        <template partial='head'>
          <tr>
<!--            <th>小区</th>-->
            <th>安检员</th>
            <th>无计划总数</th>
            <th>无计划入户</th>
            <th>无计划拒检</th>
            <th>无计划到访不遇</th>
            <th>无计划未检</th>
          </tr>
        </template>
        <template partial='body'>
<!--          <td style="text-align: center">{{row.f_residential_area}}</td>-->
          <td style="text-align: center">{{row.f_checker_name}}</td>
          <td style="text-align: center">{{row.noplannum}}</td>
          <td style="text-align: center">{{row.wuruhu}}</td>
          <td style="text-align: center">{{row.wujujian}}</td>
          <td style="text-align: center">{{row.wudaofang}}</td>
          <td style="text-align: center">{{row.wuweijian}}</td>
        </template>
        <template partial="foot">
          <td style="text-align: center"><span><b>合计：</b></span></td>
          <td style="text-align: center">{{model.sums.noplannum}}</td>
          <td style="text-align: center">{{model.sums.wuruhu}}</td>
          <td style="text-align: center">{{model.sums.wujujian}}</td>
          <td style="text-align: center">{{model.sums.wudaofang}}</td>
          <td style="text-align: center">{{model.sums.wuweijian}}</td>
        </template>
      </data-grid>
    </criteria-paged>

<!--    <modal :show.sync="showcheckmsg">-->
<!--      <div slot="modal-header" class="modal-header">-->
<!--        <span class="modal-title font">-->
<!--          安检员考核单打印-->
<!--        </span>-->
<!--      </div>-->
<!--      <div slot="modal-body" class="modal-body">-->
<!--        <div>-->
<!--          <print-material-bill-noplan v-if="showcheckmsg" :show="showcheckmsg"-->
<!--                                      :data="checkInfo"></print-material-bill-noplan>-->
<!--        </div>-->
<!--      </div>-->
<!--      <div slot="modal-footer" class="modal-footer">-->
<!--        <button type="button" class="btn btn-cancel" @click="cancel()">取消</button>-->
<!--        <print-element class="btn btn-primary" id="print2" styleid='style2' top='40' left='60' width='100%'-->
<!--                       height='100%' v-ref:printelement>打印-->
<!--        </print-element>-->

<!--      </div>-->
<!--    </modal>-->

  </div>

</template>
<script>
  import {HttpResetClass, PagedList} from 'vue-client'

  export default {
    title: '无计划安检查询',
    data() {
      let options = []
      let year = (new Date()).getFullYear()
      for (let i = year - 8; i <= year + 1; i++)
        options.push({label: i + '', value: i + ''})
      let model = new PagedList('rs/sql/noplanCount', 20, {
        f_filialeids: 'this.f_filialeids',
        f_start_time: 'this.f_start_time',
        f_end_time: 'this.f_end_time'
      }, {noplannum: '', wuruhu: '', wujujian: '', wudaofang: '', wuweijian: ''})
      model.f_filialeids = '(' + this.$login.f.orgid + ')'
      return {
        excelHeaders: {
          'f_checker_name': '安检员',
          // 'f_residential_area': '小区',
          'noplannum': '无计划总数',
          'wuruhu': '无计划入户',
          'wujujian': '无计划拒捡',
          'wudaofang': '无计划到访不遇',
          'wuweijian':'无计划未检'
        },
        searchData: {
          condition: "1=1",
          f_plan_year: year[0],
          f_checker: '',
          f_filialeids: '(' + this.$login.f.orgid + ')',
          f_start_time: '',
          f_end_time: ''
        },
        checker_name:'',
        checker: this.$login.f,
        checkers: [],
        checkersname: [],
        showcheckmsg: false,
        checkInfo: {},
        checkStates: this.$appdata.getParam('安检状态'),
        f: this.$login.f,
        criteriaShow: false,
        model: model,
        c_year_list: options,
        f_check_start: '',
        f_check_end: '',
        f_start_time: '',
        f_end_time: '',
        depments:[{label:'居民安检班组',value:'居民安检'},{label:'非居民安检班组',value:'非居民安检'}],
      }
    },
    methods: {
      getchecker(val){
        this.$refs.paged.$refs.cri.model.f_checker_id = ''
        if(val && val.length > 0){
          this.checker_name = ''
          val.forEach(user => {
            this.checker_name += `'${user.name}',`
          })
          this.checker_name = this.checker_name.slice(0,this.checker_name.length-1)
        }else{
          this.checker_name = ''
        }
      },
      cancel() {
        this.showcheckmsg = false
      },
      print(model) {
        console.log("传给打印的数据" + JSON.stringify(model))
        this.showcheckmsg = true
        this.checkInfo = model
      },
      hidden() {
        this.criteriaShow = !this.criteriaShow
      },
      hiddenr() {
        this.$parent.showItem = !this.$parent.showItem
      },
      search(args) {
        if(this.checker_name){
          args.condition += ` and  f_checker_name in (${this.checker_name}) `
        }
        if (this.f_start_time) {
          args.condition += ` AND f_offsite_time >= '${this.f_start_time} 00:00:00' `
        }
        if (this.f_end_time) {
          args.condition += ` AND f_offsite_time <= '${this.f_end_time} 23:59:59' `
        }
        //this.$dispatch('checkstatus-changed', this.$refs.paged.$refs.cri.model.f_last_check_state[0])
        //tag
        // this.model.f_start_time = this.f_start_time
        // this.model.f_end_time = this.f_end_time
        //tag
        this.model.search(args.condition, args.model)
        //tag
        //tag
      },
      getOrgid() {
        this.depments = []
        let http = new HttpResetClass()
        http.load('POST', 'rs/logic/GetOrgid', {
          orgid: this.$login.f.orgid
        }, {resolveMsg: null, rejectMsg: null}).then((ress) => {
          this.depments.push({label: '全部', value: ''})
          ress.data.forEach(ress => {
            this.depments.push({
              label: ress.name,
              value: ress.id
            })
          })
        })
      },
      getRes(obj) {
        // this.model.f_filialeids = this.$login.convertToIn(obj.resids);
        //tag
      }
    },
    ready() {
      // this.getOrgid()
      this.model.id = this.$login.f.id
      this.model.f_subcompany = this.$login.f.f_fengongsi
      this.model.f_filialeid = this.$login.f.orgid
    },

    watch: {
      'model.condition'(val) {
        if (val) {
          this.searchData.condition = val
        }
      },
      'model.f_checker'(val) {
        if (val) {
          this.searchData.f_checker = val
        }
      },
      'f_start_time'(val) {
        if (val) {
          this.searchData.f_start_time = val
        }
      },
      'f_end_time'(val) {
        if (val) {
          this.searchData.f_end_time = val
        }
      },
      'checker'() {
        // //tag
        //tag
        this.model.chosenOrg = this.checker[0]
      },
      'model.rows.length'() {
        // 如果查询无结果，将合计置为0
        if (this.model.rows.length < 1 && this.model.sums) {
          this.model.sums.noplannum = 0
          this.model.sums.wuruhu = 0
          this.model.sums.wujujian = 0
          // this.model.sums.unchecked = 0
          this.model.sums.wudaofang = 0
          this.model.sums.wuweijian = 0
        }
      }
    },
    computed: {
      selected() {
        // //tag
        // this.$parent.showItem=!this.$parent.showItem
        return this.$refs.paged.$refs.grid.selected
      }
    }
  }
</script>
