feature.vue 3.49 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" :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() {
			try {
				const value = uni.getStorageSync('feature_select');
				if (value) {
					this.selectList = value;
					this.menuList.forEach(item => {
						if (!value.includes(item.label)) {
							item.checked = false;
						}
					});

				}
			} catch (e) {
				// error
			}

		},
		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.$wx.showToast({
					title: '保存成功!'
				});
				this.$prePage().handleSelect(this.selectList);
				try {
					uni.setStorageSync('feature_select', this.selectList);
				} catch (e) {
					// error
				};
				this.timer = setTimeout(() => {
					this.loading = false;
					this.disabled = false;
					uni.navigateBack()
				}, 400);


			}
		}
	}
</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;

		}
	}
</style>