<template>
  <div class="app-content">
    <div class="page-top">
      <div class="page-top-img">
        <image mode="widthFix" :src="`${constant.imgUrl}/retail/order/bg.png`" alt />
      </div>
      <div class="page-top-det">
        <div>
          <div class="page-status">{{ data.status | constantfilter('ORDER_STATUS') }}</div>
          <div class="page-prompt" v-if="data.status == 0">请尽快支付哟~</div>
          <div class="page-prompt" v-if="data.status == 1 || data.status == 2">请耐心等待~</div>
        </div>
        <div class="page-status-img">
          <img :src="statusImg" alt />
        </div>
      </div>
    </div>
    <!-- 订单详情 -->
    <div class="page-det">
      <!-- 商品信息 -->
      <div class="module-com">
        <div class="module-tit">商品信息</div>
        <div class="module-det">
          <block v-if="!$util.isEmpty(data.goodsInfoList)">
            <list-module
              v-for="(items, subIndex) in data.goodsInfoList"
              :key="subIndex"
              :info="items"
            />
          </block>
        </div>
      </div>
      <!-- 订单信息 -->
      <div class="module-com order-msg">
        <div class="module-tit">订单信息</div>
        <div class="module-det">
          <!--  -->
          <div class="order-msg-blo">
            <div class="msg-list">
              <div class="label">收花人</div>
              <div class="value">{{ data.receiveUserName }}</div>
            </div>
            <div class="msg-list">
              <div class="label">电话</div>
              <div class="value">{{ data.receiveMobile }}</div>
            </div>
            <div class="msg-list">
              <div class="label">地址</div>
              <div class="value">{{ data.fullAddress }}</div>
            </div>
          </div>
          <!--  -->
          <div class="order-msg-blo">
            <div class="msg-list">
              <div class="label">送达时间</div>
              <div v-if="data.reachDate == '0000-00-00'" class="value"></div>
              <div v-else class="value">{{ data.reachDate ? data.reachDate+' '+reachPeriodInfo : '' }}</div>
            </div>
            <div class="msg-list">
              <div class="label">贺卡</div>
              <div class="value">{{ data.needCard == 1 ? "需要" : '不需要' }}</div>
            </div>
            <div class="msg-list" v-show="data.needCard == 1">
              <div class="label">贺卡内容</div>
              <div class="value">{{ data.cardInfo}}</div>
            </div>
            <div class="msg-list">
              <div class="label">匿名派送</div>
              <div class="value">{{ data.anonymity == 1 ? '是' : '' }}</div>
            </div>
          </div>
          <!--  -->
          <div class="order-msg-blo">
            <div class="msg-list">
              <div class="label">订单号</div>
              <div class="value">{{ data.orderSn }}</div>
            </div>
            <div class="msg-list">
              <div class="label">时间</div>
              <div class="value">{{ data.addTime}}</div>
            </div>
            <div class="msg-list">
              <div class="label">运费</div>
              <div class="value">￥{{ data.sendCost }}</div>
            </div>
            <div class="msg-list">
              <div class="label">总价</div>
              <div class="value">￥{{ data.prePrice }}</div>
            </div>
            <div class="msg-list">
              <div class="label">支付方式</div>
              <div class="value">{{ payWayInfo }}</div>
            </div>
          </div>
        </div>
      </div>
      <!-- 优惠信息 -->
      <block v-if="data.status == 0">
        <div class="module-com coupon-wrap" v-if="!$util.isEmpty(discountArr)">
          <div class="module-tit">优惠信息</div>
          <div class="module-det">
            <app-coupon-sel
              ref="couponSel"
              :price="data.prePrice * data.goodsNum"
              :discountArr="['member', 'coupon']"
            />
          </div>
        </div>
      </block>
      <block v-else>
        <div
          class="module-com coupon-wrap"
          v-if="data.discountAmount && data.discountAmount != '0.00'"
        >
          <div class="module-tit">优惠信息</div>
          <div class="module-det">
            <div
              class="app-color-3"
            >{{ data.discountType == 1 ? '优惠券' : data.discountType == 2 ? '会员优惠' : '随机优惠' }}</div>
            <div class="app-price">-￥{{ data.discountAmount }}</div>
          </div>
        </div>
      </block>
    </div>
    <!-- 按钮 -->
    <div class="page-btn app-footer">
      <div class="flex-center">
        <span v-if="data.status == 0">待付款</span>
        <span v-else>实付款</span>
        <span class="app-price">
          <span>￥</span>
          <span class="app-size-40">{{ data.actPrice }}</span>
        </span>
      </div>
      <template v-if="data.status == 1">
        <button class="button-com red" @click="payFn">立即支付</button>
      </template>
      <template v-else-if="data.status == 5">
        <template v-if="data.grade == 0">
          <button class="button-com middle" @click="evealFn">评价</button>
        </template>
      </template>
    </div>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import ListModule from "@/components/module/app-order-list";
import AppCouponSel from "@/components/app-coupon-sel";
import { getDetail } from "@/api/order";
import { getShopUser } from "@/utils/auth";
export default {
  name: "order-detail",
  components: {
    ListModule,
    AppCouponSel
  },
  data() {
    return {
      constant: this.$constant,
      data: {},
      discountArr: false,
      payWayInfo: "微信支付",
      reachPeriodInfo: "上午"
    };
  },
  computed: {
    ...mapGetters({ shopUser: "getShopUser" }),
    statusImg() {
      let img = "";
      if (this.data.status == 0) {
        img = `${this.$constant.imgUrl}/retail/order/wait-pay.png`;
      } else if (this.data.status == 1) {
        img = `${this.$constant.imgUrl}/retail/order/wait-delivery.png`;
      } else if (this.data.status == 2) {
        img = `${this.$constant.imgUrl}/retail/order/in-delivery.png`;
      } else if (this.data.status == 5) {
        img = `${this.$constant.imgUrl}/retail/order/order-confirm.png`;
      }
      return img;
    }
  },
  onLoad() {
    // this.init()
  },
  methods: {
    init() {
      this._getDet().then(() => {
        getShopUser().then(res => {
          if (this.data.status == 0) {
            this.$refs.couponSel._getUserDiscount().then(status => {
              this.discountArr = status;
            });
          }
        });
      });
    },
    _getDet() {
      let form = {};
      if (this.option.id) {
        form.id = this.option.id;
      } else if (this.option.orderSn) {
        form.orderSn = this.option.orderSn;
      }
      return getDetail(form).then(res => {
        this.data = res.data;

        if (res.data.payWay == 0) {
          this.payWayInfo = "微信支付";
        } else if (res.data.payWay == 1) {
          this.payWayInfo = "支付宝";
        } else if (res.data.payWay == 2) {
          this.payWayInfo = "余额";
        } else {
          this.payWayInfo = "其它";
        }

        if (res.data.reachPeriod == 0) {
          this.reachPeriodInfo = "上午";
        } else if (res.data.reachPeriod == 1) {
          this.reachPeriodInfo = "下午";
        } else if (res.data.reachPeriod == 2) {
          this.reachPeriodInfo = "晚上";
        } else {
          this.reachPeriodInfo = "上午";
        }
      });
    },
    payFn() {
      let data = {
        orderSn: this.data.orderSn,
        totalPrice: this.data.prePrice,
        couponId: 0
      };
      this.$util.pageTo({
        url: "/pages/callback/index",
        query: {
          pageStatus: 1,
          id: this.data.id,
          ...data
        }
      });
    },
    evealFn() {
      this.$util.pageTo({
        url: "/pages/order/comment",
        query: {
          id: this.data.id
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.app-content {
  padding-bottom: 80px;
}
.page-top {
  position: relative;
  .page-top-det {
    position: absolute;
    top: 22px;
    @include disFlex(center, space-between);
    width: 84%;
    padding: 0 48px;
    color: #fff;
    .page-status {
      font-size: 36px;
      font-weight: bold;
      margin-bottom: 16px;
    }
    .page-prompt {
      color: #ffdede;
    }
    .page-status-img {
      width: 180px;
    }
  }
}
.page-det {
  width: 94%;
  /*  #ifdef  MP-WEIXIN  */
  margin: 0 auto 90rpx auto;
  /*  #endif  */
  /*  #ifdef  H5  */
  margin: 0 auto 25rpx auto;
  /*  #endif  */
  position: relative;
  top: -40px;
  .order-msg {
    .order-msg-blo {
      font-size: 28px;
      padding: 20px 0;
      border-top: 1px solid $borderColor;
      .msg-list {
        @include disFlex(flex-start, space-between);
        margin: 16px 0;
        .label {
          width: 40%;
          color: $fontColor3;
        }
      }
    }
    & .order-msg-blo:first-child {
      border-top: none;
    }
  }
  .coupon-wrap {
    .module-det {
      padding: 20px 0;
    }
  }
}
// 底部按钮
.page-btn {
  width: calc(100% - 60px);
  @include disFlex(center, space-between);
  padding: 0 30px;
  .app-price {
    margin-bottom: 8px;
    margin-left: 4px;
  }
  .red {
    width: 270px;
  }
  .default {
    width: 260px;
  }
}
// 公共模块
.module-com {
  border-radius: 10px;
  background-color: #fff;
  padding: 0 20px;
  box-shadow: 0px 6px 16px #ddd;
  margin-bottom: 20px;
  .module-tit {
    padding: 20px 0;
    font-size: 28px;
    font-weight: 600;
    border-bottom: 1px solid $borderColor;
  }
}
</style>
