<template>
	<div class="todo-container">
		<div class="todo-icon">
			<img :src="imgUrl" style="display:block;width:50px;height:50px" />
		</div>
		<div class="todo-content">
			<div class="content-title" :class="`title-color-${itemSetting.properties.color}`">
				<span>{{itemSetting.properties.title}}</span>
			</div>
			<span class="content-total" @click="gotoQuery">
				<countTo :startVal='0' :endVal='todoCount' :duration='500'></countTo>
				<span class="content-unit">元</span>
			</span>
			<div class="content-desc">{{itemSetting.properties.desc}}</div>
		</div>
	</div>
</template>
<script>
import countTo from 'vue-count-to'
	export default {
		components: {
			countTo
		},
		props: {
			itemSetting: {
				type: Object,
				default: () => {}
			},
		},
		computed: {
			imgUrl(){
				return require(`../assets/img/${this.itemSetting.properties.color}.png`)
			}
		},
		data() {
			return {
				obj: {
					SQL: '',
					title:'待办事项',
					templateName: '',
					icon: '#icon-_CDdaibanzhongxinh',
					desc: '',
					color: ''
				},
				todoCount: 0
			};
		},
		created() {
			console.log('itemSetting', this.itemSetting)
			let prop = this.itemSetting.properties;
			if (!prop || prop.length == 0) {
				this.itemSetting.properties = {};
				this.itemSetting.properties = this.obj;
			}
			this.getQuery(this.itemSetting.properties.SQL)
			
		},
		methods: {
			getQuery(val) {
				let url = `${osConfig.baseUrl}/rbc/bill/homePage/selectCount/${val}`
				$.ajax({
					type:"GET",
					url:url,
					async:false,
					contentType: "application/json;",
					beforeSend: function(request) {
							request.setRequestHeader("Authorization", nros.SDK.utils.getToken());
					},
					success: (res) => {
						const {msg, code, data} = res
						if(code === 0) {
							this.todoCount = data
						} else {
							console.log('msg', msg)
						}
					},
					error:function(error){
							console.log('error', error)
					}
				})
				// 封装的公共GMS根本不能用啊
				// GMS.$http.get(url).then(res => {
				// 	console.log('res', res)
				// }).catch(error => {
				// 	console.log('error', error)
				// })
			},
			gotoQuery(){
				GMS.$hideContainer.$router.push({
            path: `/backToQuery/${this.itemSetting.properties.templateName}`
        })
			}
		}
	};

</script>
<style lang="less" scoped>

.todo-container{
	width: 100%;
	height: 100%;
	// display: flex;
	padding: 30px;
	// padding: 46px 24px;
	.todo-content{
		// width: 70%;
		// width: 70%;
		overflow: hidden;
		text-align: left;
		.content-title {
			font-size: 20px;
			line-height: 20px;
		}
		.content-total {
			cursor: pointer;
			font-size: 26px;
			font-weight: 400;
			color: #555555;
		}
		.content-unit{
			color: #555555;
			font-size: 14px;
		}
		.content-desc {
			color: #888888;
			font-size: 14px;
		}
	}
	.todo-icon{
		width: 50px;
		float: left;
		margin-right: 16px;
		// width: 30%;
		font-size: 50px;
		text-align: center;
	}
	.title-color-info {
		color: #3F7AF2;
	}
	.title-color-success {
		color: #1BE1B2;
	}
	.title-color-warning {
		color: #F3B72C;
	}
	.title-color-error {
		color: #F34466;
	}
}
</style>