<template>
  <div style="flex:1;" class="flex">
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' @condition-changed='$parent.selfSearch' v-ref:cri>
        <div novalidate class="auto form-horizontal select-overspread container-fluid auto" partial>
          <div class="row" v-show="$parent.$parent.criteriaShow">
            <div class="col-sm-2 form-group form-fix-width" >
              <label class="font_normal_body _zoom4" >开始时间</label>
              <datepicker placeholder="开始时间" class="_zoom6"
                          :value.sync="model.startDate"
                          v-model="model.startDate"
                          :format="'yyyy-MM-dd'"
              ></datepicker>
            </div>
            <div class="col-sm-2 form-group form-fix-width" >
              <label class="font_normal_body _zoom4" >结束时间</label>
              <datepicker placeholder="结束时间" class="_zoom6"
                          :value.sync="model.endDate"
                          v-model="model.endDate"
                          :format="'yyyy-MM-dd'"
              ></datepicker>
            </div>
            <div class="col-sm-2 form-group form-fix-width" >
              <label class="font_normal_body _zoom4" >具体单价</label>
              <v-select :value.sync="model.f_price"
                        :options='$parent.$parent.pricelist' placeholder='请选择'
                        v-model="model.f_price"
                        :value-single="true"
                        close-on-select></v-select>
            </div>
            <div class="col-sm-2 form-group form-fix-width" >
              <label class="font_normal_body _zoom4" >气表类型</label>
              <v-select :value.sync="model.f_meter_type"
                        :options='$parent.$parent.metertypes' placeholder='请选择' v-model="model.f_meter_type"
                        condition="f_meter_type = '{}'"
                        close-on-select></v-select>
            </div>
            <div class="col-sm-2 form-group form-fix-width" >
              <label class="font_normal_body _zoom4" >用户类型</label>
              <v-select :value.sync="model.f_user_type"
                        :options='$parent.$parent.usertypes' placeholder='请选择' v-model="model.f_user_type"
                        condition="f_user_type = '{}'"
                        close-on-select></v-select>
            </div>
            <div class="col-sm-2 form-group form-fix-width" >
              <label class="font_normal_body _zoom4" >用气性质</label>
              <v-select :value.sync="model.f_gasproperties" v-model="model.f_gasproperties"
                        :options='$parent.$parent.gasproperties' placeholder='请选择'
                        condition="f_gasproperties = '{}'"
                        close-on-select></v-select>
            </div>
            <div class="col-sm-2 form-group form-fix-width" >
              <label class="font_normal_body _zoom4" >售气单位</label>
              <v-select :value.sync="model.f_filiale"
                        v-model="model.f_filiale"
                        :options='$parent.$parent.filialelist' placeholder='请选择'
                        condition="f_filiale = '{}'"
                        close-on-select></v-select>
            </div>
            <div class="col-sm-2 form-group form-fix-width" >
              <label class="font_normal_body _zoom4" >售气部门</label>
              <v-select :value.sync="model.f_outlets"
                        v-model="model.f_outlets"
                        :options='$parent.$parent.selldep' placeholder='请选择'
                        condition="f_outlets = '{}'"
                        close-on-select></v-select>
            </div>
            <div class="col-sm-2 form-group form-fix-width" >
              <label class="font_normal_body _zoom4" >售气站点</label>
              <input  type="text" class="form-control _zoom6" v-model="model.op_spot"
                      condition="op_spot = '{}'" placeholder="售气站点">
            </div>
            <div class="col-sm-2 form-group form-fix-width" >
              <label class="font_normal_body _zoom4" >人员编号</label>
              <input  type="text" class="form-control _zoom6" v-model="model.op_id"
                      condition="op_id = '{}'" placeholder="操作员编号">
            </div>
          </div>
          <div class="row">
            <div  style="float:right" :class="{'_btnclitested':!$parent.$parent.criteriaShow}">
              <button class="btn btn-success" @click="search()">查询</button>
              <button class="btn btn-default" @click="$parent.$parent.clear()">清空</button>
              <export-excel :data="$parent.$parent.getCondition"
                            :field="$parent.$parent.getfield"
                            sqlurl="rs/logic/exportfile" sql-name="ca_sellgasgroupby_price"
                            template-name='气价单价导出'  :choose-col="true"></export-excel>
              <div
                :class="{'button_shrink_top':$parent.$parent.criteriaShow,'button_shrink_bottom':!$parent.$parent.criteriaShow}"
                @click="$parent.$parent.hidden()" class="button_spacing" style="float: right"></div>
            </div>
          </div>
        </div>
      </criteria>
      <data-grid  :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>
          </tr>
        </template>
        <template partial='body'>
          <td style="text-align: center;"><nobr>{{row.f_operate_date}}</nobr></td>
          <td style="text-align: center;"><nobr>{{row.f_price}}</nobr></td>
          <td style="text-align: center;"><nobr>{{row.f_gas}}</nobr></td>
          <td style="text-align: center;"><nobr>{{row.f_money}}</nobr></td>
          <td style="text-align: center;"><nobr>{{row.c}}</nobr></td>
        </template>
      </data-grid>
    </criteria-paged>
    <table class="table-hover">
      <tr class="table-bordered">
        <td style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;color: #5CB95C;font-weight: bold">汇总信息</td>
        <td style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px">数量合计:&emsp;{{sumsmodel.c}}</td>
        <td style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px">气量合计:&emsp;{{sumsmodel.f_gas}}</td>
        <td style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px">金额合计:&emsp;{{sumsmodel.f_money}}</td>
      </tr>
    </table>
  </div>
</template>

<script>
  import { PagedList } from 'vue-client'
  import defaultPrint from '../config/DefaultPrint'
  import exportConfig from '../config/exportConfig'

  let readySomething = async function (self) {
    console.log('收费查询获取默认配置', self.config)
    self.$refs.paged.$refs.cri.model.startDate = self.$login.toStandardDateString()
    self.$refs.paged.$refs.cri.model.endDate = self.$login.toStandardDateString()
    await self.$MagLoadParams.loadParam(self.$login.f)
  }
  export default {
    data() {
      return {
        data: {},
        criteriaShow:true,
        model: new PagedList('rs/sql/ca_sellgasgroupby_price', 20,{
          startDate: 'this.model.startDate',
          endDate:  'this.model.endDate',
          f_price: 'this.model.f_price',
        },{
          f_gas: 0,f_money: 0,c:0
        }),
        fields: {},
        filialelist: this.$appdata.getParam('售气单位') ? [{label: '全部', value: ''},...this.$appdata.getParam('售气单位')] : [],
        //合计数据
        defaultfield: [],
        metertypes: this.$appdata.getParam('气表类型') ? [{label: '全部', value: ''}, ...this.$appdata.getParam('气表类型')] : [],
        usertypes: this.$appdata.getParam('用户类型') ? [{label: '全部', value: ''}, ...this.$appdata.getParam('用户类型')] : [],
        pricelist: this.$appdata.getParam('具体单价') ? [{label: '全部', value: ''}, ...this.$appdata.getParam('具体单价')] : [],
        sumsmodel: {}
      }
    },
    ready(){
      readySomething(this).then(() => {
        this.$emit('ready')
      }).catch((error) => {
        this.$emit('error', error)
      })
    },
    methods: {
      selfSearch (args) {
        this.model.search(args.condition, args.model)
        this.sumsmodel = this.$refs.paged.$refs.grid.model.sums
      },
      hidden(){
        this.criteriaShow = !this.criteriaShow
      },
      clear(){
        Object.keys(this.$refs.paged.$refs.cri.model).forEach((key) => {
          this.$refs.paged.$refs.cri.model[key] = []
        })
      },
    },
    watch:{
    },
    computed:{
      getCondition(){
        return {
          condition: `${this.$refs.paged.$refs.cri.condition} `,
          startDate: this.$refs.paged.$refs.cri.model.startDate,
          endDate:  this.$refs.paged.$refs.cri.model.endDate,
          f_price: this.$refs.paged.$refs.cri.model.f_price,
        }
      },
      getfield(){
        return exportConfig.groupprice
      },
      selldep () {
        let rs = []
        if(this.$refs.paged.$refs.cri.model.f_filiale){
          this.$refs.paged.$refs.cri.model.f_outlets = ''
          return [{label: '全部', value: ''}, ...this.$appdata.getParam(this.$refs.paged.$refs.cri.model.f_filiale) ]
        }
        else {
          return [{label: '全部', value: ''}]
        }
      },
      gasproperties () {
        let rs = []
        if (this.$refs.paged.$refs.cri.model.f_user_type.length === 1) {
          rs = this.$appdata.getParam(this.$refs.paged.$refs.cri.model.f_user_type[0])
        }
        return [{label: '全部', value: ''}, ...rs]
      },
    }
  }
</script>
