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

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

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

export default {
  props: {
    order: {
      type: Object,
      default: {}
    }
  },
  computed: {
    ...mapState(["cancelConfirmInfo"]),
    actionList: function() {
      return this.order.buttons;
    }
  },
  methods: {
    ...mapActions(["deleteOrder", "cancelTradeConfirmInfo", "cancelTrade"]),
    async onAction(action) {
      const { owner } = this.$route.params;
      const { orderCode } = this.order;
      const { productId, storageId } = this.order.goodsInfo;

      switch (action.name) {
        // 删除订单
        case orderActionsMap.DEL_ORDER.name:
          this.$createDialog({
            type: "confirm",
            content: "确认删除订单?",
            onConfirm: async () => {
              const isOk = await this.deleteOrder({
                orderCode,
                owner
              });
              const txt = isOk ? "删除成功" : "删除失败";
              this.$createToast({ txt, type: "txt" }).show();
            }
          }).show();
          break;
        // 再次购买
        case orderActionsMap.BUY_AGAIN.name:
          this.$router.push({
            path: `/xianyu/product/${productId}.html`
          });
          break;
        // 查看详情
        case orderActionsMap.SHOW_DETAIL.name:
          this.$router.push({
            path: `/xianyu/${owner}/order/detail/${orderCode}`
          });
          break;
        // 再次出售
        case orderActionsMap.SOLD_AGAIN.name:
          this.$router.push({
            path: "/xianyu/order/sellconfirm.html",
            query: { productId, storageId }
          });
          break;
        // 查看物流
        case orderActionsMap.SHOW_EXPRESS.name:
          this.$router.push({
            path: `/xianyu/${owner}/order/logistics/${orderCode}`
          });
          break;
        // 调价
        // 非入住商家
        case orderActionsMap.NOT_ENTRY_CHANGE_PRICE.name:
          this.$router.push({
            path: `/xianyu/order/priceChangeNoEntry/${orderCode}.html`
          });
          break;
        // 入住商家
        case orderActionsMap.STORAGE_MANAGE:
          this.$router.push({
            path: `/xianyu/order/priceChangeEntry/${productId}.html`
          });
          break;

        // 取消订单 | 不卖了
        case orderActionsMap.NOT_SOLD.name:
        case orderActionsMap.CANCEL_ORDER.name:
          const confirmInfo = await this.cancelTradeConfirmInfo({
            orderCode,
            owner
          });
          let dialogConfig = {
            confirmBtn: { text: "取消订单" },
            cancelBtn: { text: "保留订单" }
          };
          if (owner === "sell") {
            dialogConfig = {
              confirmBtn: { text: "不卖了" },
              cancelBtn: { text: "继续出售" }
            };
          }
          this.$createDialog(
            {
              ...dialogConfig,
              type: "confirm",
              onConfirm: async () => {
                const isOk = await this.cancelTrade({
                  orderCode,
                  owner
                });

                const txt = isOk ? "取消成功" : "取消失败";
                this.$createToast({ txt, type: "txt" }).show();
              }
            },
            createElement => {
              return [
                createElement(CancelConfirmInfo, {
                  slot: "content",
                  props: { confirmInfo }
                })
              ];
            }
          ).show();
          break;

        default:
          return;
      }
    }
  }
};
</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;
  margin-top: 40px;

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

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