zhengyiming
2025-02-10 0f686ea1fe4700a909a6159efcf1fcb0e1f88a17
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<template>
  <ResourceCard v-bind="props">
    <template #title-right>
      <div class="more-btn" @click.stop="handleMore">
        <img :src="IconMore" class="more-btn-icon" />
      </div>
    </template>
    <template #footer>
      <div class="common-card-footer-time" style="margin-left: 0">
        创建于:{{ dayjs(props.time).format('MM-DD HH:mm') }}
      </div>
    </template>
  </ResourceCard>
</template>
 
<script setup lang="ts">
import dayjs from 'dayjs';
import { ResourceStatus } from '@12333/constants';
import IconMore from '@/assets/order/icon-more.png';
import { Portal } from 'senin-mini/components';
import { ActionSheet } from '@nutui/nutui-taro';
import { ManageActions } from '@/subpackages/setting/constants';
 
defineOptions({
  name: 'ResourceManageCard',
});
 
type Props = {
  title?: string;
  src?: string;
  name?: string;
  jobTitle?: string;
  time?: string;
  resourceCount?: number;
  intendedDeliveryCities?: API.CityInfo[];
  status?: ResourceStatus;
};
 
const props = withDefaults(defineProps<Props>(), {});
 
const emit = defineEmits<{
  (e: 'edit'): void;
  (e: 'detail'): void;
  (e: 'publish'): void;
  (e: 'stop'): void;
  (e: 'copy'): void;
  (e: 'delete'): void;
}>();
 
const menuList = computed(() => {
  let _menuList = [];
  if (props.status !== ResourceStatus.WaitAudit) {
    _menuList.push({
      name: '编辑',
      value: ManageActions.Edit,
    });
  }
  _menuList.push({
    name: '查看详情',
    value: ManageActions.Detail,
  });
  if (props.status === ResourceStatus.OffShelf) {
    _menuList.push({
      name: '重新发布',
      value: ManageActions.Publish,
    });
  }
  if (props.status === ResourceStatus.Running) {
    _menuList.push({
      name: '停止发布',
      value: ManageActions.Stop,
    });
  }
  if (props.status !== ResourceStatus.WaitAudit) {
    _menuList.push(
      {
        name: '复制',
        value: ManageActions.Copy,
      },
      {
        name: '删除',
        value: ManageActions.Delete,
      }
    );
  }
 
  return _menuList;
});
 
function handleMore() {
  Portal.add((key) => {
    return h(
      Portal.Container,
      { keyNumber: key, delayOpen: true },
      {
        default: ({ open, onClose }) =>
          // @ts-ignore
          h(ActionSheet, {
            visible: open.value,
            'onUpdate:visible': () => onClose(),
            menuItems: menuList.value,
            onChoose: (item) => {
              handleEmit(item);
              onClose();
            },
          }),
      }
    );
  });
}
 
function handleEmit(action: { name: string; value: number }) {
  switch (action.value) {
    case ManageActions.Edit:
      emit('edit');
      break;
    case ManageActions.Detail:
      emit('detail');
      break;
    case ManageActions.Publish:
      emit('publish');
      break;
    case ManageActions.Stop:
      emit('stop');
      break;
    case ManageActions.Copy:
      emit('copy');
      break;
    case ManageActions.Delete:
      emit('delete');
      break;
  }
}
</script>
 
<style lang="scss">
@import '@/styles/common.scss';
 
.more-btn {
  padding-left: 40px;
 
  .more-btn-icon {
    width: 32px;
    height: 32px;
  }
}
</style>