<template>
  <div class="after-sale-apply-con">
    <refund-goods :list="detail.orders" :type="type" />
    <div class="common type-con">
      <div class="title">选择售后类型</div>
      <div class="type-list">
        <div
          class="item flex-default"
          v-for="(item, index) of typeList"
          :key="`type-item-${index}`"
          @click="handleRefund"
        >
          <m-icon className="logo" :icon="item.icon" :size="22" />
          <div class="content">
            <div class="title">{{ item.title }}</div>
            <div class="desc">{{ item.desc }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import RefundGoods from "./components/refund-goods";
import { OrderType, OrderTypeObj, RefundType, RefundTypeObj } from "@/enums";
export default {
  components: {
    RefundGoods,
  },
  computed: {
    isOrder() {
      return this.type == OrderType.ORDER;
    },
    isDelivery() {
      return this.type == OrderType.DELIVERY;
    },
    typeList() {
      if (this.isOrder) {
        return [RefundTypeObj[RefundType.MONEY]];
      } else if (this.isDelivery) {
        return [RefundTypeObj[RefundType.GOODS]];
      }
    },
  },
  data() {
    return {
      RefundType,
      RefundTypeObj,
      type: OrderType.ORDER,
      oid: "",
      detail: {},
    };
  },
  methods: {
    requestOrder(oid) {
      this.$showLoading();
      this.$api({
        apiName: OrderTypeObj[this.type].detailApi,
        postData: oid,
        success: (res) => {
          this.detail = res;
          if (this.type == OrderType.DELIVERY) {
            let { thumb, name, propList } = res;
            this.detail.orders = [{ thumb, name, propList }];
          }
        },
        complete: () => {
          this.$hideLoading();
        },
      });
    },
    handleRefund() {
      let { oid, type } = this;
      this.$router.replace({ name: "submit-refund", query: { oid, type } });
    },
  },
  mounted() {
    this.type = this.$route.query.type;
    this.oid = this.$route.query.oid;
    this.requestOrder(this.oid);
  },
};
</script>


<style lang="less">
.after-sale-apply-con {
  height: 100%;
  background-color: #f5f7fb;
  padding-top: 5px;

  > .type-con {
    background: #ffffff;
    margin-bottom: 10px;
    border-radius: 10px;
    padding: 16px 18px;
    color: #140603;
    > .title {
      font-size: 16px;
      line-height: 18px;
      font-weight: bold;
      margin-bottom: 16px;
    }
    .item {
      align-items: center;
      margin-top: 20px;
      &:nth-of-type(1) {
        margin-top: 0;
      }
    }
    .item > .logo {
      margin-right: 10px;
    }
    .item > .content {
      flex: 1;
    }
    .item > .content > .title {
      font-size: 16px;
      font-weight: bold;
      line-height: 18px;
      margin-bottom: 4px;
    }
    .item > .content > .desc {
      font-size: 12px;
      line-height: 14px;
      color: #aeaeae;
    }
  }
}
</style>

