<template>
  <div style="margin-bottom: 20px" class="form-group select-overspread">
    <label class="control-label-justify control-label col-sm-3">选择项目</label>
    <div class="col-sm-10" >
      <button class="button_search button_spacing" type="button" style="width: max-content;position: absolute" @click="openSelect" :disabled="mark === 1">选择</button>
    </div>
  </div>

  <modal v-if="showselect" :show.sync="showselect" width="80%" title="用户信息" v-ref:modal large backdrop="false">
    <article slot="modal-body" class="modal-body" style="height: 600px!important;">
      <criteria-paged :model="model" v-ref:cp>
        <criteria partial='criteria' @condition-changed='$parent.$parent.searchCondition' v-ref:cri>
          <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
            <div class="row">
              <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="search"
                       condition="u.f_apply_num = '{}'">
              </div>
              <div class="form-group col-sm-3">
                <label class="font_normal_body">项目名称：</label>
                <input type="text" style="width:60%" class="input_search" v-model="model.f_entry_name"
                       v-on:keyup.enter="search" condition="u.f_entry_name like '%{}%'" placeholder='项目名称'>
              </div>
              <div class="form-group col-sm-3">
                <label class="font_normal_body">客户名称：</label>
                <input type="text" style="width:60%" class="input_search" v-model="model.f_user_name"
                       v-on:keyup.enter="search" condition="u.f_user_name = '{}'" placeholder='客户名称'>
              </div>

              <div class="form-group col-sm-3 button-range">
                <button class="button_search button_spacing" @click.prevent="search" v-el:cx>查询</button>
                <button class="button_clear button_spacing"  @click.prevent="$parent.$parent.$parent.clear()">清空</button>
                <div
                  :class="{'button_shrink_top':$parent.$parent.$parent.criteriaShow,'button_shrink_bottom':!$parent.$parent.$parent.criteriaShow}"
                  @click="$parent.$parent.$parent.criteriaShow = !$parent.$parent.$parent.criteriaShow"
                  class="button_spacing"
                  style="float: right">
                </div>
              </div>
            </div>
            <div class="row" v-show="$parent.$parent.$parent.criteriaShow">
              <div class="form-group col-sm-3">
                <label class="font_normal_body">电&emsp;&emsp;话：</label>
                <input type="text" style="width:60%" class="input_search" v-model="model.f_phone"
                       v-on:keyup.enter="search" condition="u.f_phone like '%{}%'" placeholder='联系电话'>
              </div>
              <div class="form-group col-sm-3">
                <label class="font_normal_body">地&emsp;&emsp;址：</label>
                <input type="text" style="width:60%" class="input_search" v-model="model.f_address"
                       v-on:keyup.enter="search" condition="u.f_address like '%{}%'" placeholder='详细地址'>
              </div>
              <div class="form-group col-sm-3">
                <label class="font_normal_body">报建类型：</label>
                <v-select
                  v-model="model.f_apply_type"
                  placeholder='报建类型'
                  condition="u.f_apply_type like '%{}%'"
                  :value.sync="model.f_apply_type"
                  :options='$parent.$parent.$parent.applyType'
                  class="select select_list"
                  :value-single="true"
                  @change="$parent.$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.defname"
                  placeholder='办理环节'
                  condition="act.defname = '{}'"
                  :value.sync="model.defname"
                  :options='$parent.$parent.$parent.defnames'
                  class="select select_list"
                  :value-single="true"
                  close-on-select ></v-select>
              </div>
            </div>
          </div>
        </criteria>
        <data-grid :model="model" partial='list' v-ref:grid class="list_area table_sy" style="height: 100%">
          <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>
            </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_entry_name }}</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_apply_type }}</font></nobr>
              </td>
              <td style="text-align: center;">
                <nobr><font>{{ row.defname }}</font></nobr>
              </td>
              <td style="text-align: center;">
                <nobr><font>{{ row.f_cumulative_payment_money }}</font></nobr>
              </td>
              <td style="text-align: center;">
                <nobr><font>
                  <button type="button" name="button" class="button_export" @click.prevent="$parent.$parent.$parent.$parent.select(row)">确认选择</button>
                </font></nobr>
              </td>
            </tr>
          </template>
        </data-grid>
      </criteria-paged>
    </article>
    <footer slot="modal-footer" class="modal-footer">
    </footer>
  </modal>
</template>
<script>
import {HttpResetClass, PagedList} from 'vue-client'
import Vue from 'vue'
import {isEmpty} from "../../../Util";

export default {
  title: '收费管理',
  props: {
    selectdata: {
      type: Object
    },
    mark: {
      type: Number,
      default: 0
    }
  },
  data () {
    return {
      showselect: false,
      model: new PagedList('rs/sql/supervisory', 20, {
        data: {
          id: this.$login.f.id,
          orgid: this.$login.f.orgid
        }
      }),
      criteriaShow: false,
      defnames: [{label: '全部', value: ''}]
    }
  },
  ready () {
  },
  methods: {
    async applyTypeChange () {
      let http = new HttpResetClass()
      if (!isEmpty(this.$refs.cp.$refs.cri.model.f_apply_type)) {
        let res = await http.load('POST', 'rs/logic/getDefnameByType', {
            f_apply_type: this.$refs.cp.$refs.cri.model.f_apply_type},
          {resolveMsg: null, rejectMsg: '流程标识获取失败！！！'}
        )
        this.defnames = [{label: '全部', value: ''}, ...res.data]
      } else {
        this.defnames = [{label: '全部', value: ''}]
      }
    },
    select (row) {
      this.$dispatch('selectApply', row)

      this.showselect = false
    },
    searchCondition (args) {
      args.condition = `${args.condition} and act.defname != '完工' and act.state = '开始活动' and u.f_apply_type != '退款报建' and u.f_cumulative_payment_money > 0`

      this.model.search(args.condition, args.model)
    },
    clear () {
      Object.keys(this.$refs.cp.$refs.cri.model).forEach((key) => {
        this.$refs.cp.$refs.cri.model[key] = null
      })
    },
    openSelect () {
      this.showselect = true
      setTimeout(() => {
        this.$refs.cp.$refs.cri.search()
      }, 100)
    }
  },
  events: {
  },
  computed: {
    applyType () {
      return [{label: '全部', value: ''}, ...this.$appdata.getParam('报建类型')]
    }
  },
  watch: {
  }
}
</script>
<style scoped>
.control-label-justify {
  display: inline-block;
  vertical-align: top;
  width: 110px;
  text-align: justify;
  font-family: PingFang-SC-Bold;
}

.control-label-justify::after {
  content: "";
  display: inline-block;
  width: 100%;
  overflow: hidden;
  height: 0;
}
.input_view{
  padding: 8px;
  background-color: #ffffff;
  border-radius: 2px;
  border: solid 1px #c7c7c7!important;
  color: #333333!important;
  font-size: 15px!important;
}

.input_view[readonly]{
  border: 1px solid #DDD!important;
  color:#ACA899!important;
}
.input_view:disabled{
  border: 1px solid #DDD!important;
  color:#ACA899!important;
}
</style>
