<template>
  <div>
    <search-box-new
      ref="searchBox"
      :formData="formData"
      :formList="formList"
      @search="search"
      @init="init"
    />
    <table-list
      :tableSets="tableSet"
      :tableData="tableData"
      :navText="navText"
      :loading="loading"
    >
      <template slot="btn" slot-scope="props">
        <el-button type="text" @click="openStudentDialog(props.scope.row)"
          >立即下单</el-button
        >
        <el-button type="text" @click="goGoodsDetail(props.scope.row)"
          >查看详情</el-button
        >
        <el-button type="text" @click="del(props.scope.row)"
          >取消收藏</el-button
        >
      </template>
    </table-list>
    <pagination
      :total="total"
      :pageSize="formData.pageSize"
      :currentPage="formData.pageNum"
      @handleSizeChange="handleSizeChange"
      @handleCurrentChange="handleCurrentChange"
    />
    <studentDialog ref="studentDialog" />
  </div>
</template>
    
<script>
import searchBoxNew from "@/components/searchBoxNew";
import tableList from "@/components/tableList";
import pagination from "@/components/pagination";
import studentDialog from "../studentDialog/index.vue";
import { mapGetters } from 'vuex';
export default {
  components: {
    searchBoxNew,
    tableList,
    pagination,
    studentDialog,
  },
  data() {
    return {
      loading: false, //当前表单加载是否加载动画
      navText: {
        title: "收藏商品",
        index: 0,
        ch: "条",
        addHide: true,
        custom: false,
        choice: false,
        backFatherBtn: {
          status: false,
          title: "未定义",
        },
      },
      //搜索
      formList: [
        {
          prop: "type",
          placeholder: "商品类型",
          scope: "select",
          options: [
            {
              label: "课程",
              value: 1,
            },
            {
              label: "题库",
              value: 2,
            },
            {
              label: "直播",
              value: 6,
            },
            {
              label: "商品包",
              value: 10,
            },
          ],
        },
        {
          prop: "educationId",
          placeholder: "教育类型",
          scope: "educationType",
        },
        {
          prop: "businessId",
          placeholder: "业务层次",
          scope: "businessLevel",
          edu: "educationId",
        },
        {
          prop: "goodsName",
          placeholder: "输入商品名称",
        },
      ],
      formData: {
        pageSize: 10,
        pageNum: 1,
      },
      tableSet: [
        {
          label: "主图",
          prop: "mainImg",
          scope: "img",
          hidden: true,
        },
        {
          label: "商品类型",
          prop: "typeName",
          hidden: true,
        },
        {
          label: "商品名称",
          prop: "goodsName",
          hidden: true,
        },
        {
          label: "教育类型",
          prop: "educationName",
          hidden: true,
        },
        {
          label: "业务层次",
          prop: "projectName",
          hidden: true,
        },
        {
          label: "专业",
          prop: "subjectName",
          hidden: true,
        },
        {
          label: "商品",
          prop: "goods",
          hidden: true,
        },
        {
          label: "年份",
          prop: "year",
          hidden: true,
        },
        {
          label: "价格",
          prop: "price",
          hidden: true,
        },
      ],
      tableData: [], //表单数据
      total: 0, //一共多少条
    };
  },
  mounted() {
    this.search();
  },
  activated() {
    // this.search();
  },
  methods: {
    // 立即下单（打开学员弹窗）
    openStudentDialog(row) {
      this.$refs.studentDialog.openBoxs(row);
    },
    // 跳转商品详情页
    goGoodsDetail(row) {
      console.log(row, "查看商品详情");
      if (row.goodsType == 10) {
        // 跳转商品包详情
        this.$router.push({
          path: "/goodsPackDetail/" + row.configId,
        });
      } else {
        // 跳转课程详情
        this.$router.push({
          path: "/goodsCourseDetail/" + row.goodsId,
        });
      }
    },
    search(int) {
      this.loading = true;
      if (int === 1) {
        this.formData.pageNum = 1;
      }
      if (int === 2) {
        this.formData = {
          pageSize: 10,
          pageNum: 1,
        };
      }
      var data = JSON.parse(JSON.stringify(this.formData));
      this.$api
        .getGoodsCollectList(data)
        .then((res) => {
          this.tableData = res.rows;
          this.total = res.total;
          this.navText.index = res.total;
        })
        .finally(() => {
          this.loading = false;
        });
    },
    /**
     * 删除
     */
    del(row) {
      this.$alert("确定取消收藏吗？", "提示", {
        dangerouslyUseHTMLString: true,
      })
        .then(() => {
          const params = {};
          row.goodsType == 10
            ? (params.configId = row.configId)
            : (params.goodsId = row.goodsId);
          this.$api.delGoodsCollect(params).then((res) => {
            this.$message.success("操作成功~");
            this.search(1);
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消操作",
          });
        });
    },
    init() {
      this.search(2);
    },
    handleSizeChange(v) {
      this.formData.pageSize = v;
      this.formData.pageNum = 1;
      this.search();
    },
    handleCurrentChange(v) {
      this.formData.pageNum = v;
      this.search();
    },
  },
};
</script>
    
<style lang="less" scoped>

</style>
    
    