<template>
  <div class="fruit5">
    <div class="content1">
      <div class="top">
        <div class="smallTop">
          <div class="icon"></div>
          <div class="title">可兑换明细</div>
        </div>
        <div class="smallBottom">
          <div class="card" v-for="(item, index) in list" :key="index">
            <div class="name">{{ item.fruitsName }}</div>
            <div class="num">{{ item.weight }}kg</div>
          </div>
        </div>
      </div>
      <div class="content">
        <div class="smallTop">
          <div class="left">
            <div class="icon"></div>
            <div class="title">提货点</div>
          </div>
          <div class="right" @click="change" v-if="num == 1">∧</div>
          <div class="right" @click="change" v-if="num == 2">∨</div>
        </div>
        <div class="smallBottom" v-if="num == 1">
          <div class="card" v-for="(item, index) in list1" :key="index">
            <div class="name">{{ item.supplyName }}</div>
            <div class="phone">联系电话：{{ item.supplyMobile }}</div>
            <div class="address">地点：{{ item.address }}</div>
          </div>
        </div>
      </div>
      <div class="bottom" v-if="this.list2.length > 0">
        <div class="smallTop">
          <div class="icon"></div>
          <div class="title">兑换历史</div>
        </div>
        <div class="smallBottom">
          <div class="card" v-for="(item, index) in list2" :key="index">
            <div class="goods">
              <div class="img"></div>
              <div class="name">{{ item.fruitsName }}</div>
              <div class="num">{{ item.weight }}kg</div>
            </div>
            <div class="address">提货点：{{ item.address }}</div>
            <div class="time">提货时间：{{ item.createTime }}</div>
          </div>
        </div>
      </div>
    </div>
    <div class="ensure">
      <div class="title">
        转为线下兑换券后<br />只能到线下提货点提货，不能在线上提货
      </div>
      <div class="operation" @click="ensure">确认兑换</div>
      <div class="safe-area"></div>
    </div>
  </div>
</template>

<script>
import { onLineToOffLine } from "@/api/fruit.js";
export default {
  name: "fruit5",
  data() {
    return {
      num: 1,
      list: [],
      list1: [],
      list2: [],
    };
  },
  created() {
    this.list = this.$route.query.convertibleInfoList;
    this.list1 = this.$route.query.supplyList;
    this.list2 = this.$route.query.exchangeRecordList;
  },
  methods: {
    change() {
      if (this.num == 1) {
        this.num = 2;
      } else {
        this.num = 1;
      }
    },
    ensure() {
      onLineToOffLine({ qrCode: this.$route.params.qrCode }).then(() => {
        this.$router.replace({
          name: "Fruit8",
          query: this.$route.params.qrCode,
        });
      });
    },
  },
};
</script>

<style lang="stylus" scoped>
.fruit5 {
  height: 100vh;
  display: flex;
  flex-direction: column;

  .content1 {
    box-sizing: border-box;
    padding-bottom: constant(safe-area-inset-bottom);
    padding-bottom: env(safe-area-inset-bottom);
    display: flex;
    flex-direction: column;
    height: calc(100vh - 240px);
    overflow-y: auto;
  }

  .top {
    display: flex;
    flex-direction: column;

    .smallTop {
      display: flex;
      align-items: center;
      background: #fff;
      padding: 30px;

      .icon {
        width: 6px;
        height: 30px;
        background: #EB4E3F;
      }

      .title {
        font-size: 30px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #333333;
        margin-left: 10px;
      }
    }

    .smallBottom {
      display: flex;
      flex-direction: column;
      align-items: center;
      background: #fff;
      padding: 0 30px 20px 30px;

      .card {
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
        font-size: 30px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #999;
        line-height: 50px;
      }
    }
  }

  .content {
    display: flex;
    flex-direction: column;
    margin-top: 10px;

    .smallTop {
      display: flex;
      align-items: center;
      justify-content: space-between;
      background: #fff;
      padding: 30px;

      .left {
        display: flex;
        align-items: center;

        .icon {
          width: 6px;
          height: 30px;
          background: #EB4E3F;
        }

        .title {
          font-size: 30px;
          font-family: PingFangSC-Medium, PingFang SC;
          font-weight: 500;
          color: #333333;
          margin-left: 10px;
        }
      }

      .right {
        font-size: 30px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 800;
        color: #333333;
      }
    }

    .smallBottom {
      display: flex;
      flex-direction: column;

      .card {
        width: 100%;
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        background: #fff;
        font-size: 30px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        line-height: 50px;
        color: #999;
        margin-top: 10px;
        padding: 30px;

        .name {
          color: #333;
        }
      }
    }
  }

  .bottom {
    display: flex;
    flex-direction: column;
    margin-top: 20px;

    .smallTop {
      display: flex;
      align-items: center;
      background: #fff;
      padding: 30px;

      .icon {
        width: 6px;
        height: 30px;
        background: #EB4E3F;
      }

      .title {
        font-size: 30px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #333333;
        margin-left: 10px;
      }
    }

    .smallBottom {
      display: flex;
      flex-direction: column;

      .card {
        width: 100%;
        box-sizing: border-box;
        background: #fff;
        display: flex;
        flex-direction: column;
        padding: 30px;
        margin-top: 10px;
        font-size: 30px;
        line-height: 50px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #999;

        .goods {
          display: flex;
          align-items: center;
          color: #333;

          .img {
            width: 30px;
            height: 30px;
            background: #EB4E3F;
          }

          .name {
            margin: 0 20px;
          }
        }
      }
    }
  }

  .ensure {
    display: flex;
    flex-direction: column;
    align-content: center;
    box-sizing: border-box;
    position: fixed;
    bottom: 0;
    width: 100%;
    left: 0px;
    padding-bottom: constant(safe-area-inset-bottom);
    padding-bottom: env(safe-area-inset-bottom);

    .title {
      text-align: center;
      font-size: 35px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #666666;
      line-height: 70px;

      span {
        color: #EB4E3F;
      }
    }

    .operation {
      width: 100%;
      background: #EB4E3F;
      font-size: 40px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #fff;
      line-height: 100px;
      text-align: center;
    }
  }
}
</style>