<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">
          <radio-group :value.sync="piece.f_point_firearm" 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_approval" 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">
          <input type="date" id="f_making_date" placeholder="投产日期"
            :value.sync="f_making_date"
            :disabled-days-of-Week="[]"
            :format="'yyyy-MM-dd'"
            :show-reset-button="reset" readonly="readonly">
        </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 && piece.f_pipe_material != '不锈钢波纹管'">
        <label class="col-sm-12 control-label">{{piece.f_pipe_material}}照片：</label>
        <div class="col-sm-12">
          <img-self  @click="takePic('f_material_path', piece.f_pipe_material + '照片')"  :src="piece.f_material_path" alt="{{piece.f_pipe_material}}照片'" width="150" height="200"></img-self>
          &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>
    </form>
    <a href="#" class="btn btn-primary" @click="goBackValidation">确定</a>
    <div style="height:200px;"></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,
      f_making_date: '',
      piece:{f_approval:'',f_pipe_material:'',f_material_path:'',f_point_firearm:''}
    }
  },
  props: ['idx'],
  components: {
    RadioGroup,
    Radio,
    Datepicker
  },
  ready() {
    this.$set('piece', this.paper.f_cookers[this.idx])
    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
    }
    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() +'-cooker-' + 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>
