<template>
  <div class="app-container">
    <!-- <div class="mb10">
      <el-button @click="getBack">返回秒杀列表</el-button>
    </div> -->
    <el-form :inline="true" :model="search" :size="ELsize" v-show="showSearch">
      <el-form-item label="商品名称">
        <el-input
          v-model="search.title"
          placeholder="商品名称"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          :size="ELsize"
          @click="addOrUpdateHandle()"
          >新增</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <el-table :data="dataList" row-key="Id" border style="width: 100%">
      <el-table-column prop="title" align="center" label="商品名称">
      </el-table-column>
      <el-table-column prop="minSalePrice" align="center" label="销售价格">
      </el-table-column>
      <el-table-column prop="minPrice" align="center" label="活动价格">
      </el-table-column>
      <el-table-column prop="limitBuyNum" align="center" label="限购">
        <template slot-scope="scope">
          <span v-if="scope.row.limitBuyNum == 0">不限购</span>
          <span v-else>{{ scope.row.limitBuyNum }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="realStockTotal" align="center" label="可售数量">
      </el-table-column>
      <el-table-column prop="resultSaleNum" align="center" label="已售数量">
      </el-table-column>
      <el-table-column prop="sort" align="center" label="商品排序">
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        label="操作"
      >
        <template slot-scope="scope">
          <el-button
            type="text"
            size="small"
            @click="updateHandle(scope.row.id, scope.row.goodsId)"
            >编辑</el-button
          >
          <el-button
            type="text"
            size="small"
            @click="deleteHandle(scope.row.id)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 弹窗,  修改 -->
    <ActivityPdAdd
      ref="activityPdAddRef"
      :showInventory="false"
      @updataList="updataList"
    ></ActivityPdAdd>
  </div>
</template>

<script>
import getListApi from "@/mixins/getListApi";
import { seckillActivityProductPage_api, seckillActivityProductDel_api } from "@/api/marketing/seckill";

import ActivityPdAdd from "./components/ActivityPdAdd";
// import seviceApi from "@/api/serviceApi.js";

export default {
  mixins: [getListApi],
  data() {
    return {
      listURL: seckillActivityProductPage_api,
      initializationShow: false,
      dataForm: {},
    };
  },
  components: {
    ActivityPdAdd,
  },
  mounted() {
    this.queryParams.seckillId = this.$route.query.id;
    this.getList();
  },
  methods: {
    updataList() {
      this.getList();
    },
    // 新增
    addOrUpdateHandle() {
      this.$router.push({
        path: "/marketing/seckill/seckillPdAddUpdate",
        query: {
          seckillId: this.queryParams.seckillId,
        },
      });
    },
    // 修改
    updateHandle(id, goodsId) {
      this.$nextTick(() => {
        this.$refs.activityPdAddRef.init(id, this.queryParams.seckillId, goodsId);
      });
    },
    // 删除
    deleteHandle(id) {
      this.$confirm(`确定要删除该条数据?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          seckillActivityProductDel_api(id).then((res) => {
            if (res && res.code == 200) {
              this.$message.success("删除成功");
              this.getList();
            }
          });
        })
        .catch(() => {});
    },
    // 返回秒杀列表
    getBack() {
      this.$tab.closeOpenPage();
      this.$router.go(-1);
    },
  },
};
</script>
<style>
.mb10 {
  margin-bottom: 10px;
}
</style>
