<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">
      <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="added"
        align="center"
        :formatter="added"
        label="商品状态"
      >
      </el-table-column>
      <el-table-column prop="realSales" align="center" label="实际销量">
      </el-table-column>
      <el-table-column prop="isJoin" align="center" label="是否已参加秒杀">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.isJoin">是</el-tag>
          <el-tag v-else type="success">否</el-tag>
        </template>
      </el-table-column>

      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        label="操作"
      >
        <template slot-scope="scope" v-if="scope.row.isJoin == false">
          <el-button
            type="text"
            size="small"
            @click="addOrUpdateHandle(scope.row.productId, scope.row.productSkuSetList || [])"
            >添加</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"
      @updataList="getBack"
    ></ActivityPdAdd>
  </div>
</template>

<script>
import getListApi from "@/mixins/getListApi";
import ActivityPdAdd from "./components/ActivityPdAdd";
import { productForActivityPage } from "@/api/goods";
// import seviceApi from "@/api/serviceApi.js";

export default {
  mixins: [getListApi],
  data() {
    return {
      listURL: productForActivityPage,
      initializationShow: false,
    };
  },
  components: {
    ActivityPdAdd,
  },
  mounted() {
    this.queryParams.seckillId = this.$route.query.seckillId;
    this.getList();
  },
  methods: {
    // updataList() {
    //   this.$router.go(-1);
    // },
    added(row, column) {
      let status = row.shelvedStatus;
      if (status === true) {
        return "上架";
      } else {
        return "下架";
      }
    },
    // 新增
    addOrUpdateHandle(productId, skuList) {
      skuList = skuList.map(v=>{
        v.originalSalePrice = v.originalSalePrice ? v.originalSalePrice * 1 : v.salePrice * 1;
        v.salePrice = v.salePrice * 1;
        v.id = undefined;
        v.originalStock = v.stock ? v.stock * 1 : 0;
        v.stock = 0;
        v.createTime = undefined;
        v.updateTime = undefined;
        return v;
      });
      this.$nextTick(() => {
        this.$refs.activityPdAddRef.init("", this.queryParams.seckillId, productId, skuList);
      });
    },
    // 返回管理商品
    getBack() {
      this.$tab.closeOpenPage();
      this.$router.go(-1);
    },
  },
};
</script>
<style>
.mb10 {
  margin-bottom: 10px;
}
</style>
