Blame view

src/views/project/order/ProfitAnalysis.vue 5.19 KB
sanmu authored
1
2
3
4
5
6
<template>
  <BasicModal
    v-bind="$attrs"
    destroyOnClose
    @register="register"
    title="利润分析表"
sanmu authored
7
    width="600px"
sanmu authored
8
9
10
    @visible-change="handleShow"
    :footer="null"
  >
sanmu authored
11
    <div className="mb-2">
sanmu authored
12
      公式:
sanmu authored
13
      <Select
sanmu authored
14
        className="w-[240px]"
sanmu authored
15
        :options="[
sanmu authored
16
17
          { label: '公式1:1 -(LOCAL总金额 / 汇率 + 包装总金额)/ 客户总金额', value: '0' },
          { label: '公式2:1 -(LOCAL总金额 / 汇率 / (客户总金额-包装费用总金额)', value: '1' },
sanmu authored
18
19
20
        ]"
        v-model:value="profitType"
        placeholder="请选择"
sanmu authored
21
        defaultValue="0"
sanmu authored
22
23
24
25
26
27
28
29
30
31
      />
    </div>
    <Space>
      <span>
        汇率:
        {{ activeRate }}
      </span>
      <a-button type="primary" @click="handleCalc" className="ml-4">计算</a-button>
    </Space>
    <!-- <Button @click="handleCalc">计算</Button> -->
sanmu authored
32
    <!-- :helpMessage="['提示1', '提示2']" -->
sanmu authored
33
34
35
36
37
38
39
40
41
42
43
    <!-- <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"
sanmu authored
44
      :data="info"
sanmu authored
45
46
47
48
49
      :schema="schema"
    />
  </BasicModal>
</template>
<script lang="ts">
sanmu authored
50
  import { computed, defineComponent, onMounted, ref, toRaw, watch } from 'vue';
sanmu authored
51
  import { BasicModal, useModalInner } from '/@/components/Modal';
sanmu authored
52
  import { Description, DescItem } from '/@/components/Description/index';
sanmu authored
53
  import { orderAnalysis } from '/@/api/project/order';
sanmu authored
54
55
56
57
  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';
58
  import { useUserStoreWithOut } from '/@/store/modules/user';
sanmu authored
59
60

  export default defineComponent({
sanmu authored
61
    components: { BasicModal, Description, Select, Space },
sanmu authored
62
    setup() {
sanmu authored
63
64
65
      const orderStore = useOrderStoreWithOut();
      const { exchangeRate } = useOrderInfo(orderStore);
      const orderIds = ref([]);
sanmu authored
66
67
      const loading = ref(true);
      const lines = ref(10);
sanmu authored
68
      const activeRate = ref();
sanmu authored
69
      const profitType = ref('0');
sanmu authored
70
      const info = ref({});
71
      const searchData = ref();
sanmu authored
72
      const [register, { setModalProps, redoModalHeight }] = useModalInner(async (data) => {
sanmu authored
73
        orderIds.value = toRaw(data.data);
74
        searchData.value = data.searchData;
sanmu authored
75
76
        info.value = {};
      });
sanmu authored
77
sanmu authored
78
79
      onMounted(async () => {
        const res = await getList({ settingCode: 'exchangeRate', page: 1, pageSize: 10 });
sanmu authored
80
        activeRate.value = res?.items?.[0]?.settingValue;
sanmu authored
81
82
83
84
      });

      const schema: DescItem[] = [
        {
sanmu authored
85
          field: 'customerTotalPrice',
sanmu authored
86
          label: '客户总金额',
sanmu authored
87
          render: (val) => '$ ' + (val || 0).toFixed(2),
sanmu authored
88
89
        },
        {
90
          field: 'productionDepartmentTotalPrice',
sanmu authored
91
          label: '供应商总价',
sanmu authored
92
          render: (val) => '¥ ' + (val || 0).toFixed(2),
sanmu authored
93
94
        },
        {
95
          field: 'packetTotalPrice',
sanmu authored
96
          label: '包装费用',
sanmu authored
97
          render: (val) => '$' + (val || 0).toFixed(2),
sanmu authored
98
99
        },
        {
sanmu authored
100
          field: 'profitRate',
sanmu authored
101
          label: '总利润率',
sanmu authored
102
          render: (val) => (Number(val || 0) * 100).toFixed(2) + '%',
sanmu authored
103
        },
104
105
        {
          field: 'orderTotalNum',
106
          label: '订单商品数量',
107
108
109
110
          render: (val) => val || 0,
        },
        {
          field: 'recordNum',
111
          label: '含有利润分析的订单数',
112
113
          render: (val) => val || 0,
        },
sanmu authored
114
115
116
117
118
119
120
121
      ];

      watch(
        () => lines.value,
        () => {
          redoModalHeight();
        },
      );
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
      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;
      }
sanmu authored
137
138
139
140
141

      function handleShow(visible: boolean) {
        if (visible) {
          loading.value = true;
          // setModalProps({ loading: true, confirmLoading: true });
sanmu authored
142
          setModalProps({ loading: false, confirmLoading: false });
sanmu authored
143
144
145
146
147
148
        }
      }

      function setLines() {
        lines.value = Math.round(Math.random() * 20 + 10);
      }
sanmu authored
149
150
151
152
153
154

      async function handleCalc() {
        const res = await orderAnalysis({
          orderIds: orderIds.value,
          profitType: profitType.value,
          exchangeRate: activeRate.value,
155
          queryVO: searchData.value,
sanmu authored
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
        });
        info.value = {
          ...(res || {}),
        };
      }
      return {
        register,
        loading,
        handleShow,
        lines,
        setLines,
        info,
        schema,
        exchangeRate,
        handleCalc,
        activeRate,
        profitType,
      };
sanmu authored
174
175
176
177
178
179
180
181
182
183
    },
  });
</script>
<style scoped>
  .empty-tips {
    height: 100px;
    line-height: 100px;
    text-align: center;
  }
</style>