<template>
  <div id='app' class="basic-main" style="height: 100%">
    <criteria-paged :model="model" v-ref:paged :pager='false'>
      <criteria partial='criteria' v-ref:criteria @condition-changed='search' class="search_area">
        <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
          <div class="row">
<!--            <div class="col-sm-4 form-group">-->
<!--              <role-selector-safe-->
<!--                role-name="安检员"-->
<!--                role-lable="安&ensp;检&ensp;员"-->
<!--                @re-res="$parent.$parent.getRes"-->
<!--                :value.sync="model.f_checker_id"-->
<!--                v-model="model.f_checker_id"-->
<!--                condition="f_checker_name like '%{}%'">-->
<!--              </role-selector-safe>-->
<!--            </div>-->
            <div class="form-group col-sm-2" >
              <label class="font_normal_body" >区&emsp;&emsp;域</label>
              <v-select :value.sync="model.f_quyu" :value-single="true" v-model="model.f_quyu"
                        :options='$parent.$parent.quyus' placeholder='区域' class="select_list select" style="width: 60%"
                        @change="$parent.$parent.quyuChange" condition="f_safe_user_region like '%{}%'"
                        close-on-select>
              </v-select>
            </div>
            <div class="form-group col-sm-2" >
              <label class="font_normal_body" >营&ensp;业&ensp;厅</label>
              <v-select :value.sync="model.f_bumen" :value-single="true" v-model="model.f_bumen"
                        :options='$parent.$parent.bumens' placeholder='营业厅' condition="f_safe_user_business_hall like '%{}%'"
                        @change="$parent.$parent.bumenChange" class="select_list select" style="width: 60%"
                        close-on-select>
              </v-select>
            </div>
            <div class="form-group col-sm-2" >
              <label class="font_normal_body">小&emsp;&emsp;组</label>
              <v-select :value.sync="model.f_team" :value-single="true" v-model="model.f_team"
                        :options='$parent.$parent.teams' placeholder='小组'
                        condition="f_safe_team like '%{}%'"
                        @change="$parent.$parent.teamChange" class="select_list select" style="width: 60%"
                        close-on-select>
              </v-select>
            </div>
            <div class="form-group col-sm-2" >
              <label class="font_normal_body" >安&ensp;检&ensp;员</label>
              <v-select :value.sync="model.f_checker_id" v-model="model.f_checker_id"
                        :multiple="true" class="select_list select" style="width: 60%"
                        :options='$parent.$parent.checkers' placeholder='安检员' condition="f_checker_name in {}"
                        close-on-select>
              </v-select>
            </div>
            <div class="col-sm-2 form-group">
              <label for="startDate" class="font_normal_body">开始日期:</label>
              <datepicker id="startDate" placeholder="开始日期"
                          v-model="model.startDate"
                          :value.sync="model.startDate"
                          style="width: 60%;"
                          :disabled-days-of-Week="[]"
                          :format="'yyyy-MM-dd 00:00:00'"
                          :show-reset-button="reset">
              </datepicker>
            </div>
            <div class="col-sm-2 form-group">
              <label for="endDate" class="font_normal_body">结束日期:</label>
              <datepicker id="endDate" placeholder="结束日期"
                          v-model="model.endDate"
                          :value.sync="model.endDate"
                          :disabled-days-of-Week="[]"
                          style="width: 60%;"
                          :format="'yyyy-MM-dd 23:59:59'"
                          :show-reset-button="reset">
              </datepicker>
            </div>
            <div class="col-sm-2 form-group" >
              <label class="font_normal_body">用气性质</label>
              <v-select
                class="select_list select"
                placeholder='用气性质' style="width: 60%"
                v-model='model.userType'
                :value.sync="model.userType"
                :options='$parent.$parent.userTypes'
                condition="tuf.f_gasproperties in {} "
                :multiple="true"
               ></v-select>
            </div>
            <div class="col-sm-2 form-group" >
              <label class="font_normal_body">气表类型</label>
              <v-select
                class="select_list select"
                placeholder='气表类型' style="width: 60%"
                v-model='model.tableType'
                :value.sync="model.tableType"
                :options='$parent.$parent.tableTypes'
                condition="tuf.f_meter_classify = '{}'"
                :value-single="true"
                close-on-select clear-button></v-select>
            </div>
            <div class="col-sm-2 form-group" >
              <label class="font_normal_body">气表品牌</label>
              <v-select
                class="select_list select"
                placeholder='气表类型' style="width: 60%"
                v-model='model.tableBrand'
                :value.sync="model.tableBrand"
                :options='$parent.$parent.tableBrands'
                condition="gb.f_meter_brand = '{}'"
                :value-single="true"
                close-on-select clear-button></v-select>
            </div>
            <div class="col-sm-2 form-group" >
              <label class="font_normal_body">用户类型</label>
              <v-select :value.sync="model.f_check_type" v-model='model.f_check_type'
                        :value-single="true" style="width: 60%"
                        class="select_list select"
                        :options='$parent.$parent.checktype' placeholder='客户类型'
                        close-on-select
                        condition="f_check_type = '{}'"></v-select>
            </div>
            <div class="col-sm-2 form-group" >
              <label class="font_normal_body">小&emsp;&emsp;区</label>
              <v-select :value.sync="model.f_residential_area" v-model='model.f_residential_area'
                        :value-single="true" style="width: 60%"
                        class="select_list select"
                        :options='$parent.$parent.areaList' placeholder='小区'
                        close-on-select
                        condition="tp.f_residential_area = '{}'"></v-select>
            </div>
            <div class="col-sm-4 form-group" style="margin-top: 8px">
              <button class="button_search button_spacing" @click="search()">查询</button>
              <button class="button_search button_spacing" @click="$parent.$parent.clearmsg()">置空</button>
              <report-print class="button_export button_spacing" style="width:28%" id='shexian'></report-print>
              <report-excel class="button_export button_spacing" style="width:28%" id='shexian'></report-excel>
            </div>
          </div>
        </div>
      </criteria>
      <div partial='list' id='shexian' class="list_area" style="overflow-y: scroll">
        <table class='tableprint' style="margin: 0px auto">
          <thead>
          <tr>
            <th colspan='5' style="font-weight: normal; text-align: left;">
              <h3 style="text-align: center">隐患报表</h3>
            </th>
          </tr>
          <tr>
            <th colspan='5' style="font-weight: normal; text-align: center;">
              开始时间：{{model.model.startDate}}&nbsp;&nbsp;&nbsp;
              结束时间：{{ model.model.endDate }}
            </th>
          </tr>
          </thead>
          <tr>
            <th colspan='5' style="font-weight: normal;">
              {{{ model.data.substring(26,model.data.length-8) }}}
            </th>
          </tr>
        </table>
      </div>
    </criteria-paged>
  </div>

</template>

<script>
  import {DataModel, HttpResetClass} from 'vue-client'

  export default {
    title: '隐患报表',
    data () {

      let model = new DataModel('rs/report/hiddensituation', {
        startDate: 'this.model.startDate',
        endDate: 'this.model.endDate',
        f_filialeid: 'this.f_filialeid'
      })
      model.f_filialeid = '(' + this.$login.f.orgid + ')'
      return {
        checktype: this.$appdata.getParam('用户类型')?[{label: '全部', value: ''}, ...this.$appdata.getParam('用户类型')]:[{label: '全部', value: ''}],
        allCheckers: [{label: '请选择', value: ''}],
        quyus: [{label: '请选择', value: ''}, ...this.$appdata.getParam('区域')],
        bumens: [{label: '请选择', value: ''}],
        teams: [{label: '请选择', value: ''}],
        checkers:[{label: '请选择', value: ''}],
        userTypes: [{label: '全部', value: ''}, ...this.$appdata.getParam('用气性质')],
        tableTypes: [{label: '全部', value: ''}, ...this.$appdata.getParam('气表类型')],
        tableBrands: [{label: '全部', value: ''}],
        filialeNameStr: '',
        filialeCodeStr: '',
        userid: this.$login.f.id,
        source: `tool.getFullTree(this.getRights().where(row.getType() != $zone$).where(row.getType() == $organization$))`,
        model: model,
        areaList:[]
      }
    },
    methods: {
      //置空 查询条件
      clearmsg() {
        this.$refs.paged.$refs.criteria.model = {
          f_area:'',
          f_check_type:'',
          tableBrand:'',
          tableType:'',
          userType:[],
          endDate:'',
          startDate:'',
          f_checker_id:[],
          f_team:'',
          f_bumen:'',
          f_quyu:''
        }
      },
      getareaList(){
        new HttpResetClass().load("POST", `${this.$androidUtil.getProxyUrl()}/rs/sql/safe_singleTable_OrderBy`, {data:{items:" * ",tablename:"t_area",orderitem:"id",condition:`f_orgid = '${this.$login.f.orgid}'`}}, {resolveMsg: null, rejectMsg: null}).then((res)=>{
          this.areaList=[]
          if(res.data.length>0){
            this.areaList.push({label:"全部",value:""})
            res.data.forEach((result)=>{
              this.areaList.push({label:result.f_residential_area,value:result.f_residential_area})
            })
          }
        })
      },
      bumenChange(val) {
        if (val) {
          this.teams = this.$appdata.getParam(`工单-` + val) ? [{
            label: '请选择',
            value: ''
          }, ...this.$appdata.getParam(`工单-` + val)] : [{label: '请选择', value: ''}]
        }else {
          this.$refs.paged.$refs.criteria.model.f_team = ''
          this.checkers = this.allCheckers
        }
      },
      teamChange(val) {
        if (val) {
          this.checkers = this.$appdata.getParam(val) ? [...this.$appdata.getParam(val)] : [{label: '请选择', value: ''}]
        }else {
          this.checkers = this.allCheckers
        }
      },
      quyuChange(val) {
        if (val) {
          this.bumens = this.$appdata.getParam(val) ? [{
            label: '请选择',
            value: ''
          }, ...this.$appdata.getParam(val)] : [{label: '请选择', value: ''}]
        }else {
          this.checkers = this.allCheckers
          this.$refs.paged.$refs.criteria.model.f_quyu = ''
        }
      },
      getRes (obj) {
        this.model.f_filialeid = this.$login.convertToIn(obj.resids)
      },
      getTableBrands() {
        new HttpResetClass().load("POST", `/rs/sql/safe_singleTable_OrderBy`,
          {data: {items: "*", tablename: "t_gasbrand", orderitem: "id", condition: ` 1=1 `}},
          {resolveMsg: null, rejectMsg: null}).then((resp) => {
          resp.data.forEach((result) => {
            this.tableBrands.push({label: result.f_meter_brand, value: result.f_meter_brand})
          })
        })
      },
      getAllChecker() {
        new HttpResetClass().load('POST', `/rs/sql/tel_singleTable_OrderBy`, {
          data: {
            items: 'name',
            tablename: 't_user',
            condition: `state = '在职' and rolestr like '%安检员%'`,
            orderitem: 'id'
          }
        }, {resolveMsg: null, rejectMsg: null}).then((res) => {
          res.data.forEach(ress => {
            this.allCheckers.push({
              label: ress.name,
              value: ress.name
            })
          })
          this.checkers = this.allCheckers
        })
      }
    },
    ready () {
      this.getAllChecker()
      this.getTableBrands()
      this.getareaList()
    },
    computed: {
      selected () {
        return this.$refs.grid.selected
      }
      // outlets () {
      //   return [{label: '全部', value: ''}, ...AppData.getParam('营业网点')]
      // },
      // operator () {
      //   return [{label: '全部', value: ''}, ...AppData.getParam('操作员')]
      // }
    }
  }
</script>
