ProductText.vue
8.17 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<template>
<!-- <BasicModal
v-bind="$attrs"
destroyOnClose
@register="register"
title="生产指示书"
width="500px"
:height="80"
wrapClassName="h-[340px]"
@visible-change="handleShow"
:footer="null"
> -->
<BasicModal
v-bind="$attrs"
destroyOnClose
@register="register"
title="生产指示书"
width="500px"
@visible-change="handleShow"
:footer="null"
:bodyStyle="{ height: '210px' }"
>
<div class="container">
<div v-if="isShow1 == true" style="margin-top: 50px">
<RadioGroup v-model:value="choose" :options="options" />
</div>
<div class="showPdf" v-if="isShow2 == true" style="margin-top: 35px; text-align: center">
<!-- <img src="/pdf.png" /> -->
<FilePptOutlined :style="{ fontSize: '20px' }" class="FilePptOutlined" />
<div style="margin-top: 1px; margin-left: 10px">生产指示书</div>
<EyeOutlined :style="{ fontSize: '20px' }" class="EyeOutlined" @click="handlePdf" />
</div>
<div class="bottom">
<a-radio v-model:checked="checked" @click="toggleChecked" v-if="isShow1 == true"
>生成弃用指示书</a-radio
>
<a-button type="primary" @click="handleProduct" className="ml-4" v-if="isShow1 == true"
>生成</a-button
>
<a-button
type="primary"
@click="handleExport"
className="ml-4"
:loading="exportLoading"
v-if="isShow1 == false"
>发送</a-button
>
<a-button type="primary" @click="handleCancel" className="ml-4" style="margin-left: 6px"
>取消</a-button
>
</div>
</div>
</BasicModal>
</template>
<script lang="ts">
import { defineComponent, ref, computed, onMounted, onUpdated } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { RadioGroup } from 'ant-design-vue';
import { EyeOutlined, FilePptOutlined } from '@ant-design/icons-vue';
import { useMessage } from '@/hooks/web/useMessage';
import { createProductText, exportProductText } from '@/api/project/order';
export default defineComponent({
props: {
role: {
type: String,
},
customerCodes: {
type: Array<string | number>,
},
},
components: { BasicModal, RadioGroup, EyeOutlined, FilePptOutlined },
setup(props) {
const loading = ref(true);
const exportLoading = ref(false);
const info = ref();
const checkedKeys = ref();
const choose = ref(); //选择公司
const isShow1 = ref(true); //选择公司页面
const isShow2 = ref(false); //生成PDF页面
const pdf = ref(['/pdf.png']);
const [register, { setModalProps, closeModal }] = useModalInner(async (data) => {
checkedKeys.value = data.checkedKeys;
});
// Define the checked state as a ref
const checked = ref(false); // Initial checked state
// Method to toggle the checked state
const toggleChecked = () => {
// Toggle the checked state between true and false
checked.value = !checked.value;
};
const options = computed(() => {
// 运营总监-基本信息,跟单,质检
return [
{ label: '青岛翱特逸格饰品有限公司', value: '青岛翱特逸格饰品有限公司' },
{ label: ' 青岛吉庆天成饰品有限公司', value: '青岛吉庆天成饰品有限公司' },
];
});
const { createMessage } = useMessage();
const { error, success } = createMessage;
const customerCodeToCompanyMap: Record<string, string> = {
A01: '青岛翱特逸格饰品有限公司',
A04: '青岛吉庆天成饰品有限公司',
A05: '青岛吉庆天成饰品有限公司',
A06: '青岛翱特逸格饰品有限公司',
A07: '青岛吉庆天成饰品有限公司',
A08: '青岛翱特逸格饰品有限公司',
A09: '青岛翱特逸格饰品有限公司',
A10: '青岛翱特逸格饰品有限公司',
A11: '青岛翱特逸格饰品有限公司',
M03: '青岛吉庆天成饰品有限公司',
M05: '青岛吉庆天成饰品有限公司',
};
function handleCancel() {
loading.value = true;
choose.value = '';
setModalProps({ loading: false, confirmLoading: false });
isShow1.value = true;
isShow2.value = false;
closeModal();
}
function handleShow(visible: boolean) {
if (visible) {
loading.value = true;
choose.value = '';
setModalProps({ loading: false, confirmLoading: false });
isShow1.value = true;
isShow2.value = false;
checked.value = false;
}
}
function validateCompany(selectedCodes: any, company: string): boolean {
for (const [customerCode] of selectedCodes) {
const mappedCompany = customerCodeToCompanyMap[customerCode];
if (mappedCompany === undefined) {
// 如果 customerCode 不在 customerCodeToCompanyMap 中,跳过
console.warn(`Customer code ${customerCode} not found in the mapping, skipping.`);
continue;
}
if (mappedCompany !== company) {
// 如果有一个不匹配,返回 false
return false;
}
}
// 如果所有匹配,返回 true
return true;
}
//生成pdf
const resText = ref();
// const customerCodeList: string[] = props.customerCodes;
//三秒内不能再次点击生成标志
let isDisabled = false;
async function handleProduct() {
if (isDisabled) {
error('请勿连续点击生成按钮,需要等待三秒再点击生成');
return;
}
const customerCodeList = props.customerCodes;
const areValid = validateCompany(customerCodeList, choose.value);
// // 设置禁用标志并在 3 秒后重置
isDisabled = true;
setTimeout(() => {
isDisabled = false;
}, 3000);
//如果选错了,弹出提示
if (!areValid) {
error('勾选订单与选择的公司不匹配');
} else {
if (
choose.value == '青岛翱特逸格饰品有限公司' ||
choose.value == '青岛吉庆天成饰品有限公司'
) {
resText.value = await createProductText({
ids: checkedKeys.value,
companyName: choose.value,
isTrue: checked.value,
});
//此处设置接口,传递选择的公司值
isShow1.value = false;
isShow2.value = true;
}
}
}
//查看pdf
function handlePdf() {
window.open(resText.value.productionUrl);
}
//发送按钮
async function handleExport() {
const res = await exportProductText({
productionUrl: resText.value.productionUrl,
productionDepartment: resText.value.productionDepartment,
personList: resText.value.personList,
isSend: true,
projects: resText.value.projects,
});
console.log();
success('操作成功,已发送给生产科、业务员、跟单员');
closeModal();
}
return {
register,
loading,
choose,
handleShow,
handleCancel,
info,
handleExport,
handleProduct,
handlePdf,
exportLoading,
isShow1,
isShow2,
options,
pdf,
checked,
toggleChecked,
};
},
});
</script>
<style scoped>
/* .container {
position: relative;
}
.bottom {
position: absolute;
bottom: 0;
} */
.container {
display: flex;
flex-direction: column;
/* min-height: 20vh; */
}
.bottom {
margin-top: 40px;
/* margin-right: auto; */
margin-left: 150px;
}
.showPdf {
display: flex;
position: relative;
height: 30px;
width: 470px;
border: 2px solid;
border-radius: 5px;
border-color: #d8d8d8;
}
.FilePptOutlined {
margin-top: 3px;
margin-left: 30px;
}
.EyeOutlined {
margin-top: 3px;
margin-left: 290px;
}
</style>