<template>
  <view class="card" @click="$emit('toInformation', itemInfo)">
    <view class="user-name">
      <view class="name">
        <image class="header-img" :src="itemInfo.member.avatar" mode=""></image>
        <text>{{ itemInfo.nickname }}</text>
      </view>
      <!-- <text class="order-status">{{ deliveryStatus }}</text> -->
      <text class="order-status">{{ itemInfo.status_name }}</text>
    </view>
    <view
      class="order-detail"
      :style="model"
      v-for="item in itemInfo.order_goods"
    >
      <view class="detail">
        <image class="order-img" :src="item.sku_item.image" mode=""></image>
        <view class="detail-right">
          <view class="title-price">
            <view class="title" v-if="language == 'zh-CN'">
              {{ item.goods.name_cn }}</view
            >
            <view class="title" v-if="language == 'en-US'">
              {{ item.goods.name_en }}</view
            >
            <view class="title" v-if="language == 'es-ES'">
              {{ item.goods.name_es }}</view
            >
            <view class="title" v-if="language == 'it-IT'">
              {{ item.goods.name_ita }}</view
            >
            <view class="price" v-if="item.sku_item">
              <text style="font-size: 20rpx">￥</text>
              <text>{{ item.discount_price.split(".")[0] }}</text
              >.
              <text style="font-size: 20rpx">{{
                item.discount_price.split(".")[1]
              }}</text>
            </view>
          </view>
          <view class="specifications">
            <view class="title"> {{ item.sku_item.item }} </view>
            <text>x{{ item.goods_num }}</text>
          </view>
        </view>
      </view>
      <view class="model" v-if="itemInfo.simplify_status == 'unreview'"> </view>
    </view>

    <view
      style="color: #222; font-size: 24rpx; text-align: right"
      v-if="language != 'zh-CN'"
    >
      <text>{{ i18n.Atotalof + itemInfo.order_goods.length }}</text>
      <text>
        {{ i18n.piece + i18n.mineCommodity + "&nbsp;" }}
      </text>
    </view>
    <view class="price-detail">
      <view style="color: #222; font-size: 24rpx" v-if="language == 'zh-CN'">
        <text>{{ i18n.Atotalof + itemInfo.order_goods.length }}</text>
        <text>
          {{ i18n.piece + i18n.mineCommodity + "&nbsp;" }}
        </text>
      </view>
      <text style="font-size: 28rpx">{{ i18n.actualPayment }}</text>
      <view class="price">
        <text style="font-size: 20rpx">￥</text>
        <text>{{ itemInfo.amount.split(".")[0] }}</text
        >.
        <text style="font-size: 20rpx">{{
          itemInfo.amount.split(".")[1]
        }}</text>
      </view>
    </view>
    <view class="remarks" v-if="itemInfo.simplify_status == 'merdelivered'">
      <view style="margin-right: 30rpx; color: #222">
        {{ i18n.merchantRemarks }}
      </view>
      <view style="color: rgba(34, 34, 34, 0.6)"> {{ itemInfo.remark }} </view>
    </view>
    <view
      class="btn-list"
      v-if="
        itemInfo.simplify_status !== 'unreview' &&
        itemInfo.simplify_status != 'undelivered'
      "
    >
      <button
        class="btn-1"
        v-if="itemInfo.order_goods[0].delivery_status == 'unfill'"
        @click.stop="toBond"
      >
        {{ i18n.PayDeposit }}
      </button>
      <!-- <button class="btn-2" v-if="itemInfo.simplify_status == 'merdelivered'">
        备注
      </button> -->
      <button
        class="btn-1"
        v-if="
          itemInfo.status != 'unfill' &&
          itemInfo.order_goods[0].delivery_status == 'merdelivered'
        "
        @click.stop="toGoods"
      >
        {{ i18n.sendOutGoods }}
      </button>
      <button class="btn-2" v-if="itemInfo.simplify_status == ' delivered'">
        {{ i18n.checkLogistics }}
      </button>
    </view>
  </view>
</template>

<script>
export default {
  props: {
    itemInfo: {
      typeof: Object,
      default: {},
    },
    language: {
      typeof: String,
      default: "",
    },
  },
  computed: {
    model() {
      if (this.itemInfo.simplify_status == "unreview") {
        return "filter: blur(5px);";
      } else {
        return "";
      }
    },
    //根据状态 返回不同的字段
    deliveryStatus() {
      if (this.itemInfo.simplify_status == "unreview") {
        return "待审核";
      } else if (this.itemInfo.simplify_status == "unfill") {
        return "待缴纳保证金";
      } else if (this.itemInfo.simplify_status == "merdelivered") {
        return "待团长发货";
      } else if (this.itemInfo.simplify_status == "undelivered") {
        return "待总部发货";
      } else if (this.itemInfo.simplify_status == "delivered") {
        return "已发货";
      } else if (this.itemInfo.simplify_status == "domestic_delivered") {
        return "团长已发货";
      }
    },
    i18n() {
      return this.$t("index");
    },
  },
  data() {
    return {};
  },
  methods: {
    toBond() {
      //所有需要缴纳保证金的金额相加
      let goodsMoney = 0;
      this.itemInfo.order_goods.map((item) => {
        goodsMoney += Number(item.earnest_money);
      });
      //跳转支付
      uni.navigateTo({
        url: `/pageA/payorder?sum=${goodsMoney}&orderid=${this.itemInfo.id}&orderType=bond`,
      });
    },
    toGoods() {
      uni.navigateTo({
        url: `/pageD/deliverGoods/deliverGoods?id=${this.itemInfo.id}`,
      });
    },
  },
};
</script>

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

  .user-name {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 84rpx;
    border-bottom: 2rpx solid rgba(151, 151, 151, 0.2);

    .name {
      display: flex;
      align-items: center;
      font-size: 24rpx;
      color: #333;

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

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

  .order-detail {
    margin-top: 22rpx;
    position: relative;

    .detail {
      display: flex;

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

      .detail-right {
        width: 70%;

        .title-price {
          display: flex;
          font-size: 28rpx;
          justify-content: space-between;
          align-items: center;

          .title {
            width: 330rpx;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
          }
        }

        .specifications {
          display: flex;
          justify-content: space-between;
          align-items: center;
          font-size: 28rpx;
          color: #777;
          margin-top: 10rpx;

          .title {
            width: 330rpx;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
          }
        }
      }
    }
  }

  .price-detail {
    display: flex;
    justify-content: flex-end;
    align-items: flex-end;
    margin-top: 20rpx;

    .price {
      font-weight: 600;
    }
  }

  .remarks {
    display: flex;
    font-size: 28rpx;
    background-color: #f4f4f4;
    border-radius: 10rpx;
    padding: 14rpx 20rpx;
    margin-top: 20rpx;
  }

  .btn-list {
    display: flex;
    justify-content: flex-end;
    margin-top: 30rpx;

    .btn-1 {
      font-size: 28rpx;
      color: #f83224;
      border: 2rpx solid #f83224;
      background-color: #fff;
      margin: 0;
      border-radius: 34rpx;
      min-width: 162rpx;
      margin-left: 20rpx;
    }

    .btn-2 {
      font-size: 28rpx;
      color: #222;
      border: 2rpx solid #979797;
      background-color: #fff;
      margin: 0;
      border-radius: 34rpx;
      min-width: 162rpx;
    }
  }
}
</style>
