index.vue
4.67 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
<template>
<view
class="boxCon dataAdmin"
v-if="store.state.user.deliveryData.length > 0"
>
<button class="uni-btn concelBtn" @click="handleAdmin" v-if="!isAdmin">
管理
</button>
<view v-else class="adminInfo">
<view class="selectInfo">
<label class="checkRadio">
<radio
value="1"
:checked="selected.size === store.state.user.deliveryData.length"
:class="
selected.size === store.state.user.deliveryData.length
? 'active'
: ''
"
@click="allSelect"
/>
全选
</label>
总计
<text class="num">{{ selected.size }}</text>
条
</view>
<view>
<button
class="uni-btn concelBtn"
v-if="isAdmin"
@click="handleAccomplish"
>
完成
</button>
<button
class="uni-btn btn-default"
v-if="tabIndex === 0 && !isDelivery"
@click="handleOrder"
>
转单
</button>
<button
class="uni-btn btn-default"
v-else-if="tabIndex === 1 && !isDelivery"
@click="handlePrint"
>
打印
</button>
<button
class="uni-btn btn-default"
v-if="!isDelivery && tabIndex === 2"
@click="handleBatchDelete"
>
批量删除
</button>
</view>
</view>
<!-- 提示窗示例 -->
<UniPopup
ref="popup"
:tipInfo="tipInfo"
@handleClick="handleClick"
></UniPopup>
<!-- end -->
</view>
</template>
<script setup>
import {ref} from "vue";
import {useStore} from "vuex";
// 弹层
import UniPopup from "@/components/uni-popup/index.vue";
// ------定义变量------
// 获取父组件数据
const props = defineProps({
// 已选内容
selected: {
type: Map,
default: () => [],
},
// 当前tab切换值,判断是已取件还是待取件
tabIndex: {
type: Number,
default: null,
},
// 是否触发管理按钮,此处是用来控制是否显示全选、条数、转单、打印、删除按钮
isAdmin: {
type: Boolean,
default: false,
},
// 区分取件派件
isDelivery: {
type: Boolean,
default: false,
},
});
const store = useStore();
const users = store.state.user;
const emit = defineEmits();
let popup = ref();
const tipInfo = ref("确定要批量删除吗?");
let itemData = store.state.user.deliveryData;
// ------定义方法------
// 管理数据
const handleAdmin = () => {
emit("getAdmin", true);
};
// 全选
const allSelect = () => {
emit("allSelect");
};
// 转单
const handleOrder = () => {
if (props.selected.size > 0) {
let ids = [];
for (let [key, value] of props.selected) {
ids.push(value);
}
if (props.isDelivery) {
store.commit("user/setIsDelivery", true);
} else {
store.commit("user/setIsDelivery", false);
}
uni.navigateTo({
url: "/pages/turnorder/index",
});
} else {
return uni.showToast({
title: "请选择任务!",
duration: 1000,
icon: "none",
});
}
};
// 批量删除
const handleBatchDelete = () => {
if (props.selected.size > 0) {
popup.value.dialogOpen();
} else {
return uni.showToast({
title: "请选择要删除的任务!",
duration: 1000,
icon: "none",
});
}
};
// 打印
const handlePrint = () => {
uni.showToast({
title: "程序员哥哥正在实现中",
duration: 1000,
icon: "none",
});
};
// 完成
const handleAccomplish = () => {
let itemData = users.deliveryData;
props.selected.clear(); // 全部清除
itemData.forEach((element) => {
element.selected = false; // 全部不选,就行了
});
store.commit("user/setDeliveryData", itemData);
emit("getAdmin", false);
};
// 确认删除
const handleClick = () => {
emit("handleClick");
};
</script>
<style lang="scss" scoped>
.dataAdmin {
padding: 24rpx 30rpx 24rpx 36rpx;
position: fixed;
bottom: 100rpx;
left: 0;
right: 0;
z-index: 0;
.concelBtn,
.btn-default {
height: 60rpx;
line-height: 60rpx;
width: 140rpx;
border-radius: 30rpx;
font-weight: 600;
}
.btn-default {
margin-left: 20rpx !important;
}
.concelBtn {
float: right;
}
.num {
color: var(--essential-color-red);
padding: 0 4rpx;
}
.adminInfo {
display: flex;
align-items: center;
height: 60rpx;
line-height: 60rpx;
& > view {
&.selectInfo {
flex: 1;
.checkRadio {
padding-right: 24rpx;
}
}
&:last-child {
text-align: right;
display: flex;
}
}
}
}
</style>