<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.revision" label=" 版本" :rules="form.rules.revisionRules"></v-text-field>

    <v-combobox
      v-model="form.model.templateNId"
      :items="bOMData"
      item-text="label"
      item-value="value"
      label="物料清单模板"
      :isMultiple="isMultiple"
      outlined
      solo
      :return-object="returnObject"
    ></v-combobox>
    <!-- v-show="form.model.id == null || form.model.id == ''" -->
    <nm-unit-combobox v-model="form.model.uomNId" :model="form.model.uomNId" :unitDataRules="form.rules.uoMNIdRules"></nm-unit-combobox>

    <v-text-field v-model="form.model.referenceQuantity" label=" 数量" :rules="form.rules.referenceQuantityRules"></v-text-field>
  </nm-form-vuetify-drawer>
</template>
<script>
import { mixins } from 'xmanager-ui'
const { add, edit, update } = $api.materialApp.billOfMaterial
const api = $api.materialApp.billOfMaterial

export default {
  mixins: [mixins.formSave],
  data() {
    return {
      isMultiple: false,
      returnObject: true,
      uoMData: [],
      bOMData: [],
      title: '物料清单',
      actions: { add, edit, update },
      parent: this,
      form: {
        model: {
          /** 编码 */
          nId: '',
          /** 名称 */
          name: '',
          /** 详情 */
          description: '',
          /** 数量 */
          referenceQuantity: '',
          /** 物料清单模板 */
          templateNId: '',
          /**  版本 */
          revision: '',
          /** 单位 */
          uomNId: '',
          /** 是否锁定 */
          isLocked: false,
          /** 是否冻结 */
          isFrozen: false
        },
        rules: {
          nIdRules: [v => !!v || '编码 is required'],
          nameRules: [],
          descriptionRules: [],
          referenceQuantityRules: [v => !!v || '值不能为空', v => /^[0-9]+$/.test(v) || '只能是数字'],
          templateNIdRules: [v => !!v || '物料清单模板 is required'],
          revisionRules: [v => !!v || ' 版本 is required'],
          uomNIdRules: [v => !!v || '单位 is required'],
          isLockedRules: [],
          isFrozenRules: []
        }
      }
    }
  },
  methods: {
    getbomdata() {
      api.getBom().then(res => {
        this.bOMData = res
      })
    }
  },
  mounted() {
    this.getbomdata()
  }
}
</script>
