<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="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 for="startDate" class="font_normal_body _zoom4" >开始日期</label>
              <datepicker id="startDate" placeholder="开始日期" class="_zoom6"
                          v-model="model.startDate"
                          :value.sync="model.startDate"
                          :format="'yyyy-MM-dd'"
                          :show-reset-button="true"
                          condition="f_operate_date >= to_date('{} 00:00:00','yyyy-mm-dd hh24:mi:ss')">
              </datepicker>
            </div>
             <div class="col-sm-2 form-group form-fix-width" >
              <label for="endDate" class="font_normal_body _zoom4" >结束日期</label>
              <datepicker id="endDate" placeholder="结束日期" class="_zoom6"
                          v-model="model.endDate"
                          :value.sync="model.endDate"
                          :format="'yyyy-MM-dd'"
                          :show-reset-button="true"
                          condition="f_operate_date <= to_date('{} 23.59.59','yyyy-mm-dd hh24:mi:ss')">
              </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_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.getExportField"
                            sqlurl="rs/logic/exportfile" sql-name="changan_sellgasByItem" template-name='表具查询导出' :choose-col="true"></export-excel>
              <print-data :model="$parent.model" :field="$parent.$parent.getExportField"
                          :defaultfield="$parent.$parent.defaultfield" print-name="售气按站点"></print-data>
              <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 :classname="$parent.classname">
        <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>
          </tr>
        </template>
        <template partial='body'>
          <td style="text-align: center;"><nobr>{{row.f_outlets}}</nobr></td>
          <td style="text-align: center;"><nobr>{{row.op_spot}}</nobr></td>
          <td style="text-align: center;"><nobr>{{row.f_operator}}</nobr></td>
          <td style="text-align: center;"><nobr>{{row.f_pregas}}</nobr></td>
          <td style="text-align: center;"><nobr>{{row.f_preamount}}</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.f_pregas}}</td>
        <td style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px">金额合计:&emsp;{{sumsmodel.f_preamount}}</td>
        <td style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px">数量合计:&emsp;{{sumsmodel.c}}</td>
      </tr>
    </table>
  </div>
</template>
<script>
  import { PagedList } from 'vue-client'
  import exportConfig from '../config/exportConfig'

  export default {
    data() {
      return {
        defaultfield:[],
        sumsmodel: {},
        criteriaShow:true,
        model: new PagedList('rs/sql/changan_sellgasByItem', 20,{item:"'f_outlets,op_spot,f_operator'"},{
          f_pregas: 0,f_preamount: 0,c:0
        }),
        metertypes: this.$appdata.getParam('气表类型') ? [{label: '全部', value: ''}, ...this.$appdata.getParam('气表类型')] : [],
        usertypes: this.$appdata.getParam('用户类型') ? [{label: '全部', value: ''}, ...this.$appdata.getParam('用户类型')] : [],
        filialelist: this.$appdata.getParam('售气单位') ? [{label: '全部', value: ''},...this.$appdata.getParam('售气单位')] : [],
      }
    },
    ready(){
      this.$refs.paged.$refs.cri.model.startDate = this.$login.toStandardDateString()
      this.$refs.paged.$refs.cri.model.endDate = this.$login.toStandardDateString()
    },
    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:{
      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]
      },
      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: ''}]
        }
      },
      getCondition(){
        return {condition: `${this.$refs.paged.$refs.cri.condition}`}
      },
      getExportField () {
        return {
          'f_outlets': '部门','op_spot': '站号','f_operator': '名称',
          'f_pregas':'气量',
          'f_preamount': '金额','.c':'数量',
        }
      },
    }
  }
</script>
