<template>
  <div class="setupActivityList">
    <div class="el-card__header">
      <span>活动管理</span>
      <div style="display: flex;flex-direction: row;align-items: center">
        <el-button type="primary" class="el-button--small" @click="gowinning()">中奖列表</el-button>
        <el-button type="primary" class="el-button--small" @click="addRecharge">新增</el-button>
      </div>
    </div>
    <div class="content">
      <div style="display: flex;flex-direction: row;align-items: center">
        <div class="block">
          <div class="searchInput" style="width:250px">
            <el-input style="display:inline-block;width:225px;height:30px"
                      placeholder="请输入活动名称搜索"
                      v-model="msg.ActivityName"
                      size="small"
                      @clear="getList"
                      @keyup.enter.native="getList"
                      clearable>
            </el-input>
            <span @click="getList" class="el-icon-search" style="color:#979dad;font-size:14px;position:relative;top:1px"></span>
          </div>
          <span style="margin-left:15px">是否启用：</span>
          <el-select class="w120" @change="msg.pageIndex=1,getList()" v-model="msg.Enable" size="small"
                     placeholder="请选择">
            <el-option label="不限" :value="0"></el-option>
            <el-option label="是" :value="1"></el-option>
            <el-option label="否" :value="2"></el-option>

          </el-select>
        </div>
      </div>
    </div>


    <div style="padding: 20px;background: #fff;">
      <el-table
        :data="tableData"
        header-cell-class-name="headClass"
        style="width: 100%"
        border
      >

        <el-table-column
          prop="Id"
          label="Id"
          width="60">
        </el-table-column>

        <el-table-column
          prop="ActivityName"
          label="活动名称">
          <template slot-scope="scope">
            <div class="app-image" :style="{backgroundImage:'url(' + scope.row.CoverImage + ')',backgroundSize:'cover'}"></div>
            <div flex="dir:left cross:center">
              {{scope.row.ActivityName}}
            </div>


          </template>
        </el-table-column>
        <el-table-column
          prop="Type"
          label="活动规则">
          <template slot-scope="scope">
            <div v-if="scope.row.Type==1">订单数量：{{scope.row.OrderNum}}单</div>
            <div v-if="scope.row.Type==2">订单金额：{{scope.row.OrderNum}}元</div>
            <div v-if="scope.row.Type==3">商品数量：{{scope.row.OrderNum}}个</div>

            <div v-if="scope.row.Tier==0">层级范围：全部</div>
            <div v-if="scope.row.Tier==1">层级范围：一级分销</div>
            <div v-if="scope.row.Tier==2">层级范围：二级分销</div>
            <div v-if="scope.row.Tier==3">层级范围：三级分销</div>
          </template>
        </el-table-column>
        <el-table-column
          prop="Type"
          label="活动奖励信息">
          <template slot-scope="scope">
            <div class="app-image" :style="{backgroundImage:'url(' + scope.row.PrizeImage + ')',backgroundSize:'cover'}"></div>
            <div flex="dir:left cross:center">
              {{scope.row.PrizeName}}
            </div>
          </template>
        </el-table-column>


        <el-table-column
          label="范围类型"
          prop="RangeType" width="300">
          <template slot-scope="scope">
            <div >{{scope.row.RangeType==1?'分类':'指定商品'}}</div>
            <span style="font-size: 12px;color: #409EFF" v-for="(x,y) in scope.row.RangeList" :key="y">{{x.Name}}{{y+1==scope.row.RangeList.length?'':'、'}}</span>
          </template>
        </el-table-column>

        <el-table-column
          label="活动时间"
          prop="StartTime" width="200">
          <template slot-scope="scope">
            <div>开始时间：{{scope.row.StartTime}}</div>
            <div>结束时间：{{scope.row.EndTime}}</div>
            <div>兑换期限：{{scope.row.ReceiveTime}}</div>
          </template>

        </el-table-column>
        <el-table-column
          label="验证码"
          prop="CodeLength" width="80">
          <template slot-scope="scope">
            <div >{{scope.row.CodeLength}}位</div>

          </template>
        </el-table-column>

        <el-table-column
          label="状态"
          prop="Enable" width="60">
          <template slot-scope="scope">
            <div >{{scope.row.Enable==1?'启用':'禁用'}}</div>

          </template>
        </el-table-column>
        <el-table-column
          label="创建时间"
          prop="CreateDate" width="120">
          <template slot-scope="scope">
            <div>{{scope.row.CreateDate}}</div>
          </template>

        </el-table-column>

        <el-table-column
          fixed="right"
          label="操作"
          width="180"
        >
          <template slot-scope="scope">
            <el-tooltip class="item" effect="dark" content="编辑" placement="top" >
              <img src="../../assets/img/setup/edit.png" alt="" class="imgstyle" @click="Edit(scope.row)">
            </el-tooltip>
            <el-tooltip class="item" effect="dark" content="启用" placement="top" v-if="scope.row.Enable==2">
              <img src="../../assets/img/userman/pass.png" alt="" class="imgstyle" @click="grant(scope.row,1)" v-if="scope.row.Enable==2">
            </el-tooltip>
            <el-tooltip class="item" effect="dark" content="禁止" placement="top" v-if="scope.row.Enable==1">
              <img src="../../assets/img/userman/nopass.png" alt="" class="imgstyle" @click="grant(scope.row,2)" v-if="scope.row.Enable==1">
            </el-tooltip>
            <el-tooltip class="item" effect="dark" content="删除" placement="top" >
              <img src="../../assets/img/setup/del.png" alt="" class="imgstyle" @click="delete_b(scope.row)">
            </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="count">
      </el-pagination>
    </div>
  </div>
</template>

<script>
  export default {
    name: "setupActivityList",
    data(){
      return{
        msg:{
          pageIndex:1,
          pageSize:20,
          ActivityName:'',
          Enable:0,
        },
        tableData:[],
        count:0,
        loading:false
      }
    },
    created(){
      this.getDateList();

    },
    methods:{
      getDateList(){
        this.loading=true;
        this.apipost("/api/product/GetGoodsActivityPageList", this.msg, res => {
          this.loading=false;
          if(res.data.resultCode==1){
            this.tableData = res.data.data.pageData;
            this.count = res.data.data.count;
          }else {
            this.Info(res.data.message);
          }

        })
      },
      addRecharge(){
        this.$router.push('/AddsetupActicity');

      },
      gowinning(){
        this.$router.push('/winningList');

      },
      grant(row,type){
        this.apipost(
          "/api/product/SetGoodsActivityState",
          {ActivityId:row.Id,Type:type},
          res => {
            if (res.data.resultCode == 1) {
              this.Success(res.data.message);
              this.getDateList();
            } else {
              this.Error(res.data.message);
            }
          },
        );
      },
      Edit(row){
        this.$router.push({
          name: 'AddsetupActicity',
          query: {
            ID:row.Id,
            blank: "y"
          }
        });
      },
      delete_b(row){
        let that=this;
        that.Confirm("是否删除?", function () {
          that.apipost(
            "/api/product/SetGoodsActivityState",
            {ActivityId:row.Id,Type:3},
            res => {
              if (res.data.resultCode == 1) {
                that.Success(res.data.message);
                that.getDateList();
              } else {
                that.Error(res.data.message);
              }
            },
          );
        });
      },

      getList(){
        this.msg.pageIndex = 1
        this.getDateList()
      },

      handleCurrentChange(val) {
        this.msg.pageIndex = val;
        this.getDateList();
      },
    },
  }
</script>

<style >
  .setupActivityList .el-card__header{
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    background: #fff;

  }
  .setupActivityList .el-button--small{
    padding: 9px 15px;
  }
  .setupActivityList .content .searchInput{
    border: 1px solid #DCDFE6;
    border-radius: 4px;
    margin-left: 20px;
  }
  .setupActivityList .content .searchInput .el-input__inner{
    border:none;outline:none;
    height: 30px;
    line-height: 30px;
  }
  .setupActivityList .content .searchInput{
    line-height: normal;
    display: inline-table;
    border-collapse: separate;
    border-spacing: 0;
    width:250px;
  }
  .setupActivityList .content{
    background: #fff;
    margin-top:10px;
    padding: 15px;
    box-sizing: border-box;
  }
  .setupActivityList .app-image{
    background-position: center center;
    width: 50px;
    height: 50px;
    border-radius:0%;
    float: left;
    margin-right: 8px;
  }
</style>
