index.vue
7.45 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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<template>
<el-dialog
:title="$t('system.custom.transferDialogTitle')"
v-loading="loading"
:visible.sync="dialogVisible"
style="min-width: 700px"
width="40%"
center
append-to-body
:close-on-click-modal="false"
:before-close="handleClose"
>
<el-radio-group class="inlineRadio" v-model="radio" @change="radioChange">
<el-radio :label="1">{{ $t("system.custom.transferRadio1") }}</el-radio>
<el-radio :label="2">{{ $t("system.custom.transferRadio2") }}</el-radio>
</el-radio-group>
<div class="transferDom">
<el-transfer
class="customTransfer"
ref="customTransfer"
filterable
target-order="push"
:titles="titles"
v-model="value"
:data="customData"
:props="{
key: 'poolCode',
label: 'displayName',
disabled: 'disabled',
}"
@change="valueChange"
@right-check-change="rightCheckChange"
>
<span slot-scope="{ option }">{{ option.displayName }} </span>
</el-transfer>
<div class="transfer-rightOption">
<el-button
type="text"
class="el-icon-arrow-up"
:disabled="
rightSelect.length != 1 || value.length == 1 || rightSelectIdx == 0
"
@click="up"
></el-button>
<el-button
type="text"
class="el-icon-arrow-down"
:disabled="
rightSelect.length != 1 ||
value.length == 1 ||
rightSelectIdx == value.length - 1
"
@click="down"
></el-button>
</div>
</div>
<span slot="footer" class="dialog-footer">
<el-button class="entrySaveButton" @click="handleClose">{{
$t("system.close")
}}</el-button>
<el-button
class="entrySaveButton entrySaveButton-background"
type="primary"
:loading="submitLoading"
@click="submit"
>{{ $t("system.confirm") }}</el-button
>
</span>
</el-dialog>
</template>
<script>
import { getCustomData, setCustomData } from "@/api/custom-api.js";
import i18n from "@/assets/languages";
export default {
props: {
dialogVisible: {
type: Boolean,
default: false,
},
belongBizType: {
//页面标识代码 11#员工端预审,12#员工端站点,13#员工端口岸,14#员工端运单查询
type: Number,
default: 0,
},
titles: {
type: Array,
default: () => {
return [
i18n.t("system.custom.transferLeftTitle"),
i18n.t("system.custom.transferRightTitle"),
];
},
},
},
data() {
return {
customData: [], //总数据集
value: [], //
rightSelect: [],
rightSelectIdx: 0,
radio: 1,
loading: false,
submitLoading: false,
};
},
watch: {
dialogVisible(val) {
if (val) {
this.getCustom();
}
},
value(val) {
this.$emit("transfeChange", { customData: this.customData, value: val });
},
},
methods: {
//获取自定义数据
getCustom() {
this.loading = true;
this.submitLoading = true;
return new Promise((resolve, reject) => {
getCustomData({
belongBizType: this.belongBizType,
queryType: this.radio,
})
.then((res) => {
if (res.code === "200") {
this.rightSelectIdx = 0;
this.customDataInfo(res);
resolve();
} else {
this.alertWarningMsg(res.message);
reject();
}
this.loading = false;
this.submitLoading = false;
})
.catch((err) => {
this.loading = false;
this.submitLoading = false;
console.log(err);
reject();
});
});
},
//上移
up() {
let arr = JSON.parse(JSON.stringify(this.value));
let selectid = JSON.parse(
JSON.stringify(this.value[this.rightSelectIdx])
);
let shiftSelect = JSON.parse(
JSON.stringify(this.value[this.rightSelectIdx - 1])
);
arr[this.rightSelectIdx] = shiftSelect;
arr[this.rightSelectIdx - 1] = selectid;
this.$nextTick(() => {
this.value = arr;
// this.rightSelect = [];
this.rightSelectIdx = this.rightSelectIdx - 1;
// this.$refs.customTransfer.$children[3].checked = [];
});
},
//下移
down() {
let arr = JSON.parse(JSON.stringify(this.value));
let selectid = JSON.parse(
JSON.stringify(this.value[this.rightSelectIdx])
);
let shiftSelect = JSON.parse(
JSON.stringify(this.value[this.rightSelectIdx + 1])
);
arr[this.rightSelectIdx] = shiftSelect;
arr[this.rightSelectIdx + 1] = selectid;
this.$nextTick(() => {
this.value = arr;
// this.rightSelect = [];
this.rightSelectIdx = this.rightSelectIdx + 1;
// this.$refs.customTransfer.$children[3].checked = [];
});
},
//切换类型
radioChange(val) {
this.customData = [];
this.value = [];
this.$nextTick(() => {
this.getCustom();
});
},
//保存修改数据
submit() {
this.submitLoading = true;
let arr = [];
this.value.forEach((val) => {
this.customData.forEach((item) => {
if (val == item.poolCode) {
arr.push({
defaultOrderNum: item.defaultOrderNum,
displayName: item.displayName,
id: null,
orderNum:
arr.length == 0 ? 2001 : Number("200" + (arr.length + 1)),
poolCode: item.poolCode,
});
}
});
});
setCustomData({
belongBizType: this.belongBizType,
queryType: this.radio,
target: arr,
})
.then((res) => {
if (res.code === "200") {
this.loading = true;
this.customDataInfo(res);
this.$emit("customTransferSubmit", { selectData: this.radio });
this.handleClose();
} else {
this.alertWarningMsg(res.message);
}
this.submitLoading = false;
})
.catch((err) => {
this.submitLoading = false;
console.log(err);
});
},
//右侧数据改变
valueChange(val) {
this.rightSelect = [];
this.rightSelectIdx = 0;
},
//右侧选中数据改变
rightCheckChange(val) {
this.rightSelect = val;
this.value.find((value, index) => {
if (value == val) {
this.rightSelectIdx = index;
}
});
},
//数据初始化
customDataInfo(val) {
let arr = val.data.extra.source;
val.data.extra.target.forEach((item) => {
this.value.push(item.poolCode);
let status = true;
arr.forEach((value) => {
if (item.poolCode == value.poolCode) {
status = false;
}
});
if (status) {
arr.push({
poolCode: item.poolCode,
displayName: item.displayName,
defaultOrderNum: item.orderNum,
});
}
});
this.customData = arr.sort(this.compare("defaultOrderNum"));
this.loading = false;
},
//关闭页面
handleClose() {
this.$emit("close");
this.customData = [];
this.value = [];
this.rightSelect = [];
this.rightSelectIdx = 0;
this.radio = 1;
},
},
};
</script>
<style></style>