<template>
  <div class="pintuanActive">
    <div class="head-title">
      拼团活动
      <el-button style="float:right;margin-top: -5px;" size="small" @click="CommonJump('pintuanActive')" type="primary">
        新建活动</el-button>
    </div>
    <div class="content">
      <div>
        <el-tabs v-model="activeName" @tab-click="handleClick">
          <el-tab-pane :dataId="0" label="全部" name="first"></el-tab-pane>
          <el-tab-pane :dataId="1" label="未开始" name="second"></el-tab-pane>
          <el-tab-pane :dataId="2" label="进行中" name="third"></el-tab-pane>
          <el-tab-pane :dataId="3" label="已结束" name="fourth"></el-tab-pane>
          <el-tab-pane :dataId="4" label="下架中" name="fifth"></el-tab-pane>
        </el-tabs>
      </div>
      <div>
        <span>活动时间：</span>
        <el-date-picker v-model="dateList" @change="msg.pageIndex=1,getList()" size="small" type="datetimerange"
          range-separator="至" value-format="yyyy-MM-dd HH:mm:ss" start-placeholder="开始日期" end-placeholder="结束日期">
        </el-date-picker>
        <div class="searchInput" style="width:250px;margin-right: 0px;">
          <el-input @keyup.enter.native="msg.pageIndex=1,getList()" style="display:inline-block;width:225px;height:30px"
            placeholder="请输入商品名称搜索" v-model="msg.QGoodName" @clear="msg.pageIndex=1,getList()" size="small" clearable>
          </el-input>
          <span @click="msg.pageIndex=1,getList()" class="el-icon-search"
            style="color:#979dad;font-size:14px;position:relative;top:1px"></span>
        </div>
        <span @click="Clearconditions" v-if="msg.QGoodName!='' || (dateList && dateList.length>0)"
          class='blue point'>清空筛选条件</span>
      </div>
      <div style="margin-top:15px">
        <el-button @click="tableSet(4)" style="margin-left:10px;" size="mini">上架</el-button>
        <el-button @click="tableSet(5)" style="margin-left:10px;" size="mini">下架</el-button>
        <el-button @click="tableSet(6)" style="margin-left:10px;" size="mini">删除</el-button>
      </div>
      <el-table :data="tableData" v-loading="loading" border @selection-change="tableSelect"
        style="width: 100%;margin:20px 0">
        <el-table-column type="selection" width="55">
        </el-table-column>
        <el-table-column prop="GoodId" width="120" label="商品ID">
        </el-table-column>
        <el-table-column label="商品名称" width="320">
          <template slot-scope="scope">
            <div class="cell">
              <div flex="box:first">
                <div style="padding-right:10px;">
                  <div class="app-image" :style="{backgroundImage:'url(' + scope.row.Cover_Img + ')'}"></div>
                </div>
                <div class="app-ellipsis">
                  <div class="vue-line-clamp" style="word-break:break-all;-webkit-line-clamp: 2;" >
                    {{scope.row.QGoodName}}</div>
                </div>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="Goods_Stock" label="库存">
        </el-table-column>
        <el-table-column label="活动时间" min-width="180">
          <template slot-scope="scope">
            <div style="width:160px;">
              <div>{{scope.row.StartTimeStr}}至</div>
              <div>{{scope.row.EndTimeStr}}</div>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="GroupList" width="200" label="拼团组/拼团价">
          <template slot-scope="scope">
            <div class="cell">
              <div flex="dir:top">
                <div v-for="(SubItem,SubIndex) in scope.row.GroupList" :key="SubIndex">
                  <el-tag style="margin-bottom:10px;">{{SubItem.People_Num}}人|￥<template v-if="SubItem.StepPriceList&&SubItem.StepPriceList.length>0">{{SubItem.StepPriceList[0].PinTuanPrice}}</template></el-tag>
                </div>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="GoodsStatusStr" width="100" label="活动状态">
          <template slot-scope="scope">
            <el-tag>{{scope.row.GoodsStatusStr}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="address" label="操作" min-width="130">
          <template slot-scope="scope">
            <el-tooltip class="item" effect="dark" content="编辑" placement="top">
              <img style="width:32px;height:32px;margin:0 10px" @click="CommonJump('pintuanActive',{Id:scope.row.ActivityId})" src="../../assets/img/userman/edit.png" alt="">
            </el-tooltip>
            <el-tooltip class="item" effect="dark" content="活动数据" placement="top">
              <img style="width:32px;height:32px;margin:0 10px" @click="CommonJump('ActiveDataDetail',{Id:scope.row.ActivityId})" src="../../assets/img/userman/order.png" alt="">
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination style="text-align:right" background @current-change="handleCurrentChange" :page-size="msg.pageSize"
        layout="prev, pager, next" :current-page.sync="msg.pageIndex" :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
  export default {
    name: "pintuanActive",
    data() {
      return {
        //日期数组
        dateList: [],
        activeName: 'first',
        msg: {
          pageIndex: 1,
          pageSize: 15,
          QGoodName: '', //商品名称
          QStartDate: '', //开始日期
          QEndDate: '', //结束日期
        },
        tableData:[],//列表数据
        total: 0,
        loading: false,
      }
    },
    created() {
      this.getList();
    },
    methods: {
      //获取数据
      getList() {
        if (this.dateList && this.dateList.length > 0) {
          this.msg.QStartDate = this.dateList[0];
          this.msg.QEndDate = this.dateList[1];
        } else {
          this.msg.QStartDate = '';
          this.msg.QEndDate = '';
        }
        this.loading = true;
        this.apipost("/api/GroupBuy/GetGroupbuyActivityPageList", this.msg, res => {
          this.loading = false;
          if (res.data.resultCode == 1) {
            this.total = res.data.data.count;
            let pageData = res.data.data.pageData;
            this.tableData = pageData;
          }
        })
      },
      // 上架 下架 删除
      tableSet(num) {

      },
      //切换活动状态
      handleClick(val) {
        this.msg.pageIndex = 1
        this.getList();
      },
      handleCurrentChange(val) {
        this.msg.pageIndex = val;
        this.getList();
      },
      //清空筛选条件
      Clearconditions() {
        this.msg.QGoodName = '';
        this.dateList = [];
        this.getList();
      },
      //单选 全选返回数据
      tableSelect() {

      }
    },
  };

</script>
<style>
  .pintuanActive .content {
    background: #fff;
    margin-top: 10px;
    padding: 20px;
    box-sizing: border-box;
  }

  .pintuanActive .app-image {
    background-size: cover;
    background-position: center center;
    width: 50px;
    height: 50px;
  }

</style>
