<template>
	<view>
		<u-cell-group>
			<!-- 			<u-cell icon="rmb-circle" title="积分余额" value="">
				<u--text slot="right-icon" :text="acTitle" color="rgb(55,186,189)"></u--text>
				<u--text slot="right-icon" :text="amassScore" color="rgb(55,186,189)"></u--text>
			</u-cell> -->
			<!-- <u-cell icon="calendar" title="积分订单" @click="toExpenseCalendarPage" :isLink="true"></u-cell> -->
			<u-cell icon="scan" title="积分卡激活" :isLink="true" @click="takeMeal"></u-cell>
			<!-- <u-cell icon="tags" title="积分卡发放" :isLink="true" @click="grantMeal"></u-cell> -->
			<u-cell icon="map" title="收件地址" :isLink="true" @click="toAddressMgtPage"></u-cell>
			<u-cell icon="clock" title="积分历史" :isLink="true" @click="toAmassScoreRecordPage"></u-cell>
		</u-cell-group>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				acTitle: '',
				amassScore: 0
			}
		},
		onLoad() {
			this.acTitle = uni.getStorageSync('orgInfo').organizationName.substring(0, 1) + "："
			this.getDataAmassScore()
		},
		methods: {

			toExpenseCalendarPage() {
				uni.navigateTo({
					url: "expense/expenseCalendar"
				})
			},
			toAmassScoreRecordPage() {
				this.$goto('amassScoreRecord')
			},
			takeMeal() {
				var that = this;
				uni.scanCode({
					scanType: ['qrCode'],
					success: function(res) {
						// uni.showModal({
						// 	content: JSON.stringify(res),
						// })
						if (res.result) {
							uni.setStorageSync("rfiCard", res.result)
						}
						if (res.result.indexOf("type") !== -1) {
							if (JSON.parse(res.result).data) {
								uni.setStorageSync("rfiCard", JSON.parse(res.result).data)
							}
						}
						that.$goto('activetion');
					},
					fail: function(a) {},
					complete: function(b) {}
				})
			},
			grantMeal() {
				var that = this;
				uni.scanCode({
					scanType: ['qrCode'],
					success: function(res) {
						uni.setStorageSync("rfiCard", res.result)
						that.grantUpLoad(res)
					},
					fail: function(a) {},
					complete: function(b) {}
				})
			},
			toAddressMgtPage() {
				uni.setStorageSync("clickType", 0)
				this.$goto('addressList')
			},
			async grantUpLoad(data) {
				const {
					data: res
				} = await this.$httpRequest({
					url: '/app/scg?cn=' + data.result + "&on=" + uni.getStorageSync("orgInfo")
						.organizationName,
					method: 'get',
					urlType: this.$getUrlType()
				});
				if (res.code === 200) {
					this.$showModal("发放成功")
				} else {
					uni.showToast({
						duration: 2500,
						title: res.msg,
						icon: 'error',
					});
				}
			},
			async getDataAmassScore(data) {
				const {
					data: res
				} = await this.$httpRequest({
					url: '/app/ac?uc=' + uni.getStorageSync("setUserName"),
					method: 'get',
					urlType: this.$getUrlType()
				});
				if (res.code === 200) {
					this.amassScore = res.data
				} else {
					uni.showToast({
						duration: 2500,
						title: res.msg,
						icon: 'error',
					});
				}
			}
		}
	}
</script>

<style>

</style>
