<template>
	<view class="content">
		
		<view class="home-model">
			<div class="model-title">
				<text class="text">综合办公</text>
			</div>
			<div class="model-content">
				<view class="model-c-menu" v-for="item in workMode" hover-class="navigator-hover" :key="item.id" @tap="toPage(item)">

					<image :src="menus[item.id]==1?item.imagePath:item.noImagePath" mode="aspectFill"></image>

					<text class="ico-t-count" v-if="ToDoList[item.id]>0">{{ToDoList[item.id]> 99 ? '99+' : ToDoList[item.id]}}</text>

					<text class="menu-text" :class="{'noFn': !menus[item.id] || menus[item.id]==0}">{{item.name}}</text>
				</view>
				
			</div>
		</view>
		<view class="line-block"></view>
		<view class="home-model">
			<div class="model-title">
				<text class="text">业务审批</text>
			</div>
			<div class="model-content">
				<view class="model-c-menu" v-for="item in yewuMode" hover-class="navigator-hover" :key="item.id" @tap="toPage(item)">

					<image :src="menus[item.id]==1?item.imagePath:item.noImagePath" mode="aspectFill"></image>

					<text class="ico-t-count" v-if="ToDoList[item.id]>0">{{ToDoList[item.id]> 99 ? '99+' : ToDoList[item.id]}}</text>
					<text class="menu-text" :class="{'noFn': !menus[item.id] || menus[item.id]==0}">{{item.name}}</text>
				</view>

			</div>
		</view>
		<view class="line-block"></view>
		<view class="home-model">
			<div class="model-title">
				<text class="text">现场管理</text>
			</div>
			<div class="model-content">
				<view class="model-c-menu" v-for="item in sceneMode" hover-class="navigator-hover" :key="item.id" @tap="toPage(item)">

					<image :src="menus[item.id]==1?item.imagePath:item.noImagePath" mode="aspectFill"></image>
					<text class="ico-t-count" v-if="ToDoList[item.id]>0">{{ToDoList[item.id]> 99 ? '99+' : ToDoList[item.id]}}</text>

					<text class="menu-text" :class="{'noFn': !menus[item.id] || menus[item.id]==0}">{{item.name}}</text>
				</view>
				<view class="model-c-menu" @tap="scanCode()">

					<image src="../../static/images/index/saoyisao.png" mode="aspectFill" v-if="user.Membership_Id"></image>
					<image src=" ../../static/images/index/saoyisao-no.png" mode="aspectFill" v-else></image>

					<text class="menu-text">扫一扫</text>
				</view>
				
			</div>
		</view>
		<view class="line-block"></view>
		<view class="home-model">
			<div class="model-title">
				<text class="text">商业经营</text>
			</div>
			<div class="model-content">
				<view class="model-c-menu" v-for="item in managementMode" hover-class="navigator-hover" :key="item.id" @tap="toPage(item)">

					<image :src="menus[item.id]==1?item.imagePath:item.noImagePath" mode="aspectFill"></image>

					<text class="ico-t-count" v-if="ToDoList[item.id]>0">{{ToDoList[item.id]> 99 ? '99+' : ToDoList[item.id]}}</text>

					<text class="menu-text" :class="{'noFn': !menus[item.id] || menus[item.id]==0}">{{item.name}}</text>
				</view>

			</div>
		</view>
	</view>
</template>

<script>
	import {
		mapGetters,
		mapMutations,
		mapActions
	} from 'vuex'
	const yewu = [{
		"name": "财务审批",
		"id": "1a2907bd-c2f5-4ef9-9ead-70496650ace6",
		"modelName": "FinancialApproval",
		"imagePath": "../../static/images/index/cwsp.png",
		"noImagePath": "../../static/images/index/cwsp-no.png",
		"homeUrl": "/pages/expenseApproval/expenseApproval"
	}, {
		"name": "招标投标",
		"id": "916cdbb5-f05b-4624-b6c4-9f111d4389fc",
		"modelName": "Tender",
		"imagePath": "../../static/images/index/zbtb.png",
		"noImagePath": "../../static/images/index/zbtb-no.png",
		"homeUrl": "/pages/tender/tender"
	}, {
		"name": "服务区报销",
		"id": "8fea5036-d67e-476e-9e56-5f379ba6ae18",
		"modelName": "ServerPartFinancialApproval",
		"imagePath": "../../static/images/index/fwqbx.png",
		"noImagePath": "../../static/images/index/fwqbx-no.png",
		"homeUrl": "/pages/serviceAreaReimbursement/serviceAreaReimbursement"
	}, {
		"name": "合同审批",
		"id": "ac661db4-1af1-4732-88db-76bc05eec335",
		"modelName": "ServerPartCompactApproval",
		"imagePath": "../../static/images/index/htsp.png",
		"noImagePath": "../../static/images/index/htsp-no.png",
		"homeUrl": "/pages/contract/contract"
	}];
	const work = [{
			"name": "公文阅办",
			"id": "2580cb9f-ad2c-4d0b-b478-0be52eaf6ef6",
			"modelName": "Publicity",
			"imagePath": "../../static/images/index/gwyb.png",
			"noImagePath": "../../static/images/index/gwyb-no.png",
			"homeUrl": "/pages/officialDocManagement/officialDocManagement"
		},
		{
			"name": "阳光公示",
			"id": "c870b1bc-95c8-473d-81c8-8596eb793bd4",
			"modelName": "Publicity",
			"imagePath": "../../static/images/index/publicity.png",
			"noImagePath": "../../static/images/index/publicity-no.png",
			"homeUrl": "/pages/publicity/publicity"
		}, {
			"name": "请假加班",
			"id": "1ceeaa5c-d11e-4dcd-8d33-0c3df4cd4937",
			"modelName": "Publicity",
			"imagePath": "../../static/images/index/qjjb.png",
			"noImagePath": "../../static/images/index/qjjb-no.png",
			"homeUrl": "/pages/askForLeave/askForLeave"
		},
		{
			"name": "安全问答",
			"id": "5733dfdd-29f6-4233-9ff0-6f077d80d778",
			"modelName": "Questionnaire",
			"imagePath": "../../static/images/index/aqwd.png",
			"noImagePath": "../../static/images/index/aqwd-no.png",
			"homeUrl": "/pages/webview/webview?name=questionnaire"
		},{
			"name": "考勤打卡",
			"id": "ff04b551-c382-4638-a947-f95c42387ada",
			"modelName": "positionPunching",
			"imagePath": "../../static/images/index/kqdk.png",
			"noImagePath": "../../static/images/index/kqdk-no.png",
			"homeUrl": "/pages/additionalFeatures/positionPunching"
		}
	];
	const scene = [{
			"name": "走动式管理",
			"id": "c26c1620-2149-4b3d-ac2e-07e0c0494042",
			"modelName": "Mbwa",
			"imagePath": "../../static/images/index/zdsgl.png",
			"noImagePath": "../../static/images/index/zdsgl-no.png",
			"homeUrl": "/pages/mbwa/mbwa"
		}, {
			"name": "投诉建议",
			"id": "d405ae13-3388-41c0-a5f6-d11194d0a943",
			"modelName": "Suggestion",
			"imagePath": "../../static/images/index/tsjy.png",
			"noImagePath": "../../static/images/index/tsjy-no.png",
			"homeUrl": "/pages/suggestion/suggestion"
		},
		{
			"name": "收银稽核",
			"id": "",
			"modelName": "Mbwa",
			"imagePath": "../../static/images/index/syjh.png",
			"noImagePath": "../../static/images/index/syjh-no.png",
			"homeUrl": ""
		}, {
			"name": "设备巡检",
			"id": "",
			"modelName": "Suggestion",
			"imagePath": "../../static/images/index/sbxj.png",
			"noImagePath": "../../static/images/index/sbxj-no.png",
			"homeUrl": ""
		},
		{
			"name": "物业管理",
			"id": "",
			"modelName": "Suggestion",
			"imagePath": "../../static/images/index/wygl.png",
			"noImagePath": "../../static/images/index/wygl-no.png",
			"homeUrl": ""
		},
	]
	const management = [{
			"name": "每日营收",
			"id": "74934d31-385a-4eed-80bb-9c9ed7da29b5",
			"modelName": "EverdayRenven",
			"imagePath": "../../static/images/index/mrys.png",
			"noImagePath": "../../static/images/index/mrys-no.png",
			"homeUrl": "/pages/everdayRenven/index"
		},
		{
			"name": "日结校验",
			"id": "b0b63a75-56c9-4f1d-aacb-a26e62b47e3e",
			"modelName": "DataValidation", 
			"imagePath": "../../static/images/index/sjjy.png",
			"noImagePath": "../../static/images/index/sjjy-no.png",
			"homeUrl": "/pages/dataSummary/dataSummary"
		},
		{
			"name": "商品审批",
			"id": "056b29d7-4721-47ee-ad25-660814e1f3a9",
			"modelName": "CommodityApproval",
			"imagePath": "../../static/images/index/spsp.png",
			"noImagePath": "../../static/images/index/spsp-no.png",
			"homeUrl": "/pages/businessApproval/businessApproval"
		},
		{
			"name": "招商审批",
			"id": "2290e96d-c6d7-4dde-b5b7-e699b615ff2f",
			"modelName": "Mnangement",
			"imagePath": "../../static/images/index/zsgl.png",
			"noImagePath": "../../static/images/index/zsgl-no.png",
			"homeUrl": "/pages/investment/investment"
		},
		{
			"name": "商业BI",
			"id": "9125e837-1961-4d92-bdc1-2200260d9643",
			"modelName": "AnnualData",
			"imagePath": "../../static/images/index/ndsj.png",
			"noImagePath": "../../static/images/index/ndsj-no.png",
			"homeUrl": "/pages/webview/webview?src=https://datav.aliyuncs.com/share/4c027574b3a124835e767f1b7dea1a86"
		}
	]
	export default {
		data() {
			return {
				workMode: work,
				yewuMode: yewu,
				sceneMode: scene,
				managementMode: management,
				ToDoList: {}
			}
		},
		onLoad() {
			let _this = this
			setTimeout(function() {
				if (_this.user.UserId) {

					_this.getTodoList()
				}
			}, 2000)

		},
		computed: {
			...mapGetters({
				'user': 'getUser',
				'menus': 'getMenu',
			})
		},
		methods: {
			...mapMutations(['isGetTodoList']),
			...mapActions(['updateUser']),
			scanCode() {
				let _this = this
				uni.scanCode({
					onlyFromCamera: true,
					success: function(res) {
						console.log('条码类型：' + res.scanType)
						console.log('条码内容：' + res.result)
						if (res.scanType.indexOf("QR_CODE") > -1) {

							let result = res.result.toLocaleLowerCase()
							if (result.indexOf('http://eshangtech.com:8000/mbwa/index.html') > -1) {
								let mbwaId = res.result.split('?')[1]
								mbwaId = mbwaId.split('=')[1]
								
								_this.$util.toNextRoute('navigateTo', "/pages/mbwa/mbwaUpload?mbwaID=" + mbwaId)
								
							} else if (res.result.indexOf("http") > -1) {
								_this.$util.toNextRoute('navigateTo', "/pages/webview/webview?src=" + encodeURIComponent(res.result))
								
							} else {
								let invoice = res.result.split(",")
								// console.log(invoice.length)
								if (invoice.length == 9) {
									_this.$util.toNextRoute('navigateTo', "/pages/invoice/invoice?invoice=" + invoice)
									
								} else {
									uni.showModal({
										title: "温馨提示",
										content: "不识别该二维码，请扫描发票或商品条形码",
										showCancel: false,
										confirmText: "确定"
									})
								}
							}
						} else if (res.scanType.indexOf("EAN_13") > -1) {
							this.$util.toNextRoute('navigateTo', "/pages/commodtity/commodtity?commodtity=" + res.result)
							
						} else {
							uni.showModal({
								title: "温馨提示",
								content: "不识别该二维码，请扫描发票或商品条形码",
								showCancel: false,
								confirmText: "确定"
							})
						}
					}
				})

			},
			getTodoList() {
				let _this = this
				_this.$request.$get("ToDoList", {
					userId: _this.user.UserId,
					userName: _this.user.UserName || ''
				}).then(res => {
					_this.ToDoList = res.Data
				})
			},
			recordBrowsing(item) { // 点击业务模块事件

				let _this = this
				if (!item.id) {

					uni.showModal({
						title: ' 温馨提示',
						content: '该模块正在开发，尽请期待',
						
					})
				} else if (_this.menus && _this.menus[item.id] == 1) { // 记录用户访问业务事件
					this.$util.toNextRoute('navigateTo', item.homeUrl)
				} else {
					uni.showToast({
						title: '您没有该模块权限',
						icon: 'none'
					})
				}

			},
			toPage(item) {

				let _this = this
				if (!this.user.Membership_Phone) {
					uni.showModal({
						title: ' 温馨提示',
						content: '您还没有登录，快去登录吧!',
						success(res) {
							if (res.confirm) {
								_this.$util.toNextRoute('navigateTo', '/pages/register/register')
							
							}

						}
					})

				} else if (this.user.UserId == '') {
					uni.showModal({
						title: ' 温馨提示',
						content: '您的账户未绑定综管平台账户，请先绑定以获取业务权限',
						success(res) {
							if (res.confirm) {
								_this.$util.toNextRoute('navigateTo', '/pages/bindingBack/bindingBack')
								
							}

						}
					})
				} else {
					this.recordBrowsing(item)
				}
			},

		},
		onReady() {
			
			this.isGetTodoList(false)
		},
		onShow() {
			if (this.user.UserId) {
				this.getTodoList();
			}
		},
		onPullDownRefresh() {
			let _this = this
			this.updateUser()

			setTimeout(function() {
				uni.stopPullDownRefresh()
				_this.getTodoList()
			}, 1000)
		},
		onTabItemTap(e) {
			
			this.$util.addUserBehavior({
				outtoRoute: '/pages/index/index',
				intoRoute: '/pages/userCenter/userCenter'
			})
		}
	}
</script>

<style scoped>
	.line-block {
		height: 13upx;
		background-color: #F5F5F5;
	}

	.content {
		display: flex;
		flex-direction: column;
		justify-content: center;
	}

	.home-model {
		padding: 24upx 0 32upx 0;
		flex: 1;
		background-color: #fff;
	}

	.model-title {
		display: flex;
		align-items: center;
		padding-left: 16upx;
	}

	.model-title:before {
		content: '';
		height: 26upx;
		width: 6upx;
		background: #2689EE;
		margin-right: 12upx;
	}

	.model-title .text {
		font-size: 30upx;
		font-family: 'SimHei';
		font-weight: bold;
		color: #000000;
	}

	.model-content {
		display: flex;
		align-items: center;
		flex-wrap: wrap;
	}

	.model-c-menu {
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-top: 16upx;
		padding-top: 16upx;
		width: 25%;
		border-radius: 6upx;
		position: relative;
	}

	.model-c-menu image {
		width: 73upx;
		height: 72upx;
	}

	.menu-text {
		font-family: 'SimHei';
		font-size: 24upx;
		color: #3C3C3C;
		margin-top: 8upx;
	}

	.menu-text.noFn {
		color: #D6D8D9;
	}

	.ico-t-count {
		position: absolute;
		color: #fff;
		border-radius: 18upx;
		min-width: 16upx;
		width: auto;
		height: auto;
		padding: 1upx 8upx;
		font-size: 20upx;
		line-height: 1.2;
		text-align: center;
		white-space: nowrap;
		background-color: #ed4d3e;
		position: absolute;
		right: 44upx;
		top: 16upx;
	}
</style>
