<template>
  <div class="auto">
    <modal :show.sync="show_devices" width="80%"  title="设备信息" v-ref:modal large backdrop="false">
      <article slot="modal-body" class="modal-body" style="height: auto">
        <div class="flex-row flex-deviceinfo">
          <div class="flex-row flex-two-info panel panel-default" v-for="row in devicesinfo">
            <avatar-upload :img-src.sync="row.img.content" :filename.sync="row.img.filename"></avatar-upload>
            <form class="form-horizontal select-overspread " style="flex: 1;">
              <div class="row auto"  style="margin-top: 10px;margin-left: 10px;">
                <div class="col-sm-6 form-group" style="padding-right: 5px;">
                  <label class="font_normal_body">设备类型</label>
                  <v-select :value.sync="row.f_devices_type" v-model="row.f_devices_type"
                            :options='devicetypes' placeholder='设备类型' :value-single="true"
                            close-on-select></v-select>
                </div>
                <div class="col-sm-6 form-group" style="padding-right: 5px;">
                  <label class=" font_normal_body">设备编号</label>
                  <input type="text" class="input_search" style="width:60%" v-model="row.f_devices_no" placeholder='设备编号' v-next-el="{id: $index+'brand'}">
                </div>
              </div>
              <div class="row auto"  style="margin-left: 10px;">
                <div class="col-sm-6 form-group" style="padding-right: 5px;">
                  <label class="font_normal_body">设备品牌</label>
                  <input type="text" class="input_search" style="width:60%" v-model="row.f_brand" placeholder='设备品牌' v-next-el="{id: $index+'devicesmodel'}"   :id="$index+'brand'">
                </div>
                <div class="col-sm-6 form-group" style="padding-right: 5px;">
                  <label class="font_normal_body">安装人&nbsp;&nbsp;&nbsp;</label>
                  <input type="text" class="input_search" style="width:60%" v-model="row.f_instaler_person" placeholder='安装人' v-next-el="{id: $index+'devicesmodel'}"   :id="$index+'brand'">
                </div>

              </div>
              <div class="row auto"  style="margin-left: 10px;">
                <div class="col-sm-6 form-group" style="padding-right: 5px;">
                  <label class="font_normal_body">设备型号</label>
                  <input type="text" class="input_search" style="width:60%" v-model="row.f_devices_model" placeholder='设备型号'  :id="$index+'devicesmodel'">
                </div>
                <div class="col-sm-6 form-group" style="padding-right: 5px;">
                  <label class="font_normal_body">安装日期</label>
                  <datepicker  placeholder="安装日期" style="width: 60%"
                               v-model="row.f_input_date"
                               :value.sync="row.f_input_date"
                               :format="'yyyy-MM-dd HH:mm:ss'">
                  </datepicker>
                </div>
              </div>
              <div class="row auto"  style="margin-left: 10px;">

                <div class="col-sm-6 form-group" style="padding-right: 5px;">
                  <label class="font_normal_body">生产日期</label>
                  <datepicker  placeholder="生产日期" style="width: 60%"
                               v-model="row.f_make_date"
                               :value.sync="row.f_make_date"
                               :format="'yyyy-MM-dd HH:mm:ss'">
                  </datepicker>
                </div>
              </div>
              <div class="row auto"  style="margin-left: 10px;">
                <div class="col-sm-6 form-group" style="padding-right: 5px;">
                  <label class="font_normal_body">到期日期</label>
                  <datepicker  placeholder="到期日期" style="width: 60%"
                               v-model="row.f_expire_date"
                               :value.sync="row.f_expire_date"
                               :format="'yyyy-MM-dd HH:mm:ss'">
                  </datepicker>
                </div>
                <div class="col-sm-6 form-group" style="padding-right: 5px;">
                  <label class="font_normal_body">管道类型</label>

                  <v-select :value.sync="row.f_pipe_type" v-model="row.f_pipe_type"
                            :options='pipetypes' placeholder='连接管类型' :value-single="true"
                            close-on-select></v-select>
                </div>
              </div>
              <div class="row auto"  style="margin-left: 10px;">
                <div class="col-sm-6 form-group" style="padding-right: 5px;">
                  <label class="font_normal_body">安装日期</label>
                  <datepicker  placeholder="连接管安装日期" style="width: 60%"
                               v-model="row.f_pipeinstall_date"
                               :value.sync="row.f_pipeinstall_date"
                               :format="'yyyy-MM-dd HH:mm:ss'">
                  </datepicker>
                </div>
                <div class="col-sm-6 form-group" style="padding-right: 5px;">
                  <label class="font_normal_body">到期日期</label>
                  <datepicker  placeholder="连接管到期日期" style="width: 60%"
                               v-model="row.f_pipeexpire_date"
                               :value.sync="row.f_pipeexpire_date"
                               :format="'yyyy-MM-dd HH:mm:ss'">
                  </datepicker>
                </div>
              </div>
            </form>
            <img :src="imgdelete" alt="图片加载失败" class="img-rounded" style="width: 60px;padding: 20px;margin-left: -15px;cursor: pointer;"
                 @click="deleteDevice($index, row)" v-if="row.f_state !== '有效'">
          </div>
          <div class="panel panel-default flex-two-info text-center" style="line-height: 164px;">
            <img :src="imgadd" alt="图片加载失败1" class="img-rounded" style="width: 60px;padding: 10px;cursor: pointer;" @click="addDevice()" >
          </div>
        </div>
      </article>
      <footer slot="modal-footer" class="modal-footer">
      </footer>
    </modal>
  </div>

</template>

<script>
  export default {
    title: '设备信息',
    data () {
      return {
        imgdelete: '/images/mainicon/deletedevice.png',
        imgadd: '/images/mainicon/adddevice.png',
        devicetypes: this.$appdata.getParam('设备类型'),
        pipetypes: this.$appdata.getParam('连接管类型')
      }
    },
    props: {
      devicesinfo: {
        type: Array
      },
      show_devices: {
        type: Boolean,
        default: false
      }
    },
    methods: {
      deleteDevice (index, row) {
        this.devicesinfo.splice(index, 1)
      },
      addDevice () {
        console.log('设备信息', this.devicesinfo)
        this.devicesinfo.push({f_devices_type: '家用灶具',
          f_input_date: this.$login.toStandardTimeString()})
      }
    }
  }
</script>
<style lang="less">
  .flex-deviceinfo {
    padding: 0px 20px;
    justify-content: space-between;
    height: auto;
    flex-wrap: wrap;
  }
  .flex-two-info {
    margin-bottom: 10px;
    align-items: center;
    width: 48%;
  }
</style>
