<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-useBillOfMaterials="{ row }">
        <!-- <nm-label type="primary" v-if="row.useBillOfMaterials == '1'">Never绝不</nm-label>
        <nm-label type="danger" v-else-if="row.useBillOfMaterials == '2'">IfAvailable不可用</nm-label>
        <nm-label type="primary" v-else-if="row.useBillOfMaterials == '3'">Always总是</nm-label>
        <nm-label type="danger" v-else-if="row.useBillOfMaterials == 'false'">不使用</nm-label> -->
        <v-chip v-if="row.useBillOfMaterials === '1'" color="green" dark>Never绝不</v-chip>
        <v-chip v-else-if="row.useBillOfMaterials === '2'" color="green" dark>IfAvailable不可用</v-chip>
        <v-chip v-else-if="row.useBillOfMaterials === '3'" color="green" dark>Always总是</v-chip>
        <v-chip v-else color="red" dark>不使用</v-chip>
      </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" :billOfMaterialId="billOfMaterialNId" />
    <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.billOfMaterialsItem

export default {
  name: page.name,
  mixins: [mixins.list],
  components: { SavePage },
  data() {
    return {
      billOfMaterialNId: '',
      list: {
        title: page.title,
        cols,
        action: this.query,
        model: {
          /** 编码 */
          nId: '',
          /** 名称 */
          name: '',
          /** 详情 */
          description: '',
          /** 物料清单代替类型 */
          alternative: '',
          /** 物料编码 */
          materialNId: '',
          /** 物料版本 */
          materialRevision: '',
          /** 数量 */
          quantity: '',
          /** 排序 */
          sequence: '',
          /** 工序编码 */
          operationNId: '',
          /** 工序版本 */
          operationRevision: '',
          /** 物料组 */
          materialGroup: '',
          /** 物料清单 */
          billOfMaterials: '',
          /** 是否按原物料使用 */
          useBillOfMaterials: '',
          /** 是否锁定 */
          isLocked: '',
          /** 是否冻结 */
          isFrozen: ''
        },
        isVuetify: true,
        isSearch: true,
        isAdd: true,
        isExport: false,
        showSelect: true,
        singleSelect: false,
        operationWidth: '250'
      },
      removeAction: api.remove,
      buttons: page.buttons,
      /**Code Manage 开始 */
      list_LoadMode: false,
      index_LoadMode: false,
      save_LoadMode: false,
      formModel: {},
      rule: [],
      option: {
        submitBtn: false
      }
    }
  },
  methods: {
    query() {
      return new Promise(resolve => {
        api.query({ BillOfMaterials: this.billOfMaterialNId }).then(datas => {
          let options = datas
          resolve(options)
        })
      })
    }
  },
  mounted() {
    //获取值
  },
  watch: {
    billOfMaterialNId: function() {
      //获取接口数据
      this.$refs.list.query()
    }
  }
}
</script>
