<template>
  <div class="flex">
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' @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-4" >
              <label class="font_normal_body">客户编号</label>
              <input type="text" class="input_search" style="width:60%" v-model="model.f_userinfo_code" placeholder='客户编号'
                     condition="f_userinfo_code = '{}'" @keyup.enter="search()">
            </div>
            <div class="form-group col-sm-4" >
              <label class="font_normal_body">用户类型</label>
              <v-select style="width:60% "
                        class="select select_list"
                        :value.sync="model.f_user_type"
                        v-model="model.f_user_type"
                        :options='$parent.$parent.userType'
                        placeholder='用户类型'
                        condition="f_user_type = '{}'"
                        close-on-select>
              </v-select>
            </div>
            <div class="form-group col-sm-4" >
              <label class="font_normal_body">是否已检</label>
              <v-select style="width:60% "
                        class="select select_list"
                        :value.sync="model.f_state"
                        v-model="model.f_state"
                        :options='$parent.$parent.checkState'
                        placeholder='是否已检'
                        condition="f_state = '{}'"
                        close-on-select>
              </v-select>
            </div>
            <div class="form-group col-sm-4" >
              <label class="font_normal_body">安检状态</label>
              <v-select style="width:60% "
                        class="select select_list"
                        :value.sync="model.f_entry_status"
                        v-model="model.f_entry_status"
                        :options='$parent.$parent.entry_status'
                        placeholder='安检状态'
                        condition="f_entry_status = '{}'"
                        close-on-select>
              </v-select>
            </div>
          </div>
          <div class="row" v-show="$parent.$parent.criteriaShow">
            <div class="form-group col-sm-4" >
              <label class="font_normal_body">气表编号</label>
              <input type="text" class="input_search" style="width:60%" v-model="model.f_meternumber" placeholder='气表编号'
                     condition="f_meternumber = '{}'" @keyup.enter="search()">
            </div>
            <div class="form-group col-sm-4" >
              <label class="font_normal_body">气表品牌</label>
              <input type="text" class="input_search" style="width:60%" v-model="model.f_meter_brand" placeholder='气表品牌'
                     condition="f_meter_brand like '%{}%'" @keyup.enter="search()">
            </div>
            <div class="form-group col-sm-4" >
              <label class="font_normal_body">区域</label>
              <input type="text" class="input_search" style="width:60%" v-model="model.f_slice_area" placeholder='区域'
                     condition="f_slice_area like '%{}%'" @keyup.enter="search()">
            </div>
            <div class="form-group col-sm-4" >
              <label class="font_normal_body">用户性质</label>
              <input type="text" class="input_search" style="width:60%" v-model="model.f_gasproperties" placeholder='用户性质'
                     condition="f_gasproperties like '%{}%'" @keyup.enter="search()">
            </div>
          </div>
          <div class="row">
            <div class="form-group col-sm-2 button-range" >
              <button class="button_search" style="margin-right: 10px"  @click="search()" v-el:cba>查询</button>
              <export-excel-safe   :data="$parent.$parent.exportParameter"
                                   :field="$parent.$parent.excelHeaders"
                                   sqlurl="rs/logic/SafeExportExcel" sql-name="getCheckPlanUserList"
                                   template-name='安检情况明细' :choose-col="true">
              </export-excel-safe>
              <!--展示下方条件或隐藏-->
              <div class="span" style="float:right;">
                <div class="button_spacing" style="float: right;margin-left:10px"
                     :class="{'button_shrink_top':$parent.$parent.criteriaShow,'button_shrink_bottom':!$parent.$parent.criteriaShow}"
                     @click="$parent.$parent.hidden()">
                </div>
              </div>
            </div>
          </div>
        </div>
      </criteria>
      <data-grid :model="model" class="table_sy"  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>

          </tr>
        </template>
        <template partial='body' >
          <tr >
            <td style="text-align:center;">{{$index+1}}</td>
            <td style="text-align:center"><span @click="$parent.$parent.$parent.dealmsg(row)"><a>{{row.f_userinfo_code}}</a></span></td>
            <td style="text-align:center">{{row.f_user_name}}</td>
            <td style="text-align:center">{{row.f_user_phone}}</td>
            <td style="text-align:center">{{row.f_slice_area}}</td>
            <td style="text-align:center">{{row.f_gasproperties}}</td>
            <td style="text-align:center">{{row.f_meternumber}}</td>
            <td style="text-align:center">{{row.f_meter_brand}}</td>
            <td style="text-align:center">{{row.f_meter_type}}</td>
            <td style="text-align:center">{{row.f_meter_base}}</td>
            <td style="text-align:center">{{row.f_total_fee}}</td>
            <td style="text-align:center">{{row.f_total_gas}}</td>
            <td style="text-align:center">{{row.f_user_type}}</td>
            <td style="text-align:center;white-space: nowrap;">{{row.f_address}}</td>
            <td style="text-align:center">{{row.f_state}}</td>
            <td style="text-align:center">{{row.f_entry_status}}</td>
            <td style="text-align:center">{{row.f_offsite_time}}</td>
            <td style="text-align:center">{{row.f_defect_content}}</td>
            <td style="text-align:center">{{row.f_check_number}}</td>
          </tr>
        </template>
        <template partial='foot'></template>
      </data-grid>
    </criteria-paged>
  </div>
</template>

<script>
  import { PagedList } from 'vue-client'
  export default {
    title: '安检情况明细',
    data () {
      return {
        model: new PagedList('rs/sql/getCheckPlanUserList', 50, {}),
        condition: '',
        getfield: {},
        userType:[{label:'全部',value:''}, ...this.$appdata.getParam('用户类型')],
        entry_status:[{label:'全部',value:''}, ...this.$appdata.getParam('安检状态')],
        checkState:[{label:'全部',value:''},{label:'已检',value:'已检'},{label:'未检',value:'未检'}],
        config: {
          excelHeaders: {
            'f_price_name': '气价名称', 'f_userinfo_code': '客户编号', 'f_user_name': '客户姓名', 'f_address': '客户地址',
            'f_orgname': '组织机构'
          }
        },
        criteriaShow:false,
        excelHeaders: {
          'f_userinfo_code':'用户编号',
          'f_user_name':'用户姓名',
          'f_user_phone':'用户电话',
          'f_slice_area':'区域',
          'f_gasproperties':'用户性质',
          'f_meternumber':'气表编号',
          'f_meter_brand':'气表品牌',
          ' f_meter_type':'气表类型',
          ' f_meter_base':'累够气量',
          ' f_total_fee':'累够金额',
          ' f_total_gas':'用气量',
          'f_user_type':'用户类型',
          'f_address':'用户地址',
          'f_state':'是否已检',
          'f_entry_status':'安检状态',
          'f_offsite_time':'安检时间',
          'f_defect_content':'隐患状态',
          'f_check_number':'上报条数'
        }
      }
    },
    props: ['checkrow'],
    ready () {

        this.search()
        this.getfield = this.config.excelHeaders
    },
    methods: {
      search () {
        this.$refs.paged.$refs.criteria.search()
      },
      selfSearch (args) {
        if(!this.checkrow){
          return
        }
        // args.condition = `${args.condition} and f_price_id = '${this.priceid}'`
        //tag
        var cc= this.$parent.$refs.list.model.condition
        //tag
        this.condition = args.condition
        args.condition=args.condition+' and '+ cc
        //tag
        var self=this
        this.$parent.$refs.list.nameForSql.forEach(function (s) {

          if(s!='f_user_number'&&self.checkrow[s]!='undefined'&&self.checkrow[s]){
            var rowsname=self.checkrow[s].replace('*&','')
            args.condition=args.condition+" and  s."+s+"=\'"+rowsname+"\'"
          }
        })

        //tag
        this.model.search(args.condition, args.model)
      },
      dealmsg (val) {
        //tag
        this.$parent.f_userinfo_id=val.f_userinfoid
        this.$parent.listpage=false
      },
      hidden() {
        this.criteriaShow = !this.criteriaShow
      },
    },
    watch: {
      'checkrow' () {
        this.search()
      }
    },computed: {
      // 导出到Excel的条件构造
      exportParameter() {
        return {
          condition: this.$refs.paged.model.condition,
          startyear: this.$parent.$refs.list.model.params.startyear,
          startmon: this.$parent.$refs.list.model.params.startmon,
          endyear :this.$parent.$refs.list.model.params.endyear,
          endmon: this.$parent.$refs.list.model.params.endmon,
          f_user_type: this.$parent.$refs.list.model.params.f_user_type
        }
      }
    }
  }
</script>
