<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 id="palletTable" :table-props="tableProps" :page="listQuery.page" ref="palletTable1"
        highlight-current-row :limit="listQuery.limit" :table-data="tableData" @current-change="handleCurrentChange">
        <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>
      <!-- <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 available from "./components/available.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: "remark",
    label: i18n.t('schedule.remark'),
  },
];
const tableBtn = [
  {
    type: "edit",
    btnName: i18n.t('t.edit'),
  },
  {
    type: "delete",
    btnName: i18n.t('t.delete'),
  }
];
export default {
  mixins: [basicPage],
  data() {
    return {
      urlOptions: {
        getDataListURL: "/basic/qmsProduct/page",
        deleteURL: "/basic/qmsProduct",
        exportURL: '/basic/qmsProduct/export',
      },
      tableProps,
      tableBtn,
      productData: {},
      searchOrEditTitle: "",
      searchOrUpdateVisible: false,
      productOrEditTitle: "",
      addOrEditTitle: '',
      addOrUpdateVisible: false,
      productOrUpdateVisible: false,
      formConfig: [
        {
          type: 'input',
          label: i18n.t('basic.name'),
          placeholder: i18n.t('basic.name'),
          param: 'name',
          clearable: true
        },
        {
          type: 'input',
          label: i18n.t('basic.code'),
          placeholder: i18n.t('basic.code'),
          param: 'code',
          clearable: true
        },
        {
          type: "button",
          btnName: "搜索",
          name: "search",
          color: "primary",
          // plain: true,
        },
        {
          type: "button",
          btnName: "新增",
          name: "add",
          color: 'success',
          plain: true
          // plain: true,
        },
        {
          type: "button",
          btnName: "导出",
          name: "export",
          color: "primary",
          plain: true
        }
      ],
    };
  },
  components: {
    productAdd
  },
  methods: {
    //search-bar点击
    handleProductCancel() {
      this.productOrUpdateVisible = false;
      this.productOrEditTitle = "";
    },
    handleCurrentChange(val) {
      console.log(val);
      this.productData = val.newVal ? val.newVal : {}
    },
    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 === "delete") {
        this.$confirm(`确定对[名称=${val.data.customerTypeName}]进行删除操作?`, "提示", {
          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);
        });
      }
    },
    // addOrUpdateHandle(productData) {
    //   this.addOrUpdateVisible = true;
    //   this.$nextTick(() => {
    //     this.$refs.addOrUpdate.init(productData);
    //   });
    // },
    buttonClick(val) {
      console.log(val);
      switch (val.btnName) {
        case "search":
          // this.listQuery.paramCode = val.paramCode;
          this.listQuery.productName =val.name ?val.name: null
          this.listQuery.productCode = val.code ? val.code : null
          // console.log(i18n);
          this.listQuery.page = 1;
          this.getDataList();
          break;
        case "correlation":
          this.productOrEditTitle = "产品";
          this.productOrUpdateVisible = true;
          // this.searchOrUpdateHandle(this.productData);
          // this.searchOrUpdateVisible = true;
          this.$nextTick(() => {
            this.$refs.productOrUpdate.init(this.productData);
          });
          console.log(this.productId);
          break;
        case "add":
          this.addOrEditTitle = '新增'
          this.addOrUpdateVisible = true
          this.addOrUpdateHandle()
          break;
        case "export":
          this.exportHandle()
          break;
        default:
          console.log(val);
      }
    },
  },
};
</script>
