<template>
	<view class="">
		<view class="item-inner">
			<view class="content">
				<view class="content-list">
					<view class="online-ready" v-if="accountData == 1">当前积分</view>
					<view class="online-ready" v-if="accountData == 2">余额(不可提现)</view>
					<view class="online-ready" v-if="accountData == 3">余额(可提现)</view>
					<view class="online-ready" v-if="accountData == 4">成长值</view>

					<input type="text" v-if="accountData == 1" :value="parseInt(numMsg.point)"
						style="height: 100rpx;text-align: right;" disabled="disabled" />
					<input type="text" v-if="accountData == 2" :value="numMsg.balance "
						style="height: 100rpx;text-align: right;" disabled="disabled" />
					<input type="text" v-if="accountData == 3" :value="numMsg.balance_money"
						style="height: 100rpx;text-align: right;" disabled="disabled" />
					<input type="text" v-if="accountData == 4" :value="numMsg.growth"
						style="height: 100rpx;text-align: right;" disabled="disabled" />
				</view>

		
				<view class="content-list">
					<view class="online-ready">调整数额</view>
					<input type="number" v-model="adjust_num" style="height: 100rpx;text-align: right;"
						@blur="onKeyNumberInput($event)" v-if="accountData == 1"/>
					<input type="digit" v-model="adjust_num" style="height: 100rpx;text-align: right;"
							@blur="onKeyNumberInput($event)" v-else/>
				</view>

				<view class="remark-list">
					<view class="online-ready">备注</view>
					<input type="text" v-model="remark" style="height: 100rpx;text-align: right;"
						@blur="onKeyNameInput($event)" />
				</view>
			</view>

			<view class="explain">
				
				说明：调整数额与当前<text v-if="accountData == 1">积分</text><text v-if="accountData == 2">余额(不可提现)</text><text v-if="accountData == 3">余额(可提现)</text><text v-if="accountData == 4">成长值</text>数相加不能小于0；正数表示增加，负数表示减少
			</view>
			<view class="bottom-btn" @click="save()">保存</view>
		</view>
	</view>

</template>

<script>
	import validate from '@/common/js/validate.js';

	export default {
		data() {
			return {
				dataList: [],
				accountData: 1,
				member_id: '',
				numMsg: {},
				adjust_num: '',
				remark: ''
			}
		},
		onLoad: function(option) {
			this.accountData = option.type;
			this.member_id = option.member_id
			this.$api.sendRequest({
				url: '/shopapi/member/detail',
				data: {
					member_id: option.member_id
				},
				success: res => {
					let msg = res.message;
					if (res.code == 0 && res.data) {
						this.numMsg = res.data.member_info
					} else {
						this.$util.showToast({
							title: msg
						});
					}
				}
			});
		},
		onShow() {
			if (!this.$util.checkToken('/pages/member/list')) return;
			this.$store.dispatch('getShopInfo');
		},
		mounted() {
			
		},

		methods: {
			onKeyNumberInput: function(event) {
				this.adjust_num = event.detail.value
			},

			onKeyNameInput: function(event) {
				this.remark = event.detail.value
			},
			verify() {
				let flag = true
					if (isNaN(this.adjust_num) || !this.$util.data().regExp.number.test(this.adjust_num)) {
						this.$util.showToast({ title: `格式输入错误` });
						flag = false;
					}
				return flag;
			},
			save: function() {
				if (!this.verify()) return;
				console.log(this.numMsg.member_id)
				var accountData = this.accountData
				var url = ''
				// console.log(accountData,'111')
				switch (parseInt(accountData)) {
					case 1:
						url = '/shopapi/Member/modifyPoint';
						break;
					case 2:
						url = '/shopapi/Member/modifyBalance';
						break;
					case 3:
						url = '/shopapi/Member/modifyBalanceMoney';
						break;
					case 4:
						url = '/shopapi/Member/modifyGrowth';
						break;
				}
				// console.log( url,'0000')
				this.$api.sendRequest({
					url: url,
					data: {
						adjust_num: this.adjust_num,
						remark: this.remark,
						member_id: this.numMsg.member_id
					},
					success: res => {
						let newArr = [];
						let msg = res.message
						this.$util.showToast({
							title: msg
						});
						setTimeout(() => {
							this.$util.redirectTo('/pages/member/list')
						}, 500);
					}
				});
			},

			getListData(mescroll) {
				let data = {
					page_size: mescroll.size,
					page: mescroll.num,
					search_text: ''
				};
				this.mescroll = mescroll;
				this.$api.sendRequest({
					url: '/shopapi/member/lists',
					data: data,
					success: res => {
						let newArr = [];
						let msg = res.message;
						if (res.code == 0 && res.data) {
							newArr = res.data.list;
						} else {
							this.$util.showToast({
								title: msg
							});
						}
						mescroll.endSuccess(newArr.length);
						//设置列表数据
						if (mescroll.num == 1) this.dataList = []; //如果是第一页需手动制空列表
						newArr.forEach(v => {
							v.is_off = 0;
						});
						this.dataList = this.dataList.concat(newArr); //追加新数据
						if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
					}
				});
			},
			searchMember() {
				this.mescroll.resetUpScroll();
			},
			linkSkip(item, type) {
				item.is_off = 0;
				if (type) this.$util.redirectTo('/pages/member/coupon', {
					member_id: item.member_id
				});
				else this.$util.redirectTo('/pages/member/detail', {
					member_id: item.member_id
				});
			},
			imgError(index) {
				this.dataList[index].headimg = this.$util.getDefaultImage().default_headimg;
				this.$forceUpdate();
			}
		},
	};
</script>

<style>
	.content {
		/* width: 750rpx; */
		height: 302rpx;
		background: #FFFFFF;
		margin: 20rpx auto;

	}

	.online-ready {
		line-height: 100rpx;
	}

	.content-list {
		display: flex;
		/* width: 690rpx; */
		justify-content: space-between;
		border-bottom: 1rpx solid #EEEEEE;
		margin: auto;
		margin-left: 30rpx;
		margin-right: 30rpx;
	}

	.remark-list {
		display: flex;
		/* width: 690rpx; */
		justify-content: space-between;
		margin: auto;
		margin-left: 30rpx;
		margin-right: 30rpx;
	}

	.explain {
		/* width: 684rpx; */
		height: 59rpx;
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #909399;
		line-height: 36rpx;
		margin-top: 20rpx;
		margin-left: 30rpx;
		margin-right: 30rpx;
	}

	.bottom-btn {
		width: 690rpx;
		height: 80rpx;
		background: #FF6A00;
		color: #FFFFFF;
		border-radius: 40rpx;
		text-align: center;
		line-height: 80rpx;
		position: absolute;
		left: 30rpx;
		bottom: 40rpx;
	}
</style>
