<template>
  <div style="padding: 0 10px;background: #fff;margin: 0 10px;">
    <div style="display: flex;" class="pending">
      <div style="width: 30%;margin-right: 3%;text-align: center;padding: 20px 0;border-radius: 3px;border: 2px solid #eee;">
        <div style="font-size: 14px;color: #a8abb2;">总金额</div>
        <div style="font-size: 22px;margin-top: 10px;color: rgb(63, 155, 106);" v-if="alltoji">{{Number(alltoji.amount)/100 || 0}}</div>
      </div>
    </div>
    <div class="pending">
      <!-- 表格 -->
      <div class="tableBox" v-if="alltoji && alltoji.shopCouponSubsidies">
        <el-table
          ref="multipleTable"
          :data="alltoji.shopCouponSubsidies"
        :header-cell-style="{fontSize: '14px',color:'#0009',fontWeight: 'normal',backgroundColor:'#F2F3F5'}"
          tooltip-effect="dark"
        >
          <el-table-column label="优惠券名称" width="220">
            <template slot-scope="scope">{{ scope.row.couponName }}</template>
          </el-table-column>
          <el-table-column label="类型" show-overflow-tooltip>
            <template slot-scope="scope">
              <span v-if="scope.row.couponType == 1">满减券</span>
              <span v-if="scope.row.couponType == 2">折扣券</span>
            </template>
          </el-table-column>


          <el-table-column label="商品">
            <template slot-scope="scope">
                <el-popover trigger="hover" placement="top">
                  <p style="max-width: 300px;">{{ scope.row.productName }}</p>
                  <div slot="reference" style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis;width: 100%;" >
                    {{ scope.row.productName }}
                  </div>
                </el-popover>
              </template>
            <!-- <template slot-scope="scope">{{ scope.row.productName }}</template> -->
          </el-table-column>
          <el-table-column label="用户手机号">
            <template slot-scope="scope">{{ scope.row.userPhone }}</template>
          </el-table-column>
          <el-table-column label="订单金额">
            <template slot-scope="scope">{{ Number(scope.row.orderAmount)/100 }}</template>
          </el-table-column>

          <el-table-column label="优惠金额">
            <template slot-scope="scope">{{ Number(scope.row.discountAmount)/100 }}</template>
          </el-table-column>
        </el-table>
 
        <div v-if="alltoji && alltoji.shopCouponSubsidies" style="display: flex;justify-content: space-between;margin-top: 30px;" class="bom">
            <div style="font-size: 14px;">共 <span style="color: #3F9B6A;">{{alltoji.shopCouponSubsidies.length}}</span> 项数据</div>
            <!-- <el-pagination :current-page="formInline.page" :page-sizes="[10, 20, 50, 100]" :page-size="10" background
              small layout="prev, pager, next" :total="total" @size-change="handleSizeChange"
              @current-change="handleCurrentChange">
            </el-pagination> -->
          </div>
      </div>
    </div>
  </div>
</template>

<script>
import AddCoupon from '@/views/marketing/coupon/add.vue'
import { getCoupon, delCoupon, getCouponData, stopCoupon,getShopCouponSubsidy } from '@/api/marketing'
import activityMixin from '@/views/marketing/mixin/index.js'

function CouponQueryForm() {
  this.couponName = '' // 优惠券名称
  this.couponType = null // 优惠券类型
  this.dates = [] // 创建时间数组
  this.endTime = '' // 创建时间结束时间
  this.page = 1 // 当前页
  this.pageSize = 10 // 每页记录数
  this.startTime = '' // 创建时间开始时间
  this.state = null // 优惠券状态
}
export default {
  name: 'Coupon',
  components: {
    AddCoupon
  },
  mixins: [activityMixin],
  data() {
    return {
      info:{},
      type:'2',
      formInline: new CouponQueryForm(),
      isDataVisible: false, // 数据效果展示
      dataInfo: [], // 商品使用数据
      total: 1,
      tableData: [],
      dataEffect: [],
      alltoji:null
    }
  },
  mounted() {
    this.getAll(this.formInline)
  },
  methods: {
    closeModal() {
      this.activityId = null
      this.$refs.addCoupon.resetData()
    },
    //  查询
    search() {
      this.total = 1
      this.formInline.page = 1
      if (this.formInline.dates.length !== 0) {
        this.formInline.startTime = this.formInline.dates[0]
        this.formInline.endTime = this.formInline.dates[1]
      }
      this.getAll(this.formInline)
    },
    // 清除
    clear() {
      this.formInline = new CouponQueryForm()
      this.getAll(this.formInline)
    },
    handleSizeChange(val) {
      this.formInline.pageSize = val
      this.getAll(this.formInline)
    },
    handleCurrentChange(val) {
      this.formInline.page = val
      this.getAll(this.formInline)
    },
    // 停止优惠券活动
    stopFn(id) {
      let that = this
      this.$confirm('是否将该优惠券停止?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        console.error(id)
        stopCoupon({ shopCouponId: id }).then(res => {
          if (res.code === '') {
            that.$message.success('停止成功')
            that.formInline.page = 1
            that.getAll(that.formInline)
          } else {
            that.$message.error(res.message)
          }
        })
      }).catch(() => {
      
      });
    },
    // 初始化查询所有数据
    async getAll(formInline) {
      formInline.type = 1
      const res = await getCoupon(formInline)
      this.total = res.data.total
      this.tableData = res.data.list
      getShopCouponSubsidy({usedMerchantId:'154'}).then(res => {
        console.error(res)
        this.alltoji = res.data
      })
    },
    // 显示数据效果
    showData(id) {
      getCouponData({ shopCouponId: id }).then(res => {
        if (res.code === '') {
          this.dataInfo = res.data
        } else {
          this.$message.error(res.message)
        }
      })
      this.isDataVisible = true
    },
    // 删除优惠券
    delCouponFn(data) {
      let that = this
      this.$confirm('是否将该优惠券删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        delCoupon({ shopCouponId: data.shopCouponId }).then(res => {
        if (res.code === '') {
          that.$message.success('删除成功')
          that.formInline.page = 1
          that.getAll(that.formInline)
        } else {
          that.$message.error(res.message)
        }
      })
      }).catch(() => {
      
      });
    }
  }
}
</script>

<style lang='scss' scoped>
//@import url(); 引入公共css类
@import url("../../styles/elDialog.scss");

.pending {
 padding: 0 20px 20px 20px;
    background-color:#fff;
//  min-height: calc(100vh - 50px - 20px);
}
.fenye {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
  position: relative;
}
.dataEffect {
  .couponTit {
    margin: 20px 0;
  }
  .dataListBox {
    display: flex;
    justify-content: center;
    margin: 30px 0;
    .dataItem {
      width: 220px;
      height: 120px;
      border-radius: 8px;
      border: 1px solid #999999;
      text-align: center;
      margin: 0 10px;
      span {
        display: block;
        margin-top: 35px;
      }
    }
  }
  .tabListInfo {
    margin: 20px 0;
  }

}
 .formSearch {
      display: flex;
      width: 100%;
      font-size: 14px;
      justify-content: space-between;
    }
 ::v-deep .el-pagination__total {
    position: absolute;
    left: 10px;
  }
</style>
<style scoped>
.btnList /deep/ .delCls {
  margin-left: 10px;
}
.group-dialog /deep/ .el-dialog__headerbtn .el-dialog__close {
  color: #FFFFFF;
}
 ::v-deep .el-input__inner:focus {
      border: #11be59 1px solid;
   }
   ::v-deep .el-input__inner:hover {
        border: #11be59 1px solid;
     }
   ::v-deep .el-select .el-input.is-focus .el-input__inner{
         border-color:#11be59
     }
    ::v-deep .el-form-item__label{
        font-weight: normal;
         font-size: 14px;
       }
      ::v-deep .btn .el-button:focus,
       .el-button:hover {
         border: 1px solid #3F9B6A;
       }
       ::v-deep .el-button {
          border: 1px solid #3F9B6A;
        }
   ::v-deep .el-pagination.is-background .el-pager li:not(.disabled).active {
    background-color: #3F9B6A;
  }
  .el-radio__input.is-checked+.el-radio__label{
    color:#3F9B6A;
  }

</style>
<style>
  .el-select-dropdown__item.selected{
    color: #3F9B6A;
  }
</style>
