ProfitAnalysis.vue
4.87 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<template>
<BasicModal
v-bind="$attrs"
destroyOnClose
@register="register"
title="利润分析表"
width="600px"
@visible-change="handleShow"
:footer="null"
>
<div className="mb-2">
公式:
<Select
className="w-[240px]"
:options="[
{ label: '公式1:1 -(LOCAL总金额 / 汇率 + 包装总金额)/ 客户总金额', value: '0' },
{ label: '公式2:1 -(LOCAL总金额 / 汇率 / (客户总金额-包装费用总金额)', value: '1' },
]"
v-model:value="profitType"
placeholder="请选择"
defaultValue="0"
/>
</div>
<Space>
<span>
汇率:
{{ activeRate }}
</span>
<a-button type="primary" @click="handleCalc" className="ml-4">计算</a-button>
</Space>
<!-- <Button @click="handleCalc">计算</Button> -->
<!-- :helpMessage="['提示1', '提示2']" -->
<!-- <template #insertFooter>
<a-button type="primary" danger @click="setLines" :disabled="loading">点我更新内容</a-button>
</template> -->
<!-- <template v-if="loading">
<div class="empty-tips">加载中,稍等3秒……</div>
</template> -->
<Description
class="mt-4"
layout="vertical"
:collapseOptions="{ canExpand: true, helpMessage: 'help me' }"
:column="2"
:data="info"
:schema="schema"
/>
</BasicModal>
</template>
<script lang="ts">
import { computed, defineComponent, onMounted, ref, toRaw, watch } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { Description, DescItem } from '/@/components/Description/index';
import { orderAnalysis } from '/@/api/project/order';
import { Select, Space } from 'ant-design-vue';
import { useOrderStoreWithOut } from '/@/store/modules/order';
import { getList } from '/@/api/sys/config';
import { useOrderInfo } from '/@/hooks/component/order';
import { useUserStoreWithOut } from '/@/store/modules/user';
export default defineComponent({
components: { BasicModal, Description, Select, Space },
setup() {
const orderStore = useOrderStoreWithOut();
const { exchangeRate } = useOrderInfo(orderStore);
const orderIds = ref([]);
const loading = ref(true);
const lines = ref(10);
const activeRate = ref();
const profitType = ref('0');
const info = ref({});
const [register, { setModalProps, redoModalHeight }] = useModalInner(async (data) => {
orderIds.value = toRaw(data.data);
info.value = {};
});
onMounted(async () => {
const res = await getList({ settingCode: 'exchangeRate', page: 1, pageSize: 10 });
activeRate.value = res?.items?.[0]?.settingValue;
});
const schema: DescItem[] = [
{
field: 'customerTotalPrice',
label: '客户总金额',
render: (val) => '$ ' + (val || 0).toFixed(2),
},
{
field: 'productionDepartmentTotalPrice',
label: '供应商总价',
render: (val) => '¥ ' + (val || 0).toFixed(2),
},
{
field: 'packetTotalPrice',
label: '包装费用',
show: isTracker,
render: (val) => '$' + (val || 0).toFixed(2),
},
{
field: 'profitRate',
label: '总利润率',
show: isTracker,
render: (val) => (Number(val || 0) * 100).toFixed(2) + '%',
},
];
watch(
() => lines.value,
() => {
redoModalHeight();
},
);
const userStore = useUserStoreWithOut();
const user = userStore.getUserInfo;
const role = computed(() => {
return user?.roleSmallVO?.code;
});
/**
* 检查当前角色是否是跟单员
*/
function isTracker() {
if (role.value === 'tracker_user') {
return false;
}
return true;
}
function handleShow(visible: boolean) {
if (visible) {
loading.value = true;
// setModalProps({ loading: true, confirmLoading: true });
setModalProps({ loading: false, confirmLoading: false });
}
}
function setLines() {
lines.value = Math.round(Math.random() * 20 + 10);
}
async function handleCalc() {
const res = await orderAnalysis({
orderIds: orderIds.value,
profitType: profitType.value,
exchangeRate: activeRate.value,
});
info.value = {
...(res || {}),
};
}
return {
register,
loading,
handleShow,
lines,
setLines,
info,
schema,
exchangeRate,
handleCalc,
activeRate,
profitType,
};
},
});
</script>
<style scoped>
.empty-tips {
height: 100px;
line-height: 100px;
text-align: center;
}
</style>