<template >
  <div  class="flex">
    <div @keyup.enter="search" style="height:100%" class="basic-main">
      <criteria-paged :model="model" v-ref:paged>
        <criteria @condition-changed='$parent.selfsearch' partial='criteria' v-ref:criteria>
          <div class="form-horizontal select-overspread container-fluid auto" novalidate partial>
            <div class="row" width="100%">
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">组织机构</label>
                <res-select restype='organization'
                            class="select select_list"
                            style="width: 60%"
                            @res-select="$parent.$parent.getorg"
                            :initresid='$parent.$parent.curorgid'>
                </res-select>
              </div>
              <div class="col-sm-2 form-group">
                <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 like '%{}%'" v-next-el="cx" v-el:qjmc>
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">客户名称</label>
                <input type="text" class="input_search" style="width:60%" v-model="model.f_user_name" placeholder='客户名称'
                       condition="f_user_name = '{}'">
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">开始时间</label>
                <datepicker :format="'yyyy-MM-dd HH:mm:ss'" :value.sync="model.f_start_date"
                            class="datepicker"

                            placeholder="起始时间"
                            style="width:60%"
                            v-model="model.f_start_date"
                ></datepicker>
              </div>
              <div class="col-sm-2 form-group" >
                <label class="font_normal_body" >结束时间</label>
                <datepicker :format="'yyyy-MM-dd HH:mm:ss'" :value.sync="model.f_end_date"
                            class="datepicker"

                            placeholder="结束时间"
                            style="width:60%"
                            v-model="model.f_end_date"
                ></datepicker>
              </div>

              <div style="float: right">
                <div class="span" style="float:right;">
                  <button class="button_search" @click="$parent.$parent.search()" v-el:cx>查询</button>
                  <button class="button_clear button_spacing" @click="clear">清空</button>
                  <export-excel
                    :data="{condition: $parent.$parent.getCondition}"
                    :field="$parent.$parent.fields"
                    sqlurl="rs/logic/saleExport" progress="saleGetExportProgress" sql-name="outstockquery" template-name='断档数据导出'
                    :choose-col="true">
                  </export-excel>
                  <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>
            </div>
            <div class="row" v-show="$parent.$parent.criteriaShow">
              <div class="col-sm-2 form-group" >
                <label class="font_normal_body">客户类型</label>
                <v-select :value.sync="model.f_user_type"
                          :options='$parent.$parent.Gasusertype' placeholder='请选择'
                          v-model="model.f_user_type"
                          condition="f_user_type = '{}'"
                          close-on-select></v-select>
              </div>
              <div class="col-sm-2">
                <label class="font_normal_body">用气性质</label>
                <v-select
                  placeholder='用气性质'
                  value-single="true"
                  :value.sync="model.f_gasproperties"
                  style="width:60%"
                  v-model="model.f_gasproperties"
                  :options='$parent.$parent.Gasproperties'
                  close-on-select condition="f_gasproperties ='{}'">
                </v-select>
              </div>
              <div class="col-sm-2">
                <label class="font_normal_body">客户地址</label>
                <input @keyup.enter="search" type="text" class="input_search" style="width:60%"
                       v-model="model.f_address"
                       placeholder='客户地址'
                       :size="model.f_address ? model.f_address.length : 6"
                       condition="f_address like '%{}%'"
                >
              </div>
              <div class="col-sm-2">
                <label class="font_normal_body">气表状态</label>
                <v-select
                  placeholder='气表状态'
                  :value.sync="model.f_table_state"
                  style="width:60%"
                  v-model="model.f_table_state"
                  :options='$parent.$parent.TableStates'
                  close-on-select
                  condition="f_table_state='{}'">
                </v-select>
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">气表类型</label>
                <v-select :value.sync="model.f_meter_type"
                          :options='$parent.$parent.metertypes' placeholder='请选择' v-model="model.f_meter_type"
                          condition="f_meter_classify in {}"
                          close-on-select></v-select>
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">气表品牌</label>
                <v-select :value.sync="model.f_meter_brand"
                          v-model="model.f_meter_brand"
                          :options='$parent.$parent.meterbrands' placeholder='请选择'
                          condition="f_meter_brand in {}"
                          close-on-select></v-select>
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">是否断档</label>
                <v-select :value.sync="model.f_out_stock"
                          v-model="model.f_out_stock"
                          :options='$parent.$parent.outstocks' placeholder='请选择'
                          condition="f_out_stock ='{}'"
                          close-on-select></v-select>
              </div>
              <div class="col-sm-2 form-group">
                <label  class="font_normal_body">差值大于</label>
                <input type="text" class="input_search" style="width:60%" v-model="model.f_out_gas" placeholder='差值大于'
                       condition="f_out_gas >= {}" v-next-el="cx" v-el:qjmc>
              </div>
              <div class="col-sm-2 form-group">
                <label  class="font_normal_body">差值小于</label>
                <input type="text" class="input_search" style="width:60%" v-model="model.f_out_gas1" placeholder='差值小于'
                       condition="f_out_gas <= {}" v-next-el="cx" v-el:qjmc>
              </div>
            </div>
          </div>


        </criteria>
        <data-grid :model="model" class="list_area 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>
            </tr>
          </template>
          <template partial='body' partial='list' v-ref:grid>
            <tr >
              <td :style="{background:(row.f_out_stock=='1'? '#f1dec2':'')}" style="text-align:center">{{$index+1}}</td>
              <td :style="{background:(row.f_out_stock=='1'? '#f1dec2':'')}" style="text-align:center">{{row.f_userinfo_code}}</td>
              <td :style="{background:(row.f_out_stock=='1'? '#f1dec2':'')}" style="text-align:center">{{row.f_user_name}}</td>
              <td :style="{background:(row.f_out_stock=='1'? '#f1dec2':'')}" style="text-align:center">{{row.f_user_phone}}</td>
              <td :style="{background:(row.f_out_stock=='1'? '#f1dec2':'')}" style="text-align:center">{{row.f_address}}</td>
              <td :style="{background:(row.f_out_stock=='1'? '#f1dec2':'')}" style="text-align:center">{{row.f_user_type}}</td>
              <td :style="{background:(row.f_out_stock=='1'? '#f1dec2':'')}" style="text-align:center">{{row.f_gasproperties}}</td>
              <td :style="{background:(row.f_out_stock=='1'? '#f1dec2':'')}" style="text-align:center">{{row.f_meter_classify}}</td>
              <td :style="{background:(row.f_out_stock=='1'? '#f1dec2':'')}" style="text-align:center">{{row.f_meter_brand}}</td>
              <td :style="{background:(row.f_out_stock=='1'? '#f1dec2':'')}"  style="text-align:center">{{row.f_balance}}</td>
              <td :style="{background:(row.f_out_stock=='1'? '#f1dec2':'')}"  style="text-align:center">{{row.f_balance_amount}}</td>
              <td :style="{background:(row.f_out_stock=='1'? '#f1dec2':'')}"   style="text-align:center">{{row.f_tablebase}}</td>
              <td :style="{background:(row.f_out_stock=='1'? '#f1dec2':'')}"   style="text-align:center">{{row.f_last_tablebase}}</td>
              <td :style="{background:(row.f_out_stock=='1'? '#f1dec2':'')}"   style="text-align:center">{{row.f_real_last_tablebase}}</td>
              <td :style="{background:(row.f_out_stock=='1'? '#f1dec2':'')}"   style="text-align:center">{{row.f_out_gas}}</td>
              <td :style="{background:(row.f_out_stock=='1'? '#f1dec2':'')}"   style="text-align:center">{{row.f_hand_date}}</td>
              <td :style="{background:(row.f_out_stock=='1'? '#f1dec2':'')}"   style="text-align:center">{{row.f_orgname}}</td>
            </tr>
          </template>
          <template partial='foot'></template>
        </data-grid>
      </criteria-paged>
    </div>
  </div>
</template>

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

let readyGen = async function (self) {
  self.$refs.paged.$refs.criteria.model.f_start_date = self.$login.toStandardDateString() + ' 00:00:00'
  self.$refs.paged.$refs.criteria.model.f_end_date = self.$login.toStandardDateString() + ' 23:59:59'
  await self.$MagLoadParams.loadParam();
  self.initParams();

}

export default {
    title: '断档分析',
    data () {
      return {
        condition: 'f_orgid = ' + this.$login.f.orgid,
        orgcondition: `and f_orgid = '${this.$login.f.orgid}'`,
        meterbrands: [],
        criteriaShow: false,
        model: new PagedList('rs/sql/outstockquery', 20, {startDate: 'this.model.f_start_date', endDate: 'this.model.f_end_date'}),
        curorgid: [this.$login.f.orgid],
        outstocks:[{label:'全部',value:''},{label:'是',value:'1'},{label:'否',value:'0'}],
        fields: {'f_userinfo_code': '客户编号', 'f_user_name': '客户姓名', 'f_user_phone': '电话号码', 'f_address': '客户地址','f_user_type,': '用户类型', 'f_gasproperties': '用气性质', 'f_meter_classify': '气表类型','f_meter_brand':'气表品牌','f_balance':'机表/卡表余额','f_balance_amount':'物联网表余额','f_tablebase':'本期底数(本期记录)','f_last_tablebase':'上期底数(本期记录)','f_real_last_tablebase':'上期底数(上期记录)','f_out_gas':'差值','f_hand_date':'抄表时间','f_orgname':'所属公司'},
      }
    },
    ready () {
      this.$refs.paged.$refs.criteria.model.f_state = ['有效']
      readyGen(this);
    },
    methods: {
      hidden () {
        this.criteriaShow = !this.criteriaShow
      },
      search(){
        this.$refs.paged.$refs.criteria.search()
      },
      selfsearch (args) {
        if(this.$refs.paged.$refs.criteria.model.f_start_date === '' || this.$refs.paged.$refs.criteria.model.f_end_date === ''){
          this.$showAlert('请选择开始时间或结束时间，不能为空！', 'danger', 3000)
        }
        this.isBusy = true
        args.condition = `${args.condition} ` + this.orgcondition
        this.condition = args.condition
        this.model.search(args.condition, args.model)
      },
      getorg (obj) {
        if (plugins.convertToIn(obj) !== null && plugins.convertToIn(obj) !== '') {
          this.orgcondition = ' and f_orgid in ' + plugins.convertToIn(obj)
        } else {
          this.orgcondition = ' and f_orgid = ' + this.$login.f.orgid
        }
      },
      initParams() {
        // 初始化气表品牌
        let brandArr = []
        this.$MagGetSaleParam.getGasbrand().forEach((item) => {
          let temp = {}
          temp.label = item.label
          temp.value = item.value.f_meter_brand
          brandArr.push(temp)
        })
        this.meterbrands = [{label: '全部', value: ''}, ...brandArr]
      },
    },
    computed: {
      getCondition() {
        return {
          startDate: this.$refs.paged.$refs.criteria.model.f_start_date,
          endDate: this.$refs.paged.$refs.criteria.model.f_end_date,
          condition: `${this.$refs.paged.$refs.criteria.condition}` + this.orgcondition,
        }
      },
      Gasproperties () {
        let rs = []
        if (this.model.model.f_user_type) {
          rs = this.$appdata.getParam(this.model.model.f_user_type[0])
        }
        return rs
        // return [{label: '全部', value: ''}, ...this.$appdata.getParam('用气性质')]
      },
      Gasusertype () {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('用户类型')]
      },
      TableStates () {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('气表状态')]
      },
      metertypes() {
        return [{label: ' 全部 ', value: ''}, ...this.$appdata.getParam('气表类型')]
      },
    }
  }
</script>

