<template>
  <div class="main-container">
    <ul>
      <li class="order-item" v-for="(item, index) in order" :key="index">
        <div class="order-info">
          <img :src="item.product_image" />
          <div class="txt">{{item.product_name}}</div>
        </div>
        <div class="deti">
          <div class="tit">课程状态：</div>
          <div class="val">{{item.status | courseStatusText }}</div>
        </div>
        <div class="deti">
          <div class="tit">共计：</div>
          <div class="val">{{item.total_fee}}</div>
        </div>
        <div class="deti">
          <div class="val col" v-if="item.status === '-1'" @click="goBuy(item)">继续支付</div>
          <div class="val col" v-else>{{item.status | orderStatusText}}</div>
        </div>
      </li>
    </ul>
  </div>
</template>
<script>
import * as api from '@/api/pay.js'
export default {
  metaInfo: {
    title: '已购课程'
  },
  data() {
    return {
      order: []
    }
  },
  mounted() {
    this.getMyOrder()
  },
  computed: {
    isWeapp() {
      return this.$store.state.isWeapp
    }
  },
  filters: {
    courseStatusText(status) {
      return status === '1' ? '已付款' : '未付款'
    },
    orderStatusText(status) {
      const map = {
        '-1': '待支付',
        0: '已取消',
        1: '购买成功',
        2: '已超时'
      }
      return map[status]
    }
  },
  methods: {
    getMyOrder() {
      api.getMyOrder().then(res => {
        if (res.code === 0) {
          this.order = res.data.orders
        }
      })
    },
    goBuy(data) {
      wx.miniProgram.navigateTo({
        url: `/pages/pay/index?data=${data.product_id}`
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.main-container {
  .order-item {
    margin: 0.4rem 0;
  }
  .order-info {
    display: flex;
    img {
      width: 2.4rem;
      height: 2.4rem;
      display: block;
      background-color: #eee;
      object-fit: contain;
    }
    .txt {
      margin-left: 0.2rem;
      font-size: 0.3rem;
      color: #222;
      word-wrap: break-word;
    }
  }
  .deti {
    display: flex;
    margin-top: 0.4rem;
    .tit {
      font-size: 0.26rem;
      color: #222;
    }
    .val {
      font-size: 0.26rem;
      color: #222;
      margin-left: auto;
    }
    .col {
      color: #ff6767;
      font-size: 0.3rem;
    }
  }
}
</style>
