<template>
  <view class="page">
    <!-- 订单状态 -->
    <view class="title">
      <view>
        <view class="payment">
          {{ title }}
        </view>
      </view>
    </view>
    <!-- 订单状态 -->

    <!-- 地址信息 -->
    <view class="address">
      <view class="name-phone">
        <u-icon name="map" size="22"></u-icon>
        <view style="margin: 0 20rpx; font-size: 32rpx">{{
          orderDetail.address_name
        }}</view>
        <text class="phone">{{ orderDetail.address_mobile }}</text>
      </view>
      <view class="address-detail">
        {{ orderDetail.full_address }}
      </view>

      <view
        class="logistics"
        v-if="
          orderDetail.status == 'undelivered' ||
          orderDetail.status == 'domestic_delivered'
        "
      >
        <text class="_label">{{ i18n.logisticsNumber }}</text>
        <view class="num" v-if="orderDetail.logistics.length">
          <text>{{ orderDetail.logistics[0].delivery_company }}</text>
          <text>{{ "&nbsp;" + "|" + "&nbsp;" }}</text>
          <text>{{ orderDetail.logistics[0].delivery_no }}</text>
          <image
            class="cope-icon"
            src="../../static/mine/349.png"
            @click="cope(orderDetail.delivery_no)"
            mode=""
          ></image>
        </view>
      </view>
    </view>

    <commodityDetailVue
      :status="orderDetail.simplify_status"
      :commodityInformation="orderDetail"
      :language="language"
    />

    <view class="order">
      <view class="order-number">
        <text> {{ i18n.OrderNumber }} </text>
        <view>
          {{ orderDetail.order_no }} |
          <text decode @click="cope(orderDetail.order_no)">{{
            "&nbsp;" + i18n.cope
          }}</text>
        </view>
      </view>
      <view class="order-number">
        <text> {{ i18n.payMethod }} </text>
        <view> {{ orderDetail.pay_type_name }} </view>
      </view>
      <view class="order-number">
        <text> {{ i18n.payTime }} </text>
        <view> {{ orderDetail.updated_at }} </view>
      </view>
      <view class="order-number">
        <text> {{ i18n.creationTime }} </text>
        <view> {{ orderDetail.created_at }} </view>
      </view>
      <view class="order-number">
        <text> {{ i18n.modeTransport }} </text>
        <view>
          {{ transportType }}
        </view>
      </view>
    </view>
    <view
      class="footer"
      v-if="
        orderDetail.status == 'domestic_delivered' ||
        orderDetail.status == 'delivered'
      "
    >
      <button
        class="status-1"
        v-if="
          orderDetail.status == 'domestic_delivered' ||
          orderDetail.status == 'delivered'
        "
        @click.stop="toLogistics"
      >
        {{ i18n.checkLogistics }}
      </button>
      <!-- <button
        class="status-2"
        @click="toPayOrder"
        v-if="orderDetail.status == 'undifference'"
      >
        立即付款
      </button> -->
    </view>
    <view
      class="footer"
      v-else-if="orderDetail.goods[0].delivery_status == 'merdelivered'"
    >
      <button class="status-2" @click="toSendOutGoods">
        {{ i18n.immediateDelivery }}
      </button></view
    >
    <view
      class="footer"
      v-else-if="orderDetail.goods[0].delivery_status == 'unfill'"
    >
      <button class="status-2" @click="toPay">
        {{ i18n.PayDeposit }}
      </button></view
    >

    <Remark :show="remarkShow" @remarkClose="remarkClose" />
  </view>
</template>

<script>
import commodityDetailVue from "./component/commodityDetail.vue";
import Remark from "../components/remark.vue";
export default {
  components: {
    commodityDetailVue,
    Remark,
  },
  data() {
    return {
      status: 6,
      show: false,
      title: "",
      orderDetail: {},
      transportType: "",
      remarkShow: false,
      payStatus: "",
      language: this._language, //当前用户选择的语言
    };
  },
  onLoad(option) {
    //获取上个页面传输的值，通过该值获取接口数据
    this.status = option.orderStatus;
    this.payStatus = option.status;
    if (option.status == "unfill") {
      this.getUnfillOrderDetail(option.orderStatus);
    } else {
      this.getDetail(option.orderStatus);
    }
  },
  computed: {
    i18n() {
      return this.$t("index");
    },
  },
  onShow() {
    console.log(this.payStatus);
    if (this.payStatus == "unfill") {
      this.getUnfillOrderDetail(this.status);
    } else {
      this.getDetail(this.status);
    }
  },

  methods: {
    //复制
    cope(e) {
      uni.setClipboardData({
        data: e,
        success() {
          uni.showToast({
            title: this.i18n.replicatingSuccess,
            icon: "none",
          });
        },
      });
    },

    //查看物流进度
    toLogistics(value) {
      uni.navigateTo({
        url: `/pageD/logisticsProgress/logisticsProgress?package=0`,
      });
    },

    //打开备注弹框
    addRemark() {
      this.remarkShow = true;
    },

    //关闭备注弹框
    remarkClose(value) {
      this.remarkShow = false;
      console.log(this.remarkShow);
      //没有接口，有接口再补充
      if (value) {
      }
    },

    getUnfillOrderDetail(id) {
      uni.$u.http
        .post(`/api/order/merchant_order_detail`, { id })
        .then((res) => {
          this.orderDetail = res;
          //直接在dom中使用会报错，首先判断字段存不存在，重新复制后使用
          if (res.container) {
            this.transportType = res.container.transport_type.name;
          }
          this.title = this.i18n.depositPaid;
        });
    },

    //获取订单详情
    getDetail(id) {
      uni.$u.http
        .post(`/api/order/merchant_order_detail`, { id })
        .then((res) => {
          this.orderDetail = res;
          //直接在dom中使用会报错，首先判断字段存不存在，重新复制后使用
          if (res.container) {
            this.transportType = res.container.transport_type.name;
          }
          this.title = res.status_name;
        });
    },

    //跳转支付
    toPay() {
      //所有需要缴纳保证金的金额相加
      let goodsMoney = 0;
      this.orderDetail.goods.map((item) => {
        goodsMoney += Number(item.earnest_money);
      });
      uni.navigateTo({
        url: `/pageA/payorder?sum=${goodsMoney}&orderid=${this.orderDetail.id}&orderType=bond`,
      });
    },

    //跳转支付
    toPayOrder() {
      uni.navigateTo({
        url: `/pageA/payorder?sum=${this.orderDetail.fill_price}&orderid=${this.orderDetail.id}&orderType=difference`,
      });
    },
    //跳转发货页面
    toSendOutGoods() {
      uni.navigateTo({
        url: `/pageD/deliverGoods/deliverGoods?id=${this.orderDetail.id}`,
      });
    },
  },
  created() {
    //设置顶部标题栏颜色
    uni.setNavigationBarColor({
      frontColor: "#000000",
      backgroundColor: "#f4f4f4",
    });
  },
};
</script>

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

  .title {
    .payment {
      font-size: 44rpx;
      font-weight: 600;
      margin-bottom: 20rpx;
    }

    .timer {
      font-size: 28rpx;
      color: #666;
    }
  }

  .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;
      margin-left: 60rpx;
    }
    .logistics {
      display: flex;
      justify-content: space-between;
      align-items: center;
      font-size: 28rpx;
      padding-top: 20rpx;
      border-top: 2rpx solid #f4f4f4;
      margin-top: 20rpx;
      ._label {
        color: #222;
      }
      .num {
        color: #555;
        display: flex;
        align-items: center;
      }
      .cope-icon {
        width: 28rpx;
        height: 28rpx;
        margin-left: 6rpx;
      }
    }
  }

  .order {
    background-color: #fff;
    border-radius: 16rpx;
    color: rgba(54, 54, 54, 0.7);
    font-size: 28rpx;
    margin-top: 20rpx;
    padding: 20rpx 20rpx;

    .order-number {
      display: flex;
      justify-content: space-between;
      margin-bottom: 32rpx;
    }
  }

  .contact {
    padding: 20rpx 0;
    background-color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 16rpx;
    margin-top: 20rpx;
    margin-bottom: 160rpx;
  }

  .footer {
    position: fixed;
    bottom: 0;
    left: 0;
    background-color: #fff;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding-top: 20rpx;
    padding-bottom: 80rpx;
    height: 66rpx;
    width: 100%;

    .status-1 {
      background-color: #fff;
      border-radius: 34rpx;
      margin: 0;
      padding: 0;
      font-size: 28rpx;
      color: #222;
      width: 168rpx;
      height: 68rpx;
      margin-right: 20rpx;
      border: 2rpx solid #979797;
    }

    .status-2 {
      background-color: #ffffff;
      border-radius: 34rpx;
      margin: 0;
      padding: 0;
      font-size: 28rpx;
      color: #f83224;
      height: 68rpx;
      border: 2rpx solid #f83224;
      margin-right: 24rpx;
      line-height: 68rpx;
      padding: 0 34rpx;
    }
  }

  .transition {
    width: 164rpx;
    height: 88rpx;
    background: #ffffff;
    box-shadow: 0rpx 0rpx 20rpx -6rpx rgba(0, 0, 0, 0.3);
    position: fixed;
    bottom: 160rpx;
    text-align: center;
    line-height: 88rpx;
    font-size: 26rpx;
    color: #222;
  }
}
</style>
