<!--
 * @Author: zhp
 * @Date: 2023-05-08 11:11:06
 * @LastEditTime: 2023-07-13 09:18:15
 * @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="6" 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">
        <qmsGageResume-add ref="addOrUpdate" @refreshDataList="successSubmit">
        </qmsGageResume-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">
        <gageResume-search ref="searchOrUpdate" @refreshDataList="conditionSearchSubmit">
        </gageResume-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>
      <parameter-show v-if="showParameterVisible" ref="showParameterOrUpdate" @refreshDataList="getDataList" />
    </div>
  </el-card>
</template>

<script>
import basicPage from "@/mixins/basic-page"
import parameterShow from './components/parameter-show'

import qmsGageResumeAdd from "./components/qmsGageResume-add"
// import gage from '@/filters/gage'
import { timeFormatter } from '@/filters'
import gage from '@/filters/gage'
// import AddOrUpdate from './params-add-or-update'
import gageResumeSearch from "./components/gageResumeSearch"
// import available from "./components/available.vue"
import basicSearch from "@/mixins/basic-search"
import i18n from "@/i18n"
const tableProps = [
  {
    prop: 'gageCode',
    label: i18n.t("gage.gageCode"),
    align: 'center'
  },
  {
    prop: 'gageName',
    label: i18n.t("gage.gageName"),
    align: 'center'
  },
  {
    prop: 'measurToolEvent',
    label: i18n.t("gage.measurToolEvent"),
    align: 'center',
    filter: gage('eventList')
  },
  {
    prop: 'createDate',
    label: i18n.t("gage.createDate"),
    filter: timeFormatter,
    align: 'center'
  },
  {
    prop: 'recipientName',
    label: i18n.t("gage.recipientName"),
    align: 'center'
  },
  {
    prop: 'userDepartment',
    label: i18n.t("gage.userDepartment"),
    align: 'center'
  },
  {
    prop: 'useLocation',
    label: i18n.t("gage.useLocation"),
    align: 'center'
  },
  {
    prop: 'remark',
    label: i18n.t("gage.remark"),
    align: 'center'
  }
  // {
  //   prop: 'measurementType',
  //   label: i18n.t("gage.measurementType"),
  //   align: 'center',
  //   filter: gage('measurementType'),
  // }
]
const tableBtn = [
  {
    type: "edit",
    btnName: "编辑",
  },
  {
    type: "delete",
    btnName: "删除",
  },
  {
    type: "parameter",
    btnName: "台差参数",
    showParam: {
      type: '&',
      data: [
        {
          name: 'measurToolEvent',
          type: 'equal',
          value: 5
        }
      ]
    }
  }
];
export default {
  mixins: [basicPage, basicSearch],
  components: {
    gageResumeSearch,
    qmsGageResumeAdd,
    parameterShow
  },
  data() {
    return {
      urlOptions: {
        getDataListURL: "/gage/qmsGageResume/page",
        deleteURL: "/gage/qmsGageResume",
        // exportUrl: '/nonconform/qmsNonconformityReviewSheet/export'
      },
      tableProps,
      tableBtn,
      showParameterVisible:false,
      searchOrEditTitle: '',
      searchOrUpdateVisible: false,
      formConfig: [
        {
          type: "button",
          btnName: i18n.t('add'),
          name: "add",
          color: "success",
          plain:true
        },
        {
          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.gageName = dataForm.gageName
      this.listQuery.gageCode = dataForm.gageCode
      this.listQuery.measurToolEvent = dataForm.measurToolEvent
      this.listQuery.process = dataForm.process
      this.listQuery.startTime = dataForm.timeSlot ? dataForm.timeSlot[0] : null
      this.listQuery.endTime = dataForm.timeSlot ? dataForm.timeSlot[1] : null
      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.showParameterVisible = true
        this.$nextTick(() => {
          console.log(Object.prototype.toString.call(val.data.id) )
          this.$refs.showParameterOrUpdate.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>
