<template>
  <div class="auto">
      <form novalidate class="form-horizontal">
        <div class="row">
          <div class="col-sm-4 form-group" >
            <label for="f_price_name" class="font_normal_body">气价名称</label>
            <input type="text" v-show="false" v-model="$refs.name.selectedItems">
            <v-select :value.sync="model.f_price_name" v-model="model.f_price_name"
                      :placeholder='model.f_price_name' :options="getPricenames"
                      @change="priceChange"
                      :value-single="true" v-ref:name
                      close-on-select>
            </v-select>
          </div>
          <div class="col-sm-4 form-group">
            <label class="font_normal_body">气价类型</label>
            <input type="text" class="input_search" style="width:60%" :disabled="true" v-model="model.f_price_type" placeholder='气价类型' >
          </div>
        </div>
        <div class="row">
          <div class="col-sm-4 form-group" >
            <label class="font_normal_body">设备类型</label>
            <v-select :value.sync="model.deviceInfo.f_devices_type" v-model="model.deviceInfo.f_devices_type"
                      placeholder='无壁挂炉'
                      :value-single="true"
                      :disabled="true"
                      close-on-select>
            </v-select>
          </div>
          <div class="col-sm-4 form-group" >
            <label class="font_normal_body">设备品牌</label>
            <input type="text" class="input_search" style="width:60%" v-model="model.deviceInfo.f_brand" placeholder='设备品牌' >
          </div>
          <div class="col-sm-4 form-group" >
            <label class="font_normal_body">施工单位</label>
            <!--<input type="text" class="input_search" style="width:60%" v-model="model.deviceInfo.f_builderunit" placeholder='施工单位' >-->
            <v-select :value.sync="model.deviceInfo.f_builderunit" v-model="model.deviceInfo.f_builderunit"
                      :options='builders' placeholder='施工单位' :value-single="true"
                      close-on-select></v-select>
          </div>
        </div>
        <div class="row">
          <div class="col-sm-4 form-group" >
            <label class="font_normal_body">联系电话</label>
            <input type="text" class="input_search" style="width:60%" v-model="model.deviceInfo.f_builder_phone"
                   placeholder='施工单位联系方式'>
          </div>
          <div class="col-sm-4 form-group" >
            <label class="font_normal_body">安装日期</label>
            <datepicker placeholder="安装日期" style="width: 60%"
                        v-model="model.deviceInfo.f_input_date"
                        :value.sync="model.deviceInfo.f_input_date"

                        :format="'yyyy-MM-dd HH:mm:ss'">
            </datepicker>
          </div>
          <div class="col-sm-4 form-group" >
            <label class="font_normal_body">购买方式</label>
            <v-select :value.sync="model.deviceInfo.watchpurchase" v-model="model.deviceInfo.watchpurchase"
                      :options='WatchPurchases' placeholder='购买方式' :value-single="true"
                      close-on-select></v-select>
          </div>
        </div>
      </form>
      <div style="text-align:right;">
        <button class="button_search btn-gn" @click="confirm()">确认</button>
      </div>
  </div>
</template>



<script>
  import {HttpResetClass} from 'vue-client'
  export default {
    title: '壁挂炉信息变更',
    data () {
      return {
        model: {
          f_price_name: {},
          f_price_type: '',
          deviceInfo: {
            f_devices_type: '壁挂炉',
            f_brand: '',
            f_builderunit: '',
            f_builder_phone: '',
            watchpurchase: ''
          }
        },
        WatchPurchases: this.$appdata.getParam('购买方式'),
        builders: this.$appdata.getParam('施工单位')
      }
    },
    props: ['row'],
    ready () {
      this.getDeviceInfo()
    },
    methods: {
      async confirm () {
        let param = {
          priceInfo: {},
          priceIsChange: false,
          deviceInfo: this.model.deviceInfo,
          f_oldprice_id: this.row.f_stairprice_id,
          f_old_price_id: this.row.f_price_id,
          f_user_name: this.row.f_user_name,
          f_filialeid: this.row.f_filialeid,
          f_userinfo_id: this.row.f_userinfo_id,
          f_operator: this.$login.f.name,
          f_operatorid: this.$login.f.id,
          f_orgid: this.$login.f.orgid,
          f_orgname: this.$login.f.orgs,
          f_depid: this.$login.f.depids,
          f_depname: this.$login.f.deps,
          f_user_id: this.row.f_user_id,
          f_userfiles_id: this.row.f_userfiles_id,
          userfile_version: this.row.version
        }
        if(this.model.f_price_name !== this.row.f_price_name && this.model.f_price_name.f_price_name!== this.row.f_price_name){
          param.priceIsChange = true
          param.priceInfo = this.model.f_price_name
        }
        await this.$resetpost('rs/logic/changeWallHeatInfo', param, {resolveMsg: '更改成功！', rejectMsg: '更改失败！'})
        },
      async getDeviceInfo () {
        let http = new HttpResetClass()
        let device = await http.load('POST', 'rs/sql/singleTable_OrderBy', {
          data: {
            items: '*',
            tablename: 't_devices',
            condition: `f_user_id = '${this.row.f_user_id}'`,
            orderitem: 'id desc'
          }
        }, {resolveMsg: null, rejectMsg: '获取设备信息出错！！！'})
        device.data.forEach((item) => {
          if(item.f_devices_type === '壁挂炉'){
            this.model.deviceInfo = item
            return
          }
        })
      },
      priceChange (val) {
        this.model.f_user_type = [val.f_user_type]
        this.model.f_gasproperties = [val.f_gasproperties]
        this.model.f_price_type = val.f_price_type
      }
    },
    computed: {
      getPricenames () {
        let f_filialeid = this.row.f_filialeid
        let result = []
        this.$GetSaleParam.prices.forEach((item) => {
          if (item.f_state === '有效' && f_filialeid == item.f_filialeid) {
            if(item.f_price_name == null){
              item.f_price_name = ''
            }
            if(item.f_price_name.search('壁挂炉') != -1){
              if(item.f_price_name == this.row.f_price_name){
                this.model.f_price_name = item
                this.model.f_price_type = item.f_price_type
              }
              let value = {
                label: item.f_price_name,
                value: item
              }
              result.push(value)
            }
          }
        })
        return result
      }
    }
  }
</script>
