<!--
 * @Author: zwq
 * @Date: 2020-12-29 16:37:56
 * @LastEditors: zhp
 * @LastEditTime: 2023-06-20 15:35:58
 * @remark: 报废原因--新增
-->
<template>
  <el-drawer :title="$t('gage.verifyLog')" :visible.sync="visible" :direction="direction" size="50%"
    :close-on-press-escape="true">
    <div class="demo-drawer__content">
      <el-tabs v-model="tabValue" @tab-click="clickTabs" :tab-position="tabPosition" style="height: 200px;">
        <el-tab-pane name="0" :label="$t('gage.insideVerify')">
          <SearchBar :formConfigs="formConfig" ref="ruleForm" @headBtnClick="buttonClick">
          </SearchBar>
          <base-table :table-props="tableProps" :page="listQuery.page" :limit="listQuery.limit" :table-data="tableData">
            <method-btn v-if="tableBtn.length" slot="handleBtn" :width="100" label="操作" :method-list="tableBtn"
              @clickBtn="handleClick" />
          </base-table>
          <pagination :limit.sync="listQuery.limit" :page.sync="listQuery.page" :total="listQuery.total"
            @pagination="getDataList" />
        </el-tab-pane>
        <el-tab-pane name="1" :label="$t('gage.outsideVerify')">
          <SearchBar :formConfigs="formConfig" ref="ruleForm" @headBtnClick="buttonClick">

          </SearchBar>
          <base-table :table-props="tableProps" :page="listQuery.page" :limit="listQuery.limit" :table-data="tableData">
            <method-btn v-if="tableBtn.length" slot="handleBtn" :width="100" label="操作" :method-list="tableBtn"
              @clickBtn="handleClick" />
          </base-table>
          <pagination :limit.sync="listQuery.limit" :page.sync="listQuery.page" :total="listQuery.total"
            @pagination="getDataList" />
        </el-tab-pane>
      </el-tabs>
    </div>
    <base-dialog :dialogTitle="addOrEditTitle" :dialogVisible="addOrUpdateVisible" @cancel="handleCancel" append-to-body
      @confirm="handleConfirm" :before-close="handleCancel">
      <verifyShow-add ref="addOrUpdate" @refreshDataList="successSubmit">
      </verifyShow-add>
    </base-dialog>
  </el-drawer>

</template>

<script>
import basicPage from "@/mixins/basic-page"
import basicAdd from "@/mixins/basic-add"

// import gage from '@/filters/gage'
import { timeFormatter } from '@/filters'
import gage from '@/filters/gage'

import verifyShowAdd from './verifyShow-add'
// import available from "./components/available.vue"
import basicSearch from "@/mixins/basic-search"
import i18n from "@/i18n"
const tableProps = [
  {
    prop: 'client',
    label: i18n.t("gage.client"),
    align: 'center'
  },
  {
    prop: 'certificateNo',
    label: i18n.t("gage.certificateCode"),
    align: 'center'
  },
  {
    prop: 'gageName',
    label: i18n.t("gage.gageName"),
    align: 'center'
  },
  {
    prop: 'parityBit',
    label: i18n.t("gage.parityBit"),
    align: 'center',
    filter: gage('verifyType'),
  },
  {
    prop: 'inspectionTime',
    label: i18n.t("gage.inspectionTime"),
    align: 'center',
    filter: timeFormatter
  },
  {
    prop: 'calibrationUnit',
    label: i18n.t("gage.calibrationUnit"),
    align: 'center'
  },
  {
    prop: 'calibrationDepartment',
    label: i18n.t("gage.calibrationDepartment"),
    align: 'center'
  },
  {
    prop: 'checker',
    label: i18n.t("gage.checker"),
    align: 'center'
  },
  {
    prop: 'verificationResult',
    label: i18n.t("gage.verificationResult"),
    align: 'center'
  },
  {
    prop: 'remark',
    label: i18n.t("gage.remark"),
    align: 'center'
  }
]
const tableBtn = [
  {
    type: "edit",
    btnName: "编辑",
  },
  {
    type: "delete",
    btnName: "删除",
  }
];
export default {
  mixins: [basicPage, basicSearch, basicAdd],
  components: {
    verifyShowAdd
  },
  data() {
    return {
      urlOptions: {
        getDataListURL: "/gage/qmsGageVerification/page",
        deleteURL: "/gage/qmsGageVerification",
        // exportUrl: '/nonconform/qmsNonconformityReviewSheet/export'
      },
      direction: 'ttb',
      tableProps,
      tableBtn,
      tabValue: 0,
      visible: false,
      gageId:null,
      tabPosition:'left',
      addOrUpdateVisible:false,
      showParameterVisible: false,
      searchOrEditTitle: '',
      addOrEditTitle:'',
      searchOrUpdateVisible: false,
      formConfig: [
        {
          type: "button",
          btnName: i18n.t('add'),
          name: "add",
          color: "primary",
        },
        {
          type: "button",
          btnName: i18n.t('search'),
          name: "search",
          color: "primary",
        }
      ],
    };
  },
  // components: {
  //   AddOrUpdate,
  // },
  methods: {
    handleClose() {
      this.visible  = true
    },
    clickTabs(el) {
      this.listQuery.gageId =this.gageId
      this.listQuery.parityBit = Number(el.name)
      this.getDataList()
    },
    //search-bar点击
    init(id,) {
      this.gageId = id || ""
      this.visible = true
      this.$nextTick(() => {
        this.listQuery.gageId = id ? id : ''
        this.listQuery.parityBit = Number(this.tabValue)
        this.getDataList()
        // this.$refs["dataForm"].resetFields();
        // if (this.dataForm.id) {
        //   this.getInfo()
        // } else {
        //   // this.getCode()
        // }
      });
    },
    handleProductCancel() {
      this.productOrUpdateVisible = false;
      this.productOrEditTitle = "";
    },
    // handleSearchCancel() {
    //   this.searchOrEditTitle = "";
    //   this.searchOrUpdateVisible = false;
    // },
    conditionSearch() {
      this.searchOrEditTitle = "搜索";
      this.searchOrUpdateVisible = true;
      this.$nextTick(() => {
        this.$refs.searchOrUpdate.init();
      });
    },
    conditionSearchSubmit(dataForm) {
      this.listQuery.page = 1
      this.getDataList();
      this.searchOrUpdateVisible = false;
      // console.log(11111);
      // this.conditionSearchSubmit();
    },
    handleClick(val) {
      console.log(val);
      if (val.type === "delete") {
        this.$confirm(`确定对[名称=${val.data.name}]进行删除操作?`, "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            this.$http.delete(this.urlOptions.deleteURL, { data: [val.data.id] }).then(({ data }) => {
              if (data && data.code === 0) {
                this.$message({
                  message: "操作成功",
                  type: "success",
                  duration: 1500,
                  onClose: () => {
                    this.getDataList();
                  },
                });
              } else {
                this.$message.error(data.msg);
              }
            });
          })
          .catch(() => { });
      } else if (val.type === 'edit') {
        this.addOrUpdateVisible = true
        this.addOrEditTitle = this.$t('edit')
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(val.data.id)
        });
      }
    },
    buttonClick(val) {
      switch (val.btnName) {
        case "search":
          // this.listQuery.paramCode = val.paramCode;
          this.listQuery.page = 1
          this.getDataList();
          break;
        case "export":
          // this.listQuery.paramCode = val.paramCode;
          this.listQuery.page = 1
          this.exportHandle();
          break;
        case "add":
          this.addOrEditTitle = '新增'
          this.addOrUpdateVisible = true;
          this.addOrUpdateHandle()
          break;
        default:
          console.log(val)
      }
    },
  }
};
</script>
