<template>
  <div id="unit" class="flex-row">
    <div class="basic-main" @keyup.enter="search">
      <div class="flex" v-if="!show">

        <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 form-group">
                  <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 HH:mm:ss'"
                              :show-reset-button="true"
                              condition="f_operate_date >= '{}'">
                  </datepicker>
                </div>
                <div class="col-sm-2 form-group">
                  <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 HH:mm:ss'"
                              :show-reset-button="true"
                              condition="f_operate_date <= '{}'">
                  </datepicker>
                </div>
                <div class="col-sm-2 form-group">
                  <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 form-group">
                  <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 form-group">
                  <label class="font_normal_body">收费状态</label>
                  <v-select :value.sync="model.f_state" multiple
                            v-model="model.f_state"
                            :options='$parent.$parent.charge_state' placeholder='请选择'
                            condition="f_state in {}"
                            close-on-select></v-select>
                </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"
                                :footer="$parent.$parent.footer"
                                :field="$parent.$parent.getfield" :header="$parent.$parent.other"
                                sqlurl="api/af-revenue/logic/openapi/exportfile" sql-name="flotsampriceChargeQuery" template-name='垃圾费查询导出'
                                :choose-col="true">
                  </export-excel>
                </div>
              </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>
              </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_user_phone}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.f_price_type}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.f_state}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.f_price}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.f_money}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.f_operate_date}}</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;font-weight: bold">
              垃圾费金额合计:&emsp;{{sumsmodel.f_money}}
            </td>
          </tr>
        </table>
      </div>
    </div>
  </div>


</template>

<script>
import {PagedList} from 'vue-client'
import exportConfig from "../config/exportConfig";
let readySomething = async function (self) {
  self.$refs.paged.$refs.cri.model.startDate = self.data ? self.data.startDate : self.$login.toStandardDateString() + ' 00:00:00'
  self.$refs.paged.$refs.cri.model.endDate = self.data ? self.data.endDate : self.$login.toStandardDateString() + ' 23:59:59'
}
export default {
  props:['data'],
  title: '垃圾费查询',
  data() {
    return {
      data: {},
      model: new PagedList('api/af-revenue/sql/flotsampriceChargeQuery', 20, {orderitem: this.orderitem?`${this.orderitem}`: " 'f_operate_date desc'"}
      ,{f_money:0}),
      orgCondtionStr: '',
      footer:[],
      other:[],
      //排序
      orderitem:'f_operate_date desc',
      show:false,
      sumsmodel : {}
    }
  },
  watch:{
    sumsmodel:{
      handler: function(val) {
        this.getotherfooter();
      },
      deep: true
    }
  },
  ready() {
    readySomething(this).then(() => {
      this.$emit('ready')
    }).catch((error) => {
      this.$emit('error', error)
    })
  },
  methods: {
    getotherfooter () {
      // this.$refs.paged.$refs.cri.$refs.exports.otherData = [];
      // this.$refs.paged.$refs.cri.$refs.exports.footerData = [];
      this.other = [];
      this.footer = [];
      let exportdata = this.getCondition;
      let otherInData = [];
      otherInData.push(`导出时间: ${this.$login.toStandardTimeString()}`);

      // otherInData.push(``)
      let footerData = [], exportfield = this.getfield;
      footerData.push("合计");
      let self = this;
      for (var field in self.sumsmodel) {
        footerData.push(`${exportfield[field]}合计:${self.sumsmodel[field]}`);
      }
      this.footer.push(footerData);
      this.other.push(otherInData);
      let date = []
      date.push(`起始时间:${this.$refs.paged.$refs.cri.model.startDate}`)
      date.push(`终止时间:${this.$refs.paged.$refs.cri.model.endDate}`)
      this.other.push(date)
      // this.other.push(enddate)
    },
    search(){
      this.$refs.paged.$refs.cri.search()
    },
    async  selfSearch(args) {
      if (this.data) {
        this.$parent.$parent.$parent.data.startDate=this.$refs.paged.$refs.cri.model.startDate
        this.$parent.$parent.$parent.data.endDate=this.$refs.paged.$refs.cri.model.endDate
      }
      if(!this.$refs.paged.$refs.cri.model.startDate){
        this.$refs.paged.$refs.cri.model.startDate = this.$login.toStandardDateString() + ' 00:00:00'
      }
      if(!this.$refs.paged.$refs.cri.model.endDate){
        this.$refs.paged.$refs.cri.model.endDate = this.$login.toStandardDateString() + ' 23:59:59'
      }
      args.condition = `${args.condition}` + this.orgCondtionStr
      await this.model.search(args.condition, args.model)
      this.sumsmodel = this.$refs.paged.$refs.grid.model.sums;
    },
    clear() {
      Object.keys(this.$refs.paged.$refs.cri.model).forEach((key) => {
        this.$refs.paged.$refs.cri.model[key] = []
      })
    },
    cancel() {
      this.show = false
    }
  },
  computed: {
    getfield() {
      return exportConfig.flotsamprice
    },
    getCondition() {
      return {
        condition: `${this.$refs.paged.$refs.cri.condition}` + this.orgCondtionStr,
        orderitem: this.orderitem?`${this.orderitem}`: " f_operate_date desc"}
    },
    charge_state() {
      return [{label: '全部', value: ''}, ...this.$appdata.getParam('收费状态')]
    },
  }
}
</script>
