<template>
  <div class="flex" style="flex: 1;">
    <div style="flex: 1.2">
      <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="form-group"
                   :class="{'col-sm-2':!$parent.$parent.$parent.isdetail,'col-sm-4':$parent.$parent.$parent.isdetail}">
                <label for="startDate" class="font_normal_body">开始日期</label>
                <datepicker id="startDate" placeholder="开始日期" width='100%'
                            v-model="model.startDate"
                            :value.sync="model.startDate"
                            :format="'yyyy-MM-dd'"
                            style="width:60%"
                            :show-reset-button="true"
                            condition="f_account_end_date >= '{} 00:00:00'">
                </datepicker>
              </div>
              <div class="form-group"
                   :class="{'col-sm-2':!$parent.$parent.$parent.isdetail,'col-sm-4':$parent.$parent.$parent.isdetail}">
                <label for="endDate" class="font_normal_body">结束日期</label>
                <datepicker id="endDate" placeholder="结束日期" width='100%'
                            v-model="model.endDate"
                            :value.sync="model.endDate"
                            :format="'yyyy-MM-dd'"
                            style="width:60%"
                            :show-reset-button="true"
                            condition="f_account_end_date <= '{} 23:59:59'">
                </datepicker>
              </div>
              <div class="form-group"
                   :class="{'col-sm-2':!$parent.$parent.$parent.isdetail,'col-sm-4':$parent.$parent.$parent.isdetail}">
                <label for="f_userinfo_code" class="font_normal_body">用户编号</label>
                <input type="text" class="input_search" style="width:60%" v-model="model.f_userinfo_code"
                       condition="f_userinfo_code like '%{}%'" placeholder='用户编号'>
              </div>
              <div class="form-group"
                   :class="{'col-sm-2':!$parent.$parent.$parent.isdetail,'col-sm-4':$parent.$parent.$parent.isdetail}">
                <label for="f_user_name" class="font_normal_body">用户姓名</label>
                <input type="text" class="input_search" style="width:60%" v-model="model.f_user_name"
                       condition="f_user_name like '%{}%'" placeholder='用户姓名'>
              </div>
              <div class="form-group"
                   :class="{'col-sm-2':!$parent.$parent.$parent.isdetail,'col-sm-4':$parent.$parent.$parent.isdetail}">
                <label for="f_address" class="font_normal_body">用户地址</label>
                <input type="text" class="input_search" style="width:60%" v-model="model.f_address"
                       condition="f_address like '%{}%'" placeholder='用户地址'>
              </div>

              <div class="form-group"
                   :class="{'col-sm-2':!$parent.$parent.$parent.isdetail,'col-sm-4':$parent.$parent.$parent.isdetail}">
                <label class="font_normal_body">气表品牌</label>
                <v-select :value.sync="model.f_meter_brand"
                          v-model="model.f_meter_brand"
                          :options.sync='$parent.$parent.meterbrands' placeholder='请选择'
                          condition="f_meter_brand = '{}'"
                          close-on-select></v-select>
              </div>
              <div class="form-group"
                   :class="{'col-sm-2':!$parent.$parent.$parent.isdetail,'col-sm-4':$parent.$parent.$parent.isdetail}">
                <label class="font_normal_body">是否开票</label>
                <v-select :value.sync="model.f_eticket_id"
                          v-model="model.f_eticket_id"
                          :options.sync='$parent.$parent.isOpenBill' placeholder='请选择'
                          condition="f_eticket_id {}"
                          close-on-select></v-select>
              </div>
              <div class="form-group"
                   :class="{'col-sm-2':!$parent.$parent.$parent.isdetail,'col-sm-4':$parent.$parent.$parent.isdetail}">
                <label class="font_normal_body">用户类型</label>
                <v-select :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="span" style="float:right;margin-top:5px">
                <button class="button_search" @click="$parent.$parent.search()" v-el:cx>查询</button>
                <export-excel
                  :data="$parent.$parent.getCondition"
                  :field="$parent.$parent.getfield"
                  sqlurl="rs/logic/saleExport" sql-name="getWebInfoAccount" template-name='抄表结算查询导出'
                  :choose-col="true"></export-excel>
                <print-data :model="$parent.model" :field="$parent.$parent.getfield"
                            :defaultfield="$parent.$parent.defaultfield" print-name="结算查询"></print-data>
              </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>
            </tr>
          </template>
          <template partial='body'>
            <td style="text-align: center;">{{ row.f_userinfo_code }}</td>
            <td style="text-align: center;">{{ row.f_user_name }}</td>
            <td style="text-align: center;">{{ row.f_user_type }}</td>
            <td style="text-align: center;">{{ row.f_user_phone }}</td>
            <td style="text-align: center;">{{ row.f_address }}</td>
            <td style="text-align: center;">{{ row.f_last_balance }}</td>
            <td style="text-align: center;">{{ row.f_collection }}</td>
            <td style="text-align: center;">{{ row.f_pregas }}</td>
            <td style="text-align: center;">{{ row.f_preamount }}</td>
            <td style="text-align: center;">{{ row.f_balance }}</td>
            <td style="text-align: center;">{{ row.f_account_start_date }}</td>
            <td style="text-align: center;">{{ row.f_account_end_date }}</td>
            <td style="text-align: center;">{{ row.f_operator }}</td>
            <td style="text-align: center;">{{ row.f_operate_date }}</td>
          </template>
        </data-grid>
      </criteria-paged>
    </div>
  </div>
</template>
<script>
import {PagedList} from 'vue-client'

export default {
  title: '抄表结算单',
  data () {
    return {
      model: new PagedList('rs/sql/getWebInfoAccount', 20, {
        startDate: 'this.model.startDate',
        endDate: 'this.model.endDate'
      }),
      condition: '',
      metertype: this.$appdata.getParam('气表类型') ? [{
        label: '全部',
        value: ''
      }, ...this.$appdata.getParam('气表类型')] : [],
      getfield: {
        'f_userinfo_code': '用户编号',
        'f_user_name': '用户姓名',
        'f_user_type': '用户类型',
        'f_user_phone': '用户电话',
        'f_address': '用户地址',
        'f_last_balance': '上期结余',
        'f_collection': '收款',
        'f_pregas': '用气量',
        'f_preamount': '用气金额',
        'f_balance': '本期结余',
        'f_account_start_date': '上次结算日期',
        'f_account_end_date': '本次结算日期',
        'f_operator': '操作员',
        'f_operate_date': '操作日期'
      },
      meterbrands: [],
      isOpenBill: [{label: '全部', value: ''}, {label: '是', value: 'is not null'}, {label: '否', value: 'is null'}],
      defaultfield: []
    }
  },
  async ready () {
    this.$refs.paged.$refs.cri.model.startDate = this.$login.toStandardDateString()
    this.$refs.paged.$refs.cri.model.endDate = this.$login.toStandardDateString()
    await this.$LoadParams.loadParam()
    let arr = []
    this.$GetSaleParam.getGasbrand().forEach((item) => {
      let temp = {}
      if (item.value.f_meter_type === '物联网表' || item.value.f_meter_type === '机表') {
        temp.label = item.label
        temp.value = item.value.f_meter_brand
        arr.push(temp)
      }
    })
    this.meterbrands = [{label: '全部', value: ''}, ...arr]
  },
  methods: {
    search () {
      this.$refs.paged.$refs.cri.search()
      this.$dispatch('search')
    },
    selfSearch (args) {
      console.log('aa', this.meterbrands)
      args.condition = `${args.condition} and f_orgid = '${this.$login.f.orgid}'`
      this.condition = args.condition
      this.model.search(args.condition, args.model)
    }
  },
  computed: {
    userType () {
      return [{label: '全部', value: ''}, ...this.$appdata.getParam('用户类型')]
    },
    getCondition () {
      return {
        condition: this.condition
      }
    }
  }
}
</script>
