<template>
  <view
    class="detail"
    @click="$emit('toDetail', itemInfo)"
    v-if="itemInfo.order"
  >
    <view class="title">
      <view class="title-left">
        <image class="header-img" :src="itemInfo.image" mode=""></image>
        <text>{{ itemInfo.merchant_name }}</text>
        <image
          class="right-325"
          src="../../../static/mine/325.png"
          mode=""
        ></image>
      </view>
      <text
        class="order-status"
        :style="itemInfo.order.status == 'closed' ? 'color:#666' : ''"
        >{{ itemInfo.order.status_text }}</text
      >
    </view>
    <view
      class="commodity-information"
      v-for="item in itemInfo.order_goods"
      :key="item.id"
    >
      <view class="commodity-1">
        <image class="commodity-img" :src="item.goods_image" mode=""></image>
        <view style="width: 70%">
          <view class="commodity-2">
            <view class="commodity-title"> {{ item.goods.name_cn }} </view>
            <view class="commodity-price">
              <text style="font-size: 20rpx">￥</text>
              <text>{{ item.goods.price.split(".")[0] }}</text
              >.
              <text style="font-size: 20rpx">{{
                item.goods.price.split(".")[1]
              }}</text>
            </view>
          </view>

          <view class="commodity-3">
            <view class="specifications"> {{ item.sku_item.item }} </view>
            <view style="font-size: 24rpx"> x{{ item.goods_num }} </view>
          </view>

          <button
            v-if="itemInfo.order.status == 'unreview'"
            @click.stop="$emit('unreviewAfter', item)"
            class="application"
          >
            申请退款
          </button>
        </view>
      </view>
    </view>
    <view class="price">
      <text>需付款</text>
      <text style="font-size: 20rpx">￥</text>
      <text>{{ itemInfo.order.amount.split(".")[0] }}</text
      >.
      <text style="font-size: 20rpx">{{
        itemInfo.order.amount.split(".")[1]
      }}</text>
    </view>
    <view class="btn-list">
      <view class="more" v-if="itemInfo.order.status == 'finished'">
        更多
      </view>
      <button
        class="status-1"
        @click.stop="$emit('cancellationOrder', itemInfo)"
        v-if="itemInfo.order.status == 'unpaid'"
      >
        取消订单
      </button>
      <button
        class="status-2"
        v-if="itemInfo.order.status == 'unpaid'"
        @click.stop="$emit('toPay', itemInfo)"
      >
        继续付款
      </button>
      <button
        class="status-1"
        v-if="
          itemInfo.order.status == 'closed' || itemInfo.order.status == 'refund'
        "
      >
        删除订单
      </button>
      <button class="status-2" v-if="itemInfo.order.status == 'closed'">
        再次购买
      </button>
      <button
        class="status-1"
        v-if="
          itemInfo.order.status == 'delivered' ||
          itemInfo.order.status == 'finished'
        "
      >
        查看物流
      </button>
      <button
        class="status-1"
        v-if="
          itemInfo.order.status == 'refund' ||
          itemInfo.order.status == 'finished'
        "
      >
        再来一单
      </button>
      <button
        class="status-2"
        v-if="itemInfo.order.status == 'delivered'"
        @click.stop="$emit('confirm', itemInfo)"
      >
        确认收货
      </button>

      <button
        class="status-2"
        v-if="itemInfo.order.status == 'finished'"
        @click.stop="$emit('toEvaluate', itemInfo)"
      >
        评价
      </button>
    </view>
  </view>
</template>

<script>
import textRight from "../../accountSecurity/component/textRight.vue";
export default {
  components: {
    textRight,
  },
  props: {
    itemInfo: {
      typeof: Object,
      default: {},
    },
  },
  computed: {
    statusName() {
      if (this.itemInfo.order.status == "unpaid") {
        return "待付款";
      } else if (this.itemInfo.order.status == "closed") {
        return "已取消";
      } else if (this.itemInfo.order.status == "refund") {
        return "退款成功";
      } else if (this.itemInfo.order.status == "refunding") {
        return "退款中";
      } else if (this.itemInfo.order.status == "unreview") {
        return "拼团中";
      } else if (
        this.itemInfo.order.status == "undelivered" ||
        this.itemInfo.order.status == "paid"
      ) {
        return "等待发货";
      } else if (this.itemInfo.order.status == "delivered") {
        return "等待收货";
      } else if (this.itemInfo.order.status == "finished") {
        return "交易完成";
      } else if (this.itemInfo.order.status == "undifference") {
        return "待补邮费";
      }
    },
  },
  data() {
    return {};
  },
  watch: {
    itemInfo(newVal) {},
  },
  methods: {
    // toEvaluate() {
    //   uni.navigateTo({
    //     url: "/pageD/evaluate/evaluate?",
    //   });
    // },
  },
};
</script>

<style scoped lang="scss">
.detail {
  padding: 28rpx 20rpx;
  background-color: #fff;
  border-radius: 16rpx;
  margin-top: 28rpx;

  .title {
    display: flex;
    justify-content: space-between;

    .title-left {
      display: flex;
      font-size: 32rpx;
      align-items: center;

      .header-img {
        width: 36rpx;
        height: 36rpx;
        border-radius: 50%;
        margin-right: 20rpx;
      }

      .right-325 {
        width: 32rpx;
        height: 32rpx;
      }
    }

    .order-status {
      color: #f83224;
      font-size: 26rpx;
    }
  }

  .commodity-information {
    margin-top: 28rpx;

    .commodity-1 {
      display: flex;

      .commodity-img {
        width: 180rpx;
        height: 180rpx;
        margin-right: 20rpx;
        border-radius: 10rpx;
      }

      .commodity-2 {
        display: flex;
        justify-content: space-between;

        .commodity-title {
          width: 328rpx;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
          margin-right: 38rpx;
        }
      }
      .commodity-3 {
        display: flex;
        justify-content: space-between;
        margin-top: 20rpx;
        color: #777;
        .specifications {
          font-size: 28rpx;
          color: #777;
        }
      }
      .application {
        background-color: #fff;
        border-radius: 34rpx;
        padding: 0;
        margin: 0;
        // padding: 0 26rpx;
        font-size: 28rpx;
        color: #222;
        height: 58rpx;
        line-height: 58rpx;
        margin-left: 20rpx;
        border: 2rpx solid #979797;
        margin-top: 10rpx;
        width: 140rpx;
        font-size: 22rpx;
        float: right;
      }
    }
  }
  .price {
    display: flex;
    justify-content: flex-end;
    font-size: 28rpx;
    align-items: flex-end;
  }
  .btn-list {
    display: flex;
    justify-content: flex-end;
    margin-top: 34rpx;
    .more {
      color: #777;
      font-size: 28rpx;
      line-height: 68rpx;
      margin-right: 20rpx;
    }
    .status-1 {
      background-color: #fff;
      border-radius: 34rpx;
      margin: 0;
      padding: 0;
      font-size: 28rpx;
      color: #222;
      width: 168rpx;
      height: 68rpx;
      line-height: 68rpx;
      margin-left: 20rpx;
      border: 2rpx solid #979797;
    }
    .status-2 {
      background-color: #ffffff;
      border-radius: 34rpx;
      margin: 0;
      padding: 0;
      font-size: 28rpx;
      color: #f83224;
      width: 168rpx;
      height: 68rpx;
      line-height: 68rpx;
      margin-left: 20rpx;
      border: 2rpx solid #f83224;
    }
  }
}
</style>
