<template>
  <div class="flex-row">
    <div class="basic-main">
      <criteria-paged :model="model" v-ref:paged @sort="sort">
        <criteria partial='criteria' class="search_area" @condition-changed='$parent.selfSearch' v-ref:criteria>
          <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
            <div class="row">
              <div class="form-group col-sm-2"  >
                <label class="font_normal_body">客户编号</label>
                <input type="text" class="input_search" v-model="model.f_userid"
                       style="width: 60%" placeholder="客户编号" condition="f_userid='{}'">
              </div>
              <div class="form-group col-sm-2"  >
                <label class="font_normal_body">客户名称</label>
                <input type="text" class="input_search" v-model="model.f_consumername"
                       style="width: 60%" placeholder="客户名称" condition="f_consumername like '%{}%'">
              </div>
              <div class="form-group col-sm-2"  >
                <label class="font_normal_body">客户电话</label>
                <input type="text" class="input_search" v-model="model.f_consumerphone"
                       style="width: 60%" placeholder="客户电话" condition="f_consumerphone like '%{}%'">
              </div>
              <div class="form-group col-sm-2"  >
                <label class="font_normal_body">小&emsp;&emsp;区</label>
                <input type="text" class="input_search" v-model="model.f_residential_area"
                       style="width: 60%" placeholder="小区" condition="f_residential_area like '%{}%'">
              </div>
              <div class="form-group col-sm-2"  >
                <label class="font_normal_body">详细地址</label>
                <input type="text" class="input_search" v-model="model.f_address"
                       style="width: 60%" placeholder="详细地址" condition="f_address like '%{}%'">
              </div>
              <div class="form-group col-sm-2" style="width: auto;margin-top:8px;float: right">

                <export-excel-safe :data="$parent.$parent.searchData"
                              :field="$parent.$parent.excelHeaders"
                              :choose-col="true"
                              sqlurl="rs/logic/SafeExportExcel" sql-name="查找安检单" template-name='旧安检查询'></export-excel-safe>

                <button class="button_spacing button_search" @click="search()">查询</button>
                <div style="float: right" class="button_spacing"
                     :class="{'button_shrink_top':$parent.$parent.criteriaShow,'button_shrink_bottom':!$parent.$parent.criteriaShow}"
                     @click="$parent.$parent.hidden()"></div>
              </div>
              <div class="form-group col-sm-2"  v-show="$parent.$parent.criteriaShow" >
                <label class="font_normal_body">开始时间</label>
                <datepicker
                  :value.sync="model.f_check_start"
                  placeholder='开始时间' style="width: 60%"
                  :disabled-days-of-week="[]"
                  :format="'yyyy-MM-dd'"
                  :show-rest-button="reset"
                  v-model="model.f_check_start"
                  condition="f_anjianriqi > ='{} 00:00:00'">
                </datepicker>
              </div>
              <div class="form-group col-sm-2"  v-show="$parent.$parent.criteriaShow" >
                <label class="font_normal_body">结束时间</label>
                <datepicker
                  :value.sync="model.f_check_end"
                  placeholder='结束时间' style="width: 60%"
                  :disabled-days-of-week="[]"
                  :format="'yyyy-MM-dd'"
                  :show-rest-button="reset"
                  v-model="model.f_check_end"
                  condition="f_anjianriqi <=  '{} 23:59:59'">
                </datepicker>
              </div>

<!--              <div class="form-group col-sm-2" v-show="$parent.$parent.criteriaShow"  >-->
<!--                <label class="font_normal_body">安检类型</label>-->
<!--                <v-select :value.sync="model.f_safecheck_type" v-model='model.f_safecheck_type'-->
<!--                          :value-single="true" style="width: 60%"-->
<!--                          class="select_list select"-->
<!--                          :options='$parent.$parent.safetype' placeholder='安检类型'-->
<!--                          close-on-select-->
<!--                          condition="f_safecheck_type = '{}'"></v-select>-->
<!--              </div>-->

<!--              <div class="form-group col-sm-2" v-show="$parent.$parent.criteriaShow"  >-->

<!--                <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="form-group col-sm-2"   v-show="$parent.$parent.criteriaShow">-->
<!--              <label class="font_normal_body">安检状态</label>-->
<!--              <v-select id="f_entry"-->
<!--                        class="select_list select"-->
<!--                        placeholder='安检状态' style="width: 60%"-->
<!--                        v-model='model.f_entry'-->
<!--                        :value.sync="$parent.$parent.model.f_entry"-->
<!--                        :options='$parent.$parent.f_entry_status'-->
<!--                        condition=""-->
<!--                        :value-single="true"-->
<!--                        close-on-select clear-button></v-select>-->
<!--            </div>-->
            <div class="col-sm-4 form-group" v-show="$parent.$parent.criteriaShow" style="margin: 0">
              <role-selector-safe
                role-name="安检员"
                role-lable="安&nbsp;检&nbsp;员&nbsp;"
                @re-res="$parent.$parent.getRes"
                :value.sync="model.f_checker_id"
                v-model="model.f_checker_id"
                condition="f_checker_name = '{}'">
              </role-selector-safe>
            </div>
            </div>
          </div>
        </criteria>
        <data-grid class="list_area table_sy" style="overflow: hidden" :model="model" partial='list' v-ref:grid>
          <template partial='head'>
            <tr>
              <th>
                <nobr>卡号</nobr>
              </th>
              <th>
                <nobr>客户编号</nobr>
              </th>
              <th>
                <nobr>客户名称</nobr>
              </th>
              <th>
                <nobr>客户电话</nobr>
              </th>
              <th>
                <nobr>小区名称</nobr>
              </th>
              <th>
                <nobr>客户地址</nobr>
              </th>
              <th>
                <nobr>安检日期</nobr>
              </th>
              <th>
                <nobr>安检状态</nobr>
              </th>
              <th>
                <nobr>安检员</nobr>
              </th>
              <th>
                <nobr>到达时间</nobr>
              </th>
              <th>
                <nobr>离开时间</nobr>
              </th>
              <th>
                <nobr>表信息</nobr>
              </th>
              <th>
                <nobr>剩余气量</nobr>
              </th>
              <th>
                <nobr>剩余金额</nobr>
              </th>
              <th>
                <nobr>是否有报警器</nobr>
              </th>
              <th>
                <nobr>报警器厂家</nobr>
              </th>
              <th>
                <nobr>是否使用热水器</nobr>
              </th>
              <th>
                <nobr>热水器信息</nobr>
              </th>
              <th>
                <nobr>是否使用壁挂炉</nobr>
              </th>
              <th>
                <nobr>壁挂炉信息</nobr>
              </th>
              <th>
                <nobr>是否使用灶具</nobr>
              </th>
              <th>
                <nobr>灶具信息</nobr>
              </th>
              <th>
                <nobr>立管隐患</nobr>
              </th>
              <th>
                <nobr>气表隐患</nobr>
              </th>
              <th>
                <nobr>评价</nobr>
              </th>
            </tr>
          </template>
          <template partial='body'>
            <td style="text-align: center">{{row.f_cardnum}}</td>
            <td style="text-align: center">{{row.f_userid}}</td>
            <td style="text-align: center">{{row.f_consumername}}</td>
            <td style="text-align: center">{{row.f_consumerphone}}</td>
            <td style="text-align: center">{{row.f_residential_area}}</td>
            <td style="text-align: center">{{row.f_address}}</td>
            <td style="text-align: center">{{row.f_anjianriqi}}</td>
            <td style="text-align: center">{{row.f_state}} {{row.f_entry_status}}</td>
            <td style="text-align: center">{{row.f_checker_name}}</td>
            <td style="text-align: center">{{row.f_onsite_time}}</td>
            <td style="text-align: center">{{row.f_offsite_time}}</td>
            <td style="text-align: center">{{row.f_biaohao}} {{row.f_kachangjia}} {{row.f_meter_type}} {{row.f_rqbiaoxing}}</td>
            <td style="text-align: center">{{row.f_shengyu}}</td>
            <td style="text-align: center">{{row.f_buygas}}</td>
            <td style="text-align: center">{{row.f_baojingqi}}</td>
            <td style="text-align: center">{{row.f_baojingqichang}}</td>
            <td style="text-align: center">{{row.f_rshqshiyong}}</td>
            <td style="text-align: center">{{row.f_rshqpinpai}} {{row.f_rshqxinghao}} {{row.f_rshqxianzhuang}}</td>
            <td style="text-align: center">{{row.f_bglshiyong}}</td>
            <td style="text-align: center">{{row.f_bglpinpai}} {{row.f_bglweizhi}} {{row.f_bglxianzhuang}}</td>
            <td style="text-align: center">{{row.f_zjshiyong}}</td>
            <td style="text-align: center">{{row.f_zjpinpa}} {{row.f_zjleixing}}</td>
            <td style="text-align: center">{{row.f_lgzhengchang}} {{row.f_lgfushi}} {{row.f_lgsigai}} {{row.f_lglouqi}}</td>
            <td style="text-align: center">{{row.f_sibiao}} {{row.f_changtong}} {{row.f_fanzhuang}} {{row.f_qblouqi}}</td>
            <td style="text-align: center">{{row.f_kehupingjia}}</td>
          </template>
        </data-grid>
      </criteria-paged>
    </div>
  </div>
</template>

<script>
  import {PagedList} from 'vue-client'
  import co from 'co'
  import HttpResetClass from "vue-client/src/plugins/HttpResetClass";


  let select = function* (self) {
    let http = new HttpResetClass()
    let getGasman = yield http.load('POST', '/rs/search', {
      source: 'this.getParentByType($department$).getAllChildrens().where(row.getAttributes().get($rolestr$).indexOf($安检员$) != -1))',
      userid: self.$login.f.id
    }, {resolveMsg: null, rejectMsg: null})
    ////tag
    self.checkersid.push({label: '全部', value: ''})
    getGasman.data.forEach((checker) => {
      self.checkersid.push({label: checker.name, value: checker.id})
    })
  }

  export default {
    title: '安检结果查看',
    data() {
      return {
        model: new PagedList('rs/sql/getOldCheckPaper', 20),
        audioshow:false,
        searchData: {
          condition: "1=1"
        },
        excelHeaders: {
          'f_cardnum': '卡号',
          'f_userid': '客户编号',
          'f_consumername': '客户姓名',
          'f_consumerphone':'客户电话',
          'f_residential_area': '小区',
          'f_address': '客户地址',
          'f_state': '安检状态',
          'f_anjianriqi': '安检时间',
          'f_checker_name': '安检员',
          'f_jujian':'是否拒检',
          'f_ruhu':'是否入户',
          'f_biaohao':'表号',
          'f_kachangjia':'气表厂家',
          'f_meter_type':'气表型号',
          'f_rqbiaoxing':'左右表',
          'f_shengyu':'剩余',
          'f_buygas':'剩余金额',
          'f_onsite_time':'到达时间',
          'f_offsite_time':'离开时间',
          'f_kehupingjia':'评价',
        },
        fun: this.$login.f,
        pcds:[],
        checkersid: [],
        criteriaShow: false,
        showModal: false,
        f_entry_status: this.$appdata.getParam('安检状态')?[{label: '全部', value: ''}, ...this.$appdata.getParam('安检状态')]:[{label: '全部', value: ''}],
        showcheckmsg: false,
        checkInfo: {},
        orderDefault: "'f_offsite_time'",
        orderFields: {
          f_offsite_time: 'no'
        }
      }
    },
    methods: {
      getRes(obj) {
        this.model.f_filialeid = this.$login.convertToIn(obj.resids);
        this.searchData.f_filialeid = this.$login.convertToIn(obj.resids);
      },
      hidden() {
        this.criteriaShow = !this.criteriaShow
      },

      sort(field, rule) {
        // 将所有排序方式设为不排序，实现相互排斥
        for (let key in this.orderFields) {
          if (key === field) {
            this.orderFields[key] = rule
          } else {
            this.orderFields[key] = 'no'
          }
        }
        // 如果新规则不排序，还原为默认排序
        if (rule === 'no') {
          this.model.paramSource.orderitem = `'${this.orderDefault}'`
        } else {
          this.model.paramSource.orderitem = `'${field} ${rule}'`
        }
        this.search()
      },
      search() {
        this.$refs.paged.$refs.criteria.search()
      },
      selfSearch(args) {
        this.model.search(args.condition, args.model, args.condValue)
      }
    },
    ready() {
      let gen = select(this)
      co(gen)
    },
    watch: {
      'model.condition'(val) {
        if (val) {
          this.searchData.condition = val
        }
      }
    }

  }
</script>
