<template>
  <div class="flex-auto" style="overflow-y: scroll">
    <validator name='v'>
      <div novalidate class=" select-overspread container-fluid auto" partial>
        <ul class="nav nav-tabs">
          <li class="active a-tabs"><a href="#">低保信息</a></li>
        </ul>
        <div>
          <div class="row">
            <div class="col-sm-4" id="f_user_id" :class="[$v.f_userinfo_code.required ? 'has-error' : 'has-success']">
              <label for="f_userinfo_code" class="font_normal_body">用户编号</label>
              <input class="input_search" style="width:60%" type="text" class="input_search" style="width:60%"
                     v-model="model.f_userinfo_code" @blur.prevent="getinfo()" style="width: 100px"
                     v-validate:f_userinfo_code='{required: true }' :disabled='isEdit' placeholder="用户编号">
            </div>
            <div class="col-sm-4" id="name">
              <label for="f_user_name" class=" font_normal_body">用户姓名</label>
              <input class="input_search" style="width:60%" type="text" class="input_search" style="width:60%"
                     v-model="model.f_user_name" readonly style="width: 100px"
                     placeholder="用户姓名">

            </div>
            <div class="col-sm-4" id="phone">
              <label for="f_user_phone" class=" font_normal_body">联系方式</label>
              <input class="input_search" style="width:60%" type="text" class="input_search" style="width:60%"
                     v-model="model.f_user_phone" readonly style="width: 100px"
                     placeholder="联系方式">

            </div>
          </div>

          <div>
            <div class="col-sm-12" id="address">
              <label for="f_address" class=" font_normal_body">地&nbsp;&nbsp;&nbsp;&nbsp;址&nbsp;&nbsp;</label>
              <input class="input_search" type="text" class="input_search" style="width:87%" v-model="model.f_address"
                     readonly
                     placeholder="地址">
            </div>

          </div>

          <div>
            <div class="col-sm-4" id="f_start_date" :class="[$v.f_start_date.required ? 'has-error' : 'has-success']">
              <input type="text" class="input_search" style="width:60%" v-show="false" v-model="model.f_start_date"
                     v-validate:f_start_date='{required: true }'>
              <label for="f_start_data" class=" font_normal_body">开始日期</label>

              <datepicker style="width: 60%"
                          placeholder="开始日期"
                          v-model="model.f_start_date"
                          :value.sync="model.f_start_date"
                          :format="'yyyy-MM-dd'"
                          :disabled='isEdit'>
              </datepicker>
            </div>
            <div class="col-sm-4" id="f_period" :class="[$v.f_period.required ? 'has-error' : 'has-success']">
              <label for="f_period" class=" font_normal_body">周&nbsp;&nbsp;&nbsp;&nbsp;期&nbsp;&nbsp;&nbsp;</label>
              <input type="text" class="input_search" style="width:60%" v-model="model.f_period" style="width: 60px"
                     v-validate:f_period='{required: true }' :disabled='isEdit' placeholder="周期">

            </div>
            <!--<div class="col-sm-4" id="f_end_date">-->
            <!--<input type="text"  class="input_search" style="width:60%"v-show="false" v-model="model.f_end_date">-->
            <!--<label for="f_end_date" class=" font_normal_body">结束日期</label>-->
            <!--<input class="input_search" style="width:60%" type="text"  class="input_search" style="width:60%"v-model="model.f_end_date" readonly style="width: 100px"-->
            <!--placeholder="结束日期">-->
            <!--</div>-->
            <!--</div>-->
            <!--<div >-->
            <div class="col-sm-4" :class="[$v.f_price_id.required ? 'has-error' : 'has-success']">
              <label class="font_normal_body">气&nbsp;&nbsp;&nbsp;&nbsp;价&nbsp;&nbsp;</label>
              <input type="text" class="input_search" style="width:60%" v-show="false" v-model="model.f_price_id"
                     v-validate:f_price_id='{required: true }'>
              <v-select id="f_price_name"
                        v-model="model.f_price_id"
                        :value.sync="model.f_price_id"
                        :options='pricename'
                        :value-single="true"
                        close-on-select></v-select>

            </div>

          </div>
          <div style="text-align:right;height:auto;margin-top:6px;">
            <button class="button_search" style="width:80px;" @click="confirm()" v-if="!isEdit" :disabled='!$v.valid'>
              确认
            </button>

            <button class="button_export" style="width:80px;" @click="close()">取消</button>
          </div>
        </div>

      </div>


    </validator>

  </div>
</template>
<script>

  import {HttpResetClass} from 'vue-client'

  let initGen = async function (self, val) {
//获取低保气价
    self.$resetpost('rs/sql/get_priceId',
      {data: {f_orgid: self.$login.f.orgid, condition: `f_islow_income = '1'`}},
      {resolveMsg: null, rejectMsg: null}).then((res) => {
      let rs = []
      for (let i = 0; i < res.data.length; i++) {
        let temp = {
          label: res.data[i].f_price_name,
          value: res.data[i].f_price_id
        }
        rs.push(temp)
      }
      self.pricename = [...rs]
    })
    let http = new HttpResetClass()
    let res = await http.load('POST', 'rs/sql/get_BasicLiving',
      {data: {condition: `f_userinfo_code = '${val.f_userinfo_code}' and f_orgid='${self.$login.f.orgid}'`}}, {
      resolveMsg: null,
      rejectMsg: null
    })
    console.log(res.data)
    self.model = Object.assign({}, self.model, val)
    self.model.f_userinfo_code = res.data[0].f_userinfo_code
    self.model.f_userinfo_id = res.data[0].f_userinfo_id
    self.model.f_user_phone = res.data[0].f_user_phone
    self.model.f_address = res.data[0].f_address
    self.model.f_user_phone = res.data[0].f_user_phone
    self.model.f_start_date = res.data[0].f_start_date
    self.model.f_end_date = res.data[0].f_end_date
    self.model.f_period = res.data[0].f_period
    self.model.f_price_id = res.data[0].f_price_id
    self.model.f_price_name = res.data[0].f_price_name
    self.model.f_operator = self.$login.f.name
    self.model.f_operatorid = self.$login.f.id
    self.model.f_filialeid = self.model.f_filialeid ? self.model.f_filialeid : self.$login.f.orgid
    self.model.f_orgid = self.model.f_orgid ? self.model.f_orgid : self.$login.f.orgid
    self.model.f_orgname = self.model.f_orgname ? self.model.f_orgname : self.$login.f.orgs
    self.model.f_depid = self.model.f_depid ? self.model.f_depid : self.$login.f.depids
    self.model.f_depname = self.model.f_depname ? self.model.f_depname : self.$login.f.deps


  }

  export default {
    title: '低保户',
    props: {
      f_islow_income: {
        type: String,
        default: '1'
      },
      data: {
        type: Object
      }
    },
    data() {
      return {
        pricename: [{value: '', label: ''}],
        model: {
          f_userinfo_code: '',
          f_userinfo_id: '',
          f_user_name: '',
          f_address: '',
          f_price_id: '',
          f_price_name: '',
          f_user_phone: '',
          f_start_date: '',
          f_end_date: '',
          f_period: '',
          f_state: '正常',

        },
        // 编辑控制
        isEdit: false,
        f_filialeid: '',  // 所属公司
        f_filialename: ''  // 所属公司名称

      }
    },
    watch: {
      'data'(val) {
        if (val) {
          initGen(this, val)
        } else {
          this.initModel()
        }
      }

    },
    ready() {
      console.log("============================")
      initGen(this, this.data)

    },
    methods: {

      getinfo() {
        this.$resetpost('rs/sql/sale_getUserAndPeriod',
          {data: {condition: "f_userinfo_code = '" + this.model.f_userinfo_code + "' and f_orgid ='"+ this.$login.f.orgid+"'"}}, {
          resolveMsg: null,
          rejectMsg: null
        }).then((res) => {
          console.log(res.data[0])
          this.model = res.data[0]

        })
      },
      async confirm() {
        await this.$LogicService.basicLiving(this.model, this.data)
        this.initModel()
        this.$dispatch('success','isBasicLiving')
      },
      getorg(id, name) {
        this.f_filialeid = id[0]
        this.f_filialename = name[0]
      },
      initModel() {
        this.model = {
          f_userinfo_code: '',
          f_userinfo_id: '',
          f_user_name: '',
          f_address: '',
          f_price_id: 0,
          f_price_name: '',
          f_user_phone: '',
          f_start_date: '',
          f_end_date: '',
          f_period: '',
          f_state: '正常'


        }
      },
      close() {
        this.$dispatch('close')
      }


    }
  }
</script>
<style lang="less">
  #gas-price-form {
    .form-group {
      margin-left: 0px;
      margin-right: 0px;
    }
  }

</style>
