<template>
	<view class="member-detail-wrap">
		<view class="member-head">会员详情</view>
		<view class="member-content">
			<view class="content-block">
				<view class="item-img">
					<image mode="aspectFill" v-if="memberInfo && memberInfo.headimg" :src="$util.img(memberInfo.headimg)" @error="headError(memberInfo)"></image>
					<image mode="aspectFill" v-else :src="$util.img('public/uniapp/default_img/head.png')"></image>
				</view>
				<view class="item-content">
					<view class="item-title">
						<view class="item-title-text">{{ memberInfo && memberInfo.nickname ? memberInfo.nickname : '' }}</view>
						<view class="item-label" v-if="memberInfo && memberInfo.member_level && memberInfo.member_level_name != 'undefined'">
							{{ memberInfo.member_level_name }}
						</view>
					</view>
					<view class="info-list">
						<view class="info-item">手机：{{ memberInfo && memberInfo.mobile ? memberInfo.mobile : '' }}</view>
						<view class="info-item" v-if="memberInfo && memberInfo.sex == 0">性别：未知</view>
						<view class="info-item" v-if="memberInfo && memberInfo.sex == 1">性别：男</view>
						<view class="info-item" v-if="memberInfo && memberInfo.sex == 2">性别：女</view>
						<view class="info-item">生日：{{ memberInfo && memberInfo.birthday ? memberInfo.birthday : '' }}</view>
						<view class="info-item" v-if="memberInfo && memberInfo.member_time">成为会员：{{ $util.timeFormat(memberInfo.member_time) }}</view>
					</view>
				</view>
			</view>

			<view class="content-block account">
				<view class="content-data-item">
					<view class="data-item-title">积分</view>
					<view class="data-item-value">{{ memberInfo && memberInfo.point ? parseInt(memberInfo.point) : '0' }}</view>
					<view class="data-item-action" @click="memberAction('point_list')">查看</view>
				</view>
				<view class="content-data-item">
					<view class="data-item-title">储值消费券(元)</view>
					<view class="data-item-value">{{ memberInfo && memberInfo.balance ? memberInfo.balance : '0.00' }}</view>
					<view class="data-item-action" @click="memberAction('balance_list')">查看</view>
					<!-- <view class="data-item-action" v-if="memberInfo && memberInfo.balance > 0" @click="refundBalance">退储值</view> -->
				</view>
				<view class="content-data-item">
					<view class="data-item-title">现金消费券(元)</view>
					<view class="data-item-value">{{ memberInfo && memberInfo.balance_money ? memberInfo.balance_money : '0.00' }}</view>
				</view>
				<view class="content-data-item">
					<view class="data-item-title">成长值</view>
					<view class="data-item-value">{{ memberInfo && memberInfo.growth ? memberInfo.growth : '0' }}</view>
					<view class="data-item-action" @click="memberAction('growth_list')">查看</view>
				</view>
				<view class="content-data-item">
					<view class="data-item-title">优惠券(张)</view>
					<view class="data-item-value">{{ memberInfo && memberInfo.coupon_num ? memberInfo.coupon_num : '0' }}</view>
					<view class="data-item-action" @click="memberAction('couponlist')">查看</view>
				</view>
				<view class="content-data-item">
					<view class="data-item-title">卡包</view>
					<view class="data-item-value">{{ memberInfo && memberInfo.card_num ? memberInfo.card_num : '0' }}</view>
					<view class="data-item-action" @click="memberAction('cardlist')">查看</view>
				</view>
			</view>

			<view class="content-block action">
				<view class="content-data-item">
					<view class="data-item-icon">
						<image mode="aspectFit" @click="memberAction('memberinfo')" :src="$util.img('public/uniapp/cashier/icon-member-info.png')"></image>
					</view>
					<view class="data-item-value">会员信息</view>
				</view>
				<view class="content-data-item" @click="memberAction('point')">
					<view class="data-item-icon"><image mode="aspectFit" :src="$util.img('public/uniapp/cashier/icon-member-point.png')"></image></view>
					<view class="data-item-value">积分调整</view>
				</view>
				<view class="content-data-item" @click="memberAction('balance')">
					<view class="data-item-icon"><image mode="aspectFit" :src="$util.img('public/uniapp/cashier/icon-member-balance.png')"></image></view>
					<view class="data-item-value">消费券充值</view>
				</view>
				<view class="content-data-item" @click="memberAction('sendCoupon')">
					<view class="data-item-icon"><image mode="aspectFit" :src="$util.img('public/uniapp/cashier/icon-member-coupon.png')"></image></view>
					<view class="data-item-value">送优惠券</view>
				</view>
				<view class="content-data-item" @click="memberAction('growth')">
					<view class="data-item-icon"><image mode="aspectFit" :src="$util.img('public/uniapp/cashier/icon-member-growth.png')"></image></view>
					<view class="data-item-value">成长值调整</view>
				</view>
				<view class="content-data-item" @click="memberAction('applyMember')" v-if="memberInfo && !memberInfo.is_member">
					<view class="data-item-icon"><image mode="aspectFit" :src="$util.img('public/uniapp/cashier/icon-member-apply.png')"></image></view>
					<view class="data-item-value">办理会员</view>
				</view>
			</view>
		</view>

		<!-- 会员详情 -->
		<uni-popup ref="memberInfoPop">
			<view class="pop-box memberInfo-box">
				<view class="pop-header">
					<view class="pop-header-text">会员详情</view>
					<view class="pop-header-close" @click="popClose('memberinfo')"><i class="iconguanbi1 iconfont"></i></view>
				</view>

				<scroll-view scroll-y="true" class="common-scrollbar pop-content">
					<view class="form-content" v-if="memberInfo">
						<view class="form-item">
							<view class="form-label">
								<text class="required"></text>
								昵称：
							</view>
							<view class="form-inline"><input class="form-input" placeholder="请输入会员昵称" v-model="memberInfo.nickname" /></view>
						</view>

						<view class="form-item">
							<view class="form-label">
								<text class="required"></text>
								手机号：
							</view>
							<view class="form-inline"><input class="form-input " placeholder="请输入手机号" v-model="memberInfo.mobile" /></view>
						</view>

						<view class="form-item">
							<view class="form-label">
								<text class="required"></text>
								会员等级：
							</view>
							<view class="form-inline">
								<select-lay
									:zindex="10"
									:value="memberInfo.member_level"
									name="names"
									placeholder="请选择会员等级"
									:options="memberLevelList"
									@selectitem="selectMemberLevel"
								></select-lay>
							</view>
						</view>

						<view class="form-item">
							<view class="form-label">
								<text class="required"></text>
								性别：
							</view>
							<view class="form-inline"><uni-data-checkbox v-model="memberInfo.sex" selectedColor="#8558FA" :localdata="sex"></uni-data-checkbox></view>
						</view>

						<view class="form-item">
							<view class="form-label">
								<text class="required"></text>
								生日：
							</view>
							<view class="form-inline"><uni-datetime-picker :end="endTime" v-model="memberInfo.birthday" type="date" :clearIcon="false" /></view>
						</view>

						<view class="form-item">
							<view class="form-label">
								<text class="required"></text>
								注册时间：
							</view>
							<view class="form-inline">{{ memberInfo && memberInfo.reg_time ? $util.timeFormat(memberInfo.reg_time) : '--' }}</view>
						</view>

						<view class="form-item">
							<view class="form-label">
								<text class="required"></text>
								最后访问时间：
							</view>
							<view class="form-inline">{{ memberInfo && memberInfo.last_login_time ? $util.timeFormat(memberInfo.last_login_time) : '--' }}</view>
						</view>
					</view>
				</scroll-view>
				<view class="pop-bottom"><button class="primary-btn" @click="saveMemberInfo">确定</button></view>
			</view>
		</uni-popup>

		<!-- 积分调整 -->
		<uni-popup ref="pointPop">
			<view class="pop-box pointPop-box">
				<view class="pop-header">
					<view class="pop-header-text">调整积分</view>
					<view class="pop-header-close" @click="popClose('point')"><i class="iconguanbi1 iconfont"></i></view>
				</view>

				<scroll-view scroll-y="true" class="common-scrollbar pop-content">
					<view class="form-content">
						<view class="form-item">
							<view class="form-label">
								<text class="required"></text>
								当前积分：
							</view>
							<view class="form-inline">{{ memberInfo && memberInfo.point ? memberInfo.point : '0' }}</view>
						</view>

						<view class="form-item">
							<view class="form-label">
								<text class="required"></text>
								调整数额：
							</view>
							<view class="form-inline">
								<input class="form-input" type="number" placeholder="请输入调整数额" v-model="pointData.num" />
								<view class="word-aux">调整数额与当前积分数相加不能小于0</view>
							</view>
						</view>

						<view class="form-item">
							<view class="form-label">
								<text class="required"></text>
								备注：
							</view>
							<view class="form-inline"><textarea class="form-textarea" v-model="pointData.desc"></textarea></view>
						</view>
					</view>
				</scroll-view>
				<view class="pop-bottom"><button class="primary-btn" @click="savePoint">确定</button></view>
			</view>
		</uni-popup>

		<!-- 发放优惠券 -->
		<uni-popup ref="sendCouponPop">
			<view class="pop-box sendCoupon-box">
				<view class="pop-header">
					<view class="pop-header-text">送优惠券</view>
					<view class="pop-header-close" @click="popClose('sendCoupon')"><i class="iconguanbi1 iconfont"></i></view>
				</view>

				<view class="common-scrollbar sendCoupon-content">
					<view class="coupon-table-head">
						<view class="coupon-table-th">优惠券名称</view>
						<view class="coupon-table-th">金额</view>
						<view class="coupon-table-th">有效期</view>
						<view class="coupon-table-th">发放数量</view>
					</view>
					<scroll-view class="coupon-table-body" @scrolltolower="getCouponList()" scroll-y="true">
						<view class="coupon-table-tr" v-for="(item, index) in sendCoupon.list" :key="index">
							<view class="coupon-table-td">{{ item.coupon_name }}</view>
							<view class="coupon-table-td">{{ item.money }}</view>
							<view class="coupon-table-td">{{ item.validity_name }}</view>
							<view class="coupon-table-td">
								<view class="item-num">
									<view class="num-dec" v-on:click="dec(item)">-</view>
									<input class="table-input" type="text" v-model="item.num" />
									<view class="num-inc" v-on:click="inc(item)">+</view>
								</view>
							</view>
						</view>
						<view class="empty" v-if="!sendCoupon.list.length">
							<view class="iconfont iconwushuju"></view>
							<view>暂无数据</view>
						</view>
					</scroll-view>
				</view>
				<view class="pop-bottom ">
					<button :class="[sendCoupon.list.length ? 'primary-btn' : 'default-btn']" @click="sendCouponFn">
						{{ sendCoupon.list.length ? '发放优惠券' : '暂无优惠券' }}
					</button>
				</view>
			</view>
		</uni-popup>

		<!-- 消费券调整 -->
		<uni-popup ref="balancePop">
			<view class="pop-box pointPop-box">
				<view class="pop-header">
					<view class="pop-header-text">调整消费券</view>
					<view class="pop-header-close" @click="popClose('balance')"><i class="iconguanbi1 iconfont"></i></view>
				</view>

				<scroll-view scroll-y="true" class="common-scrollbar pop-content">
					<view class="form-content">
						<view class="form-item">
							<view class="form-label">
								<text class="required"></text>
								当前消费券：
							</view>
							<view class="form-inline">{{ memberInfo && memberInfo.balance ? memberInfo.balance : '0.00' }}</view>
						</view>

						<view class="form-item">
							<view class="form-label">
								<text class="required"></text>
								调整数额：
							</view>
							<view class="form-inline">
								<input class="form-input" type="number" placeholder="请输入调整数额" v-model="balanceData.num" />
								<view class="word-aux">调整数额与当前储值消费券相加不能小于0</view>
							</view>
						</view>

						<view class="form-item">
							<view class="form-label">
								<text class="required"></text>
								备注：
							</view>
							<view class="form-inline"><textarea class="form-textarea" v-model="balanceData.desc"></textarea></view>
						</view>
					</view>
				</scroll-view>
				<view class="pop-bottom"><button class="primary-btn" @click="saveBalance">确定</button></view>
			</view>
		</uni-popup>

		<!-- 成长值调整 -->
		<uni-popup ref="growthPop">
			<view class="pop-box pointPop-box">
				<view class="pop-header">
					<view class="pop-header-text">调整成长值</view>
					<view class="pop-header-close" @click="popClose('growth')"><i class="iconguanbi1 iconfont"></i></view>
				</view>

				<scroll-view scroll-y="true" class="common-scrollbar pop-content">
					<view class="form-content">
						<view class="form-item">
							<view class="form-label">
								<text class="required"></text>
								当前成长值：
							</view>
							<view class="form-inline">{{ memberInfo && memberInfo.growth ? memberInfo.growth : '0' }}</view>
						</view>

						<view class="form-item">
							<view class="form-label">
								<text class="required"></text>
								调整数额：
							</view>
							<view class="form-inline">
								<input class="form-input" type="number" placeholder="请输入调整数额" v-model="growthData.num" />
								<view class="word-aux">调整数额与当前成长值相加不能小于0</view>
							</view>
						</view>

						<view class="form-item">
							<view class="form-label">
								<text class="required"></text>
								备注：
							</view>
							<view class="form-inline"><textarea class="form-textarea" v-model="growthData.desc"></textarea></view>
						</view>
					</view>
				</scroll-view>
				<view class="pop-bottom"><button class="primary-btn" @click="saveGrowth">确定</button></view>
			</view>
		</uni-popup>

		<!-- 办理会员 -->
		<uni-popup ref="applyMemberPop">
			<view class="pop-box applyMemberPop-box">
				<view class="pop-header">
					<view class="pop-header-text">办理会员</view>
					<view class="pop-header-close" @click="popClose('applyMember')"><i class="iconguanbi1 iconfont"></i></view>
				</view>

				<view class="common-scrollbar pop-content">
					<view class="form-content">
						<view class="form-item">
							<view class="form-label">
								<text class="required"></text>
								会员等级：
							</view>
							<view class="form-inline">
								<select-lay
									:zindex="10"
									:value="applyMember.level_id"
									name="names"
									placeholder="请选择会员等级"
									:options="memberLevelList"
									@selectitem="selectMemberLevel"
								></select-lay>
							</view>
						</view>
						<view class="form-item">
							<view class="form-label">
								<text class="required"></text>
								会员卡号：
							</view>
							<view class="form-inline">
								<input class="form-input" type="text" placeholder="请输入会员卡号" v-model="applyMember.member_code" />
								<view class="word-aux">会员卡号为会员唯一编号，若不设置将会自动生成</view>
							</view>
						</view>
					</view>
				</view>
				<view class="pop-bottom"><button class="primary-btn" @click="saveApplyMember">确定</button></view>
			</view>
		</uni-popup>

		<!-- 优惠券列表 -->
		<uni-popup ref="couponlistPop">
			<view class="pop-box couponlistPop-box">
				<view class="pop-header">
					<view class="pop-header-text">优惠券</view>
					<view class="pop-header-close" @click="popClose('couponlist')"><i class="iconguanbi1 iconfont"></i></view>
				</view>
				<scroll-view scroll-y="true" class="common-scrollbar pop-content">
					<dataTable url="/cashier/storeapi/member/coupon" :cols="couponcols" ref="table" :option="option" :pagesize="pagesize"></dataTable>
				</scroll-view>
			</view>
		</uni-popup>
		<uni-popup ref="refundBalance">
			<view class="pop-box refund-balance-box">
				<view class="pop-header">
					<view class="pop-header-text">退储值</view>
					<view class="pop-header-close" @click="$refs.refundBalance.close()"><i class="iconguanbi1 iconfont"></i></view>
				</view>
				<view class="pop-content" v-if="refundData">
					<view class="info-item">
						<view class="title">账户可用储值：</view>
						<view class="data">￥{{ $util.moneyFormat(parseFloat(refundData.member_account.balance) + parseFloat(refundData.member_account.balance_money)) }}</view>
					</view>
					<view class="info-item">
						<view class="title">实充储值：</view>
						<view class="data">￥{{ refundData.refund_total_balance | moneyFormat }}</view>
					</view>
					<view class="info-item">
						<view class="title">已使用储值：</view>
						<view class="data">￥{{ refundData.use_total_balance | moneyFormat }}</view>
					</view>
					<view class="info-item">
						<view class="title">可退储值金额：</view>
						<view class="data">￥{{ refundData.can_refund_balance | moneyFormat }}</view>
					</view>
					<view class="info-item">
						<view class="title">退还金额：</view>
						<view class="data"><input type="number" value="" v-model="refundData.refund_balance" /></view>
					</view>
					<view class="info-item">
						<view class="title">退款方式：</view>
						<view class="data refund-type">
							<view
								class="value-item"
								:class="{ active: index == refundTransferType }"
								@click="refundTransferType = index"
								v-for="(item, index) in refundTransferTypeList"
								:key="index"
							>
								{{ item.name }}
							</view>
						</view>
					</view>
				</view>
				<view class="pop-bottom">
					<button class="primary-btn" @click="confirmRefundBalance">确定</button>
					<button class="default-btn" @click="$refs.refundBalance.close()">取消</button>
				</view>
			</view>
		</uni-popup>

		<!-- 积分列表 -->
		<uni-popup ref="pointListPop">
			<view class="pop-box couponlistPop-box">
				<view class="pop-header">
					<view class="pop-header-text">积分</view>
					<view class="pop-header-close" @click="popClose('point_list')"><i class="iconguanbi1 iconfont"></i></view>
				</view>

				<scroll-view scroll-y="true" class="common-scrollbar pop-content">
					<dataTable url="/cashier/storeapi/member/memberaccountlist" :cols="pointCols" ref="table" :option="option" :pagesize="pagesize"></dataTable>
				</scroll-view>
			</view>
		</uni-popup>

		<!-- 消费券列表 -->
		<uni-popup ref="balanceListPop">
			<view class="pop-box couponlistPop-box">
				<view class="pop-header">
					<view class="pop-header-text">消费券</view>
					<view class="pop-header-close" @click="popClose('balance_list')"><i class="iconguanbi1 iconfont"></i></view>
				</view>

				<scroll-view scroll-y="true" class="common-scrollbar pop-content">
					<dataTable url="/cashier/storeapi/member/memberaccountlist" :cols="balanceCols" ref="table" :option="option" :pagesize="pagesize"></dataTable>
				</scroll-view>
			</view>
		</uni-popup>

		<!-- 成长值列表 -->
		<uni-popup ref="growthListPop">
			<view class="pop-box couponlistPop-box">
				<view class="pop-header">
					<view class="pop-header-text">成长值</view>
					<view class="pop-header-close" @click="popClose('growth_list')"><i class="iconguanbi1 iconfont"></i></view>
				</view>

				<scroll-view scroll-y="true" class="common-scrollbar pop-content">
					<dataTable url="/cashier/storeapi/member/memberaccountlist" :cols="growthCols" ref="table" :option="option" :pagesize="pagesize"></dataTable>
				</scroll-view>
			</view>
		</uni-popup>

		<!-- 卡项 -->
		<nc-member-card ref="memberCard" :option="option"></nc-member-card>
	</view>
</template>

<script>
import dataTable from '@/components/uni-data-table/uni-data-table.vue';
export default {
	components: {
		dataTable
	},
	props: {
		memberId: {
			type: Number,
			default: 0
		}
	},
	data() {
		return {
			memberList: [],
			pagesize: 8,
			endTime: '',
			sex: [
				{
					text: '未知',
					value: 0
				},
				{
					text: '男',
					value: 1
				},
				{
					text: '女',
					value: 2
				}
			],
			pointData: {
				num: 0,
				desc: ''
			},
			growthData: {
				num: 0,
				desc: ''
			},
			balanceData: {
				num: 0,
				desc: ''
			},
			couponcols: [
				{
					width: 15,
					title: '优惠券名称',
					align: 'left',
					field: 'coupon_name'
				},
				{
					width: 10,
					title: '类型',
					align: 'left',
					templet: function(data) {
						if (data.type == 'reward') return '满减';
						if (data.type == 'discount') return '折扣';
					}
				},
				{
					width: 20,
					title: '优惠金额',
					align: 'left',
					templet: function(data) {
						if (data.type == 'reward') {
							var html = `满${data.at_least}元减${data.money}`;
							return `<view title="${html}">${html}</view>`;
						}
						if (data.type == 'discount') {
							var text = '满' + data.at_least + '元打' + data.discount + '折';
							if (data.discount_limit) text += '（最多抵扣' + data.discount_limit + '元）';
							return '<view title="' + text + '">' + text + '</view>';
						}
					}
				},
				{
					width: 20,
					title: '有效期',
					align: 'center',
					templet: data => {
						if (data.end_time) return this.$util.timeFormat(data.end_time);
						else return '长期有效';
					}
				},
				{
					width: 15,
					title: '状态',
					align: 'center',
					return: data => {
						if (data.state == 1) return '未使用';
						if (data.state == 2) return '已使用';
						if (data.state == 3) return '已过期';
					}
				},
				{
					width: 20,
					title: '领取时间',
					align: 'right',
					templet: data => {
						return this.$util.timeFormat(data.fetch_time);
					}
				}
			],
			pointCols: [
				{
					width: 20,
					title: '积分',
					align: 'left',
					field: 'account_data'
				},
				{
					width: 25,
					title: '发生方式',
					align: 'left',
					field: 'type_name'
				},
				{
					width: 25,
					title: '发生时间',
					align: 'left',
					templet: data => {
						var html = this.$util.timeFormat(data.create_time);
						return html;
					}
				},
				{
					width: 30,
					title: '备注',
					align: 'left',
					field: 'remark'
				}
			],
			balanceCols: [
				{
					width: 10,
					title: '账户类型',
					align: 'left',
					field: 'account_type_name'
				},
				{
					width: 15,
					title: '消费券',
					align: 'left',
					field: 'account_data'
				},
				{
					width: 20,
					title: '发生方式',
					align: 'left',
					field: 'type_name'
				},
				{
					width: 25,
					title: '发生时间',
					align: 'left',
					templet: data => {
						var html = this.$util.timeFormat(data.create_time);
						return html;
					}
				},
				{
					width: 30,
					title: '备注',
					align: 'left',
					field: 'remark'
				}
			],
			growthCols: [
				{
					width: 20,
					title: '成长值',
					align: 'left',
					field: 'account_data'
				},
				{
					width: 25,
					title: '发生方式',
					align: 'left',
					field: 'type_name'
				},
				{
					width: 25,
					title: '发生时间',
					align: 'left',
					templet: data => {
						var html = this.$util.timeFormat(data.create_time);
						return html;
					}
				},
				{
					width: 30,
					title: '备注',
					align: 'left',
					field: 'remark'
				}
			],
			option: {},
			addMemberData: {
				mobile: '',
				nickname: '',
				sex: 0,
				birthday: ''
			},
			refundTransferTypeList: {},
			refundTransferType: '',
			refundData: null,
			isRepeat: false,
			sendCoupon: {
				list: [],
				page: 1
			},
			memberLevelList: [],
			applyMember: {
				level_id: '',
				member_level_name: '',
				member_code: ''
			}
		};
	},
	created() {
		this.getMemberInfo();
		this.getMemberLevel();
		let date = new Date();
		var y = date.getFullYear();
		var m = date.getMonth() + 1;
		var d = date.getDate();
		this.endTime = y + '-' + m + '-' + d;
	},
	watch: {
		memberId: function() {
			this.getMemberInfo();
		}
	},
	methods: {
		getMemberInfo() {
			this.$api.sendRequest({
				url: '/cashier/storeapi/member/info',
				data: {
					member_id: this.memberId
				},
				success: res => {
					if (res.code >= 0) {
						res.data.birthday = res.data.birthday > 0 ? this.$util.timeFormat(res.data.birthday, 'y-m-d') : '';
						this.$store.commit('setMemberInfo', res.data);
					}
				}
			});
		},
		getMemberLevel() {
			this.memberLevelList = [];
			this.$api.sendRequest({
				url: '/cashier/storeapi/memberlevel/lists',
				success: res => {
					if (res.code == 0 && res.data) {
						for (let i in res.data) {
							this.memberLevelList.push({
								label: res.data[i]['level_name'],
								value: res.data[i]['level_id'].toString(),
								disabled: false
							});
						}
					}
				}
			});
		},
		selectMemberLevel(index, item) {
			if (index >= 0) {
				this.applyMember.level_id = item.value;
				this.memberInfo.member_level = item.value;
				this.applyMember.member_level_name = item.label;
			} else {
				this.applyMember.level_id = '';
				this.memberInfo.level_id = '';
				this.applyMember.member_level_name = '';
			}
			this.$forceUpdate();
		},
		verify() {
			if (!this.addMemberData.mobile) {
				this.$util.showToast({
					title: '请输入客户手机号'
				});
				return false;
			}
			if (!/^1(3|4|5|6|7|8|9)\d{9}$/.test(this.addMemberData.mobile)) {
				this.$util.showToast({
					title: '请输入正确的手机号码'
				});
				return false;
			}

			return true;
		},
		// 客户操作
		memberAction(type) {
			switch (type) {
				case 'memberinfo':
					this.$refs.memberInfoPop.open('center');
					break;
				case 'point':
					this.$refs.pointPop.open('center');
					break;
				case 'balance':
					this.$api.sendRequest({
						url: '/cashier/storeapi/member/info',
						data: {
							member_id: this.memberId
						},
						success: res => {
							if (res.code >= 0) {
								this.$store.commit('setMemberInfo', res.data);
							}

							if (getCurrentPages()[0].route == 'pages/recharge/index') this.$root.type = 'topUp';
							else this.$util.redirectTo('/pages/recharge/index');
						}
					});
					break;
				case 'sendCoupon':
					this.getCouponList();
					this.$refs.sendCouponPop.open('center');
					break;
				case 'growth':
					this.$refs.growthPop.open('center');
					break;
				case 'couponlist':
					this.option = {
						member_id: this.memberId
					};
					this.$refs.couponlistPop.open('center');
					break;
				case 'cardlist':
					this.option = {
						member_id: this.memberId
					};
					this.$refs.memberCard.open('center');
					break;
				case 'point_list':
					// 积分列表
					this.option = {
						member_id: this.memberId,
						account_type: 'point'
					};
					this.$refs.pointListPop.open();
					break;
				case 'balance_list':
					// 余额列表
					this.option = {
						member_id: this.memberId,
						account_type: 'balance'
					};
					this.$refs.balanceListPop.open();
					break;
				case 'growth_list':
					// 成长值列表
					this.option = {
						member_id: this.memberId,
						account_type: 'growth'
					};
					this.$refs.growthListPop.open();
					break;
				case 'applyMember':
					this.$refs.applyMemberPop.open();
					break;
			}
		},
		popClose(type) {
			switch (type) {
				case 'memberinfo':
					this.$refs.memberInfoPop.close();
					break;
				case 'point':
					this.$refs.pointPop.close();
					break;
				case 'balance':
					this.$refs.balancePop.close();
					break;
				case 'sendCoupon':
					this.$refs.sendCouponPop.close();
					break;
				case 'growth':
					this.$refs.growthPop.close();
					break;
				case 'couponlist':
					this.$refs.couponlistPop.close();
					break;
				case 'cardlist':
					this.$refs.cardlistPop.close();
					break;

				case 'point_list':
					// 积分列表
					this.$refs.pointListPop.close();
					break;
				case 'balance_list':
					// 余额列表
					this.$refs.balanceListPop.close();
					break;
				case 'growth_list':
					// 成长值列表
					this.$refs.growthListPop.close();
					break;
				case 'applyMember':
					// 办理会员
					this.$refs.applyMemberPop.close();
					break;
			}
		},
		//获取发放优惠券列表
		getCouponList() {
			// console.log("获取里诶博爱");
			let data = {
				page: this.sendCoupon.page,
				page_size: 7
			};
			this.$api.sendRequest({
				url: '/cashier/storeapi/coupon/couponTypeList',
				data: data,
				success: res => {
					if (res.code >= 0) {
						if (this.sendCoupon.page == 1) this.sendCoupon.list = [];
						if (res.data.list && res.data.list.length) {
							res.data.list.forEach((item, index) => {
								if (item.validity_type == 0) item.validity_name = '失效日期：' + this.$util.timeFormat(item.end_time);
								else if (item.validity_type == 1) item.validity_name = '领取后，' + item.fixed_term + '天有效';
								else item.validity_name = '长期有效';
								item.num = 0;
							});
						}
						this.sendCoupon.list = this.sendCoupon.list.concat(res.data.list);
						if (res.data.page_count >= this.sendCoupon.page) this.sendCoupon.page++;
					}
				}
			});
		},
		// 发放数量
		dec: function(item) {
			if (item.num > 0) {
				item.num = item.num - 1;
			}
		},
		inc: function(item) {
			item.num = item.num + 1;
		},

		// 发放优惠券
		sendCouponFn() {
			if (!this.sendCoupon.list || !this.sendCoupon.list.length) return false;
			let data = {};
			data.member_id = this.memberInfo.member_id;
			data.coupon_data = '';
			let couponDataArr = [];

			this.sendCoupon.list.forEach((item, index) => {
				if (item.num > 0) {
					let obj = {};
					obj.coupon_type_id = item.coupon_type_id;
					obj.num = item.num;
					couponDataArr.push(obj);
				}
			});
			if (couponDataArr.length <= 0) return false;
			data.coupon_data = JSON.stringify(couponDataArr);
			this.$api.sendRequest({
				url: '/cashier/storeapi/member/sendCoupon',
				data: data,
				success: res => {
					this.$util.showToast({
						title: res.message
					});
					if (res.code >= 0) {
						this.sendCoupon.page = 1;
						this.sendCoupon.list = [];
						this.getMemberInfo();
						this.$refs.sendCouponPop.close();
					}
				}
			});
		},
		//修改客户信息
		saveMemberInfo() {
			this.$api.sendRequest({
				url: '/cashier/storeapi/member/editmember',
				data: {
					nickname: this.memberInfo.nickname,
					sex: this.memberInfo.sex,
					birthday: this.memberInfo.birthday,
					member_id: this.memberInfo.member_id,
					mobile: this.memberInfo.mobile,
					level_id: this.memberInfo.member_level
				},
				success: res => {
					this.$util.showToast({
						title: res.message
					});
					if (res.code >= 0) {
						this.getMemberInfo();
						this.popClose('memberinfo');
					}
				}
			});
		},
		// 调整积分
		savePoint() {
			this.$api.sendRequest({
				url: '/cashier/storeapi/member/modifypoint',
				data: {
					member_id: this.memberInfo.member_id,
					adjust_num: this.pointData.num,
					remark: this.pointData.desc
				},
				success: res => {
					this.$util.showToast({
						title: res.message
					});
					if (res.code >= 0) {
						this.pointData.num = 0;
						this.pointData.desc = '';
						this.getMemberInfo();
						this.popClose('point');
					}
				}
			});
		},
		// 调整消费券
		saveBalance() {
			this.$api.sendRequest({
				url: '/cashier/storeapi/member/modifybalance',
				data: {
					member_id: this.memberInfo.member_id,
					adjust_num: this.balanceData.num,
					remark: this.balanceData.desc
				},
				success: res => {
					this.$util.showToast({
						title: res.message
					});
					if (res.code >= 0) {
						this.balanceData.num = 0;
						this.balanceData.desc = '';
						this.getMemberInfo();
						this.popClose('balance');
					}
				}
			});
		},
		// 调整成长值
		saveGrowth() {
			this.$api.sendRequest({
				url: '/cashier/storeapi/member/modifygrowth',
				data: {
					member_id: this.memberInfo.member_id,
					adjust_num: this.growthData.num,
					remark: this.growthData.desc
				},
				success: res => {
					this.$util.showToast({
						title: res.message
					});
					if (res.code >= 0) {
						this.growthData.num = 0;
						this.growthData.desc = '';
						this.getMemberInfo();
						this.popClose('growth');
					}
				}
			});
		},
		// 办理会员卡
		saveApplyMember() {
			if (!this.applyMember.level_id) {
				this.$util.showToast({
					title: '请选择会员卡等级'
				});
				return false;
			}
			this.$api.sendRequest({
				url: '/cashier/storeapi/member/handleMember',
				data: {
					member_id: this.memberInfo.member_id,
					level_id: this.applyMember.level_id,
					member_code: this.applyMember.member_code
				},
				success: res => {
					this.$util.showToast({
						title: res.message
					});
					if (res.code >= 0) {
						this.$root.page = 1;
						this.$root.search_text = 1;
						this.$root.getMemberList();
						this.popClose('applyMember');
					}
				}
			});
		},
		refundBalance() {
			this.$api.sendRequest({
				url: '/cashier/storeapi/cashierorderrefund/getMemberBalanceRefundData',
				data: {
					member_id: this.memberInfo.member_id
				},
				success: res => {
					if (res.code == 0) {
						this.refundData = res.data;
						this.refundData.refund_balance = this.$util.moneyFormat(res.data.can_refund_balance);
						this.refundTransferTypeList = res.data.refund_transfer_type_list;
						this.refundTransferType = Object.keys(res.data.refund_transfer_type_list)[0];
						this.$refs.refundBalance.open();
					} else {
						this.$util.showToast({
							title: res.message
						});
					}
				}
			});
		},
		confirmRefundBalance() {
			if (isNaN(parseFloat(this.refundData.refund_balance))) {
				this.$util.showToast({
					title: '退还金额格式错误'
				});
				return;
			}
			if (parseFloat(this.refundData.refund_balance) > parseFloat(this.refundData.can_refund_balance)) {
				this.$util.showToast({
					title: '退还金额超出最大可退金额'
				});
				return;
			}
			if (this.refundData.refund_balance <= 0) {
				this.$util.showToast({
					title: '退还金额不能小于等于0'
				});
				return;
			}

			if (this.isRepeat) return;
			this.isRepeat = true;

			this.$api.sendRequest({
				url: '/cashier/storeapi/cashierorderrefund/memberRefundBalance',
				data: {
					refund_balance: this.$util.moneyFormat(this.refundData.refund_balance),
					member_id: this.memberInfo.member_id,
					refund_transfer_type: this.refundTransferType
				},
				success: res => {
					if (res.code == 0) {
						this.$util.showToast({
							title: '储值退还成功'
						});
						this.getMemberInfo();
						this.$refs.refundBalance.close();
					} else {
						this.$util.showToast({
							title: res.message
						});
					}
					this.isRepeat = true;
				}
			});
		},
		headError(item) {
			item.headimg = 'public/uniapp/default_img/head.png';
		}
	}
};
</script>

<style lang="scss">
.member-detail-wrap {
	width: 100%;
	border-left: 0;

	.member-head {
		height: 0.66rem;
		line-height: 0.66rem;
		box-sizing: border-box;
		border-bottom: 0.01rem solid #e6e6e6;
		font-size: 0.14rem;
	}

	.member-content {
		padding: 0.15rem;
		width: 100%;
		height: calc(100vh - 0.8rem);
		box-sizing: border-box;

		.content-block {
			width: 100%;
			box-sizing: border-box;
			display: flex;
			align-items: center;

			.item-img {
				width: 0.7rem;
				height: 0.7rem;
				border-radius: 50%;
				box-sizing: border-box;

				image {
					width: 100%;
					height: 100%;
					border-radius: 50%;
				}
			}

			.item-content {
				padding-left: 0.15rem;
				width: calc(100% - 0.7rem);
				box-sizing: border-box;

				.item-title {
					width: 100%;
					font-size: 0.16rem;
					align-items: center;
					display: flex;

					.item-label {
						border: 0.01rem solid $primary-color;
						color: $primary-color;
						background-color: #fff;
						border-radius: 0.02rem;
						width: fit-content;
						padding: 0.01rem 0.05rem;
						margin-left: 0.15rem;
					}

					.item-title-text {
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
						max-width: 50%;
						font-size: 0.16rem;
					}
				}

				.info-list {
					margin-top: 0.15rem;
					display: flex;
					justify-content: space-between;

					.info-item {
						font-size: 0.14rem;
						margin-right: 0.2rem;
					}
				}
			}
		}

		.content-block.account {
			border: 0.01rem solid #e6e6e6;
			background-color: #ffffff;
			padding: 0.25rem 0;
			display: flex;
			justify-content: space-around;
			margin-top: 0.2rem;
			border-radius: 0.03rem;
			align-items: baseline;

			.content-data-item {
				.data-item-title {
				}

				.data-item-value {
					font-size: 0.26rem;
					margin-top: 0.1rem;
				}

				.data-item-action {
					margin-top: 0.1rem;
					color: $primary-color;
					cursor: pointer;
					float: left;

					&:nth-child(2n) {
						margin-left: 0.1rem;
					}
				}
			}
		}

		.content-block.assets {
			display: flex;
			justify-content: space-around;
			margin-top: 0.2rem;

			.content-data-left {
				background-color: #ffffff;
				padding: 0.25rem 0;
				border-radius: 0.03rem;
				width: calc(50% - 0.075rem);
				margin-right: 0.15rem;
				display: flex;
				justify-content: space-around;
				height: 1rem;

				.content-data-item {
					.data-item-title {
					}

					.data-item-value {
						font-size: 0.26rem;
						margin-top: 0.1rem;
					}

					.data-item-action {
						margin-top: 0.15rem;
						color: $primary-color;
						cursor: pointer;
					}
				}
			}

			.content-data-right {
				background-color: #ffffff;
				padding: 0.25rem 0;
				border-radius: 0.03rem;
				width: calc(50% - 0.075rem);
				display: flex;
				justify-content: space-around;
				height: 1rem;

				.content-data-item {
					.data-item-title {
					}

					.data-item-value {
						font-size: 0.26rem;
						margin-top: 0.1rem;
					}

					.data-item-action {
						margin-top: 0.15rem;
						color: $primary-color;
					}
				}
			}
		}

		.content-block.action {
			display: flex;
			justify-content: flex-start;
			margin-top: 0.2rem;

			.content-data-item {
				border: 0.01rem solid #e6e6e6;
				width: calc(100% / 6);
				background-color: #ffffff;
				display: flex;
				padding: 0.15rem 0;
				border-radius: 0.03rem;
				align-items: center;
				text-align: center;
				flex-direction: column;
				margin-right: 0.15rem;
				cursor: pointer;

				.data-item-icon {
					width: 0.55rem;
					height: 0.55rem;

					image {
						width: 100%;
						height: 100%;
					}
				}

				.data-item-value {
					margin-top: 0.1rem;
				}

				&:last-child {
					margin-right: 0;
				}
			}
		}
	}
}

// pop弹框
.pop-box {
	background: #ffffff;
	width: 8rem;
	height: 7rem;

	.pop-header {
		padding: 0 0.15rem 0 0.2rem;
		height: 0.5rem;
		line-height: 0.5rem;
		border-bottom: 0.01rem solid #f0f0f0;
		font-size: 0.14rem;
		color: #333;
		overflow: hidden;
		border-radius: 0.02rem 0.2rem 0 0;
		box-sizing: border-box;
		display: flex;
		justify-content: space-between;

		.pop-header-text {
		}

		.pop-header-close {
			cursor: pointer;

			i {
				font-size: 0.18rem;
			}
		}
	}

	.pop-content {
		height: calc(100% - 1rem);
		overflow-y: scroll;
		padding: 0.1rem 0.2rem;
		box-sizing: border-box;
	}

	.pop-bottom {
		button {
			width: 95%;
		}
	}
}

//表单
.form-content {
	display: flex;
	flex-direction: column;
	align-items: center;

	.form-item {
		margin-bottom: 0.1rem;
		display: flex;

		&:last-of-type {
			margin-bottom: 0;
		}

		.form-label {
			width: 1.2rem;
			text-align: right;
			padding-right: 0.1rem;
			box-sizing: border-box;
			height: 0.32rem;
			line-height: 0.32rem;

			.required {
				color: red;
				margin-right: 0.03rem;
			}
		}

		.form-inline {
			width: 2.4rem;
			line-height: 0.32rem;
			margin-right: 0.1rem;
			box-sizing: border-box;

			.form-input {
				border-width: 0.01rem;
				border-style: solid;
				background-color: #fff;
				color: rgba(0, 0, 0, 0.85);
				border-radius: 0.02rem;
				padding-left: 0.1rem;
				height: 0.32rem;
				line-height: 0.32rem;
				font-size: 0.14rem;
				border-color: #e6e6e6;
				border-radius: 0.02rem;
			}

			.form-textarea {
				border-width: 0.01rem;
				border-style: solid;
				background-color: #fff;
				color: rgba(0, 0, 0, 0.85);
				border-radius: 0.02rem;
				padding-left: 0.1rem;
				line-height: 0.32rem;
				font-size: 0.14rem;
				border-color: #e6e6e6;
				width: 100%;
			}

			.word-aux {
				color: #999;
				font-size: 0.12rem;
				line-height: 1.5;
				margin-top: 0.05rem;
			}
		}

		.search-wrap {
			position: relative;

			i {
				position: absolute;
				top: 50%;
				right: 0.1rem;
				transform: translateY(-50%);
				border-left: 0.01rem solid #e6e6e6;
				line-height: 0.3rem;
				padding-left: 0.1rem;
				cursor: pointer;
			}
		}
	}
}

.memberInfo-box {
	width: 7.5rem;
	height: 4.21rem;
}

.pointPop-box {
	width: 7rem;
	height: 3.94rem;
}

.balancePop-box {
	width: 6rem;
	height: 4.2rem;
}

.couponlistPop-box {
	width: 10rem;
	height: 5.7rem;

	.pop-content {
		height: calc(100% - 0.5rem);
	}

	/deep/ .tpage {
		position: absolute;
		right: 0;
		bottom: 0;
	}
}
.applyMemberPop-box {
	width: 6rem;
	height: 3.38rem;
	.pop-content {
		overflow: initial;
	}
}

.cardlistPop-box {
	width: 10rem;
	height: 5.7rem;

	.pop-content {
		height: calc(100% - 0.5rem);
	}

	/deep/ .tpage {
		position: absolute;
		right: 0;
		bottom: 0;
	}
}

.sendCoupon-box {
	width: 9rem;
	height: 5.06rem;

	.sendCoupon-content {
		padding: 0.1rem 0.2rem;

		.coupon-table-head {
			display: flex;
			background: #f7f8fa;
		}

		.coupon-table-body {
			height: 3.2rem;

			.coupon-table-tr {
				display: flex;
				border-bottom: 0.01rem solid #e6e6e6;
			}

			.table-input {
				height: 0.3rem;
				line-height: 0.3rem;
				border: 0.01rem solid #e6e6e6;
				padding: 0 0.1rem;
				text-align: center;
			}

			.item-num {
				display: flex;
				align-items: center;
				margin-left: 0.1rem;

				.num-dec {
					width: 0.6rem;
					height: 0.25rem;
					background: #e6e6e6;
					border: 0.01rem solid #e6e6e6;
					border-radius: 30%;
					text-align: center;
					line-height: 0.23rem;
					font-size: 0.25rem;
					margin-right: 0.1rem;
					cursor: pointer;
					transition: 0.3s;
				}

				.num-inc {
					width: 0.6rem;
					height: 0.25rem;
					background: $primary-color;
					border: 0.01rem solid #e6e6e6;
					border-radius: 30%;
					text-align: center;
					line-height: 0.23rem;
					font-size: 0.25rem;
					margin-left: 0.1rem;
					cursor: pointer;
					transition: 0.3s;
					color: #fff;
				}
			}

			.coupon-table-td:nth-child(4) {
				padding: 0 0.05rem;
			}
		}

		.coupon-table-td,
		.coupon-table-th {
			padding: 0 0.1rem;
			display: flex;
			align-items: center;
			height: 0.5rem;

			&:nth-child(1) {
				flex-basis: 30%;
			}

			&:nth-child(2) {
				flex-basis: 20%;
			}

			&:nth-child(3) {
				flex-basis: 30%;
			}

			&:nth-child(4) {
				justify-content: flex-end;
				flex-basis: 20%;
				text-align: right;
			}
		}
	}

	.pop-bottom {
		margin-top: 0.12rem;
	}

	.empty {
		display: flex;
		align-items: center;
		justify-content: center;
		height: 0.5rem;
		border-bottom: 0.01rem solid #e6e6e6;
		color: #909399;

		.iconfont {
			font-size: 0.25rem;
			margin: 0.05rem;
		}
	}
}
</style>
