<template>
  <view class="page">
    <!-- #ifdef H5-->
    <uni-nav-bar v-if="!$isWxBrowser()" :fixed="true" background-color="#FFE05C" :border="false" :statusBar="false"
                 left-icon="left" title="我的规则" @clickLeft="back"/>
    <!-- #endif -->

    <view class="flex-col item" v-for="(item,index) in list" :key="index">
      <view class="flex-row justify-between">
        <text class="storeName">{{ item.title }}</text>
        <text class="time">{{ item.createTime }}</text>
      </view>
      <view class="flex-row">
        <text class="key">直推:</text>
        <view>
          <view class="phone">注册现金:{{ item.awardAmount }}元</view>
          <view class="flex-row">
            <view class="phone">消费现金:{{ item.consumeAmount }}元</view>
            <view class="phone">消费比例:{{ item.consumeRatio * 100 }}%</view>
          </view>
        </view>
      </view>
      <view class="flex-row">
        <text class="key">间推:</text>
        <view>
          <view class="flex-row">
            <view class="phone">间推现金:{{ item.indirectRechargeAmount }}元</view>
            <view class="phone">间推比例:{{ item.indirectRechargeRatio * 100 }}%</view>
          </view>
        </view>
      </view>
      <view class="flex-row" v-for="i in item.strategyList">
        <text class="key">优惠券:</text>
        <view>
          <view class="phone">{{i.name}} <span style="font-size: 16rpx"> ({{ i.startTime }}至{{ i.endTime }})</span></view>
        </view>
      </view>
    </view>

    <!--#ifdef H5-->
    <liu-drag-button v-if="$isWxBrowser()" @clickBtn="back">返回</liu-drag-button>
    <!--#endif-->
  </view>
</template>

<script>
export default {
  data() {
    return {
      height: '',
      list: [],
      roleId:null,
    }
  },
  onLoad(options) {
    if(options.id){
      this.roleId = options.id
      this.getInfoById()
    }else {
     this.roleId = uni.getStorageSync('spreadUserInfo').roleId
      console.log(this.roleId)
      this.getInfoById()
    }
    let sysInfo = uni.getSystemInfoSync()
    this.height = sysInfo.windowHeight - 120 + 'px' //除标题栏栏外的屏幕可用高度
  },
  methods: {
    back() {
      let pages = getCurrentPages()
      if (pages.length > 1) {
        uni.navigateBack({
          delta: 1,
          fail: err => {
            console.log(err)
          }
        })
      } else {
        uni.switchTab({
          url: '/pages/my/my'
        });
      }
    },
    getInfo() {
      this.$api.service.getRuleList( {roleId:this.roleId}).then((res) => {
        this.list = res.data.data
      })
    },
    getInfoById(){
      this.$api.service.getRuleByRoleId({roleId:this.roleId}).then((res) => {
        this.list = res.data.data
      })
    }
  }
}
</script>


<style lang="scss" scoped>
@import './index.rpx.css';
</style>
