order-actions.vue 4.56 KB
<template>
  <div class="actions-wrapper">
    <Button
      v-for="action in actionList"
      :key="action.code"
      @click="() => onActionHandler(action)"
    >
      {{ action.text }}
    </Button>
  </div>
</template>

<script>
import {
  orderActionsMap,
  ownType
} from "../../../../constants/order-constants";
import { createNamespacedHelpers } from "vuex";
import CancelConfirmInfo from "./order-list/cancel-confirm-info";

const { mapActions, mapState } = createNamespacedHelpers("order/orderList");

const { mapMutations: orderMapMutations } = createNamespacedHelpers("order");

const { mapMutations: inSaleOrderMapMutations } = createNamespacedHelpers(
  "order/inSaleOrderList"
);

export default {
  props: {
    order: {
      type: Object,
      default: {}
    }
  },
  computed: {
    ...mapState(["cancelConfirmInfo"]),
    actionList: function() {
      return this.order.buttons;
    }
  },
  methods: {
    ...mapActions([
      "deleteOrder",
      "cancelTradeConfirmInfo",
      "cancelTrade",
      "confirmReceipt"
    ]),
    onActionHandler(action) {
      const { owner = ownType.SELL } = this.$route.params;
      const {
        orderCode,
        earnestMoney = 0,
        realPrice = "",
        priceInfo = {}
      } = this.order;

      const { productId, storageId, skup } = this.order.goodsInfo;

      switch (action.name) {
        // 再次购买
        case orderActionsMap.BUY_AGAIN.name:
          this.$router.push({
            name: "ProductDetail",
            params: { productId }
          });
          break;

        // 查看详情
        case orderActionsMap.SHOW_DETAIL.name:
          const name =
            owner === ownType.SELL ? "sellOrderDetail" : "buyOrderDetail";
          this.$router.push({
            name,
            params: { owner, orderCode }
          });
          break;

        // 再次出售
        case orderActionsMap.SOLD_AGAIN.name:
          this.$router.push({
            name: "OrderSellConfirm",
            query: { productId, storageId }
          });
          break;

        // 查看物流
        case orderActionsMap.SHOW_EXPRESS.name:
          this.$router.push({
            name: "orderLogisticsInfo",
            params: { owner, orderCode }
          });
          break;
        // 调价
        // 非入住商家
        case orderActionsMap.NOT_ENTRY_CHANGE_PRICE.name:
          this.$router.push({
            name: "PriceChangeNoEntry",
            params: { orderCode }
          });
          break;

        // 入住商家
        case orderActionsMap.STORAGE_MANAGE.name:
          this.$router.push({
            name: "PriceChangeEntry",
            params: { orderId: productId }
          });
          break;

        // 我要发货
        case orderActionsMap.DELIVER_GOODS.name:
          this.$router.push({
            name: "order.deliver",
            params: { skup, code: orderCode }
          });
          break;
        // 确认收货
        case orderActionsMap.CONFIRM_DELIVERY.name:
          this.$createDialog({
            type: "confirm",
            onConfirm: async () => {
              const isOk = await this.confirmReceipt({
                orderCode,
                owner
              });

              // const txt = isOk ? "收货成功" : "收货失败";
              // this.$createToast({ txt, type: "txt" }).show();
            }
          });
          break;

        case orderActionsMap.PAY_EARNESTMONEY.name:
          this.$createOrderPayType({
            orderCode,
            price: earnestMoney,
            desc: "保证金"
          }).show();
          break;
        // 订单列表和订单详情字段不一致
        case orderActionsMap.NOW_BUY.name:
          this.$createOrderPayType({
            orderCode,
            price: parseFloat(realPrice || priceInfo.realPayPrice || ""),
            desc: ""
          }).show();
          break;

        default:
          this.$emit("on-action", action);
      }
    }
  }
};
</script>

<style lang="scss">
.action-dialog-content {
  text-align: center;
  color: #000;
}

.action-confirm {
  color: #d0021b;
}

.action-cancel {
  color: #000;
}
</style>

<style lang="scss" scoped>
.actions-wrapper {
  display: flex;
  justify-content: flex-end;

  button {
    font-size: 24px;
    padding: 18.4px 64px;
    color: #999;
    letter-spacing: 0;
    background: #fff;
    border: 1px solid #ccc;
    line-height: 1.4;
    margin-right: 20px;
    white-space: nowrap;
    border-radius: 40px;
  }

  & :last-child {
    background: #002b47;
    color: #fff;
    border: 1px solid #002b47;
    margin-right: 0;
  }
}
</style>