<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'
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/item-quality',
      //常用按钮数据
      currenButtonData: [
        this.defaultAddBtn(),//新增
        this.defaultImportBtn(),//导入
        this.defaultExportBtn(),//导出
        this.defaultFieldSettingBtn(),//字段设置
        this.defaultFreshBtn(),//刷新
        this.defaultFilterBtn(),//筛选
      ],
      //新增
      CreateFormData: {
        code:null,
        codeSuffix:null,
        codeType:"Q",
        stdPackQty:null,
        creationTime:null,
        createUser:null,
      },
      //编辑
      editFormData: {
        code:null,
        codeSuffix:null,
        codeType:"Q",
        stdPackQty:null,
        creationTime:null,
        createUser:null,
        concurrencyStamp: ""
      },
      editOptions: {},
      CreateForm: [
        { type: "prefixInput", label: "器具号", prop: "codeSuffix",prefixProp:"codeType",prefixWidth:'50px',prefixDisabled:true, colSpan: 12 },
        { type: "inputNumber", label: "标包数量", prop: "stdPackQty", colSpan: 12, min:1 },
      ],
      editForm: [
        { type: "prefixInput", label: "器具号", prop: "codeSuffix",prefixProp:"codeType",prefixWidth:'50px',prefixDisabled:true, colSpan: 12 },
        { type: "inputNumber", label: "标包数量", prop: "stdPackQty", colSpan: 12, min:1 },
      ],
      editRules: {
        cerateRule: {
          codeSuffix: [{ required: true, trigger: "blur", message: "不可为空" }],
          stdPackQty: [{ required: true, trigger: "blur", message: "不可为空" }],
        },
        editRule: {
          codeSuffix: [{ required: true, trigger: "blur", message: "不可为空" }],
          stdPackQty: [{ required: true, trigger: "blur", message: "不可为空" }],
        }
      },
    };
  },
  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.codeType = 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.codeType + this.CreateFormData.codeSuffix
      }else{
        this.editFormData.code = this.editFormData.codeType + this.editFormData.codeSuffix
      }
      this.$nextTick(()=>{
        this.FormSubmit(val)
      })
    },
  }
};
</script>
<style lang="scss" scoped>
@import "../../../styles/basicData.scss";
</style>