<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.materialNId" label="物料" :rules="form.rules.materialNIdRules"></v-text-field> -->

    <!-- <v-text-field v-model="form.model.bomNId" label="物料清单" :rules="form.rules.bomNIdRules"></v-text-field> -->
    <v-combobox
      v-model="form.model.bomNId"
      :rules="form.rules.bomNIdRules"
      :items="bomData"
      item-disabled="disabled"
      item-text="name"
      item-value="nId"
      label="物料清单"
      :isMultiple="isMultiple"
      outlined
      disable-lookup
      clearable
      solo
      :return-object="returnObject"
    ></v-combobox>
  </nm-form-vuetify-drawer>
</template>
<script>
import { mixins } from 'xmanager-ui'
const { add, edit, update } = $api.materialApp.billOfMaterialRelevanceMaterial
const api = $api.materialApp.billOfMaterialRelevanceMaterial

export default {
  mixins: [mixins.formSave],
  props: {
    materialId: {
      type: String,
      required: false
    }
  },
  data() {
    return {
      bomData: [],
      isMultiple: false,
      returnObject: false,
      title: '物料清单物料',
      actions: { add, edit, update },
      parent: this,
      form: {
        model: {
          /** 物料 */
          nId: '',
          materialNId: this.materialId,
          /** 物料清单 */
          bomNId: '',
          /** 是否锁定 */
          isLocked: false,
          /** 是否冻结 */
          isFrozen: false
        },
        rules: {
          materialNIdRules: [v => !!v || '物料 is required'],
          bomNIdRules: [v => !!v || '物料清单 is required'],
          isLockedRules: [],
          isFrozenRules: []
        }
      }
    }
  },
  methods: {
    customResetFunction() {
      this.form.model.materialNId = this.materialId
      this.form.model.bomNId = ''
      this.form.model.isLocked = null
      this.form.model.isFrozen = null
    }
  },
  mounted() {
    api.getBom().then(res => {
      this.bomData = res.rows
    })
  }
}
</script>
