<template>
    <criteria-paged :model="model" v-ref:cp>
      <criteria partial='criteria' @condition-changed='$parent.searchCondition' v-ref:cri>
        <div class="form-horizontal select-overspread container-fluid auto" partial>
          <div class="row">
            <div class="form-group col-sm-3">
              <label  for="startDate" class="font_normal_body">开始时间：</label>
              <datepicker id="startDate" placeholder="开始日期"
                          style="width: 60%!important;"
                          v-model="model.startDate"
                          :value.sync="model.startDate"
                          :format="'yyyy-MM-dd 00:00:00'"
                          :show-reset-button="true"
                          condition="cr.f_charge_date >= '{}'">
              </datepicker>
            </div>
            <div class="form-group col-sm-3">
              <label for="endDate" class="font_normal_body">结束时间：</label>
              <datepicker id="endDate" placeholder="结束日期"
                          style="width: 60%!important;"
                          v-model="model.endDate"
                          :value.sync="model.endDate"
                          :format="'yyyy-MM-dd 23:59:59'"
                          :show-reset-button="true"
                          condition="cr.f_charge_date <= '{}'">
              </datepicker>
            </div>
            <div class="form-group col-sm-3 button-range">
              <button class="button_search button_spacing" @click="$parent.$parent.search()" v-el:cx>查询</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/applyExportfile"
                            sql-name="getApplyCharge"
                            template-name='收费记录信息导出'
                            :choose-col="true"></export-excel>
              <div
                :class="{'button_shrink_top':$parent.$parent.criteriaShow,'button_shrink_bottom':!$parent.$parent.criteriaShow}"
                @click="$parent.$parent.criteriaShow = !$parent.$parent.criteriaShow"
                class="button_spacing"
                style="float: right">
              </div>
            </div>
          </div>
          <div class="row" v-show="$parent.$parent.criteriaShow">
            <div class="form-group col-sm-3">
              <label class="font_normal_body">工程编号：</label>
              <input type="text" style="width: 60%" class="input_search" placeholder='工程编号' v-model="model.f_apply_num"
                     v-on:keyup.enter="$parent.$parent.search()"
                     condition="a.f_apply_num like '%{}%'">
            </div>
            <div class="form-group col-sm-3">
              <label class="font_normal_body">合同编号：</label>
              <input type="text" style="width: 60%" class="input_search" placeholder='合同编号' v-model="model.f_contract_number"
                     v-on:keyup.enter="$parent.$parent.search()"
                     condition="a.f_contract_number = '{}'">
            </div>
            <div class="form-group col-sm-3">
              <label class="font_normal_body">报建类型：</label>
              <v-select
                v-model="model.f_apply_type"
                placeholder='请选择'
                condition="a.f_apply_type = '{}'"
                :value.sync="model.f_apply_type"
                :options='$parent.$parent.applytype'
                class="select select_list"
                :value-single="true"
                @change="$parent.$parent.applyTypeChange()"
                close-on-select ></v-select>
            </div>
            <div class="form-group col-sm-3">
              <label class="font_normal_body">报建性质：</label>
              <v-select
                v-model="model.f_apply_nature"
                placeholder='报建性质'
                condition="a.f_apply_nature = '{}'"
                :value.sync="model.f_apply_nature"
                :options='$parent.$parent.applyNatures'
                class="select select_list"
                :value-single="true"
                close-on-select ></v-select>
            </div>
            <div class="form-group col-sm-3">
              <label class="font_normal_body">缴费编码：</label>
              <input type="text" class="input_search" style="width: 60%" placeholder='缴费编码' v-model="model.f_charge_number"
                     v-on:keyup.enter="$parent.$parent.search()"
                     condition="cr.f_charge_number like '%{}%'">
            </div>
            <div class="form-group col-sm-3">
              <label class="font_normal_body">付款方式：</label>
              <v-select
                v-model="model.f_payment_method"
                placeholder='请选择'
                condition="cr.f_payment_method = '{}'"
                :value.sync="model.f_payment_method"
                :options='$parent.$parent.paymentMethod'
                class="select select_list"
                :value-single="true"
                close-on-select ></v-select>
            </div>
            <div class="form-group col-sm-3">
              <label class="font_normal_body">收费项目：</label>
              <v-select
                v-model="model.f_payment_term"
                placeholder='请选择'
                condition="cr.f_payment_term = '{}'"
                :value.sync="model.f_payment_term"
                :options='$parent.$parent.paymentTerm'
                class="select select_list"
                :value-single="true"
                close-on-select ></v-select>
            </div>
            <div class="form-group col-sm-3">
              <label class="font_normal_body">流&ensp;水&ensp;号：</label>
              <input type="text" style="width: 60%" class="input_search" placeholder='流水号' v-model="model.f_payer_number"
                     v-on:keyup.enter="$parent.$parent.search()"
                     condition="cr.f_payer_number = '{}'">
            </div>
            <div class="form-group col-sm-3">
              <label class="font_normal_body">部&emsp;&emsp;门：</label>
              <res-select
                restype='department'
                :parentresid="$parent.$parent.curorgid"
                :initresid='$parent.$parent.curdepid'
                @res-select="$parent.$parent.getdep"
                :is-mul="true"
              ></res-select>
            </div>
            <div class="form-group col-sm-3">
              <label class="font_normal_body">人&emsp;&emsp;员：</label>
              <res-select
                restype='user'
                :parentresid="$parent.$parent.curdepid"
                :initresid='$parent.$parent.curuserid'
                @res-select="$parent.$parent.getuser"
                :is-mul="true"></res-select>
            </div>
            <div class="form-group col-sm-3">
              <label class="font_normal_body">缴费状态：</label>
              <v-select
                v-model="model.f_charge_status"
                placeholder='请选择'
                condition="cr.f_charge_status = '{}'"
                :value.sync="model.f_charge_status"
                :options='$parent.$parent.chargeStatus'
                class="select select_list"
                :value-single="true"
                close-on-select ></v-select>
            </div>
            <div class="form-group col-sm-3">
              <label class="font_normal_body">服务人：</label>
              <v-select
                v-model="model.f_servicer"
                placeholder='请选择'
                condition="a.f_servicer = '{}'"
                :value.sync="model.f_servicer"
                class="select select_list"
                :options='$parent.$parent.servicerList'
                :value-single="true"
                close-on-select ></v-select>
            </div>
            <div class="form-group col-sm-3">
              <label class="font_normal_body">报建发起人：</label>
              <v-select
                v-model="model.f_operator"
                placeholder='请选择'
                condition="a.f_operator = '{}'"
                :value.sync="model.f_operator"
                class="select select_list"
                :options='$parent.$parent.operatorList'
                :value-single="true"
                close-on-select ></v-select>
            </div>
          </div>
        </div>
      </criteria>
      <data-grid :model="model" partial='list' v-ref:grid style="overflow: auto" class="list_area table_sy">
        <template partial='head'>
          <tr>
            <th style="white-space: nowrap;">序号</th>
            <th style="white-space: nowrap;">工程编号</th>
            <th style="white-space: nowrap;">合同编号</th>
            <th style="white-space: nowrap;">报建类型</th>
            <th style="white-space: nowrap;">报建性质</th>
            <th style="white-space: nowrap;">用户名称</th>
            <th style="white-space: nowrap;">用户电话</th>
            <th style="white-space: nowrap;">用户地址</th>
            <th style="white-space: nowrap;">身份证号</th>
            <th style="white-space: nowrap;">缴费编码</th>
            <th style="white-space: nowrap;">收费项目</th>
            <th style="white-space: nowrap;">收费金额(退款金额)</th>
            <th style="white-space: nowrap;">付款方式</th>
            <th style="white-space: nowrap;">流水号</th>
            <th style="white-space: nowrap;">服务人</th>
            <th style="white-space: nowrap;">报建发起人</th>
            <th style="white-space: nowrap;">收费人员(退款人员)</th>
            <th style="white-space: nowrap;">收费日期(退款日期)</th>
            <th style="white-space: nowrap;">实际收费时间</th>
            <th style="white-space: nowrap;">状态</th>
          </tr>
        </template>
        <template partial='body'>
          <tr >
            <td style="text-align: center;">
              <nobr><font>{{$index+1}}</font></nobr>
            </td>
            <td style="text-align: center;">
              <nobr><font>{{row.f_apply_num}}</font></nobr>
            </td>
            <td style="text-align: center;">
              <nobr><font>{{row.f_contract_number}}</font></nobr>
            </td>
            <td style="text-align: center;">
              <nobr><font>{{row.f_apply_type}}</font></nobr>
            </td>
            <td style="text-align: center;">
              <nobr><font>{{row.f_apply_nature}}</font></nobr>
            </td>
            <td style="text-align: center;">
              <nobr><font>{{row.f_user_name}}</font></nobr>
            </td>
            <td style="text-align: center;">
              <nobr><font>{{row.f_phone}}</font></nobr>
            </td>
            <td style="text-align: center;">
              <nobr><font>{{row.f_address}}</font></nobr>
            </td>
            <td style="text-align: center;">
              <nobr><font>{{row.f_idnumber}}</font></nobr>
            </td>
            <td style="text-align: center;">
              <nobr><font>{{row.f_charge_number}}</font></nobr>
            </td>
            <td style="text-align: center;">
              <nobr><font>{{row.f_payment_term}}</font></nobr>
            </td>
            <td style="text-align: center;">
              <nobr><font>{{row.f_charge_money}}</font></nobr>
            </td>
            <td style="text-align: center;">
              <nobr><font>{{row.f_payment_method}}</font></nobr>
            </td>
            <td style="text-align: center;">
              <nobr><font>{{row.f_payer_number}}</font></nobr>
            </td>
            <td style="text-align: center;">
              <nobr><font>{{row.f_servicer}}</font></nobr>
            </td>
            <td style="text-align: center;">
              <nobr><font>{{row.f_operator}}</font></nobr>
            </td>
            <td style="text-align: center;">
              <nobr><font>{{row.f_charge_collectors}}</font></nobr>
            </td>
            <td style="text-align: center;">
              <nobr><font>{{row.f_charge_date}}</font></nobr>
            </td>
            <td style="text-align: center;">
              <nobr><font>{{row.f_actual_date}}</font></nobr>
            </td>
            <td style="text-align: center;">
              <nobr><font>{{row.f_charge_status}}</font></nobr>
            </td>
          </tr>
        </template>
      </data-grid>
    </criteria-paged>
</template>

<script>
import {PagedList} from 'vue-client'
import {HttpResetClass} from 'vue-client'
import {isEmpty} from "../../../../../Util";
export default {
  title: '报建收费列表',
  props: ['row'],
  data () {
    return {
      model: new PagedList('rs/sql/getApplyCharge', 30, null, {
        f_charge_money: 0
      }),
      curorgid: [this.$login.f.orgid],
      curdepid: [],
      servicerList:[],
      operatorList:[],
      curuserid: [],
      paymentTerm :[{label: '全部', value: ''}, ...this.$appdata.getParam('收费项目')],
      applytype: [{label: '全部', value: ''}, ...this.$appdata.getParam('报建类型')],
      applyNatures: [{label: '全部', value: ''}], // 报建性质
      paymentMethod: [{label: '全部', value: ''}, ...this.$appdata.getParam('付款方式')],
      chargeStatus: [
        {label: '全部', value: ''},
        {label: '有效', value: '有效'},
        {label: '作废', value: '作废'},
        {label: '退款', value: '退款'}
      ],
      criteriaShow: false,
      chargeAll: {
        count: 0,
        sum: 0
      },
      getfield: {
        'f_apply_num': '工程编号',
        'f_contract_number': '合同编号',
        'f_apply_type': '报建类型',
        'f_apply_nature': '报建性质',
        'f_user_name': '用户名称',
        'f_phone': '用户电话',
        'f_address': '用户地址',
          'f_idnumber': '身份证号',
        'f_charge_number': '缴费编码',
        'f_charge_money': '收费金额',
        'f_payment_method': '付款方式',
        'f_payer_number': '流水号',
        'f_charge_collectors': '收费人员',
        'f_charge_date': '收费日期',
        'f_actual_date': '实际收费时间',
        'f_charge_status': '状态'
      }
    }
  },
  ready () {
    // 调用查询
    this.search()
    this.getservicer()
    this.getapplyoperator()
  },
  methods: {
   async getservicer(){
      debugger
      let data = {
        tablename: 't_user',
        condition: `1=1`
      }
      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/sql/apply_singleTable`,
        {data: data},
        {resolveMsg: null, rejectMsg: '服务人查询失败！！！'}
      )
      res.data.forEach(item => {
         this.servicerList.push({
             'label': item.name,
              'value': item.name
     })
})},

    async getapplyoperator(){
      debugger
      let data = {
        condition: `1=1`
      }
      let http = new HttpResetClass()
      let res = await http.load('POST', 'rs/sql/getapplyOperator', {data: data}, {resolveMsg: null, rejectMsg: null})
      res.data.forEach(item => {
        this.operatorList.push({
          'label': item.f_operator,
          'value': item.f_operator
        })
      })},

    applyTypeChange () {
      if (!isEmpty(this.$refs.cp.$refs.cri.model.f_apply_type)) {
        this.applyNatures = isEmpty(this.$appdata.getParam(`${this.$refs.cp.$refs.cri.model.f_apply_type}性质`)) ? [{label: '全部', value: ''}] : [{label: '全部', value: ''}, ...this.$appdata.getParam(`${this.$refs.cp.$refs.cri.model.f_apply_type}性质`)]
      } else {
        this.applyNatures = [{label: '全部', value: ''}]
      }
    },
    clear () {
      Object.keys(this.$refs.cp.$refs.cri.model).forEach((key) => {
        this.$refs.cp.$refs.cri.model[key] = ''
      })
      this.curdepid = []
      this.curuserid = []
    },
    searchCondition (args) {
      args.condition = args.condition + `and a.f_userinfo_code like '%${this.row.f_userinfo_code}%'`
      args.condition = args.condition + ` and cr.f_orgid in (${this.curorgid})`
      if (this.curdepid.length > 0) {
        args.condition = args.condition + ` and cr.f_depid in (${this.curdepid})`
      }
      if (this.curuserid.length > 0) {
        args.condition = args.condition + ` and cr.f_charge_collectors_id in (${this.curuserid})`
      }
      this.model.search(args.condition, args.model)
    },
    // 查询
    search () {
      this.$refs.cp.$refs.cri.search()
      this.getChargeAll()
      this.getapplyoperator()
    },
    async getChargeAll () {
      let http = new HttpResetClass()
      let data = {
        condition: this.model.condition
      }
      let res = await http.load('POST', 'rs/sql/getChargeAll', {data: data}, {resolveMsg: null, rejectMsg: null})

      this.chargeAll = res.data[0]
    },
    getuser (val) {
      if (val.length <= 0) {
        return
      }
      this.curuserid = val
      this.search()
    },
    getdep (val) {
      if (val.length <= 0) {
        return
      }
      this.curdepid = val
      this.curuserid = []
      this.search()
    },
    getorg (val) {
      if (val.length <= 0) {
        return
      }
      this.curorgid = val
      this.curdepid = []
      this.curuserid = []
      this.search()
    },

  },
  computed: {
    getCondition () {
      return {
        condition: this.model.condition
      }
    }
  }
}
</script>

<style scoped>
</style>
