<template>
  <div>
    <form>
      <div class="form-group">
        <label class="col-sm-12 control-label">热水器照片(要求正面照片)：</label>
        <div class="col-sm-4">
          <img-self  @click="takePic('f_pic1_path', '热水器照片')"  :src="piece.f_pic1_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_pic1_path', this.piece.f_pic1_path)"></span>
        </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_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">
          <input type="date" id="f_making_date" placeholder="出厂日期"
            :value.sync="f_making_date"
            :disabled-days-of-Week="[]"
            :format="'yyyy-MM'"
            :show-reset-button="reset" readonly="readonly">
        </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">
        </div>
      </div>
      <div>
        <h4>软管</h4>
      </div>
      <div :class="paper.style__" class="form-group">
        <label class="col-sm-12 control-label">安检项</label>
        <div class="col-sm-12">
            <input type="checkbox" v-model="piece.f_pipe_ok">正常</input>
            <input type="checkbox" v-model="piece.f_pipe_leakage">漏气</input>
            <input type="checkbox" v-model="piece.f_pipe_worn">老化</input>
        </div>
      </div>
      <div class="form-group" v-show="piece.f_pipe_worn">
        <label class="col-sm-12 control-label">热水器软管老化照片：</label>
        <div class="col-sm-4">
          <img-self  @click="takePic('f_worn_path', '热水器软管老化照片')"  :src="piece.f_worn_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_worn_path', this.piece.f_worn_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_pipe_material" type="success" buttons="false">
            <radio value="橡胶">橡胶</radio>
            <radio value="铝塑管">铝塑管</radio>
            <radio value="金属管">金属管</radio>
          </radio-group>
        </div>
      </div>
      <div class="form-group" v-show="piece.f_pipe_material == '橡胶'">
        <label class="col-sm-12 control-label">橡胶软管照片：</label>
        <div class="col-sm-4">
          <img-self  @click="takePic('f_material_path', '橡胶软管照片')"  :src="piece.f_material_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_material_path', this.piece.f_material_path)"></span>
        </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_pipe_fasten" number>
          <input type="checkbox" v-model="piece.f_pipe_no_fasten">无管卡</input>
        </div>
      </div>
      <div class="form-group" v-show="piece.f_pipe_no_fasten">
        <label class="col-sm-12 control-label">无管卡照片：</label>
        <div class="col-sm-4">
          <img-self  @click="takePic('f_no_fasten_path', '无管卡照片')"  :src="piece.f_no_fasten_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_no_fasten_path', this.piece.f_no_fasten_path)"></span>
        </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_pipe_length2">
        </div>
      </div>
      <div>
        <h4>烟道</h4>
      </div>
      <div :class="paper.style__" class="form-group">
        <label class="col-sm-12 control-label">安检项</label>
        <div class="col-sm-12">
            <input type="checkbox" v-model="piece.f_vent_balanced">平衡</input>
            <input type="checkbox" v-model="piece.f_vent_forced">强排</input>
            <input type="checkbox" v-model="piece.f_vent_exist">烟道</input>
            <input type="checkbox" v-model="piece.f_vent_direct">直排</input>
            <input type="checkbox" v-model="piece.f_vent_damaged">烟道破损</input>
            <input type="checkbox" v-model="piece.f_vent_direct_heater">直排热水器</input>
            <input type="checkbox" v-model="piece.f_vent_trapped">烟道未接到室外</input>
            <input type="checkbox" v-model="piece.f_vent_notsealed">与墙体间未密封</input>
        </div>
      </div>
      <div class="form-group" v-show="piece.f_vent_damaged">
        <label class="col-sm-12 control-label">烟道破损照片：</label>
        <div class="col-sm-4">
          <img-self  @click="takePic('f_vent_damaged_path', '烟道破损照片')"  :src="piece.f_vent_damaged_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_vent_damaged_path', this.piece.f_vent_damaged_path)"></span>
        </div>
      </div>
      <div class="form-group" v-show="piece.f_vent_direct_heater">
        <label class="col-sm-12 control-label">直排热水器照片：</label>
        <div class="col-sm-4">
          <img-self  @click="takePic('f_direct_heater_path', '直排热水器照片')"  :src="piece.f_direct_heater_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_direct_heater_path', this.piece.f_direct_heater_path)"></span>
        </div>
      </div>
      <div class="form-group" v-show="piece.f_vent_trapped">
        <label class="col-sm-12 control-label">烟道未接到室外照片：</label>
        <div class="col-sm-4">
          <img-self  @click="takePic('f_vent_trapped_path', '烟道未接到室外照片')"  :src="piece.f_vent_trapped_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_vent_trapped_path', this.piece.f_vent_trapped_path)"></span>
        </div>
      </div>
      <div class="form-group" v-show="piece.f_vent_notsealed">
        <label class="col-sm-12 control-label">烟道与墙体间未密封照片：</label>
        <div class="col-sm-4">
          <img-self  @click="takePic('f_vent_notsealed_path', '烟道与墙体间未密封照片')"  :src="piece.f_vent_notsealed_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_vent_notsealed_path', this.piece.f_vent_notsealed_path)"></span>
        </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-client/src/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: ''
    }
  },
  props: ['idx'],
  components: {
    RadioGroup,
    Radio,
    Datepicker
  },
  ready() {
    this.$set('piece', this.paper.f_heaters[this.idx])
    if(!this.piece.f_pic1_path)
      this.$set('piece.f_pic1_path', Vue.nopic)

    if(!this.piece.f_worn_path)
      this.$set('piece.f_worn_path', Vue.nopic)
    this.$watch("piece.f_pipe_worn", function(val){
      if(!val)
        this.$set('piece.f_worn_path', Vue.nopic)
    })
    if(!this.piece.f_no_fasten_path)
      this.$set('piece.f_no_fasten_path', Vue.nopic)
      this.$watch("piece.f_pipe_no_fasten", function(val){
        if(!val) {
          this.$set('piece.f_no_fasten_path', Vue.nopic)
        } else {
          this.$set('piece.f_pipe_fasten', 0)
        }
      })
    if(!this.piece.f_direct_heater_path)
      this.$set('piece.f_direct_heater_path', Vue.nopic)
    this.$watch("piece.f_vent_direct_heater", function(val){
      if(!val)
        this.$set('piece.f_direct_heater_path', Vue.nopic)
    })
    if(!this.piece.f_vent_trapped_path)
      this.$set('piece.f_vent_trapped_path', Vue.nopic)
    this.$watch("piece.f_vent_trapped", function(val){
      if(!val)
        this.$set('piece.f_vent_trapped_path', Vue.nopic)
    })
    if(!this.piece.f_vent_damaged_path)
      this.$set('piece.f_vent_damaged_path', Vue.nopic)
    this.$watch("piece.f_vent_damaged", function(val){
      if(!val)
        this.$set('piece.f_vent_damaged_path', Vue.nopic)
    })
    if(!this.piece.f_vent_notsealed_path)
      this.$set('piece.f_vent_notsealed_path', Vue.nopic)
    this.$watch("piece.f_vent_notsealed", function(val){
      if(!val)
        this.$set('piece.f_vent_notsealed_path', Vue.nopic)
    })
    if(!this.piece.f_material_path)
      this.$set('piece.f_material_path', Vue.nopic)
    this.$watch("piece.f_pipe_material", function(val){
      if(val != '橡胶')
        this.$set('piece.f_material_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
    }
    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]
    })
    this.$watch('f_making_date', function (val) {
        this.piece.f_making_date = val
    })
  },
  methods: {
    cameraCallBack(prop, fileName) {
      console.log(prop + ',' + fileName)
      HostApp.__this__.piece[prop] = fileName + '?' + Math.random()
      console.log(HostApp.__this__.piece[prop])
      HostApp.__callback__ = null
      HostApp.__this__ = null
    },
    takePic(prop, title) {
      HostApp.__callback__ = this.cameraCallBack
      HostApp.__this__ = this
      console.log('this.piece[prop]:' + this.piece[prop])
      let fileName
      if(!this.piece[prop] || this.piece[prop].includes("nopic.png")) {
        fileName = Util.guid() +'-heater-' + 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', {}, 'paper-router')
    },
    delfile(prop, fileName) {
      if(fileName == Vue.nopic)
        return
      else {
        HostApp.delfile(fileName)
        this.piece[prop] = Vue.nopic
      }
    }
  }
}
</script>
