<template>
  <nm-form-vuetify-drawer ref="form" v-bind="form" v-on="on" :parent="parent" :title="title" placement="left" :visible.sync="visible_">
    <v-text-field v-model="form.model.nId" label="编码" :rules="form.rules.nIdRules"></v-text-field>

    <v-text-field v-model="form.model.name" label="名称" :rules="form.rules.nameRules"></v-text-field>

    <v-text-field v-model="form.model.description" label="详情" :rules="form.rules.descriptionRules"></v-text-field>

    <v-text-field v-model="form.model.status" label="状态" :rules="form.rules.statusRules"></v-text-field>

    <!-- <v-text-field v-model="form.model.materialNId" label="物料编码" :rules="form.rules.materialNIdRules"></v-text-field> -->
    <nm-material-entitypicker v-model="form.model.materialNId" @materialinfo="materialinfos"></nm-material-entitypicker>

    <!-- <v-text-field v-model="form.model.materialRevision" label="物料修订" :rules="form.rules.materialRevisionRules"></v-text-field>

    <v-text-field v-model="form.model.materialUId" label="物料UId" :rules="form.rules.materialUIdRules"></v-text-field> -->

    <!-- <v-text-field v-model="form.model.materialLot" label="物料批次" :rules="form.rules.materialLotRules"></v-text-field> -->
    <v-combobox
      v-model="form.model.materialLot"
      :rules="form.rules.materialLot"
      :items="materialLotData"
      item-disabled="disabled"
      item-text="name"
      item-value="nId"
      label="物料批次"
      :isMultiple="isMultiple"
      outlined
      disable-lookup
      clearable
      solo
      :return-object="returnObject"
    ></v-combobox>

    <v-text-field v-model="form.model.quantity" label="数量" :rules="form.rules.quantityRules"></v-text-field>

    <v-text-field v-model="form.model.equipmentNId" label="设备编码" :rules="form.rules.equipmentNIdRules"></v-text-field>

    <v-text-field v-model="form.model.materialTrackingbUnitAggregate" label="物料跟踪单元总数" :rules="form.rules.materialTrackingbUnitAggregateRules"></v-text-field>

    <!-- <v-text-field v-model="form.model.templateNId" label="模板编码" :rules="form.rules.templateNIdRules"></v-text-field> -->
    <v-combobox
      v-model="form.model.templateNId"
      :rules="form.rules.templateNId"
      :items="templateData"
      item-disabled="disabled"
      item-text="name"
      item-value="nId"
      label="模板编码"
      :isMultiple="isMultiple"
      outlined
      disable-lookup
      clearable
      solo
      :return-object="returnObject"
    ></v-combobox>

    <!-- <v-text-field v-model="form.model.codeType" label="代码类型" :rules="form.rules.codeTypeRules"></v-text-field> -->
    <v-combobox
      v-model="form.model.codeType"
      :rules="form.rules.codeTypeRules"
      :items="codeTypeData"
      item-disabled="disabled"
      item-text="text"
      item-value="value"
      label="代码类型"
      :isMultiple="isMultiple"
      outlined
      disable-lookup
      clearable
      solo
      :return-object="returnObject"
    ></v-combobox>

    <v-text-field v-model="form.model.code" label="代码" :rules="form.rules.codeRules"></v-text-field>
  </nm-form-vuetify-drawer>
</template>
<script>
import { mixins } from 'xmanager-ui'
const { add, edit, update } = $api.materialApp.materialTrackingUnit
const api = $api.materialApp.materialTrackingUnit

export default {
  mixins: [mixins.formSave],
  data() {
    return {
      //combobox返回
      returnObject: false,
      isMultiple: false,
      codeTypeData: [
        { text: 'codetype1', value: '1' },
        { text: 'codetype2', value: '2' }
      ],
      //物料批次
      materialLotData: [],
      //物料批次模板
      templateData: [],
      title: '物料跟踪单位',
      actions: { add, edit, update },
      parent: this,
      form: {
        model: {
          /** 编码 */
          nId: '',
          /** 名称 */
          name: '',
          /** 详情 */
          description: '',
          /** 状态 */
          status: '',
          /** 物料编码 */
          materialNId: '',
          /** 物料修订 */
          materialRevision: '',
          /** 物料UId */
          materialUId: '',
          /** 物料批次 */
          materialLot: '',
          /** 数量 */
          quantity: '',
          /** 设备编码 */
          equipmentNId: '',
          /** 物料跟踪单元总数 */
          materialTrackingbUnitAggregate: '',
          /** 模板编码 */
          templateNId: '',
          /** 编码 */
          code: '',
          /** 代码类型 */
          codeType: '',
          /** 是否冻结 */
          isFrozen: false,
          /** 是否冻结 */
          isLocked: false
        },
        rules: {
          nIdRules: [v => !!v || '编码 is required'],
          nameRules: [],
          descriptionRules: [],
          statusRules: [],
          materialNIdRules: [],
          materialRevisionRules: [],
          materialUIdRules: [],
          materialLotRules: [],
          quantityRules: [],
          equipmentNIdRules: [],
          materialTrackingbUnitAggregateRules: [],
          templateNIdRules: [],
          codeRules: [],
          codeTypeRules: [],
          isFrozenRules: [],
          isLockedRules: []
        }
      }
    }
  },
  mounted() {
    //获取物料批次
    api.getLotData().then(res => {
      this.materialLotData = res.rows
    })
    //模板

    api.getTemplateData().then(res => {
      this.templateData = res.rows
    })
  },
  methods: {
    materialinfos: function(val) {
      console.log(val)
      this.form.model.materialNId = val
    }
  }
}
</script>
