<template>
  <div>
    <form>
      <div :class="paper.style__" class="form-group">
        <label class="col-sm-12 control-label">品牌：</label>
        <div class="col-sm-12">
          <input type="text" class="form-control" v-model="piece.f_brand" maxlength="20">
        </div>
      </div>
      <div :class="paper.style__" class="form-group">
        <label class="col-sm-12 control-label">型号：</label>
        <div class="col-sm-12">
          <input type="text" class="form-control" v-model="piece.f_heatingboiler_model" maxlength="20">
        </div>
      </div>
      <div :class="paper.style__" class="form-group">
        <label class="col-sm-12 control-label">生产日期：</label>
        <div class="col-sm-12">
          <datepicker placeholder="生产日期"
            :value.sync="f_making_date"
            :disabled-days-of-Week="[]"
            :format="'yyyy-MM-dd'"
            :show-reset-button="reset"  readonly="readonly">
          </datepicker>
        </div>
      </div>
      <div :class="paper.style__" class="form-group">
        <label class="col-sm-12 control-label">年检日期：</label>
        <div class="col-sm-12">
          <datepicker placeholder="年检日期"
            :value.sync="f_check_date"
            :disabled-days-of-Week="[]"
            :format="'yyyy-MM-dd'"
            :show-reset-button="reset" readonly="readonly">
          </datepicker>
        </div>
      </div>
      <div :class="paper.style__" class="form-group">
        <label class="col-sm-12 control-label">检验周期：</label>
        <div class="col-sm-12">
          <input type="text" class="form-control" v-model="piece.f_check_period" maxlength="10">
        </div>
      </div>
      <div :class="paper.style__" class="form-group">
        <label class="col-sm-12 control-label">工作压力（Pa）：</label>
        <div class="col-sm-12">
          <input type="text" class="form-control" maxlength="10" v-model="piece.f_pressure_label">
        </div>
      </div>
      <div :class="paper.style__" class="form-group">
        <label class="col-sm-12 control-label">运行压力（Pa）：</label>
        <div class="col-sm-12">
          <input type="text" class="form-control" maxlength="10" v-model="piece.f_pressure_operation">
        </div>
      </div>
      <div :class="paper.style__" class="form-group">
        <label class="col-sm-12 control-label">热功率：</label>
        <div class="col-sm-12">
          <input type="text" class="form-control" maxlength="10" v-model="piece.f_thermal_power">
        </div>
      </div>
      <div :class="paper.style__" class="form-group">
        <label class="col-sm-12 control-label">自然通风</label>
        <div class="col-sm-12">
          <radio-group :value.sync="piece.f_ventilation_state" type="success" buttons="false">
            <radio value="正常">正常</radio>
            <radio value="异常">异常</radio>
          </radio-group>
        </div>
      </div>
      <div class="form-group" v-show="piece.f_ventilation_state == '异常'">
        <label class="col-sm-12 control-label">自然通风异常照片：</label>
        <div class="col-sm-4">
          <img-self  @click="takePic('f_ventilation_state_path', '自然通风异常照片')"  :src="piece.f_ventilation_state_path" alt="自然通风异常照片" width="150" height="200"></img-self>
        </div>
        <div class="col-sm-8">
          &nbsp;&nbsp;&nbsp;&nbsp;<span :class="paper.style__" class="glyphicon glyphicon-trash" @click="delfile('f_ventilation_state_path', this.piece.f_ventilation_state_path)"></span>
        </div>
      </div>
      <div :class="paper.style__" class="form-group">
        <label class="col-sm-12 control-label">设备共振</label>
        <div class="col-sm-12">
          <radio-group :value.sync="piece.f_resonance" type="success" buttons="false">
            <radio value="有">有</radio>
            <radio value="无">无</radio>
          </radio-group>
        </div>
      </div>
      <div :class="paper.style__" class="form-group">
        <label class="col-sm-12 control-label">设备连接</label>
        <div class="col-sm-12">
          <radio-group :value.sync="piece.f_connectivity" type="success" buttons="false">
            <radio value="有连接">有连接</radio>
            <radio value="无连接">无连接</radio>
          </radio-group>
        </div>
      </div>
    </form>
    <a href="#" class="btn btn-primary" @click="goBackValidation">确定</a>
    <div style="height:50px;"></div>
  </div>
</template>

<script>
import Vue from 'vue'
import * as Util from '../Util'
import RadioGroup from 'vue-client/src/vue-strap/src/radioGroup'
import Radio from 'vue-client/src/vue-strap/src/radioBtn'
import Datepicker from 'vue-strap/src/Datepicker'

export default {
  title: '锅炉',
  data() {
    return {
      paper: this.$parent.$parent.data,
      brands: Util.choices(this.$parent.$parent.role, '锅炉品牌'),
      f_brand: '',
      f_making_date: '',
      f_check_date: '',
      piece:{f_check_period:'',f_pressure_label:'',f_pressure_operation:'',f_thermal_power:'',f_ventilation_state:'',f_resonance:'',f_connectivity:''}
    }
  },
  props: ['idx'],
  components: {
    RadioGroup,
    Radio,
    Datepicker
  },
  ready() {
    this.$set('piece', this.paper.f_furnaces[this.idx])
    if(!this.piece.f_ventilation_state_path)
      this.$set('piece.f_ventilation_state_path', Vue.nopic)
    //通风异常
    this.$watch('piece.f_ventilation_state', function (val) {
      if(val == '正常') {
        this.piece.f_ventilation_state_path = Vue.nopic
      }
    })

    if(!this.piece.f_making_date) {
      this.$set('piece.f_making_date', null)
    } else {
      this.f_making_date = this.piece.f_making_date
    }
    this.$watch('f_making_date', function (val) {
        this.piece.f_making_date = val
    })

    if(!this.piece.f_check_date) {
      this.$set('piece.f_check_date', null)
    } else {
      this.f_check_date = this.piece.f_check_date
    }
    this.$watch('f_check_date', function (val) {
        this.piece.f_check_date = val
    })

    if(!this.piece.f_brand) {
        this.$set('piece.f_brand', null)
    } else {
      this.f_brand = [this.piece.f_brand]
    }
    this.$watch('f_brand', function (val) {
        this.piece.f_brand = val[0]
    })
  },
  methods: {
    cameraCallBack(prop, fileName) {
      //tag
      HostApp.__this__.piece[prop] = fileName + '?' + Math.random()
      //tag
      HostApp.__callback__ = null
      HostApp.__this__ = null
    },
    takePic(prop, title) {
      HostApp.__callback__ = this.cameraCallBack
      HostApp.__this__ = this
      //tag
      let fileName
      if(!this.piece[prop] || this.piece[prop].includes("nopic.png")) {
        fileName = Util.guid() +'-furnace-' + this.idx + '-' + prop + '.jpg'
      } else {
        fileName = Util.getFileName(this.piece[prop])
      }
      HostApp._open_a_page({type: 'boomerang',
        page: 'com.aofeng.hybrid.android.peripheral.CameraActivity',
        param: {file: fileName, requestCode: 111, callback:'javascript:HostApp.__callback__("' + prop +'", "%s");', watermark: title + '\t时间：'+ Util.toStandardTimeString() + '\t' + Vue.user.name}
      })
    },
    goBackValidation() {
      this.$goto('paper-device-noncivil', {}, 'paper-router')
    },
    delfile(prop, fileName) {
      if(fileName == Vue.nopic)
        return
      else {
        HostApp.delfile(fileName)
        this.piece[prop] = Vue.nopic
      }
    }
  }
}
</script>
