<template>
	<view class="card-detail padding-top padding-bottom">

		<view class="cu-form-group " v-show="itemForm.courseProjectName!=undefined">
			<text>
				<view class="solid-bottom">
					{{itemForm.courseProjectName}}
				</view>
			</text>
			<text>剩余次数: {{itemForm.courseRestCount}}</text>
			<text>可用次数: {{itemForm.courseConsumeCount}}</text>
		</view>
		<view class="cu-form-group margin-bottom" v-show="itemForm.courseProjectName!=undefined">
			<text><text class="padding-right">黄金间隔期</text> 8 天</text>
		</view>
		<view class="cu-form-group margin-top margin-bottom recSize" style="font-size: 13px;" v-show="itemForm.rechargeTypeName!=undefined">
			<text>{{itemForm.rechargeTypeName}}</text>
			<text>剩余金额: <text class="text-red recSize" style="font-size: 13px;">{{itemForm.cardRestMoney}}</text></text>
			<text>可用金额: <text class="text-red  recSize" style="font-size: 13px;">{{itemForm.cardConsumeMoney}}</text></text>
			<text>赠送金额: <text class="text-red  recSize" style="font-size: 13px;">{{itemForm.cardGiftMoney}}</text></text>
		</view>
<!-- 		<scroll-view scroll-x class="bg-white nav text-center ">
			<view class="cu-item bg-cyan " :class="item.year==TabCur?'light':''" v-for="(item,index) in list"
				:key="index" @tap="tabSelect" :data-id="item.year">
				<text>{{item.month}}</text>
			</view>
		</scroll-view> -->
		<view v-show="pageInfo.total==0">
			<view class='empty cuIcon-info'></view>
			<view class='empty-text text-gray'>暂无数据</view>
		</view>

		<view class="bg-white cu-list  margin padding-xl radius shadow-warp flex justify-between"
			v-for="(item,index) in pageInfo.projectList" :key='index'>
			<view class="">
				<view>
					<text class="text-gray margin-right">消费项目</text>
					<text class="">{{item.tradeName}}<text v-show="item.tradeCount!=null" > *  {{item.tradeCount}}</text></text>
				</view>
				<view>
					<text class="text-gray margin-right">消费时间</text>
					<text class="">{{item.inputDate}}</text>
				</view>
				<view>
					<text class="text-gray margin-right">单据编号</text>
					<text class="">{{item.docNum}}</text>
				</view>
				<view>
					<text class="text-gray margin-right">单据类别</text>
					<text class="">{{item.docTypeName}}</text>
				</view>
				<view v-if="item.docType=='card_recharge'">
					<text class="text-gray margin-right">充值金额</text>
					<text class="">{{item.cashMoney}}</text>
				</view>
				<view v-if="item.docType!='card_recharge'">
					<text class="text-gray margin-right">消费卡付金额</text>
					<text class="">{{ item.accountSpendMoney }}</text>
				</view>
				<view v-if="item.docType!='card_recharge'">
					<text class="text-gray margin-right">消费赠送金额</text>
					<text class="">{{ item.accountGiftSpendMoney }}</text>
				</view>
			</view>
			<!-- <view class="">
				<button class="cu-btn round bg-red" @click="goAppraise(item)">评价</button>
			</view> -->
		</view>

		<view class="cu-info">
		</view>
		<!-- <view :class="pageInfo.total!=0?'goAppres':''">

			<navigator 	
				:url="'../../../../myHome/reservation/resevation-project/resevation-project?item=' + JSON.stringify(itemForm)">
				<button :style="pageInfo.total!=0?'':'margin-top:50upx;'" v-show="itemForm.courseProjectName!=undefined"
					size="default" class="myset_footer cu-btn bg-red  lg ">去预约</button>
			</navigator>
		</view> -->

	</view>
</template>

<script>
	import {
		listByMember
	} from '@/static/js/api/account/account.js'
	export default {
		data() {
			return {
				pageInfo: {
					total: 0,
					pageNum: 1,
					pageSize: 5,
					projectList: [],
					rechargeList: [],
				},
				itemList: [
				        //单据全部类型
				        {
				          docType: "upgrade_out",
				          docTypeName: "升级转出",
				        },
				        {
				          docType: "upgrade_in",
				          docTypeName: "升级充值",
				        },
				        {
				          docType: "demotion_out",
				          docTypeName: "降级转出",
				        },
				        {
				          docType: "demotion_in",
				          docTypeName: "降级充值",
				        },
				        {
				          docType: "store_room",
				          docTypeName: "前台收银",
				        },
				        {
				          docType: "init",
				          docTypeName: "初始化",
				        },
				        {
				          docType: "card_recharge",
				          docTypeName: "充值开卡",
				        },
				
				        {
				          docType: "recharge_roll_course",
				          docTypeName: "疗程转充值卡",
				        },
				        {
				          docType: "card_change",
				          docTypeName: "加价转疗程",
				        },
				        {
				          docType: "card_use",
				          docTypeName: "疗程开卡",
				        },
				        {
				          docType: "card_use_additione",
				          docTypeName: "疗程开卡补单",
				        },
				        {
				          docType: "store_cash",
				          docTypeName: "收银",
				        },
				        {
				          docType: "card_repay",
				          docTypeName: "还款",
				        },
				        {
				          docType: "refund_recharge",
				          docTypeName: "充值退款",
				        },
				        {
				          docType: "refund_course",
				          docTypeName: "疗程退款",
				        },
				        {
				          docType: "refund_cash",
				          docTypeName: "消费退款",
				        },
				        {
				          docType: "promotion",
				          docTypeName: "促销活动",
				        },
				        {
				          docType: "promotion_card_repay",
				          docTypeName: "促销还款",
				        },
				      ],
				userInfo: {},
				list: [{}, {}, {}],
				TabCur: null,
				itemForm: {}
			}
		},
		methods: {
			tabSelect(e) {
				this.TabCur = e.currentTarget.dataset.id;
				this.TabCur=this.TabCur.split(' ')[0]
				let arr=this.TabCur.split('-')
				this.TabCur=arr[0]+'-'+arr[1]+'-01'+' '+'00:00:00'
				console.log(this.TabCur);
				this.selectByMember()
			},
			listDate(data) {
				var nowdays = new Date();
				var year = nowdays.getFullYear();
				var month = nowdays.getMonth() + 1 - data;
				if (month == 0) {
					month = 12;
					year = year - 1;
				}
				// if (month < 10) {
				// 	month = '0' + month;
				// }
				return month
			},
			listDates(data) {
				var nowdays = new Date();
				var year = nowdays.getFullYear();
				var month = nowdays.getMonth() + 1 - data;
				var day = nowdays.getDate()
				var hours = nowdays.getHours()
				var min = nowdays.getMinutes()
				var sec = nowdays.getSeconds()
				if (month == 0) {
					month = 12;
					year = year - 1;
				}
				if (month < 10) {
					month = '0' + month;
				}
				if (day < 10) {
					day = '0' + day;
				}
				if (hours < 10) {
					hours = '0' + hours;
				}
				if (min < 10) {
					min = '0' + min;
				}
				if (sec < 10) {
					sec = '0' + sec;
				}
				return year + '-' + month + '-' + day + ' ' + hours + ":" + min + ":" + sec
			},
			goAppraise(item) {

				let ids = {
					storeId: item.storeId,
					docId: item.docId
				}
				this.$api.selectRecentRecord(ids).then(res => {
					if (res.code == '000000') {
						console.log(res);
						if (res.rows.length != 0) {
							if (res.rows[0].state == 1) {
								uni.showModal({
									title: '提示',
									content: '已评价',
									confirmText: "查看评价",
									cancelText: "关闭",
									success: (ress) => {
										if (ress.confirm) {
											console.log(res.rows[0]);
											uni.navigateTo({
												url: '../../expense/appraise/appraise?item=' +
													JSON.stringify(res.rows[0])
											})
										}
									}
								})
							} else {
								uni.navigateTo({
									url: '../../expense/appraise/appraise?item=' + JSON.stringify(res.rows[
										0])
								})
							}
						} else {
							uni.showModal({
								title: '提示',
								content: '已评价',
								showCancel: false,
							})
						}

					} else {
						uni.showModal({
							title: '提示',
							content: res.message,
							showCancel: false,
						})
					}
				})
			},
			selectByMember() {
				let page = {
					memberId: this.userInfo.id,
					// memebrName: this.userInfo.memberName,
					// storeId: this.userInfo.storeId,
					// storeName: this.userInfo.storeName,
					pageNum: this.pageInfo.pageNum,
					pageSize: this.pageInfo.pageSize
				}
				if (this.itemForm.courseProjectName != undefined) {
					page.inputDate = this.TabCur,
						page.accountId = this.itemForm.id
				}
				if (this.itemForm.rechargeTypeName != undefined) {
					page.inputDate = this.TabCur
					page.accountId = this.itemForm.id
				}
				listByMember(page).then(res => {
					if (res.code == '000000') {
						res.pageInfo.list.forEach((item) => {
						            this.itemList.forEach((items) => {
						              if (item.docType == items.docType) {
						                item.docTypeName = items.docTypeName;
						              }
						            });
						          });
						          for(let i=0;i<res.pageInfo.list.length;i++){
						            let item = res.pageInfo.list[i]
						            if(item.accountType == 'member_mobile_phone_change_old'){
						              item.docTypeName = "手机号修改（旧)";
						            }
						            if(item.accountType == 'member_mobile_phone_change_new'){
						              item.docTypeName = "手机号修改（新）";
						            }
						            if(item.accountType == 'CZZCMD'){
						              item.docTypeName = "充值卡转出门店";
						            }
						            if(item.accountType == 'CZZRMD'){
						              item.docTypeName = "充值卡转入门店";
						            }
						            if(item.accountType == 'project_consume'&& item.docType == 'store_cash'){
						              item.docTypeName = '收银疗程卡付';
						            }
						            if(item.accountType == 'project_consume'&& item.docType == 'card_change'){
						              item.docTypeName = '加价转疗程转出'
						            }
						            if(item.accountType == 'project' && item.docType=='promotion'){
						              item.docTypeName = '促销活动'
						            }
						            if (item.type == "card_repay") {
						              if (item.orderType == "course") {
						                item.docTypeName = "疗程" + item.docTypeName;
						              }
						              if (item.orderType == "recharge") {
						                item.docTypeName = "充值" + item.docTypeName;
						              }
						            }
						            if(item.docType == 'card_use_addition'){
						              item.docTypeName = '疗程开卡补单'
						            }          
						            if (item.docType == "refund_cash_room") {
						              if (item.accountType == "refund_cash_unaudit_room") {
						                item.docTypeName = "房间退反审核";
						              }
						              if (item.accountType == "refund_cash_audit_room") {
						                item.docTypeName = "房间消费退";
						              }
						            }
						            if (item.docType == "recharge_Transition") {
						              if (item.accountType == "recharge_Transition_out") {
						                item.docTypeName = "充值卡内调转出";
						              }
						              if (item.accountType == "recharge_Transition_out_cancel") {
						                item.docTypeName = "充值内调作废";
						              }
						              if (item.accountType == "recharge_Transition_in") {
						                item.docTypeName = "充值卡内调转入";
						              }
						              if (item.accountType == "recharge_Transition_in_cancel") {
						                item.docTypeName = "充值内调作废";
						                             
						              }
						              if (item.accountType == "recharge_Transition_out_cancel") {
						                item.docTypeName = "充值转出反审核";
						              }
						            }
						            if (item.accountType == "recharge_in") {
						              item.docTypeName = "转卡充值卡包转入";
						            }
						            if (item.accountType == "recharge_out") {
						              item.docTypeName = "转卡充值卡包转出";
						            }
						            if (item.accountType == "recharge_in_cancel") {
						              item.docTypeName = "转卡充值卡包转入";
						              item.orderStatu = 1
						            }
						            if (item.accountType == "recharge_out_cancel") {
						              item.orderStatu = 1
						              item.docTypeName = "转卡充值卡包转出";
						            }
						            if (item.accountType == "project_in") {
						              item.docTypeName = "转卡疗程账户转入";
						            }
						            if (item.accountType == "project_out") {
						              item.docTypeName = "转卡疗程账户转出";
						            }
						            if (item.accountType == "project_in_cancel") {
						              item.docTypeName = "转卡疗程账户转入";
						              item.orderStatu = 1
						            }
						            if (item.accountType == "project_out_cancel") {
						              item.docTypeName = "转卡疗程账户转出";
						            }
						            if (item.type == "turn_card_use") {
						              if (item.orderType == "project_in ") {
						                item.docTypeName = "转卡转入";
						              }
						            }
						            if(item.accountType == 'project'&&item.docType =='card_change'){
						              item.docTypeName = '加价转疗程转入'
						            }
						            if(item.accountType == 'project'&&item.docType =='card_use'){
						              item.docTypeName = '疗程'
						            }
						            if(item.docType =='LCZCMD'){
						              item.docTypeName = '疗程转出门店'
						            }
						            if(item.docType =='LCZRMD'){
						              item.docTypeName = '疗程转入门店'
						            }
						            if (item.docType == "card_repay"&&item.accountType == 'course_repay') {
						              item.docTypeName = "还款";
						            }
						            if(item.accountType == 'recharge_groupon_cancel'){
						              item.docTypeName = '团购卡作废'
						            }
						            if(item.accountType == 'recharge_groupon'){
						              item.docTypeName = '团购卡'
						            }
						            if(item.accountType == 'XFT'){
						              item.docTypeName = '消费退'
						            }
						            if(item.accountType == 'cancel_Debt'){
						              item.docTypeName = '取消欠款'
						            }
						            if(item.accountType == 'cancel_Debt_cancel'){
						              item.docTypeName = '取消欠款作废'
						            }
						            if(item.docType == 'dabao'){
						              item.docTypeName = '促销活动'
						            }
						            if(item.accountType == 'LCNTZR'){
						              item.docTypeName = '疗程内调转入'
						            }
						            if(item.accountType == 'LCNTZC'){
						              item.docTypeName = '疗程内调转出'
						            }
						            if(item.accountType == 'LCNTZCZF'){
						              item.docTypeName = '疗程内调作废'
						            }
						            if(item.accountType == 'zengka'){
						              item.docTypeName = '促销赠卡'
						            }
						          }
						res.pageInfo.projectList = res.pageInfo.list
						this.pageInfo = res.pageInfo
					} else {
						uni.showModal({
							title: '提示',
							content: res.message,
							showCancel: false,
						})
					}
				})

			},
			dateFormat(fmt, date) {
				let ret;
				const opt = {
					"Y+": date.getFullYear().toString(), // 年
					"m+": (date.getMonth() + 1).toString(), // 月
					"d+": date.getDate().toString(), // 日
					"H+": date.getHours().toString(), // 时
					"M+": date.getMinutes().toString(), // 分
					"S+": date.getSeconds().toString() // 秒
				};
				for (let k in opt) {
					ret = new RegExp("(" + k + ")").exec(fmt);
					if (ret) {
						fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
					};
				};
				return fmt;
			},
		},
		onShow: function() {
			let list = []
			this.TabCur = this.listDates(0)
			this.list.forEach((item, index) => {
				item.index = index
				item.month = this.listDate(index) + '月'
				item.year = this.listDates(index)
				list.push(item)
			})
			this.userInfo = uni.getStorageSync('userInfo')
			this.selectByMember()
		},
		onLoad: function(option) {
			console.log(JSON.parse(option.item));
			this.itemForm = JSON.parse(option.item)
		}

	}
</script>

<style scoped>
	.myset_footer {
		width: 95%;
		font-size: 30upx;
		margin: 0 3%;
	}

	.goAppres {
		width: 100%;
		z-index: 99;
		padding: 20rpx 0; 
		position: fixed;
		bottom: 0;
		background: #FFFFFF;
	}
</style>
