<template>
  <nm-container>
    <nm-list ref="list" v-bind="list">
      <!--查询条件-->
      <template v-slot:querybar> </template>

      <!--按钮-->
      <template v-slot:querybar-buttons>
        <nm-button v-bind="buttons.add" @click="add" />
      </template>

      <!--自定义列-->
      <!-- <template v-slot:col-name="{row}">
        <nm-button :text="row.name" type="text" />
      </template> -->

      <!--操作列-->
      <template v-slot:col-operation="{ row }">
        <nm-button v-bind="buttons.edit" @click="edit(row)" />
        <nm-button-delete v-bind="buttons.del" :id="row.id" :action="removeAction" @success="refresh" />
      </template>
    </nm-list>

    <save-page :id="curr.id" :visible.sync="dialog.save" @success="refresh" :materialId="materialNid" ref="savepage" />
    <form-create v-model="formModel" :rule="rule" :option="option" v-show="this.index_LoadMode"></form-create>
  </nm-container>
</template>
<script>
import { mixins } from 'xmanager-ui'
import page from './page'
import cols from './cols'
import SavePage from '../components/save'

const api = $api.materialApp.materialProperty

export default {
  name: page.name,
  mixins: [mixins.list],
  components: { SavePage },
  data() {
    return {
      materialNid: null,
      list: {
        // title: page.title,
        // title:'',
        cols,
        action: this.query,
        model: {
          /** 物料 */
          material: '',
          /** 主键 */
          nId: '',
          /** 属性值 */
          propertyValue: '',
          /** 属性类型 */
          propertyType: '',
          /** 属性关联id */
          propertyUoMNId: ''
        },
        isVuetify: true,
        isSearch: true,
        isAdd: true,
        isExport: false,
        showSelect: true,
        singleSelect: false
      },
      removeAction: api.remove,
      buttons: page.buttons,
      /**Code Manage 开始 */
      list_LoadMode: false,
      index_LoadMode: false,
      save_LoadMode: false,
      formModel: {},
      rule: [],
      option: {
        submitBtn: false
      }
    }
  },
  methods: {
    query() {
      if (this.materialNid == null || this.materialNid == '') {
        return new Promise(resolve => {
          api.query().then(datas => {
            let options = datas
            resolve(options)
          })
        })
      } else {
        return new Promise(resolve => {
          api.query({ Material: this.materialNid }).then(datas => {
            let options = datas
            resolve(options)
          })
        })
      }
    }
  },
  watch: {
    materialNid: function() {
      this.$refs.list.query()
    }
  }
}
</script>
