<!--
 * @Author: zhp
 * @Date: 2023-07-18 10:25:03
 * @LastEditTime: 2023-07-18 11:23:59
 * @LastEditors: zhp
 * @Description: 
-->
<template>
  <el-card shadow="never" class="aui-card--fill">
    <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" />
      <!-- 弹窗, 新增 / 修改 -->
      <base-dialog :dialogTitle="addOrEditTitle" :dialogVisible="addOrUpdateVisible" @cancel="handleCancel"
        @confirm="handleConfirm" :before-close="handleCancel">
        <!-- <product-add ref="addOrUpdate" @refreshDataList="successSubmit"></product-add> -->
        <!-- <el-row slot="footer" type="flex" justify="end"> </el-row> -->
      </base-dialog>
      <characterShow ref="characterShowList" v-if="characterShowList" @refreshDataList="getDataList">
      </characterShow>
      <!-- <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-card>
</template>

<script>
import basicPage from "@/mixins/basic-page";
// import basicSearch from "@/mixins/basic-search";
// import productSearch from "./components/productSearch.vue";
// import productAdd from "./components/product-add.vue";
import isHave from "./components/isHave.vue";
import characterShow from "./components/character-show.vue";

// import radio from "./components/radio.vue";
import i18n from "@/i18n";
// import i18n from "@/i18n";
const tableProps = [
  {
    prop: "productCode",
    label: i18n.t('basic.code'),
  },
  {
    prop: "productName",
    label: i18n.t('basic.name'),
  },
  {
    prop: "productSpecs",
    label: i18n.t('basic.specification'),
  },
  {
    prop: "productTypeName",
    label: i18n.t('basic.productTypeName'),
  },
  // {
  //   prop: "detail",
  //   label: i18n.t('basic.InspectionStage'),
  //   subcomponent: radio,
  // },
  {
    prop: "inspectionPlan",
    label: i18n.t('quality.inspectionPlan'),
    subcomponent: isHave,
  },
];
const tableBtn = [
  {
    type: "characteristics",
    btnName: i18n.t('code.characteristics'),
  }
];
export default {
  mixins: [basicPage],
  data() {
    return {
      urlOptions: {
        getDataListURL: "/basic/qmsProduct/page",
        deleteURL: "/basic/qmsProduct",
        exportURL: '/basic/qmsProduct/export',
        getProductTypeURL: '/basic/qmsProductType/page'
      },
      tableProps,
      tableBtn,
      productData: {},
      characterShowList:false,
      searchOrEditTitle: "",
      searchOrUpdateVisible: false,
      productOrEditTitle: "",
      addOrEditTitle: '',
      addOrUpdateVisible: false,
      productOrUpdateVisible: false,
      formConfig: [
        {
          type: 'input',
          label: i18n.t('basic.productCode'),
          placeholder: i18n.t('basic.productCode'),
          param: 'productName',
          clearable: true
        },
        {
          type: 'input',
          label: i18n.t('basic.productName'),
          placeholder: i18n.t('basic.productName'),
          param: 'productCode',
          clearable: true
        },
        {
          type: 'input',
          label: i18n.t('basic.specification'),
          placeholder: i18n.t('basic.specification'),
          param: 'productSpecs',
          clearable: true
        },
        {
          type: 'select',
          label: i18n.t('code.inspectionPlan'),
          placeholder: i18n.t('code.inspectionPlan'),
          param: 'inspectionPlan',
          selectOptions: [
            {
              id: '0',
              name: '没有'
            },
            {
              id: '1',
              name: '有'
            },
          ],
          clearable: true,
          filterable: true
        },
        {
          type: 'select',
          label: i18n.t('code.productType'),
          placeholder: i18n.t('code.productType'),
          param: 'productTypeId',
          selectOptions: [],
          clearable: true,
          filterable: true
        },
        {
          type: "button",
          btnName: "搜索",
          name: "search",
          color: "primary",
          // plain: true,
        }
      ],
    };
  },
  components: {
    // productAdd
    characterShow
  },
  mounted () {
    this.getDict()
  },
  methods: {
    //search-bar点击
    handleProductCancel() {
      this.productOrUpdateVisible = false;
      this.productOrEditTitle = "";
    },
    setCurrent(index) {
      this.$refs.palletTable1.setCurrent("palletTable", index);
    },
    // handleSearchCancel() {
    //   this.searchOrEditTitle = "";
    //   this.searchOrUpdateVisible = false;
    // },
    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) {
     if (val.type === 'characteristics') {
       this.characterShowList = true
        this.$nextTick(() => {
          this.$refs.characterShowList.init(val.data.id)
        })
      }
    },
    getDict() {
      this.$http
        .get(this.urlOptions.getProductTypeURL, {
          params: this.listQuery,
        })
        .then(({ data: res }) => {
          if (res.code == 0) {
            this.formConfig[4].selectOptions = res.data.list.map((item) => {
              return {
                id:item.id,
                name: item.productTypeName,
              }
            })
          }
        })
    },
    buttonClick(val) {
      console.log(val);
      switch (val.btnName) {
        case "search":
          // this.listQuery.paramCode = val.paramCode;
          this.listQuery.productName = val.productName ? val.productName : null
          this.listQuery.productCode = val.productCode ? val.productCode : null
          this.listQuery.productTypeId = val.productTypeId ? val.productTypeId : null
          this.listQuery.productSpecs = val.productSpecs ? val.productSpecs : null
          this.listQuery.inspectionPlan = val.inspectionPlan ? val.inspectionPlan : null

          // console.log(i18n);
          this.listQuery.page = 1;
          this.getDataList();
          break;
        case "add":
          this.addOrEditTitle = '新增'
          this.addOrUpdateVisible = true
          this.addOrUpdateHandle()
          break;
        default:
          console.log(val);
      }
    },
  },
};
</script>
