<template>
  <div class="page-box" v-loading="Loading.appMainLoading">
    <tablePagination
      :currenButtonData="currenButtonData"
      :tableData="tableData"
      :tableLoading="Loading.tableLoading"
      :tableColumns="tableColumns"
      @rowDrop="rowDrop"
      :totalCount="totalCount"
      :multipleSelection="multipleSelection"
      :MaxResultCount="PageListParams.MaxResultCount"
      @topbutton="topbutton"
      @inlineDialog="inlineDialog"
      @sortChange="sortChange"
      @alertoldSkipCount="alertoldSkipCount"
      @alterResultCount="alterResultCount"
      @handleSelectionChange="handleSelectionChange"
      @buttonOperationClick="buttonOperationClick"
      :currentPageProps="oldSkipCount"
      :quicklySearchOption="quicklySearchOption"
      @quicklySearchClick="quicklySearchClick"
      @quicklySearchClear="quicklySearchClear"
      :primarySearchOption="primarySearchOption"
      @overallSearchFormClick="overallSearchFormClick"
      :httpOverallSearchData="httpOverallSearchData"
    >
    </tablePagination>
    <!-- 新增与编辑 -->
    <newAndEdiDialog
      :loading="Loading.newAndEdiLoading"
      :active="active"
      :pageStatus="pageStatus"
      :formReveal="formReveal"
      :formTitle="formTitle"
      :displayDialog="editDialog"
      :FormData="formReveal ? CreateFormData : editFormData"
      :Form="formReveal ? CreateForm : editForm"
      :Options="editOptions"
      :Handle="editHandle"
      :Rules="formReveal ? editRules.cerateRule : editRules.editRule"
      @FormSubmit="FormSubmit"
      @close="FormClose"
      @goBack="goBack"
    ></newAndEdiDialog>
    <!-- 搜索按钮——窗体组件 -->
    <searchPage
      ref="searchTable"
      :tableLoading="Loading.autoTableLoading"
      :advancedFilter="advancedFilter()"
      :filterPageListParams="filterPageListParams"
      :formTitle="searchTitle"
      :displayDialog="displayDialog.AddNewDialog"
      :searchTableData="searchData"
      :searchTableColumns="searchColumns"
      :searchTotalCount="searchTotalCount"
      :supplierItemPage="searchPageListParams"
      @handleSelectionChange="prepareFormData"
      @SizeChange="searchAlterResultCount($event, searchPageListParams)"
      @CurrentChange="searchAlertoldSkipCount($event, searchPageListParams)"
      @tableButtonClick="searchSubmit(arguments)"
    ></searchPage>
    <!-- 新导入 disabledMethod 导入方式禁用 disabledIsAllowPartImport 是否局部导入禁用-->
    <!-- methodValue 导入方式默认选项  是否局部导入 默认选项  -->
    <importFile
      :loading="Loading.importLoading"
      :show="displayDialog.importDialog"
      :URL="URL"
      :disabledMethod = {method1:false,method2:false,method3:false}
      :disabledIsAllowPartImport = {isAllowPartImport1:false,isAllowPartImport2:false}
      methodValue="0"
      isAllowPartImportValue="1"
      @importClick="postImportMergeClick(arguments)"
      @postImportDown="importDown"
    ></importFile>
    <curren-Drawer
      :title="tableColumns"
      :tableColumns="tableColumns"
      :DrawerLoading="Loading.DrawerLoading"
      :drawer="displayDialog.detailsDialog"
      :dropdownData="dropdownData"
      :propsData="propsData"
      :tabsDesTions="tabsDesTions"
      @drawerShut="(val) => (displayDialog.detailsDialog = val)"
      @drawerbutton="drawerbutton"
      @handleCommand="drawerHandle"
      @close-value="closeValue"
    ></curren-Drawer>
  </div>
</template>
<script>
import { tableMixins } from "@/mixins/TableMixins"
import { LoadingMixins } from "@/mixins/LoadingMixins"
import { drawerMixins } from "@/mixins/drawerMixins"
import { TableHeaderMixins } from "@/mixins/TableHeaderMixins"
import { newAndEdiDialogMixins } from "@/mixins/newAndEdiDialogMixins"
import { mixins } from "@/mixins/mixins"
import { filterSelectMixins } from '@/mixins/filter-Select'

export default {
  name: "ItemSafetyStock",
  mixins: [
    tableMixins,
    LoadingMixins,
    drawerMixins,
    TableHeaderMixins,
    mixins,
    filterSelectMixins,
    newAndEdiDialogMixins
  ],
  watch: {
    'CreateFormData.storeRelationType': {
      handler (val) {
        this.storeValue.url = this.$staticOptions.storeRelationType(val, 'url')
        this.storeValue.tabColumns = this.$staticOptions.storeRelationType(val, 'tabColumns')
        this.CreateFormData.storeValue = ''
      },
      immediate: true
    },
    'editFormData.storeRelationType': {
      handler (val, oldVal) {
        this.ediStoreValue.url = this.$staticOptions.storeRelationType(val, 'url')
        this.ediStoreValue.tabColumns = this.$staticOptions.storeRelationType(val, 'tabColumns')
      },
      immediate: false
    },
  },
  computed: {
    editDialog: {
      get: function () {
        return this.displayDialog.newDialog || this.displayDialog.editDialog;
      },
    },
  },
  data () {
    return {
      URL: 'basedata/item-safety-stock',
      storeValue: {
        url: '',
        tabColumns: '',
      },
      ediStoreValue: {
        url: '',
        tabColumns: '',
      },
      //常用按钮数据
      currenButtonData: [
        this.defaultAddBtn(),//新增
        this.defaultImportBtn(),//导入
        this.defaultExportBtn(),//导出
        this.defaultFieldSettingBtn(),//字段设置
        this.defaultFreshBtn(),//刷新
        this.defaultFilterBtn(),//筛选
      ],
      //新增
      CreateFormData: {
        itemCode: null,
        warehouseCode: localStorage.getItem('warehouseCode'),
        storeRelationType: 1,
        storeValue: null,
        maxStock: null,
        minStock: null,
        safetyStock: null,
        feedLine: 0,
        feedQty: 0,
        feedUM: null,
        // concurrencyStamp: null,
        // company: localStorage.getItem('company'),
        remark:"",
      },
      //编辑
      editFormData: {
        itemCode: null,
        warehouseCode: localStorage.getItem('warehouseCode'),
        storeRelationType: 1,
        storeValue: null,
        maxStock: null,
        minStock: null,
        safetyStock: null,
        feedLine: 0,
        feedQty: 0,
        feedUM: null,
        concurrencyStamp: null,
        // company: localStorage.getItem('company'),
        remark:"",
      },
      editOptions: {},
      CreateForm: [
        { type: "filterSelect", label: "物品代码", prop: "itemCode", optionsLabel: "name", optionsValue: "code", 
          focus: (type,val) => { return this.getFilterList(type, val, "basedata/item-basic")},
          searchButton: (val) => { this.showSerarchPage(val, 'basedata/item-basic', 'ItemBasic', '区域选择', this.CreateFormData) }, colSpan: 12 },
        { type: "select", label: "存储关系类型", prop: "storeRelationType", options: "storeRelationType", colSpan: 12 },
        { type: "filterSelect", label: "存储关系代码", prop: "storeValue", optionsLabel: "name", optionsValue: "code", 
          focus: (type,val) => { return this.getFilterList(type, val, this.storeValue.url)},
          searchButton: (val) => { this.showSerarchPage(val, this.storeValue.url, this.storeValue.tabColumns, '值选择', this.CreateFormData) }, colSpan: 12 },
        { type: "input", label: "最大库存", validType:'pointNumber', prop: "maxStock", colSpan: 12 },
        { type: "input", label: "最小库存", validType:'pointNumber', prop: "minStock", colSpan: 12 },
        { type: "input", label: "安全库存", validType:'pointNumber', prop: "safetyStock", colSpan: 12 },
        { type: "input", label: "补料点", validType:'pointNumber', prop: "feedLine", colSpan: 12 },
        { type: "input", label: "补料数量", validType:'pointNumber', prop: "feedQty", colSpan: 12 },
        { type: "input", label: "补料单位", prop: "feedUM", colSpan: 12 },
        { type: "input", label: "备注", prop: "remark", colSpan: 12 },
        { type: "input", label: "仓库代码", prop: 'warehouseCode',  disabled:"true", colSpan: 12 },
        
      ],
      editForm: [
        { type: "input", label: "物品代码", prop: "itemCode", disabled:"true", colSpan: 12 },
        { type: "select", label: "存储关系类型", prop: "storeRelationType", options: "storeRelationType", colSpan: 12 },
        { type: "filterSelect", label: "存储关系代码", prop: "storeValue", optionsLabel: "name", optionsValue: "code", 
          focus: (type,val) => { return this.getFilterList(type, val, this.ediStoreValue.url)},
          searchButton: (val) => { this.showSerarchPage(val, this.ediStoreValue.url, this.ediStoreValue.tabColumns, '值选择', this.editFormData) }, colSpan: 12 },
        { type: "input", label: "最大库存", validType:'pointNumber', prop: "maxStock", colSpan: 12 },
        { type: "input", label: "最小库存", validType:'pointNumber', prop: "minStock", colSpan: 12 },
        { type: "input", label: "安全库存", validType:'pointNumber', prop: "safetyStock", colSpan: 12 },
        { type: "input", label: "补料点", validType:'pointNumber', prop: "feedLine", colSpan: 12 },
        { type: "input", label: "补料数量", validType:'pointNumber', prop: "feedQty", colSpan: 12 },
        { type: "input", label: "补料单位", prop: "feedUM", colSpan: 12 },
        { type: "input", label: "备注", prop: "remark", colSpan: 12 },
        { type: "input", label: "仓库代码", prop: 'warehouseCode',  disabled:"true", colSpan: 12 },
        
      ],
      editRules: {
        cerateRule: {
          itemCode: [{ required: true, trigger: "change", message: "不可为空" },],
          storeRelationType: [{ required: true, trigger: "change", message: "不可为空" },],
          storeValue: [{ required: true, trigger: "change", message: "不可为空" },],
          maxStock: [{ required: true, trigger: "change", message: "不可为空" },],
          minStock: [{ required: true, trigger: "change", message: "不可为空" },],
          safetyStock: [{ required: true, trigger: "change", message: "不可为空" },],
        },
        editRule: {
          storeRelationType: [{ required: true, trigger: "change", message: "不可为空" },],
          storeValue: [{ required: true, trigger: "change", message: "不可为空" },],
          maxStock: [{ required: true, trigger: "change", message: "不可为空" },],
          minStock: [{ required: true, trigger: "change", message: "不可为空" },],
          safetyStock: [{ required: true, trigger: "change", message: "不可为空" },],
        }
      },
    };
  },
  mounted () {
    this.paging();
  },
};
</script>
<style lang="scss" scoped>
@import "../../../styles/basicData.scss";
</style>