<template>
	<view>
		<!-- 	<scroll-view scroll-x class="bg-white nav text-center" style="margin-top: 20upx;">
			<view class="flex text-center">
				<view class="cu-item light flex-sub" v-for="(item,index) in itemList" :key='index'
					:class="[TabCur==item.docType?'bg-red cur text-white':'']" @tap="tabSelect" data-id="card_recharge">
					{{item.docTypeName}}
				</view>
			</view>
		</scroll-view> -->
		<view class="account_header">
			<view class="cu-bar bg-blue search ">
				<view class="search-form radius">
					<text class="cuIcon-search"></text>
					<input @blur="InputBlur" v-model="tradeName" :adjust-position="false" type="text"
						placeholder="输入项目名称关键字" confirm-type="search"></input>
				</view>
				<view class="action">
					<picker mode="date" fields="month" :value="date" @change="bindDateChange">
						<view class="uni-input">{{date}}</view>
					</picker>
					<text class="cuIcon-triangledownfill"></text>
				</view>
			</view>
		</view>
		<view style="height: 100rpx;width: 100%;"></view>
		<view v-show="pageInfo.total==0">
			<view class='empty cuIcon-info'></view>
			<view class='empty-text text-gray'>暂无数据</view>
		</view>

		<view class="cu-list menu-avatar accountList" v-for="(item,index) in pageInfo.accountList" :key='index'>
			<!-- <navigator :url="'account-detail/account-detail?account=' + JSON.stringify(item)"> -->
			<navigator>
				<view class=" margin-left flex justify-between ">
					<text class="text-black text-bold">{{item.tradeName}}</text>
					<text class="text-cyan margin-right">{{item.inputDate}}</text>
				</view>
				<view class="flex-sub text-center ">
					<view class="solid-bottom  padding margin">
						<text class="text-grey">
							交易金额
						</text>
						<view class=" text-xxl text-red text-price padding">
							{{item.tradeMoney}}
						</view>
					</view>
				</view>
				<view class="margin-left">
					<text class="text-gray margin-right">单据类型</text>
					<text class="">{{item.docTypeName}}</text>
				</view>
				<view class="margin-left">
					<text class="text-gray margin-right">单据编号</text>
					<text class="">{{item.docNum}}</text>
				</view>
			</navigator>
		</view>
		<text class="margin-left">共 {{pageInfo.total}} 条记录</text>
		<view class="text-bold bg-gray padding-xs shadow-warp" style="position: fixed;bottom: 20rpx;right: 30rpx;">
			共{{pageInfo.total}}条
		</view>
	</view>
</template>

<script>
	import {
		listByMember
	} from '@/static/js/api/account/account.js'
	export default {
		data() {
			return {
				userInfo: null,
				TabCur: null,
				date: null,
				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: "促销还款",
				        },
				      ],
				pageInfo: {
					total: 0,
					pageNum: 1,
					pageSize: 10,
					accountList: [],
				},
				tradeName: null,

			}
		},
		methods: {
			bindDateChange: function(e) {
				this.date = e.target.value

				this.listPage()
			},
			InputFocus() {

			},
			InputBlur() {
				this.listPage()
			},
			tabSelect(e) {
				this.TabCur = e.currentTarget.dataset.id
			},
			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;
			},

			listPage() {
				// let date = new Date(this.date)
				// date = this.dateFormat("YYYY-MM-DD hh:mm:ss", date)

				let page = {
					inputDate: this.date + '-01' + ' ' + '00:00:00',
					tradeName: this.tradeName,
					memberId: this.userInfo.id,
					// memberName: this.userInfo.memberName,
					// memberPhone: this.userInfo.mobilePhone,
					// storeId: this.userInfo.storeId,
					// storeName: this.userInfo.storeName,
					pageNum: this.pageInfo.pageNum,
					pageSize: this.pageInfo.pageSize,
				}
				listByMember(page).then(res => {
					console.log(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.accountList = res.pageInfo.list
						this.pageInfo = res.pageInfo
					} else {}
				})
			}
		},
		onShow: function() {
			this.userInfo = uni.getStorageSync('userInfo')
			let date = new Date()
			this.date = this.dateFormat("YYYY-MM", date)
			this.listPage()
		},
		onPullDownRefresh: function() {
			setTimeout(function() {
				uni.redirectTo({
					url: './account'
				})
				uni.showToast({
					title: '刷新成功',
					icon: 'success',
					duration: 2000
				});
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onReachBottom: function() {
			this.pageInfo.pageSize = this.pageInfo.pageSize + 5
			this.listPage()
		},
	}
</script>

<style scoped>
	.bg-blue{
		background-color: #409EFF !important;
		border-color: #409EFF !important;
	}
	.accountList {
		width: 94%;
		margin: 50upx 3%;
		background: #FFFFFF;
		padding: 20upx;
		border-radius: 15upx;
	}

	.account_header {
		position: fixed;
		/* top:80rpx; */
		width: 100%;
		background-color: #FFFFFF;
		z-index: 999;
		padding-top: 10rpx;
	}
</style>