<!--
 * @Author: zwq
 * @Date: 2020-12-29 16:37:56
 * @LastEditors: zhp
 * @LastEditTime: 2023-06-20 15:36:04
 * @remark: 报废原因--新增
-->
<template>
  <el-dialog :visible.sync="visible">
    <el-row :gutter="15">
      <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-row>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">{{ $t('cancel') }}</el-button>
      <el-button type="primary" @click="dataFormSubmit()">{{ $t('confirm') }}</el-button>
    </span>
    <base-dialog :dialogTitle="addOrEditTitle" :dialogVisible="addOrUpdateVisible" @cancel="handleCancel" append-to-body
      @confirm="handleConfirm" :before-close="handleCancel">
      <parameterShow-add ref="addOrUpdate" @refreshDataList="successSubmit">
      </parameterShow-add>
    </base-dialog>
  </el-dialog>
</template>

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

// import gage from '@/filters/gage'
import { timeFormatter } from '@/filters'
import parameterShowAdd from './parameterShow-add'
// import available from "./components/available.vue"
import basicSearch from "@/mixins/basic-search"
import i18n from "@/i18n"
const tableProps = [
  {
    prop: 'batchNumber',
    label: i18n.t("gage.batchTail"),
    align: 'center'
  },
  {
    prop: 'gageName',
    label: i18n.t("gage.gageName"),
    align: 'center'
  },
  {
    prop: 'measuringToolAccuracy',
    label: i18n.t("gage.measuringToolAccuracy"),
    align: 'center'
  },
  {
    prop: 'parameter',
    label: i18n.t("gage.parameter"),
    align: 'center'
  },
  {
    prop: 'price',
    label: i18n.t("gage.price"),
    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: {
    parameterShowAdd
  },
  data() {
    return {
      urlOptions: {
        getDataListURL: "/gage/qmsStationDeviationAnalysis/page",
        deleteURL: "/gage/qmsStationDeviationAnalysis",
        // exportUrl: '/nonconform/qmsNonconformityReviewSheet/export'
      },
      tableProps,
      tableBtn,
      visible: false,
      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: {
    //search-bar点击
    init(id,) {
      // this.dataForm.id = id || ""
      // console.log(11111)
      // this.dataForm.dictTypeId = dictTypeId || "";
      this.visible = true
      this.$nextTick(() => {
        this.listQuery.gageResumeId = id 
        console.log(this.listQuery.gageResumeId)
        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>
