<template>
  <div id="unit" class="flex-row">
    <div class="basic-main">
      <div 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">
                <div class="col-sm-2">
                  <label class="font_normal_body">客户编号</label>
                  <input type="text" style="width:60%" class="input_search" v-model="model.f_userinfo_code"
                         condition="f_userinfo_code = '{}' " placeholder="客户编号">
                </div>
                <div class="col-sm-2">
                  <label class="font_normal_body">客户名称</label>
                  <input type="text" style="width:60%" class="input_search" v-model="model.f_user_name"
                         condition="f_user_name like '%{}%'" placeholder="客户名称">
                </div>
                <div class="col-sm-2">
                  <label for="startDate" class="font_normal_body">开始日期</label>
                  <datepicker id="startDate" placeholder="开始日期" style="width:60%"
                              v-model="model.startDate"
                              :value.sync="model.startDate"
                              :format="'yyyy-MM-dd'"
                              :show-reset-button="true"
                              condition="f_operate_date >= '{} 00:00:00'">
                  </datepicker>
                </div>
                <div class="col-sm-2">
                  <label for="endDate" class="font_normal_body">结束日期</label>
                  <datepicker id="endDate" placeholder="结束日期" style="width:60%"
                              v-model="model.endDate"
                              :value.sync="model.endDate"
                              :format="'yyyy-MM-dd'"
                              :show-reset-button="true"
                              condition="f_operate_date <= '{} 23:59:59'">
                  </datepicker>
                </div>
                <div class="span" style="float:right;">
                  <button class="button_search button_spacing" @click="search()">查询</button>
                  <button class="button_clear button_spacing" @click="$parent.$parent.clear()">清空</button>

                  <export-excel :data="$parent.$parent.getCondition"
                                :field="$parent.$parent.getfield"
                                sqlurl="rs/logic/exportfile" sql-name="chargeQuery" template-name='收费查询导出'
                                :choose-col="true"></export-excel>

                  <print-data :model="$parent.model" :field="$parent.$parent.getfield"
                              :defaultfield="$parent.$parent.defaultfield" print-name="收费查询"
                              :sumsmodel="$parent.$parent.sumsmodel"></print-data>
                  <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 class="row" v-show="$parent.$parent.criteriaShow">
                <div class="col-sm-2">
                  <label class="font_normal_body">客户电话</label>
                  <input type="text" style="width:60%" class="input_search" v-model="model.f_user_phone"
                         condition="f_user_phone like '%{}%'" placeholder="客户电话">
                </div>
                <div class="col-sm-2">
                  <label class="font_normal_body">身份证号</label>
                  <input type="text" style="width:60%" class="input_search" v-model="model.f_idnumber"
                         condition="f_idnumber like '%{}%'" placeholder="身份证号">
                </div>
                <div class="col-sm-2">
                  <label class="font_normal_body">&nbsp;&nbsp;&nbsp;小区&nbsp;&nbsp;&nbsp;</label>
                  <input type="text" style="width:60%" class="input_search" v-model="model.f_residential_area"
                         condition="f_residential_area like '%{}%'" placeholder="小区"/>
                </div>
                <div class="col-sm-2">
                  <label class="font_normal_body">客户地址</label>
                  <input type="text" style="width:60%" class="input_search" v-model="model.f_address"
                         condition="f_address like '%{}%'" placeholder='客户地址'>
                </div>
                <div class="col-sm-2">
                  <label class="font_normal_body">付款方式</label>
                  <v-select :value.sync="model.f_payment"
                            v-model="model.f_payment"
                            :options='$parent.$parent.payment' placeholder='请选择'
                            condition="f_payment = '{}'"
                            close-on-select></v-select>
                </div>
                <div class="col-sm-2">
                  <label class="font_normal_body">收费类型</label>
                  <v-select :value.sync="model.f_type"
                            v-model="model.f_type"
                            :options='$parent.$parent.chargetype' placeholder='请选择'
                            condition="f_type = '{}'"
                            close-on-select></v-select>
                </div>
                <div class="col-sm-2">
                  <label class="font_normal_body">客户类型</label>
                  <v-select :value.sync="model.f_user_type"
                            @change="$parent.$parent.userTypeChange()"
                            :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">
                  <label class="font_normal_body">用气性质</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">
                  <label class="font_normal_body">气价类型</label>
                  <v-select :value.sync="model.pricetype" v-model="model.pricetype"
                            placeholder='气价类型' :options="$parent.$parent.pricetypes"
                            close-on-select v-ref:type>
                  </v-select>
                </div>
                <div class="col-sm-2">
                  <label class="font_normal_body">气价名称</label>
                  <v-select :value.sync="model.f_price_name"
                            v-model="model.f_price_name"
                            :options="$parent.$parent.getPricenames"
                            condition="f_price_name = '{}'"
                            close-on-select></v-select>
                </div>
                <div class="col-sm-2">
                  <label class="font_normal_body">&nbsp;&nbsp;&nbsp;表编号</label>
                  <input type="text" style="width:60%" class="input_search" v-model="model.f_user_id"
                         condition="f_user_id = '{}'" placeholder='表编号'>
                </div>
                <div class="col-sm-2">
                  <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_type = '{}'"
                            close-on-select></v-select>
                </div>
                <div class="col-sm-2">
                  <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 = '{}'"
                            close-on-select></v-select>
                </div>
                <!--                <div class="col-sm-2">-->
                <!--                  <label class="font_normal_body">气表状态</label>-->
                <!--                  <v-select :value.sync="model.f_table_state"-->
                <!--                            v-model="model.f_table_state"-->
                <!--                            :options='$parent.$parent.tablestate' placeholder='请选择'-->
                <!--                            condition="f_table_state in {}"-->
                <!--                            close-on-select></v-select>-->
                <!--                </div>-->
                <div class="col-sm-2">
                  <label class="font_normal_body">收费状态</label>
                  <v-select :value.sync="model.f_state"
                            v-model="model.f_state"
                            :options='$parent.$parent.charge_state' placeholder='请选择'
                            condition="f_state = '{}'"
                            close-on-select></v-select>
                </div>

                <res-select-group @re-res="$parent.$parent.getRes" v-ref:sel></res-select-group>
              </div>
            </div>
          </criteria>

          <data-grid :model="model" partial='list' class="list_area table_sy" 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>
              </tr>
            </template>
            <template partial='body'>
              <td style="text-align: center;">
                <nobr>{{row.f_userinfo_code}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.f_user_name}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.f_address}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.f_meternumber}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.f_times}}</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.f_delaypay}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.f_collection}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.f_balance}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.f_curbalance}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.f_payment}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.f_type}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.f_state}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.f_operate_date}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.f_comments}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.filltimes}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.f_operator}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.f_depname}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.f_orgname}}</nobr>
              </td>
            </template>
            <template partial='foot'></template>
          </data-grid>

        </criteria-paged>

        <table class="table-hover">
          <tr style="position: relative" 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.f_delaypay}}
            </td>
            <td style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px">
              收款合计:&emsp;{{sumsmodel.f_collection}}
            </td>
          </tr>
        </table>
      </div>
    </div>
  </div>
</template>

<script>
  import {PagedList} from 'vue-client'

  let readySomething = async function (self) {
    await self.$getConfig(self, 'ChargeQuery')
    console.log('收费查询获取默认配置', self.config)
    self.defaultfield = [...self.defaultfield, ...self.config.defaultPrint]
    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.initParams()
    await self.$refs.paged.$refs.cri.search()
    self.sumsmodel = self.$refs.paged.$refs.grid.model.sums
  }
  export default {
    data() {
      return {
        config: {
          defaultPrint: ['f_userinfo_code', 'f_address', 'f_pregas', 'f_preamount']
        },
        //f_price_name:[],
        gasproperties:[],
        showinfo: false,
        data: {},
        model: new PagedList('rs/sql/chargeQuery', 20, {}, {
          f_pregas: 0,
          f_preamount: 0,
          f_delaypay: 0,
          f_collection: 0
        }),
        criteriaShow: true,
        orgCondtionStr: '',
        // 下拉框
        meterbrands: [],
        pricenames: [],
        prices: [],
        //合计数据
        defaultfield: [],
        sumsmodel: {},
        f_filialeid: this.$login.f.f_orgid
      }
    },
    ready() {
      readySomething(this).then(() => {
        this.$emit('ready')
      }).catch((error) => {
        this.$emit('error', error)
      })
    },
    methods: {
      selfSearch(args) {
        let f_orgstr = this.orgCondtionStr
        args.condition = `${args.condition} ` + f_orgstr
        this.model.search(args.condition, args.model)
        this.sumsmodel = this.$refs.paged.$refs.grid.model.sums
      },
      getRes(condition) {
        this.orgCondtionStr = condition
      },
    },
    watch: {

    },
    computed: {

    }
  }
</script>
