<template>
  <div>
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' class="search_area" @condition-changed='$parent.search' v-ref:cri>
        <!--<form class="form-inline" partial>-->
        <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>

        <div class="row">
          <div :class="{'col-sm-6':$parent.$parent.$parent.showItem,'col-sm-4':!$parent.$parent.$parent.showItem}">
            <role-selector-safe
              role-name="安检员"
              role-lable="安&nbsp;检&nbsp;员"
              @re-res="$parent.$parent.getRes"
              :value.sync="model.f_checker_id"
              v-model="model.f_checker_id"
              condition="c.f_checker = '{}'">
            </role-selector-safe>
          </div>
          <div :class="{'col-sm-3 form-group':$parent.$parent.$parent.showItem,'col-sm-2 form-group':!$parent.$parent.$parent.showItem}">
            <label class="font_normal_body">计划起始</label>
            <datepicker
              :value.sync="$parent.$parent.f_check_start"
              placeholder='起始月份' style="width:60%"
              :disabled-days-of-week="[]"
              :format="'yyyy-MM'"
              :select-month="true"
              :show-rest-button="reset">
            </datepicker>
          </div>
          <div :class="{'col-sm-3 form-group':$parent.$parent.$parent.showItem,'col-sm-2 form-group':!$parent.$parent.$parent.showItem}">
            <label class="font_normal_body">计划结束</label>
            <datepicker
              :value.sync="$parent.$parent.f_check_end"
              placeholder='结束月份' style="width:60%"
              :disabled-days-of-week="[]"
              :format="'yyyy-MM'"
              :select-month="true"
              :show-rest-button="reset">
            </datepicker>
          </div>
          <div :class="{'col-sm-3 form-group':$parent.$parent.$parent.showItem,'col-sm-2 form-group':!$parent.$parent.$parent.showItem}">
            <label class="font_normal_body">安检起始</label>
            <datepicker
              :value.sync="$parent.$parent.f_start_time"
              placeholder='起始时间' style="width:60%"
              :disabled-days-of-week="[]"
              :format="'yyyy-MM-dd 00:00:00'"
              :show-rest-button="reset">
            </datepicker>
          </div>
          <div :class="{'col-sm-3 form-group':$parent.$parent.$parent.showItem,'col-sm-2 form-group':!$parent.$parent.$parent.showItem}">
            <label class="font_normal_body">安检结束</label>
            <datepicker
              :value.sync="$parent.$parent.f_end_time"
              placeholder='结束时间' style="width:60%"
              :disabled-days-of-week="[]"
              :format="'yyyy-MM-dd 23:59:99'"
              :show-rest-button="reset">
            </datepicker>
          </div>
          <div style="float:right" :class="{'col-sm-3 form-group':$parent.$parent.$parent.showItem,'col-sm-2 form-group':!$parent.$parent.$parent.showItem}">

            <button type="button" style="float: right;margin: 0 5px" class="button_search button_spacing" @click="search()">查询</button>
            <export-excel-safe   :data="$parent.$parent.search_data"
                                 :field="$parent.$parent.excelHeaders"
                                 sqlurl="rs/logic/SafeExportExcel" sql-name="planCount" template-name='安检计划明细' ></export-excel-safe>
            <div class="button_spacing" style="float: right;"
                 :class="{'button_shrink_left':$parent.$parent.$parent.showItem,'button_shrink_right':!$parent.$parent.$parent.showItem}"
                 @click="$parent.$parent.hiddenr()">
            </div>
          </div>
        </div>
          <!--<div class="row">

          </div>-->
          <!--<div :class="{'col-sm-3':$parent.$parent.$parent.showItem,'col-sm-2':!$parent.$parent.$parent.showItem}">
            <label class="font_normal_body">安检状态</label>
            <v-select :value.sync="model.f_last_check_state" :options='$parent.$parent.checkStates' placeholder='上次安检状态' close-on-select
                      style="width:60% "   class="select select_list"  v-model='model.f_last_check_state'   condition="cp.f_entry_status = '{}'">
            </v-select>
          </div>-->



          <!--<div>
            {{$parent.$parent.model.chosenOrg.fullname}}
          </div>-->
          <!--</form>-->
        </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>
            <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_checker}}</td>
          <td style="text-align: center">{{row.c}}</td>
          <!--<td style="text-align: center">{{row.checked}}</td>-->
          <td style="text-align: center">{{row.rh}}</td>
          <td style="text-align: center">{{row.unchecked+row.df+row.jj}}</td>
          <td style="text-align: center">{{row.unchecked}}</td>
          <td style="text-align: center">{{row.df}}</td>
          <td style="text-align: center">{{row.jj}}</td>
          <td style="text-align: center">{{row.zdf}}</td>
          <td style="text-align: center">{{row.zjj}}</td>
          <td style="text-align: center">{{row.temporarycheck}}</td>
          <td style="text-align: center">{{row.lsrh}}</td>
          <td style="text-align: center">{{row.lsdf}}</td>
          <td style="text-align: center">{{row.lsjj}}</td>
        </template>
        <template partial="foot">
          <td style="text-align: center"><span><b>合计：</b></span></td>
          <td style="text-align: center">{{model.sums.c}}</td>
          <!--<td style="text-align: center">{{model.sums.checked}}</td>-->
          <td style="text-align: center">{{model.sums.rh}}</td>
          <td style="text-align: center">{{model.sums.unchecked+model.sums.df+model.sums.jj}}</td>
          <td style="text-align: center">{{model.sums.unchecked}}</td>
          <td style="text-align: center">{{model.sums.df}}</td>
          <td style="text-align: center">{{model.sums.jj}}</td>
          <td style="text-align: center">{{model.sums.zdf}}</td>
          <td style="text-align: center">{{model.sums.zjj}}</td>
          <td style="text-align: center">{{model.sums.temporarycheck}}</td>
          <td style="text-align: center">{{model.sums.lsrh}}</td>
          <td style="text-align: center">{{model.sums.lsdf}}</td>
          <td style="text-align: center">{{model.sums.lsjj}}</td>
        </template>
      </data-grid>
    </criteria-paged>
  </div>
</template>
<script>
    import {PagedList} from 'vue-client'
    import co from 'co'
    import Vue from 'vue'
    import * as Util from '../../Util'


    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/planCount', 20, {
              f_plan_year: 'this.f_plan_year[0]',
              f_checker: 'this.chosenOrg.name',
              f_filialeids: 'this.f_filialeids '
            }, {c: '', checked: '', unchecked: '',
              zdf:'',zjj:'',
              rh:'',df:'',jj:'',temporarycheck:'',lsrh:'',lsdf:'',lsjj:''})
            model.f_plan_year = year + ''
          model.f_filialeids = '('+this.$login.f.orgid+')'
            model.chosenOrg = {id: 0, name: ''}
            return {
                excelHeaders:{
                  'f_checker': '安检员',
                  'c': '计划数',
                  'checked': '已检',
                  'unchecked': '未检',
                  'rh':'入户',
                  'df':'到访不遇',
                  'jj':'拒检',
                  'zdf':'总到访不遇数',
                  'zjj':'总拒检数',
                  'temporarycheck':'临时安检',
                  'lsrh':'临时入户数',
                  'lsdf':'临时到访不遇数',
                  'lsjj':'临时拒检数'
                },
                checker: this.$login.f,
                checkers: [],
                checkersname: [],
                checkStates: this.$appdata.getParam('安检状态'),
                f: this.$login.f,
                model: model,
                search_data:null,
                c_year_list: options,
                f_check_start:Util.toStartDateYearString(),
                f_check_end: '',
                f_start_time:Util.toStartDateYearString(),
                f_end_time:''
            }
        },
        methods: {
            hiddenr() {
                this.$parent.showItem = !this.$parent.showItem
            },
          search(args) {
            if (this.f_check_start) {
              args.condition += ` AND f_plan_year >= ${this.f_check_start.substr(0,4)} `
              args.condition += ` AND f_plan_month >= ${this.f_check_start.substr(5,2)} `
            }
            if (this.f_check_end) {
              args.condition += ` AND f_plan_year <= ${this.f_check_end.substr(0,4)} `
              args.condition += ` AND f_plan_month <= ${this.f_check_end.substr(5,2)} `
            }
            //this.$dispatch('checkstatus-changed', this.$refs.paged.$refs.cri.model.f_last_check_state[0])
            this.model.params.f_start_time=this.f_start_time
            this.model.params.f_end_time=this.f_end_time
            console.log('this.model---', this.model.params)
            console.log('this.search_data---', this.search_data)
            this.search_data=this.model.params
            this.model.search(args.condition, args.model)
            //tag
            //tag
          },
          getRes(obj){
            this.model.f_filialeids = this.$login.convertToIn(obj.resids);
            //tag
          }
        },
        ready() {
            //this.f_start_time
            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: {
            'checker'() {
                // //tag
                //tag
                this.model.chosenOrg = this.checker[0]
            },
            'model.rows.length'() {
              // 如果查询无结果，将合计置为0
              if(this.model.rows.length < 1){
                this.model.sums.c = 0
                this.model.sums.checked = 0
                this.model.sums.unchecked = 0
                this.model.sums.rh = 0
                this.model.sums.df = 0
                this.model.sums.jj = 0
                this.model.sums.zdf = 0
                this.model.sums.zjj = 0
                this.model.sums.temporarycheck = 0
                this.model.sums.lsrh = 0
                this.model.sums.lsdf = 0
                this.model.sums.lsjj = 0
              }
            }
        },
        computed: {
            selected() {
                // //tag
                // this.$parent.showItem=!this.$parent.showItem
                return this.$refs.paged.$refs.grid.selected
            },
            checked(){
              //tag
              return this.model.sums.unchecked+this.model.sums.df+this.model.sums.jj
            }
        }
    }
</script>
