<template>
	<view id="warp">
		<view class="bot_list">
			<block v-for="(item,index) in myNavList" :key="index">
				<block v-if="item.url == 'clear' || item.url == 'feedBack'">
					<view class="cell_list" @tap="handleCell(item.url)">
						<view class="cell_lef">
							<image :src="item.icon"></image>
							<view>{{item.text}}</view>
						</view>
						<view class="cell_rig">
							<image class="cell_icon" src="/static/images/my/right_icon.png"></image>
						</view>
					</view>
				</block>
				<block v-else>
					<view class="cell_list2">
						<picker 
							v-if="item.url == 'showGcName'"
							@change="changeShowGcName" 
							:value="showGcName_index" 
							:range="showGcName" 
							range-key="name"
						>
							<view class="picker_css">
								<view class="cell_lef2">
									<image :src="item.icon"></image>
									<view class="cell_name">{{item.text}}</view>
								</view>
								<view class="cell_rig2">
									<text>{{ showGcName[showGcName_index].name }}</text>
									<image class="cell_icon" src="/static/images/my/right_icon.png"></image>
								</view>
							</view>	
						</picker>
						<picker
							v-if="item.url == 'showRwCar'"
							@change="changeShowRwCar" 
							:value="showRwCar_index" 
							:range="showRwCar" 
							range-key="name"
						>
							<view class="picker_css">
								<view class="cell_lef2">
									<image :src="item.icon"></image>
									<view class="cell_name">{{item.text}}</view>
								</view>
								<view class="cell_rig2">
									<text>{{ showRwCar[showRwCar_index].name }}</text>
									<image class="cell_icon" src="/static/images/my/right_icon.png"></image>
								</view>
							</view>	
						</picker>
						<picker 
							v-if="item.url == 'isAddGc'"
							@change="changeAddGc" 
							:value="isAddGc_index" 
							:range="isAddGc" 
							range-key="name"
						>
							<view class="picker_css">
								<view class="cell_lef2">
									<image :src="item.icon"></image>
									<view class="cell_name">{{item.text}}</view>
								</view>
								<view class="cell_rig2">
									<text>{{ isAddGc[isAddGc_index].name }}</text>
									<image class="cell_icon" src="/static/images/my/right_icon.png"></image>
								</view>
							</view>
						</picker>
						<picker
							v-if="item.url == 'stop'"
							@change="bindPickerChange" 
							:value="stop_time_index" 
							:range="stopTime" 
							range-key="name"
						>
							<view class="picker_css">
								<view class="cell_lef2">
									<image :src="item.icon"></image>
									<view class="cell_name">{{item.text}}</view>
								</view>
								<view class="cell_rig2">
									<text>{{ stopTime[stop_time_index].name }}</text>
									<image class="cell_icon" src="/static/images/my/right_icon.png"></image>
								</view>
							</view>
						</picker>
					</view>
				</block>
			</block>
		</view>
		<view class="btn_css">
			<button class="btn" @tap="outLogin">退出登录</button>
		</view>
	</view>
</template>

<script>
	const {urlList,https} = require('@/static/api');
	export default {
		data() {
			return {
				showGcName:[{name:'不显示'},{name:'显示'}],
				showGcName_index:0,
				showRwCar:[{name:'不显示'},{name:'显示'}],
				showRwCar_index:0,
				isAddGc:[{name:'无'},{name:'有'}],
				isAddGc_index:0,
				stopTime:[],
				stop_time_index:0,
				myNavList:[
					{text:'一键派工是否显示工程名称',url:'showGcName',icon:'/static/images/setting/gcName.png'},
					{text:'一键派工是否显示任务车型',url:'showRwCar',icon:'/static/images/setting/rwCar.png'},
					{text:'调度角色添加工程名称的权限',url:'isAddGc',icon:'/static/images/setting/diaodu.png'},
					{text:'停留标示',url:'stop',icon:'/static/images/setting/speed_timer.png'},
					// {text:'修改密码',url:'pwd',icon:'/static/images/setting/change_password.png'},
					{text:'清理缓存',url:'clear',icon:'/static/images/setting/clear.png'},
					{text:'意见反馈',url:'feedBack',icon:'/static/images/setting/feedback.png'},
				]
			};
		},
		onLoad() {
			const that = this;
			that.getTimeStopTag();
			uni.getStorage({
				key:"userCompany",
				success(res) {
					console.log('公司信息',res.data)
					that.showGcName_index = res.data.isOpenDispatch == true?1:0;
					that.isAddGc_index = res.data.isSchedulingAddProject == true?1:0;
					that.showRwCar_index = res.data.isOpenVehicleType == true?1:0;
				}
			});
		},
		methods:{
			handleCell(type){
				switch (type){
					case 'pwd':
						uni.navigateTo({
							url:'/pages/changePassWord/changePassWord'
						})
						break;
					case 'feedBack':
						uni.navigateTo({
							url:'/pages/feedBack/feedBack'
						})
						break;
					case 'clear':
						uni.showModal({
							content:'清理缓存后将自动退出登录,是否清理缓存?',
							success: function (res) {
								if (res.confirm) {
									https(urlList.clearStorage,'GET','','正在清理...').then(data => {
										wx.clearStorage({
											success: (res) => {
												wx.reLaunch({
													url: '/pages/login/login',
												})
											},
										})
									}).catch(err => {
										uni.showToast({
											title:err,
											icon:'none',
											duration:1500
										})
									})
								}
							}
						})
						break;
				}
				
				
			},
			// 一键派工是否显示工程名称
			changeShowGcName(e){
				let idx = e.detail.value;
				https(urlList.setShowDispatchGcName,'PUT','','设置中...').then(data => {
					this.getCompany();
					this.showGcName_index = idx;
					uni.showToast({
						title:'设置成功',
						icon:'none',
						duration:1500
					})
				}).catch(err => {
					uni.showToast({
						title:err,
						icon:'none',
						duration:1500
					})
				})
			},
			// 一键派工是否显示任务车型选项
			changeShowRwCar(e){
				let idx = e.detail.value;
				https(urlList.setShowDispatchRwCar,'PUT','','设置中...').then(data => {
					this.getCompany();
					this.showRwCar_index = idx;
					uni.showToast({
						title:'设置成功',
						icon:'none',
						duration:1500
					})
				}).catch(err => {
					uni.showToast({
						title:err,
						icon:'none',
						duration:1500
					})
				})
			},
			// 添加工程权限
			changeAddGc(e){
				let idx = e.detail.value;
				https(urlList.setShowDDGcName,'PUT','','设置中...').then(data => {
					this.isAddGc_index = idx;
					this.getCompany();
					uni.showToast({
						title:'设置成功',
						icon:'none',
						duration:1500
					})
				}).catch(err => {
					uni.showToast({
						title:err,
						icon:'none',
						duration:1500
					})
				})
			},
			getCompany(){
				https(urlList.getUserCompany,'GET','','').then(data => {
					uni.setStorage({
						key:"userCompany",
						data:data.data,
					});
				}).catch(err => {
					uni.showToast({
						title:err,
						icon:'none',
						duration:1000
					})
				})
			},
			// 选择停留标示
			bindPickerChange(e){
				let idx = e.detail.value;
				const id = this.stopTime[idx].id;
				https(urlList.setTimeStopTagId+'/'+id,'PUT','','设置中...').then(data => {
					this.stop_time_index = idx;
					uni.showToast({
						title:'设置成功',
						icon:'none',
						duration:1500
					})
				}).catch(err => {
					uni.showToast({
						title:err,
						icon:'none',
						duration:1500
					})
				})
			},
			// 获取公司停留标示列表
			getTimeStopTag(){
				const _that = this;
				https(urlList.getTimeStopTag+'/'+'stoptag','GET','','').then(data => {
					// console.log('停留标示列表',data)
					let stopTime = data.data;
					_that.stopTime = stopTime;
					let stopTag = uni.getStorageSync('userCompany').stopTag;   
					_that.stop_time_index = stopTime.findIndex(item => item.id == stopTag);
				}).catch(err => {
					uni.showToast({
						title:err,
						icon:'none',
						duration:1500
					})
				})
			},
			// 退出登录
			outLogin(){
				uni.showModal({
				    content: '是否确定退出登录',
					success: function (res) {
						if (res.confirm) {
							uni.clearStorageSync();
							uni.reLaunch({
								url: '/pages/login/login',
							})
						}
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
#warp{
	width: 100%;
	height: 100%;
	display: flex;
	flex-direction: column;
	align-items: center;
	.bot_list{
		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		.cell_list{
			width: 700rpx;
			height: 100rpx;
			border-bottom: 1rpx solid #f4f4f4;
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: space-between;
			.cell_lef{
				width: 70%;
				display: flex;
				flex-direction: row;
				align-items: center;
				image{
					height: 45rpx;
					width: 45rpx;
					margin-right: 20rpx;
				}
			}
			.cell_rig{
				display: flex;
				flex-direction: row;
				align-items: center;
				justify-content: flex-end;
				.cell_icon{
					height: 22rpx;
					width: 22rpx;
				}
			}
		}
		.cell_list2{
			width: 700rpx;
			height: 100rpx;
			border-bottom: 1rpx solid #f4f4f4;
			display: flex;
			flex-direction: row;
			align-items: center;
			.picker_css{
				width:700rpx;
				height:100%;
				display: flex;
				flex-direction: row;
				flex-wrap: nowrap;
				align-items: center;
				justify-content: space-between;
				.cell_lef2{
					width:70%;
					// border: 1rpx solid red;
					display: flex;
					flex-direction: row;
					align-items: center;
					image{
						height: 45rpx;
						width: 45rpx;
						margin-right: 20rpx;
					}
					.cell_name{
						display: flex;
						flex-direction: row;
						align-items: center;
					}
				}
				.cell_rig2{
					width: 30%;
					display: flex;
					flex-direction: row;
					align-items: center;
					justify-content: flex-end;
					text{
						font-size: 32rpx;
						color: #999999;
						margin-right: 15rpx;
					}
					.cell_icon{
						height: 22rpx;
						width: 22rpx;
					}
				}
			}
		}
	}
	.btn_css{
		width: 95%;
		position: fixed;
		bottom: 20rpx;
		.btn{
			background-color:#1B64F8FF;
			color: white;
		}
	}
}
</style>
