unit.vue
4.73 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
<template>
<view>
<view class="header">
<uni-search-bar @confirm="handleSearch" @clear="searchClear" placeholder="输入名称"></uni-search-bar>
</view>
<view class="unit-list">
<view :class="[item.dictLabel !== '空选择'?'item' : 'empty']" v-for="(item,index) in unitList" :key="index" v-if="item.dictLabel">
<view class="top" @tap="listClick(item.dictLabel)">
<view class="t-content u-f u-f-jcsb p-10">
<view class="name empty">
{{item.dictLabel}}
</view>
<view>
<uni-icons type="arrowright" size="18" color="gray"></uni-icons>
</view>
</view>
</view>
<view class="bottom" v-if="item.dictLabel !== '空选择'">
<view class="operate p-10">
<view class="delete" @tap="delUnit(item.dictCode)">删除</view>
<view class="modify" @tap="editUnit(item.dictCode)">修改</view>
</view>
</view>
</view>
<uni-load-more :iconSize="18" :status="loadStatus"></uni-load-more>
</view>
</view>
</template>
<script>
export default {
data() {
return {
// 查询参数
queryParams: {
dictType: 'unitType',
dictLabel: '',
pageNum: 1,
pageSize: 10
},
total: null,
loadStatus: "",
unitList: [],
}
},
onNavigationBarButtonTap() {
uni.navigateTo({
url: "edit"
})
},
onPullDownRefresh() {
this.queryParams.pageNum = 1;
this.getUnitList()
},
onReachBottom() {
if (this.queryParams.pageNum >= this.total / 10) {
this.loadStatus = "noMore";
return
}
this.loadStatus = "loading";
this.queryParams.pageNum++;
this.getUnitList();
},
onLoad() {
this.getUnitList();
uni.$on('editUpdateUnit', () => {
this.getUnitList();
this.$msg("保存成功!");
});
uni.$on('addUpdateUnit', () => {
this.getUnitList();
this.$msg("保存成功!");
})
},
onUnload() {
uni.$off('editUpdateUnit');
uni.$off('addUpdateUnit');
},
methods: {
//获取单位列表
getUnitList() {
this.$http.dict.listDict(this.queryParams).then(res => {
console.log(res)
let emptySelect = {
dictLabel: "空选择",
dictSort: 0,
dictType: "unitType",
dictValue: "空选择",
status: "0"
};
if (this.queryParams.pageNum > 1) {
this.unitList = this.unitList.concat(res.data.rows);
} else {
this.unitList = res.data.rows;
this.unitList.unshift(emptySelect)
}
this.total = res.data.total;
uni.stopPullDownRefresh();
});
},
// 顶部搜索
handleSearch(e) {
console.log(e);
this.queryParams.dictLabel = e.value;
this.getUnitList()
},
// 清除搜索
searchClear() {
this.queryParams.dictLabel = '';
this.getUnitList()
},
// 列表点击
listClick(value) {
console.log(value)
let pages = getCurrentPages();
let prevPage = pages[pages.length - 2];
console.log(prevPage);
prevPage._data.abc = value;
uni.navigateBack()
},
// 修改按钮操作
editUnit(dictCode) {
uni.navigateTo({
url: 'edit?dictCode= ' + dictCode + '&type=edit'
})
},
// 删除按钮操作
delUnit(dictCode) {
uni.showModal({
title: '提示',
content: '确定要删除该计量单位吗?',
success: (res) => {
if (res.confirm) {
this.$http.dict.delDict(dictCode).then(res => {
if (res.data.code == 200) {
this.unitList.forEach((item, index) => {
this.unitList.splice(index, 1);
this.$msg('删除成功!')
})
} else {
uni.showModal({
title: '提示',
content: res.data.msg
});
}
})
} else if (res.cancel) {
console.log('用户点击取消');
}
}
});
}
},
}
</script>
<style lang="scss" scoped>
.header {
position: fixed;
top: 88rpx;
width: 100%;
z-index: 1;
}
.unit-list {
margin-top: 124rpx;
.item {
margin-top: 20rpx;
height: 180rpx;
background-color: $uni-bg-color;
.top,
.bottom {
height: 90rpx;
}
.top {
.t-content {
height: 90rpx;
line-height: 90rpx;
.name {
font-weight: bold;
}
}
}
.bottom {
hegiht: 90rpx;
line-height: 90rpx;
border-top: 2rpx solid $uni-border-color;
.operate {
text-align: right;
.delete,
.modify {
display: inline-block;
width: 100rpx;
height: 45rpx;
line-height: 45rpx;
text-align: center;
border: 1rpx solid $uni-border-color;
border-radius: 25rpx;
}
.delete {
margin-right: $uni-spacing-row-base;
}
}
}
}
.empty {
height: 90rpx;
line-height: 90rpx;
background-color: $uni-bg-color;
.name {
font-weight: bold;
color: $uni-color-primary;
}
}
}
</style>