feature.vue 3.83 KB
<template>
	<view>
		<view class="content">
			<checkbox-group @change="checkboxChange">
				<view class="content-item u-f u-f-aic plr-10" v-for="(item,index) in menuList" :key="index">
					<view class="title u-f1">
						{{item.label}}
					</view>
					<view class="inp u-f2 check-box">
						<checkbox :value="item.label" :checked="item.checked" @tap="checkboxClick" />
					</view>
				</view>
			</checkbox-group>
		</view>
		<view class="footer u-f u-f-aic">
			<button  class="btn u-f u-f-jcc u-f-aic" :loading="loading" type="warn" @tap="save"
				:disabled="disabled">保存</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				menuList: [{
						label: '总库存',
						checked: true
					},
					{
						label: '入库管理',
						checked: true
					},
					{
						label: '出库管理',
						checked: true
					},
					{
						label: '物料',
						checked: true
					},
					{
						label: '任务',
						checked: true
					},
					{
						label: '盘点单',
						checked: true
					},
					{
						label: '预警设置',
						checked: true
					}
				],
				loading: false,
				disabled: false,
				selectList: [],
				timer: null
			}
		},
		onLoad() {
			this.$api.menu.listMenu().then(res => {
				if (res.data.code == 200) {
					if (res.data.data.length > 0) {
						this.selectList = res.data.data;
						this.menuList.forEach(item => {
							if (!res.data.data.includes(item.label)) {
								item.checked = false;
							}
						});
					}
				}
			});
		},
		onUnload() {
			if (this.timer) {
				clearTimeout(this.timer);
				this.timer = null;
			}
		},
		methods: {
			checkboxClick() {
				this.flag = !this.flag
			},
			checkboxChange(e) {
				this.selectList = e.target.value;
			},
			save() {
				if (this.selectList.length == 0) {
					uni.showModal({
						title: '提示',
						content: '您至少要保留一个常用功能!',
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
					return
				}
				this.loading = true;
				this.disabled = true;
				this.$api.menu.updateMenu(this.selectList).then(res => {
					if (res.data.code == 200) {
						this.loading = false;
						this.disabled = false;
						this.$prePage().handleSelect(this.selectList);
						this.$wx.showToast({
							title: '保存成功!'
						});
						this.timer = setTimeout(() => {
							uni.navigateBack();
						}, 400);

					} else {
						uni.showModal({
							title: '提示',
							content: res.data.msg
						});
						this.loading = false;
						this.disabled = false;
					}
				}).catch(err => {
					this.loading = false;
					this.disabled = false;
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		overflow-y: auto;
		background-color: $uni-bg-color;

		.content-item {
			height: 90rpx;
			line-height: 90rpx;
			border-bottom: 2rpx solid $uni-border-color;

			.title {
				font-size: $uni-font-size-lg;
			}

			.inp {
				text-align: right;
				font-size: $uni-font-size-lg;

				/deep/ uni-checkbox .uni-checkbox-input.uni-checkbox-input-checked {
					color: $uni-text-color-inverse !important;
					background-color: $uni-color-primary;
					border-radius: 50%;
				}

				/deep/ uni-checkbox .uni-checkbox-input {
					border-radius: 50%;
				}
			}
		}

		.bottom {
			margin-top: $uni-spacing-col-base;
		}

	}

	.footer {
		position: fixed;
		bottom: 0;
		width: 100%;
		height: 140rpx;
		background-color: #fff;
		border-top: 2rpx solid #E1F3D8;

		.btn {
			width: 100%;
			height: 80rpx;
			line-height: 80rpx;
			color: #fff;
			text-align: center;
			font-size: $uni-font-size-lg;
			border-radius: 50rpx;
			margin: 0 30rpx;
			background-color: $uni-color-primary;
            &:after {
            	border: none;
            }
		}
	}
</style>