<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"
      @push="addNewDataPush"
      @FormSubmit="FormSubmitHandle"
      @close="FormClose"
      @goBack="goBack"
    ></newAndEdiDialog>
    <!-- 新导入 disabledMethod 导入方式禁用 disabledIsAllowPartImport 是否局部导入禁用-->
    <!-- methodValue 导入方式默认选项  是否局部导入 默认选项  -->
    <importFile
      :loading="Loading.importLoading"
      :show="displayDialog.importDialog"
      :URL="URL"
      :disabledMethod = {method1:false,method2:false,method3:false}
      :disabledIsAllowPartImport = {isAllowPartImport1:false,isAllowPartImport2:false}
      isAllowPartImportValue="1"
      @importClick="postImportMergeClick(arguments)"
      @postImportDown="importDown"
    ></importFile>
    <!-- 搜索按钮——窗体组件 -->
    <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>
    <!--抽屉-->
    <curren-Drawer
      :title="tableColumns"
      :tableColumns="tableColumns"
      :DrawerLoading="Loading.DrawerLoading"
      :drawer="displayDialog.detailsDialog"
      :dropdownData="dropdownData"
      :propsData="propsData"
      :tabsDesTions="tabsDesTions"
      @drawerShut="(val) => (displayDialog.detailsDialog = val)"
      @drawerbutton="drawerbuttonHandle"
      @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'
import store  from '@/store'
import detailsRules from '@/utils/rules';
export default {
  name: "Utensil",
  mixins: [
    tableMixins,
    LoadingMixins,
    drawerMixins,
    TableHeaderMixins,
    mixins,
    filterSelectMixins,
    newAndEdiDialogMixins
  ],
  computed: {
    editDialog: {
      get: function () {
        return this.displayDialog.newDialog || this.displayDialog.editDialog;
      },
    },
  },
  data () {
    return {
      URL: 'basedata/Equipment',
      //常用按钮数据
      currenButtonData: [
        this.defaultAddBtn(),//新增
        this.defaultImportBtn(),//导入
        this.defaultExportBtn(),//导出
        this.defaultFieldSettingBtn(),//字段设置
        this.defaultFreshBtn(),//刷新
        this.defaultFilterBtn(),//筛选
      ],
      //新增
      CreateFormData: {
        code:null,
        codeSuffix:null,
        type:"Q",
        stdQty:null,
        creator: null,
        remark:null,
      },
      //编辑
      editFormData: {
        code:null,
        codeSuffix:null,
        type:"Q",
        stdQty:null,
        remark:null,
        creator: null,
        concurrencyStamp: ""
      },
      editOptions: {},
      // todo:1、列表与详情添加尺寸和类型字段，标包字段是否去掉
      CreateForm: [
        { type: "prefixInput", label: "器具号", prop: "codeSuffix",prefixProp:"type",prefixWidth:'50px',prefixDisabled:true, colSpan: 12 },
        //todo:获取字典,字段确定
        { type: "select", label: "尺寸", prop: "size", colSpan: 12 },
        // todo:确定枚举（内物流，客户）,字段确定
        { type: "select",options: "utensilType", label: "类型", prop: "type2", colSpan: 12 },
        //todo：标包数量是否去掉
        { type: "inputNumber", label: "标包数量", prop: "stdQty", colSpan: 12, min:1 },
        { type: "input", label: "备注", prop: "remark", colSpan: 12 },
      ],
      editForm: [
        { disabled:true,type: "prefixInput", label: "器具号", prop: "codeSuffix",prefixProp:"type",prefixWidth:'50px',prefixDisabled:true, colSpan: 12 },
        //todo:获取字典,字段确定
        { type: "select", label: "尺寸", prop: "size", colSpan: 12 },
        // todo:确定枚举（内物流，客户）,字段确定
        { type: "select",options: "utensilType", label: "类型", prop: "type2", colSpan: 12 },
        //todo：标包数量是否去掉
        { type: "inputNumber", label: "标包数量", prop: "stdQty", colSpan: 12, min:1 },
        { type: "input", label: "备注", prop: "remark", colSpan: 12 },
      ],
      editRules: {
        cerateRule: {
          codeSuffix: [{ required: true, trigger: "blur", message: "不可为空" }],
          stdQty: [
            { required: true, trigger: "blur", message: "不可为空" },
            ...detailsRules.numberInput
          ],
        },
        editRule: {
          codeSuffix: [{ required: true, trigger: "blur", message: "不可为空" }],
          stdQty: [
            { required: true, trigger: "blur", message: "不可为空" },
            ...detailsRules.numberInput
          ],
        }
      },
    };
  },
  mounted () {
    this.paging();
  },
  methods: {
    addNewDataPush(val){
      console.log(201,val)
    },
    drawerbuttonHandle(val){
      if(val == "edit"){
        this.formTitle = this.$route.meta.title + "编辑";
        this.formReveal = false
        this.theEvent = "edit"
        const listAssign = (arr1, arr2) => {
          Object.keys(arr1).forEach(item => {
            arr1[item] = arr2[item]
          })
        }
        listAssign(this.editFormData, this.propsData)
        if(this.$route.name == 'CustomerItem'){
          this.editFormData.beginTime = new Date(this.propsData.beginTime)
          this.editFormData.endTime = new Date(this.propsData.endTime)
        }
        // this.$listAssign(this.editFormData, this.propsData)
        this.displayDialog.editDialog = true
        
       // todo:编辑-拆分类型前缀和code码
       this.editFormData.type = "Q"
        this.editFormData.codeSuffix = (this.editFormData.type == 'Q') ? (this.editFormData.code && this.editFormData.code.length > 0 ? this.editFormData.code.slice(1) : null) : this.editFormData.code
        // this.editFormData.type = this.editFormData.code && this.editFormData.code.length > 0 ? this.editFormData.code.slice(0,1) : "Q"
        // this.editFormData.codeSuffix = this.editFormData.code && this.editFormData.code.length > 0 ? this.editFormData.code.slice(1) : null
        console.log(210,this.editFormData)
      }else{
        this.drawerbutton(val)
      }
    },
    FormSubmitHandle(val){
      // todo:处理codeType + code拼接
      if(this.formReveal){
        this.CreateFormData.code = this.CreateFormData.type + this.CreateFormData.codeSuffix
        this.CreateFormData.creator = store.getters.name.userName
      }else{
        this.editFormData.code = this.editFormData.type + this.editFormData.codeSuffix
        this.editFormData.creator = store.getters.name.userName
      }
      this.$nextTick(()=>{
        this.FormSubmit(val)
      })
    },
  }
};
</script>
<style lang="scss" scoped>
@import "../../../styles/basicData.scss";
</style>