<template>
  <div class="winningList">
    <div class="el-card__header">
      <span>活动管理</span>

    </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 size="small" v-model="msg.UserId" :filter-method="ChangeListName" filterable @change="getList"
                     placeholder="请选择">
            <el-option label="不限" :value="0"></el-option>
            <el-option v-for="item in tableData2" :key="item.Id" :label="item.Name" :value="item.Id">
            </el-option>
          </el-select>
          <div class="searchInput" style="width:250px">
            <el-input style="display:inline-block;width:225px;height:30px"
                      placeholder="请输入中奖码"
                      v-model="msg.Code"
                      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.State" 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-option label="已过期" :value="3"></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="100">
        </el-table-column>

        <el-table-column
          prop="ActivityName"
          label="封面图" width="270">
          <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="Name"
          label="用户信息" width="270">
          <template slot-scope="scope">
            <div class="app-image" :style="{backgroundImage:'url(' + scope.row.Photo + ')',backgroundSize:'cover'}"></div>
            <div flex="dir:left cross:center">
              {{scope.row.Name}}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="Name"
          label="奖品信息" width="270">
          <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
          prop="Type"
          label="状态">
          <template slot-scope="scope">
            <div v-if="scope.row.State==1">未兑换</div>
            <div v-if="scope.row.State==2">已兑换</div>
            <div v-if="scope.row.State==3">已过期</div>
          </template>
        </el-table-column>



        <el-table-column
          label="验证码"
          prop="Code" >

        </el-table-column>

        <el-table-column
          label="领取方式"
          prop="Way" >
          <template slot-scope="scope">
            <div>{{scope.row.Way==1?'线上':'线下'}}</div>
          </template>

        </el-table-column>
        <el-table-column
          label="创建时间"
          prop="CreateDate">
        </el-table-column>

<!--        <el-table-column-->
<!--          label="中奖订单"-->
<!--          prop="RangeType" width="300">-->
<!--          <template slot-scope="scope">-->
<!--            <span style="font-size: 12px;color: #409EFF" v-for="(x,y) in scope.row.OrderList" :key="y">{{x.OrderId}}{{y+1==scope.row.OrderList.length?'':'、'}}</span>-->
<!--          </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" v-if="scope.row.State==1">
              <img src="../../assets/img/userman/duihuan.png" alt="" class="imgstyle" @click="grant(scope.row,1)" v-if="scope.row.State==1">
            </el-tooltip>
            <el-tooltip class="item" effect="dark" content="失效" placement="top" v-if="scope.row.State==1">
              <img src="../../assets/img/userman/nopass.png" alt="" class="imgstyle" @click="grant(scope.row,2)" v-if="scope.row.State==1">
            </el-tooltip>
            <el-tooltip class="item" effect="dark" content="查看中奖订单" placement="top" >
              <img src="../../assets/img/userman/detail.png" alt="" class="imgstyle" @click="see(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>
    <el-dialog
      title="中奖订单"
      :visible.sync="dialogVisible"
      width="30%"
      >
      <span style="font-size: 12px;color: #409EFF" v-for="(x,y) in detail" :key="y">{{x.OrderNo}}{{y+1==detail.length?'':'、'}}</span>

      <span slot="footer" class="dialog-footer">
    <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
  </span>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    name: "winningList",
    data(){
      return{
        msg:{
          pageIndex:1,
          pageSize:20,
          ActivityName:'',
          UserId:0,
          State:0,
          Code:'',
        },
        tableData:[],
        tableData2:[],
        count:0,
        loading:false,
        msg2: {
          pageIndex: 1,
          pageSize: 20,
          Name: '',
          Source: 0,
          MemberGrade: 0,
          Id: 0,
          Moblie: ''
        },
        detail:[],
        dialogVisible:false
      }
    },
    created(){
      this.getDateList();
      this.getNameList()
    },
    methods:{
      ChangeListName(val) {
        this.msg2.Name = val;
        this.getNameList();
      },
      getNameList() {
        this.apipost("/api/user/GetMemberUserDropDownList", this.msg2, res => {
          if (res.data.resultCode == 1) {
            let pageData = res.data.data.pageData;
            this.tableData2 = pageData;
          }
        })
      },
      getDateList(){
        this.loading=true;
        this.apipost("/api/product/GetGoodsActivityGetUserPageList", 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);
          }

        })
      },


      grant(row,type){
        let that=this;
        let text  ='';
        if(type==1){
          text='是否兑换？'
        }else if(type==2){
          text='是否失效？'
        }
        that.Confirm(text, function () {
          that.apipost(
            "/api/product/SetGoodsActivityUserState",
            {PrizeId:row.Id,Type:type},
            res => {
              if (res.data.resultCode == 1) {
                that.Success(res.data.message);
                that.getDateList();
              } else {
                that.Error(res.data.message);
              }
            },
          );
        });
      },
      see(row){
        this.detail = row.OrderList;
        this.dialogVisible = true
      },

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

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

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

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