<template>
  <div @keyup.enter="search" class="flex-row">
    <div  class="basic-main">
    <criteria-paged :model="model" v-ref:paged>
      <criteria @condition-changed='$parent.selfSearch' partial='criteria' v-ref:cri>
        <div class="form-horizontal select-overspread container-fluid auto" novalidate partial>
          <div class="row">
            <div class="col-sm-2 form-group">
              <label class="font_normal_body">客户编号</label>
              <input class="input_search" condition="f_userinfo_code = '{}'" placeholder='客户编号' style="width:60%" type="text"
                     v-el:qjmc v-model="model.f_userinfo_code" v-next-el="cx"
              >
            </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 = '{}'" @keyup.enter="search" placeholder='客户姓名'></input>
            </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_address"
                     condition="f_address like '%{}%'" @keyup.enter="search" placeholder='客户住址'></input>
            </div>
            <div class="form-group col-sm-3 button-range" style="float: right;" >
              <button @click="search()" class="button_search button_spacing" v-el:cx>查询</button>
              <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 class="row" v-show="$parent.$parent.criteriaShow">
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">开始时间</label>
                <datepicker :format="'yyyy-MM-dd'"
                            :value.sync="model.f_ins_start_date"
                            placeholder="生效日期"
                            condition="f_ins_start_date > '{}'"
                            v-model="model.f_ins_start_date" style="width: 55%">
                </datepicker>
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">到期时间</label>
                <datepicker :format="'yyyy-MM-dd'"
                            :value.sync="model.f_expiration_date"
                            placeholder="到期时间"
                            condition="f_expiration_date > '{}'"
                            v-model="model.f_expiration_date" style="width: 55%">
                </datepicker>
              </div>
              <res-select-group :initres="$parent.$parent.initres"  @re-res="$parent.$parent.getRes" v-ref:sel></res-select-group>
            </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>
            <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'>
          <tr>
            <td style="text-align:center"><nobr>{{$index + 1}}</nobr></td>
            <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_address}}</nobr></td>
            <!--<td style="text-align:center">{{row.id}}</td>-->
            <td style="text-align:center"><nobr>{{row.f_money}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_payment}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_salecount}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_insurance_type}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_ins_start_date}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_expiration_date}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_shengxiao_date}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_state}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_total_ins_charge}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_operator}}</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" >
              <button type="button" name="button" class="button_search-2 button_spacing width-60"
                      v-if="row.f_state === '待执行' || row.f_state === '有效'" @click="$parent.$parent.$parent.updatetime(row)">修改
              </button>
            </td>
          </tr>
        </template>
        <template partial='foot'></template>
      </data-grid>
    </criteria-paged>
    <modal :backdrop="false" :show.sync="show" v-if="show" >
      <header class="modal-header" slot="modal-header">
        <button @click="show=!show" class="close" type="button"><span>&times;</span></button>
        <h4 class="modal-title">修改客户保险信息</h4>
      </header>
      <article class="modal-body"  slot="modal-body"  style="height:100%;width:100%"  >
        <div class="row">
          <div class="col-sm-6 form-group">
            <label class="font_normal_body">开始时间</label>
            <datepicker :format="'yyyy-MM-dd HH:mm:ss'"
                        :value.sync="base.f_ins_start_date"
                        placeholder="开始时间"
                        v-model="base.f_ins_start_date" style="width: 55%">
            </datepicker>
          </div>
          <div class="col-sm-6 form-group">
            <label class="font_normal_body">&emsp;&emsp;&emsp;&emsp;到期时间</label>
            <datepicker :format="'yyyy-MM-dd HH:mm:ss'"
                        :value.sync="base.f_expiration_date"
                        placeholder="到期时间"
                        v-model="base.f_expiration_date" style="width: 55%">
            </datepicker>
          </div>
          <div class="row">
            <div class="col-sm-6  form-group" >
            <label class="font_normal_body">购买年限</label>
            <input type="number" v-model="base.f_salecount" placeholder="购买年限" style="width: 60%"
                   class="input_search" disabled/>
            </div>
            <div class="col-sm-6  form-group" >
              <label class="font_normal_body">&emsp;&emsp;&emsp;&emsp;保费金额</label>
              <input type="number" v-model="base.f_money" class="input_search" style="width:60%"
                      placeholder="保费金额" disabled/>
            </div>
          </div>
          <div class="row">
          <div class="col-sm-6  form-group" >
            <label class="font_normal_body">&emsp;&emsp;险种</label>
            <v-select
              placeholder='险种'
              :value.sync="base.f_insurance_type"
              style="width:20%"   class="select_list select"
              :value-single="true"
              v-model="base.f_insurance_type"
              :options='insurancetype'
              close-on-select>
            </v-select>
          </div>
          <div class="col-sm-6  form-group" >
            <label class="font_normal_body" title="参数:保险状态">&emsp;&emsp;&emsp;&emsp;保险状态</label>
            <v-select
              placeholder='保险状态'
              :value.sync="base.f_state"
              style="width:20%"   class="select_list select"
              :value-single="true"
              v-model="base.f_state"
              :options='insurancestate'
              close-on-select :disabled="stataDisabled">
            </v-select>
          </div>
          </div>
          <div class="row">
            <div class="col-sm-6  form-group" >
              <label class="font_normal_body">投保人：</label>
              <input type="text" v-model="base.f_user_name" placeholder="投保人" style="width: 60%"
                     class="input_search"/>
            </div>
            <div class="col-sm-6  form-group" >
              <label class="font_normal_body">&emsp;&emsp;&emsp;&emsp;保险单号</label>
              <input type="text" v-model="base.f_ins_number" class="input_search" style="width:60%"
                     placeholder="保险单号" />
            </div>
          </div>
          <div class="row">
            <div class="col-sm-12  form-group">
              <label class="font_normal_body">备注信息</label>
              <input type="textarea" v-model="base.f_comments" style="width: 80%;" class="input_search">
            </div>
          </div>
        </div>
      </article>
      <footer class="modal-footer" slot="modal-footer">
        <button type="button" class="btn btn-default" @click='editclose' id="vc-messagebox-close">取消</button>
        <button type="button" class="btn btn-success" @click='updatedefail' id="vc-messagebox-confirm">确认</button>
      </footer>
    </modal>
    </div>
  </div>
</template>

<script>
  /**
   *保险管理
   */
  import {PagedList} from 'vue-client'
  import Vue from 'vue'

  export default {
    title: '保险记录维护',
    data () {
      return {
        initres: {
          org: [this.$login.f.orgid],
          dep: [],
          user: []
        },
        base: {},
        insurancetype: this.$appdata.getParam('险种'),
        insurancestate: this.$appdata.getParam('保险状态'),
        model: new PagedList('rs/sql/insuranceguanl', 20),
        show: false,
        orgCondtionStr: '',
        stataDisabled: false,
        criteriaShow: false,
        // 公司下拉
        curorgid: [this.$login.f.orgid]
      }
    },
    ready () {
      this.$refs.paged.$refs.cri.search()
    },
    watch: {

    },
    methods: {
      updatedefail () {
        console.log('insurance_end_date', this.base.f_expiration_date, this.base.f_insurance_type)
        if (this.base.f_expiration_date || this.base.f_insurance_type) {
          this.base.f_operator = this.$login.f.name
          this.base.f_operatorid = this.$login.f.id
          this.base.f_orgid = this.$login.f.orgid
          this.base.f_orgname = this.$login.f.orgs
          this.base.f_depid = this.$login.f.depids
          this.base.f_depname = this.$login.f.deps
          this.$resetpost('rs/logic/insuranceguanl', this.base, {
            resolveMsg: '恭喜！提交成功！',
            rejectMsg: '提交错误！'
          })
          this.base = ''
          this.show = !this.show
          this.$refs.paged.$refs.cri.search()
        } else {
          this.$showAlert('请输入修改的内容', 'warning', 2000)
        }
      },
      editclose () {
        this.base = ''
        this.show = !this.show
      },
      hidden () {
        this.criteriaShow = !this.criteriaShow
      },
      getRes (obj) {
        this.orgCondtionStr = obj
      },
      search () {
        this.selfSearch()
      },
      async stateIsDisabled () {
        let data = {
          tablename: 't_userfees',
          condition: `f_state = '有效' and f_userinfo_id = '${this.base.f_userinfo_id}' and id > ${this.base.id}`
        }
        let res = await this.$resetpost('rs/sql/saleSingleTable', {data: data}, {
          resolveMsg: '',
          rejectMsg: ''
        })
        if (res.data.length > 0) {
          this.stataDisabled = true
        } else {
          this.stataDisabled = false
        }
      },
      selfSearch (args) {
        if (!this.orgCondtionStr) {
          args.condition = `${args.condition}` + ' and f_orgid = ' + `'${this.$login.f.orgid}'`
        } else {
          args.condition = `${args.condition}` + this.orgCondtionStr
        }
        this.model.search(args.condition, args.model)
      },
      updatetime (row) {
        this.base = row
        this.show = !this.show
        this.stateIsDisabled()
      }
    }
  }
</script>
