<template>
  <div class="autorelease">
    <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="addRecharge">添加自动发放方案</el-button>
      </div>
    </div>
    <div style="padding: 20px;background: #fff;">
      <el-table
        :data="tableData"
        header-cell-class-name="headClass"
        style="width: 1707px;"
        border
        v-loading="loading"
      >

        <el-table-column
          prop="ID"
          label="ID"
          width="343">
        </el-table-column>

        <el-table-column
          prop="TriggerTypeStr"
          label="触发事件"
          width="341">
        </el-table-column>
        <el-table-column
          prop="DiscountCouponName"
          label="优惠券"
          width="341">
        </el-table-column>
        <el-table-column
          prop="GrantNum"
          label="发放次数限制"
          width="341">
          <template slot-scope="scope">
            <div v-if="scope.row.GrantNum==0">
              无限制
            </div>
            <div v-if="scope.row.GrantNum>0">
              {{scope.row.GrantNum}}次
            </div>
          </template>
        </el-table-column>

        <el-table-column
          fixed="right"
          label="操作"
        >
          <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" >
              <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"
                     :total="count">
      </el-pagination>
    </div>
  </div>
</template>

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

      },
      methods:{
        getDateList(){
          this.loading=true;
          this.apipost("/api/Coupon/GetSelfMotionPageLis", 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('/addAutoreleaseCoupon');

        },
        Edit(row){
          this.$router.push({
            name: 'addAutoreleaseCoupon',
            query: {
              ID:row.ID,
              blank: "y"
            }
          });
        },
        delete_b(row){
          let that=this;
          that.Confirm("是否删除?", function () {
            that.apipost(
              "/api/Coupon/DelDiscountSelfMotion",
              {Id:row.ID},
              res => {
                if (res.data.resultCode == 1) {
                  that.Success(res.data.message);
                  that.getDateList();
                } else {
                  that.Error(res.data.message);
                }
              },
            );
          });
        },
        handleCurrentChange(val) {
          this.msg.pageIndex = val;
          this.getDateList();
        },
      }
    }
</script>

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

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