order-actions.vue 2.96 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";

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

export default {
  props: {
    actionList: {
      type: Array,
      default: () => []
    },
    code: {
      type: Number,
      default: 0
    }
  },
  methods: {
    ...mapActions(["deleteOrder"]),
    onAction(action) {
      const { owner } = this.$route.params;
      if (action.name === orderActionsMap.DEL_ORDER.name) {
        this.$createDialog({
          type: "confirm",
          content: "确认删除订单?",
          onConfirm: async () => {
            const isOk = await this.deleteOrder({
              orderCode: this.code,
              owner
            });
            const txt = isOk ? "删除成功" : "删除失败";
            this.$createToast({ txt, type: "txt" }).show();
          }
        }).show();
      }
    },
    createDialog(options) {
      const {
        confirmBtn,
        cancelBtn,
        onConfirm,
        onCancle,
        content,
        ...config
      } = options;
      this.$createDialog(config, createElement => {
        return [
          createElement(
            "a",
            {
              class: {
                "cube-dialog-btn border-top-1px action-confirm": true
              },
              slot: "btns",
              on: {
                click: () => {
                  console.log("--------btn------");
                }
              }
            },
            confirmBtn.text
          ),
          createElement(
            "a",
            {
              class: {
                "cube-dialog-btn border-top-1px action-cancel": true
              },
              slot: "btns"
            },
            cancelBtn.text
          ),
          createElement(
            "p",
            {
              class: {
                "action-dialog-content": true
              },
              slot: "content"
            },
            content
          )
        ];
      }).show();
    },
    onActionConfirm() {}
  }
};
</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: 24px 64px 22px 64px;
    color: #999;
    letter-spacing: 0;
    border-radius: 0;
    background: #fff;
    border: 1px solid #ccc;
    line-height: 1.3;
    width: 224px;
    margin-right: 20px;
    white-space: nowrap;
  }

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