
<!--
 * @Author: zhp
 * @Date: 2023-01-11 09:24:58
 * @LastEditTime: 2023-06-20 15:36:10
 * @LastEditors: zhp
 * @Description: 
-->
<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-sys__user">
      <SearchBar :formConfigs="formConfig" ref="ruleForm" @headBtnClick="buttonClick">
        <el-badge :value="2" class="item">
          <el-button type="primary" size="small" @click="conditionSearch">条件搜索</el-button>
        </el-badge>
      </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" />
      <!-- 弹窗, 新增 / 修改 -->
      <base-dialog :dialogTitle="addOrEditTitle" :dialogVisible="addOrUpdateVisible" @cancel="handleCancel"
        @confirm="handleConfirm" :before-close="handleCancel">
        <gageVerification-add ref="addOrUpdate" @refreshDataList="successSubmit">
        </gageVerification-add>
        <!-- <el-row slot="footer" type="flex" justify="end"> </el-row> -->
      </base-dialog>
      <base-dialog :dialogTitle="searchOrEditTitle" :dialogVisible="searchOrUpdateVisible" @cancel="handleSearchCancel"
        @confirm="handleSearchConfirm" :before-close="handleSearchCancel">
        <gageVerification-search ref="searchOrUpdate" @refreshDataList="conditionSearchSubmit">
          </gageVerification-search>
          <el-row slot="footer" type="flex" justify="end">
            <el-col :span="12">
              <el-button size="small" type="primary" plain class="btnTextStyle" @click="handleSearchCancel">
                {{ $t("close") }}
              </el-button>
              <el-button size="small" class="btnTextStyle" type="primary" plain @click="handleSearchReset">{{
                $t("reset")
                }}</el-button>
              <el-button type="primary" size="small" class="btnTextStyle" @click="handleSearchConfirm">
                {{ $t("search") }}
              </el-button>
            </el-col>
          </el-row>
      </base-dialog>
    </div>
  </el-card>
</template>

<script>
import basicPage from "@/mixins/basic-page"
import gageVerificationAdd from "./components/gageVerification-add"
// import gageVerificationSearch from "./components/gageVerificationSearch"

// import gage from '@/filters/gage'

// import AddOrUpdate from './params-add-or-update'
import gageVerificationSearch from "./components/gageVerificationSearch"
// import available from "./components/gageAvailable.vue"
import basicSearch from "@/mixins/basic-search"
import i18n from "@/i18n"
const tableProps = [
  {
    prop: 'certificateNo',
    label: i18n.t("gage.certificateCode"),
    align: 'center'
  },
  {
    prop: 'gageName',
    label: i18n.t("gage.gageName"),
    align: 'center'
  },
  {
    prop: 'certificateCodeBh',
    label: i18n.t("gage.certificateCodeBh"),
    align: 'center'
  },
  {
    prop: 'code',
    label: i18n.t("gage.code"),
    align: 'center'
  },
  {
    prop: 'name',
    label: i18n.t("gage.name"),
    align: 'center'
  },
  {
    prop: 'gageTypeName',
    label: i18n.t("gage.gageTypeName"),
    align: 'center'
  },
  {
    prop: 'internalInspectionCycle',
    label: i18n.t("gage.internalInspectionCycle"),
    align: 'center'
  },
  {
    prop: 'internalInspectionTime',
    label: i18n.t("gage.internalInspectionTime"),
    align: 'center'
  },
  {
    prop: 'nextInternalInspectionTime',
    label: i18n.t("gage.nextInternalInspectionTime"),
    align: 'center'
  },
  {
    prop: 'externalInspectionCycle',
    label: i18n.t("gage.externalInspectionCycle"),
    align: 'center'
  },
  {
    prop: 'externalInspectionTime',
    label: i18n.t("gage.externalInspectionTime"),
    align: 'center'
  },
  {
    prop: 'nextExternalInspectionTime',
    label: i18n.t("gage.nextExternalInspectionTime"),
    align: 'center'
  },
  {
    prop: 'description',
    label: i18n.t("gage.description"),
    align: 'center'
  },
  {
    prop: 'gageStatus',
    label: i18n.t("gage.gageStatus"),
    align: 'center'
  },
  // {
  //   prop: 'gageStatus',
  //   label: i18n.t("available"),
  //   subcomponent: available,
  //   align: 'center'
  // },
  {
    prop: 'belongPersonName',
    label: i18n.t("gage.belongPersonName"),
    align: 'center'
  },
]
const tableBtn = [
  {
    type: "edit",
    btnName: "编辑",
  },
  {
    type: "delete",
    btnName: "删除",
  },
  {
    type: "parameter",
    btnName: "台差参数",
  },
];
export default {
  mixins: [basicPage, basicSearch],
  components: {
    gageVerificationSearch,
    gageVerificationAdd
  },
  data() {
    return {
      urlOptions: {
        getDataListURL: "/gage/qmsGageVerification/page",
        deleteURL: "/gage/qmsGageVerification",
        exportUrl: '/gage/qmsGageVerification/export'
      },
      tableProps,
      tableBtn,
      searchOrEditTitle: '',
      searchOrUpdateVisible: false,
      formConfig: [
        // {
        //   type: "",
        //   label: i18n.t("params.paramCode"),
        //   placeholder: i18n.t("params.paramCode"),
        //   param: "paramCode",
        // },
        // {
        //   type: "separate",
        // },
        {
          type: "button",
          btnName: i18n.t('add'),
          name: "add",
          color: "primary",
        },
        {
          type: "button",
          btnName: i18n.t('export'),
          name: "export",
          color: "primary",
        },
        {
          type: "button",
          btnName: i18n.t('search'),
          name: "search",
          color: "primary",
        }
      ],
    };
  },
  // components: {
  //   AddOrUpdate,
  // },
  methods: {
    //search-bar点击
    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.parityBit = dataForm.parityBit
      this.listQuery.startTime = dataForm.timeSlot ? dataForm.timeSlot[0] : null
      this.listQuery.endTime = dataForm.timeSlot ? dataForm.timeSlot[1] : null
      this.listQuery.gageId = dataForm.gageId
      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);
        });
      } else if (val.type === 'parameter') {
        this.$router.push({
          name: 'gage-qmsGageTypeDifferenceParameter',
          query: {
            gageTypeId: val.data.gageTypeId
          }
        })
      } else if (val.type === 'change') {
        const obj = {
          id: val.data.id,
          measurementType: val.data.measurementType,
          name: val.data.name,
          code: val.data.code,
          gageTypeStatus: val.data.gageTypeStatus === 0 ? 1: 0,
          parentId: val.data.parentId
        }
        this.$http.put(this.urlOptions.submitURL, obj)
          .then(({ data: res }) => {
            if (res.code !== 0) {
              return this.$message.error(res.msg);
            }
            this.$message({
              message: this.$t("prompt.success"),
              type: "success",
              duration: 500,
              onClose: () => {
                this.getDataList()
              },
            });
          })
      }
    },
    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>
