<template>
  <view class="page">
    <view
      class="top"
      v-if="
        orderInformation.goods[0].refund.status == '0' ||
        orderInformation.goods[0].refund.status == '3'
      "
    >
      <view class="top-title"> {{ i18n.pleaseRefund }} </view>
      <view class="top-detail"> {{ i18n.ifAgree }} </view>
    </view>
    <view
      class="top"
      v-else-if="orderInformation.goods[0].refund.status == '2'"
    >
      <view class="top-title"> {{ i18n.refundRequest }} </view>
      <view class="top-detail">
        {{
          i18n.business + "：" + orderInformation.goods[0].refund.reason || ""
        }}
      </view>
    </view>
    <view class="top" v-else>
      <view class="top-title"> {{ i18n.haveAgreed }} </view>
    </view>
    <!-- 地址信息 -->
    <view class="address">
      <view class="name-phone">
        <view style="margin-right: 20rpx; font-size: 32rpx">{{
          orderInformation.address_name
        }}</view>
        <text class="phone">{{ orderInformation.address_mobile }}</text>
      </view>
      <view class="address-detail">
        {{ orderInformation.full_address }}
      </view>
    </view>

    <CommodityDetail
      :orderInformation="orderInformation"
      v-if="orderInformation.goods"
      :language="language"
    />
    <ApplicationInformation
      :orderInformation="orderInformation"
      v-if="orderInformation.goods"
      :refuseImg="refuseImg"
    />
    <RefusePopup :show="show" @refund="close" @close="close" />
    <AgreePopup
      :agreeShow="agreeShow"
      @close="close"
      :title="i18n.pleaseConfirm"
    />

    <view
      class="footer"
      v-if="
        (orderInformation.goods[0].refund.status == '0' ||
          orderInformation.goods[0].refund.status == '3') &&
        Number(orderInformation.goods[0].refund.is_send)
      "
    >
      <button class="btn-1" @click="refuseApplication">
        {{ i18n.refuseApplication }}</button
      ><button @click="agreeShow = true" class="btn-2">
        {{ i18n.AccettareRestituzione }}
      </button>
    </view>
  </view>
</template>

<script>
import CommodityDetail from "./component/commodityDetail.vue";
import ApplicationInformation from "./component/applicationInformation.vue";
import RefusePopup from "./component/refusePopup.vue";
import AgreePopup from "../components/agreePopup.vue";
export default {
  components: {
    CommodityDetail,
    ApplicationInformation,
    RefusePopup,
    AgreePopup,
  },
  data() {
    return {
      show: false,
      agreeShow: false,
      orderInformation: {},
      orderId: "",
      refuseImg: [], //申请退款图片
      language: this._language, //用户当前选择的语言
    };
  },
  onLoad(options) {
    this.orderId = options.id;
    this.getOrderDetail(options.id);
  },
  computed: {
    i18n() {
      return this.$t("index");
    },
  },
  methods: {
    refuseApplication() {
      this.show = true;
    },
    //关闭弹窗，确认是否退款，status有值则退款
    close(status, value) {
      this.show = false;
      this.agreeShow = false;
      if (status) {
        uni.$u.http
          .post(`/api/order_refund/examine`, {
            status,
            order_refund_id: this.orderInformation.goods[0].refund.id,
            reason: value,
            actual_refund_price: value,
          })
          .then((res) => {
            uni.showToast({
              title:
                status == 2 ? this.i18n.juJueRefund : this.i18n.agreeRefund,
              icon: "none",
            });
            this.getOrderDetail(this.orderId);
          });
      }
    },
    getOrderDetail(id) {
      uni.$u.http
        .post(`/api/order/refund_read?order_refund_id=${id}`)
        .then((res) => {
          this.orderInformation = res;
          this.refuseImg =
            this.orderInformation.goods[0].refund.images.split(",");
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.page {
  padding: 20rpx 24rpx;
  position: relative;

  .top {
    background-color: #fff;
    border-radius: 16rpx;
    padding: 28rpx 20rpx;

    .top-title {
      font-size: 36rpx;
      color: #333;
      font-weight: 600;
    }

    .top-detail {
      font-size: 26rpx;
      color: #a3a3a3;
      margin-top: 10rpx;
    }
  }

  .address {
    background-color: #fff;
    border-radius: 16rpx;
    padding: 34rpx 24rpx 28rpx;
    margin-top: 24rpx;

    .name-phone {
      display: flex;
      align-items: center;
      align-items: flex-end;

      .phone {
        font-size: 26rpx;
        color: #666;
      }
    }

    .address-detail {
      margin-top: 20rpx;
      font-size: 24rpx;
      color: #444;
    }
  }

  .footer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background-color: #fff;
    height: 146rpx;
    display: flex;
    justify-content: flex-end;
    padding: 20rpx 20rpx 0 0;

    .btn-1 {
      height: 76rpx;
      padding: 0;
      margin: 0;
      font-size: 28rpx;
      color: #f83224;
      min-width: 188rpx;
      background-color: #fff;
      border-radius: 38rpx;
      border: 2rpx solid #f83224;
      margin-right: 20rpx;
    }

    .btn-2 {
      height: 76rpx;
      padding: 0;
      margin: 0;
      font-size: 28rpx;
      color: #fff;
      min-width: 188rpx;
      background-color: #f83224;
      border-radius: 38rpx;
      margin-right: 20rpx;
    }
  }
}
</style>
