<template>
  <nm-form-vuetify-drawer ref="form" v-bind="form" v-on="on" :parent="parent" :title="title" placement="left" :visible.sync="visible_" @success="refresh()">
    <nm-auto-generateid v-model="form.model.nId" :value="form.model.nId" :disabled="this.isEdit_" DataBaseName="XManager_WorkOrder" EntityName="WorkMaster"></nm-auto-generateid>

    <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="版本" v-show="form.model.isAddOrUpd == 'add'" :rules="form.rules.revisionRules"></v-text-field>

    <v-combobox
      v-model="form.model.materialGroups"
      :rules="form.rules.materialGroups"
      :items="groupData"
      item-disabled="disabled"
      item-text="name"
      item-value="nId"
      label="物料组"
      :isMultiple="isMultiple"
      outlined
      disable-lookup
      clearable
      solo
      :return-object="returnObject"
    ></v-combobox>
    <nm-unit-combobox v-model="form.model.uoMNId" :model="form.model.uoMNId" :unitDataRules="form.rules.uoMNIdRules" :returnObject="uomReturnObject"></nm-unit-combobox>
    <!-- <v-combobox
      v-model="form.model.uoMNId"
      :rules="form.rules.uoMNIdRules"
      :items="uomData"
      item-disabled="disabled"
      item-text="label"
      item-value="value"
      label="单位"
      :isMultiple="isMultiple"
      outlined
      disable-lookup
      clearable
      solo
      :return-object="returnObject"
    ></v-combobox> -->

    <!-- <nm-entity-picker
      label="请选择物料组"
      v-model="form.model.materialGroups"
      :value="form.model.materialGroups"
      :text="form.model.materialGroups"
      :action="entityaction"
      :cols="entitycols"
      columnName="name"
      columnValue="id"
    ></nm-entity-picker> -->

    <nm-entity-picker
      label="请选择物料模板"
      v-model="form.model.templateNId"
      :action="entityaction"
      :text="form.model.templateNId"
      :value="form.model.templateNId"
      :cols="entitycols"
      columnName="name"
      columnValue="id"
      clearable
      disabled
      :rules="form.rules.templateNIdRules"
    >
    </nm-entity-picker>
  </nm-form-vuetify-drawer>
</template>
<script>
import { mixins } from 'xmanager-ui'
import cols from '../../../materialTemplate/index/cols'
const { add, edit, update } = $api.materialApp.material
const api = $api.materialApp.material
const materialTemplateapi = $api.materialApp.materialTemplate
export default {
  mixins: [mixins.formSave],
  data() {
    return {
      uomReturnObject: false,
      returnObject: false,
      uomData: [],
      listVisibles: false,
      materialinfo: null,
      materialvalue: null,
      isMultiple: false,
      entityaction: materialTemplateapi.query,
      materialNo: '',
      entitycols: cols,
      adshow: false,
      title: '物料',
      actions: { add, edit, update },
      parent: this,
      form: {
        model: {
          /** 名称 */
          name: '',
          /** 描述 */
          description: '',
          /** 物料单位id */
          uoMNId: '',
          /** 物料模板id */
          templateNId: '',
          /** 物料组 */
          materialGroups: '',
          // nId: ''
          nId: '',
          uId: '',
          revision: '',
          isAddOrUpd: ''
          // entity: ''
        },
        rules: {
          uIdRules: [v => !!v || '编码不能为空'],
          nIdRules: [v => !!v || '编码不能为空'],
          nameRules: [],
          descriptionRules: [],
          uoMNIdRules: [v => !!v || '请选择单位'],
          templateNIdRules: [v => !!v || '请选择模板'],
          materialGroupsRules: [],
          revisionRules: [v => !!v || '版本不能为空']
        }
      },

      groupData: [],
      templateData: [],
      dialog: {
        title: '物料模板',
        icon: 'dialog',
        visible: false,
        titleClass: 'text-h5 lighten-2 primary',
        footerCloseButton: true,
        footerTextColor: 'green'
      },
      generateName: { generateName: 'MaterialNo' }
    }
  },
  methods: {
    onchange(val) {
      console.log(val)
    },
    materialinfos: function(val) {
      console.log(val)
    },
    //成功
    refresh() {},
    customResetFunction() {
      this.form.model.materialTemplate = this.materialTemplateId
      this.form.model.description = ''
      this.form.model.name = ''
      this.form.model.uoMNId = ''
      this.form.model.templateNId = ''
      this.form.model.materialGroups = ''
      this.form.model.nId = ''
      this.form.model.uId = ''
      this.form.model.revision = ''
      this.form.model.isAddOrUpd = 'add'
    }
  },

  mounted() {
    //模板
    // api.gettemplate().then(res => {
    //   this.templateData = res.rows
    // })
    //物料组
    api.materialgroup().then(res => {
      this.groupData = res.rows
    })
    // //单位
    // api.getUnit().then(res => {
    //   this.uomData = res
    // })
  },
  watch: {
    materialinfo: function(val) {
      console.log(val)
    }
  }
}
</script>
