<template>
  <div class="app-container">
    <el-divider content-position="left">入库申请</el-divider>
    <el-card class="box-card">
    <el-form ref="form" :model="form"  label-width="80px" :disabled="single">
      <el-form-item label="入库类型 ">
        <el-select v-model="form.storageType" placeholder="请选择入库类型 ">
          <el-option
            v-for="dict in storageTypeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-row>
        <el-col :span="10">
          <el-form-item label="入库时间" prop="wareTime">
            <el-date-picker clearable size="small"
                            v-model="form.wareTime"
                            type="date"
                            value-format="yyyy-MM-dd"
                            placeholder="选择入库时间">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="10">
          <el-form-item label="制单人" prop="sysUserId">
            <el-input  maxlength="20"  v-model="form.sysUser" placeholder="制单人"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="资产类型" prop="dbMaterielId"  >
        <treeselect :disabled="single"
          v-model="form.dbMaterielId"
          :options="treeOptions"
          :show-count="true"
          placeholder="选择上级菜单"
        />
      </el-form-item>
      <el-form-item label="资产编号" prop="aNumber">
        <el-input  maxlength="20"  v-model="form.aNumber" placeholder="请输入资产编号"/>
      </el-form-item>
      <el-form-item label="资产名称" prop="aName">
        <el-input  maxlength="20"  v-model="form.aName" placeholder="请输入资产名称"/>
      </el-form-item>
      <el-form-item label="规格型号">
        <el-input  maxlength="20"  v-model="form.specType" placeholder="请输入型号"/>
      </el-form-item>
      <el-form-item label="供应商" prop="dbSupplierId">
        <el-select v-model="form.dbSupplierId" placeholder="请选择入库类型 " clearable size="small">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-row>
        <el-col :span="10">
          <el-form-item label="保质期" prop="shelfLifeEnd">
            <el-date-picker clearable size="small" style="width: 200px"
                            v-model="form.shelfLifeEnd"
                            type="date"
                            value-format="yyyy-MM-dd"
                            placeholder="选择保质期结束">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="10">
          <el-form-item label="结束" prop="shelfLifeEnd">
            <el-date-picker clearable size="small" style="width: 200px"
                            v-model="form.shelfLifeEnd"
                            type="date"
                            value-format="yyyy-MM-dd"
                            placeholder="选择保质期结束">
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    </el-card>
    <br/>
    <el-card class="box-card">
      <template >
        <el-tag>提交人&nbsp;:&nbsp;{{form.createUser}}</el-tag>
        <br/>
        <br/>
        <el-tag>提交时间&nbsp;:&nbsp;{{form.createTime}}</el-tag>
      </template>
    </el-card>
  </div>
</template>

<script>
  import { inputForm } from '@/api/assets/input'

  import { treelist } from '@/api/system/materiel'

  import { select } from '@/api/system/supplier'

  import Treeselect from '@riophae/vue-treeselect'
  import '@riophae/vue-treeselect/dist/vue-treeselect.css'

  export default {
    components: {
      Treeselect
    },
    props: ['id'],
    name: 'Input',
    data() {
      return {
        id:this.id,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 总条数
        total: 0,
        // 资产入库表格数据
        inputList: [],
        // 弹出层标题
        title: '',
        // 是否显示弹出层
        open: false,
        // 入库类型 字典
        storageTypeOptions: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          aNumber: undefined,
          aName: undefined,
          storageType: undefined,
          wareTime: undefined,
          dbMaterielId: undefined,
          dbSupplierId: undefined,
          specType: undefined,
          sysUserId: undefined,
          instanceId: undefined,
          shelf: undefined,
          shelfLifeStart: undefined,
          shelfLifeEnd: undefined,
          state: undefined
        },
        // 表单参数
        form: {},
        // 表单校验

        treeOptions: [],
        options: []

      }
    },
    created() {
      this.getDicts('storage_type').then(response => {
        this.storageTypeOptions = response.data
      })
      this.treelist()
      this.select()
      this.showForm(this.id)
    },
    methods: {
      // 入库类型 字典翻译
      storageTypeFormat(row, column) {
        return this.selectDictLabel(this.storageTypeOptions, row.storageType)
      },
      // 入库类型 字典翻译
      selectVo(row, column) {
        return this.selectFormat(this.options, row.dbSupplierId + '')
      },
      // 表单重置
      reset() {
        this.form = {
          aId: undefined,
          aNumber: undefined,
          aName: undefined,
          storageType: undefined,
          wareTime: undefined,
          dbMaterielId: undefined,
          dbSupplierId: undefined,
          specType: undefined,
          sysUserId: undefined,
          remark: undefined,
          instanceId: undefined,
          taskId: undefined,
          shelf: undefined,
          shelfLifeStart: undefined,
          shelfLifeEnd: undefined,
          state: undefined,
          createBy: undefined,
          createTime: undefined,
          updateBy: undefined,
          updateTime: undefined
        }
        this.resetForm('form')
      },
      /** 修改按钮操作 */
      showForm(id) {
        inputForm(id).then(response => {
          this.form = response.data
          this.form.dbSupplierId = this.form.dbSupplierId + ''
          this.form.storageType = this.form.storageType + ''
          this.open = true
          this.title = '修改资产入库'
        })
      },
      treelist() {
        treelist().then(response => {
          this.treeOptions = response.data
        })
      },
      select() {
        select().then(response => {
          this.options = response.data
        })
      }

    },
    watch: {
      'id': function(newVal){
        this.showForm(newVal);
      }
    }
  }
</script>
