<!--
 * @Author: zhp
 * @Date: 2023-07-18 10:25:03
 * @LastEditTime: 2023-07-18 14:14:55
 * @LastEditors: zhp
 * @Description: 
-->
<template>
  <el-drawer title="特性" :visible.sync="drawer" size="70%">
    <div class="mod-sys__user">
      <SearchBar :formConfigs="formConfig" ref="ruleForm" @headBtnClick="buttonClick">
      </SearchBar>
      <base-table id="palletTable" :table-props="tableProps" :page="listQuery.page" ref="palletTable1"
        :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" />
      <!-- 弹窗, 新增 / 修改 -->
      <characterShowAdd ref="characterShowAddList" v-if="characterShowAddList" @refreshDataList="getDataList">
      </characterShowAdd>
      <!-- <base-dialog :dialogTitle="searchOrEditTitle" :dialogVisible="searchOrUpdateVisible" @cancel="handleSearchCancel"
        @confirm="handleSearchConfirm" :before-close="handleSearchCancel">
        <product-search ref="searchOrUpdate" @successSubmit="conditionSearchSubmit"></product-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-drawer>
</template>

<script>
import basicPage from "@/mixins/basic-page";
// import basicSearch from "@/mixins/basic-search";
// import productSearch from "./components/productSearch.vue";
import characterShowAdd from "./characterShow-add.vue";
import quality from '@/filters/quality'

import i18n from "@/i18n";
// import i18n from "@/i18n";
const tableProps = [
  {
    prop: "processName",
    label: i18n.t('researchquality.processName'),
  },
  {
    prop: "productName",
    label: i18n.t('basic.productName'),
  },
  {
    prop: "inspectionType",
    label: i18n.t('quality.inspectionType'),
    filter: quality('inspectionType')
  },
  {
    prop: "parameterCode",
    label: i18n.t('quality.parameterCode'),
  },
  {
    prop: "parameterName",
    label: i18n.t('quality.parameterName'),
  },
  {
    prop: "measuringToolsType",
    label: i18n.t('quality.measuringToolsType'),
  },
  {
    prop: "specifications",
    label: i18n.t('quality.specifications'),
  },
  {
    prop: "characteristicsType",
    label: i18n.t('quality.characteristicsType'),
    filter: quality('characteristicsType')
  },
  {
    prop: "source",
    label: i18n.t('quality.source'),
  },
  {
    prop: "company",
    label: i18n.t('quality.company'),
  },
  {
    prop: "sampleSize",
    label: i18n.t('quality.sampleSize'),
  },
  {
    prop: "decimalDigits",
    label: i18n.t('quality.decimalDigits'),
  },
  {
    prop: "monitor",
    label: i18n.t('quality.monitor'),
    filter: quality('monitor')
  },
  {
    prop: "analyzeDrawings",
    label: i18n.t('quality.analyzeDrawings'),
  },
  {
    prop: "upperSpecificationLimit",
    label: i18n.t('quality.upperSpecificationLimit'),
  },
  {
    prop: "specificationCenterline",
    label: i18n.t('quality.specificationCenterline'),
  },
  {
    prop: "specificationOffline",
    label: i18n.t('quality.specificationOffline'),
  },
  {
    prop: "targetCpk",
    label: i18n.t('quality.targetCpk'),
  },
  {
    prop: "targetPpk",
    label: i18n.t('quality.targetPpk'),
  },
];
const tableBtn = [
  {
    type: "edit",
    btnName: i18n.t('edit'),
  },
  {
    type: "delete",
    btnName: i18n.t('delete'),
  }
];
export default {
  mixins: [basicPage],
  data() {
    return {
      urlOptions: {
        getDataListURL: "/code/characteristics/page",
        deleteURL: "/code/characteristics",
        exportURL: '/code/characteristics/export',
        // getProductTypeURL: '/basic/qmsProductType/page'
      },
      drawer:false,
      tableProps,
      characterShowAddList:false,
      tableBtn,
      productData: {},
      searchOrEditTitle: "",
      searchOrUpdateVisible: false,
      productOrEditTitle: "",
      addOrEditTitle: '',
      addOrUpdateVisible: false,
      productOrUpdateVisible: false,
      formConfig: [
        // {
        //   type: 'input',
        //   label: i18n.t('basic.productCode'),
        //   placeholder: i18n.t('basic.productCode'),
        //   param: 'name',
        //   clearable: true
        // },
        // {
        //   type: 'input',
        //   label: i18n.t('basic.productName'),
        //   placeholder: i18n.t('basic.productName'),
        //   param: 'code',
        //   clearable: true
        // },
        // {
        //   type: 'input',
        //   label: i18n.t('basic.specification'),
        //   placeholder: i18n.t('basic.specification'),
        //   param: 'code',
        //   clearable: true
        // },
        // {
        //   type: 'select',
        //   label: i18n.t('basic.inspectionPlan'),
        //   placeholder: i18n.t('basic.inspectionPlan'),
        //   param: 'code',
        //   selectOptions: [
        //     {
        //       id: '0',
        //       name: '没有'
        //     },
        //     {
        //       id: '1',
        //       name: '有'
        //     },
        //   ],
        //   clearable: true,
        //   filterable: true
        // },
        // {
        //   type: 'select',
        //   label: i18n.t('code.productType'),
        //   placeholder: i18n.t('code.productType'),
        //   param: 'code',
        //   selectOptions: [],
        //   clearable: true,
        //   filterable: true
        // },
        {
          type: "button",
          btnName: "搜索",
          name: "search",
          color: "primary",
          // plain: true,
        },
        {
          type: "button",
          btnName: "新增",
          name: "add",
          color: "success",
          plain: true
        }
      ],
    };
  },
  components: {
    // productAdd
    characterShowAdd
  },
  mounted() {
    // this.getDict()
  },
  methods: {
    //search-bar点击
    handleProductCancel() {
      this.productOrUpdateVisible = false;
      this.productOrEditTitle = "";
    },
    // handleSearchCancel() {
    //   this.searchOrEditTitle = "";
    //   this.searchOrUpdateVisible = false;
    // },
    init(id) {
      this.listQuery.productId = id || ""
      // console.log(11111)
      // this.dataForm.dictTypeId = dictTypeId || "";
      this.drawer = true
      this.$nextTick(() => {
        // if (this.dataForm.id) {
          this.getDataList()
        // } else {
          // this.getCode()
        // }
      });
    },
    conditionSearch() {
      this.searchOrEditTitle = "搜索";
      this.searchOrUpdateVisible = true;
      this.$nextTick(() => {
        this.$refs.searchOrUpdate.init()
      });
    },
    // handleConfirm() {
    //   this.$refs.addOrUpdate.dataFormSubmitHandle();
    // },
    // conditionSearchSubmit() {},
    conditionSearchSubmit(dataForm) {
      // console.log(key);
      // console.log(key);
      this.listQuery.productName = dataForm.productName
      this.listQuery.productCode = dataForm.productCode
      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.productName}]进行删除操作?`, "提示", {
          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.characterShowAddList = true
        const obj = {
          productId: this.listQuery.productId,
          id:val.data.id
        }
        this.$nextTick(() => {
          this.$refs.characterShowAddList.init(obj)
        });
      }
    },
    // getDict() {
    //   this.$http
    //     .get(this.urlOptions.getProductTypeURL, {
    //       params: this.listQuery,
    //     })
    //     .then(({ data: res }) => {
    //       if (res.code == 0) {
    //         this.formConfig[4].selectOptions = res.data.list
    //       }
    //     })
    // },
    buttonClick(val) {
      console.log(val);
      switch (val.btnName) {
        case "search":
          this.listQuery.page = 1
          this.getDataList()
          break;
        case "add":
          this.characterShowAddList = true
          const obj = {
            productId:this.listQuery.productId
          }
          this.$nextTick(() => {
            this.$refs.characterShowAddList.init(obj)
          })
          break;
        default:
          console.log(val);
      }
    },
  },
};
</script>
