<template>
  <div class="auto select-overspread" style="overflow-y: scroll;overflow-x: hidden">
    <ul class="nav nav-tabs" style="position: relative">
      <p class="bg-info text-center" style="padding: 8px;">{{ title }}</p>
      <h3 class="txtline" v-if="model.parent_name">上一级【{{ model.parent_name }}】</h3>
    </ul>
    <div class="row" style="margin-top:1rem;">
      <div class="col-sm-6">
        <label class="font_normal_body">名称</label>
        <input type="text"
               :disabled="look"
               v-model="model.name" style="width:60%"
               class="input_search full-with" placeholder="名称">
      </div>
      <div class="col-sm-6">
        <label class="font_normal_body">类别</label>
        <v-select :disabled="look"
                  v-model="model.type"
                  placeholder='项目类别'
                  :value.sync="model.type"
                  :value-single="true"
                  :options='types'></v-select>
      </div>
    </div>
    <div class="row" style="margin-top:1rem;" v-if="model.type ==='型号'">
      <div class="col-sm-6">
        <label class="font_normal_body">单位</label>
        <input type="text"
               :disabled="look"
               v-model="model.unit" style="width:60%"
               class="input_search full-with" id="name" placeholder="计量单位">
      </div>
      <div class="col-sm-6">
        <label class="font_normal_body">编码</label>
        <input type="text"
               :disabled="look"
               v-model="model.code" style="width:60%"
               class="input_search full-with" id="name" placeholder="物料编码">
      </div>
      <div class="col-sm-6">
        <label class="font_normal_body">单价</label>
        <input type="text"
               :disabled="look"
               v-model="model.price" style="width:60%"
               class="input_search full-with" id="name" placeholder="物料单价">
      </div>
    </div>
    <!--  按钮  -->
    <div class="row col-sm-12" style="margin-top: 1rem">
      <button @click="confirm()" v-show="!look" class="btn button_search col-sm-1 col-sm-offset-5"
              style="width: 70px">
        <span class="glyphicon glyphicon-floppy-disk"></span>保存
      </button>
      <button @click='cancel()' class="btn button_clear col-sm-1 col-sm-offset-1" style="width: 70px">
        <span class=" glyphicon glyphicon-log-out"></span>返回
      </button>
    </div>
    <div class="row col-sm-12" style="margin-top: 18rem">
    </div>
    <work-busy :is-busy="isbusy"></work-busy>
  </div>
</template>

<script>

export default {
  title: '功能',
  props: ['parent', 'data', 'look', 'title'],
  data () {
    return {
      model: {
        menu_id: null,
        menu_name: '',
        parent_id: '0',
        component: null,
        create_by: '',
        depict: '',
        type: ''
      },
      type: '',
      isbusy: false,
      types: this.$appdata.getParam('材料管理-项目类别') ? this.$appdata.getParam('材料管理-项目类别') : [{
        label: '型号',
        value: '型号'
      }, {label: '燃气具设备', value: '燃气具设备'}, {label: '报建', value: '报建'},
        {label: '规格', value: '规格'}, {label: '材料', value: '材料'}, {label: '品名', value: '品名'}],
      showFile: 'false',
      file: []
    }
  },
  watch: {
    data: {
      handler (n, o) {
        // if (!n.menu_id&&n.menu_id !== o.menu_id)
        this.initdata()
      },
      deep: true // 对象内部属性的监听，关键。
    }
  },
  ready () {
    this.initdata()
  },
  methods: {
    // 初始化数据
    initdata () {
      this.model = {
        id: null,
        name: '',
        parent_id: '0',
        create_by: '',
        type: ''
      }
      this.model = Object.assign({}, this.model, this.data)
      // this.type = this.model.type
      // if (this.model.id) {
      //   this.$resetpost('rs/sql/singleTable_OrderBy', {
      //     data: {
      //       items: '*',
      //       table: 't_material_info',
      //       condition: ` 1 = 1 and id = ${this.model.id}`,
      //       order: 'id desc'
      //     }
      //   }, {rejectMsg: null, resolveMsg: null})
      // }
    },
    // 关闭文件上传对话框
    closeFile () {
      this.showFile = 'false'
      // 将选的文件清空
      this.$refs.file.$el.querySelector('input').value = ''
    },
    cancel () {
      this.$dispatch('cancel')
    },
    async confirm () {
      await this.$resetpost('rs/entity/t_material_info', this.model).then(res =>
        this.$parent.$refs.funlist.searchData()
      )
    },
    importFile () {
      this.showFile = 'true'
    },
    delFile (row) {
      if (!this.look) {
        this.$resetdelete(`rs/entity/t_material_info`, {id: row.id}).then(res =>
          this.initdata()
        )
      }
    }
  },
  events: {}
}
</script>

<style>
.full-with {
  width: 100%;
}

#ldapDisplayUploadFile {
  height: auto !important;
}
</style>
