Эх сурвалжийг харах

盲票购买流程接口对接

hwb0 3 жил өмнө
parent
commit
7ca51e7e74

+ 1 - 1
packageGoods/ticket/index.vue

@@ -51,7 +51,7 @@
 						if (res.code == 0) {
 							res.rows.forEach(item => {
 								let picUrlArr = item.picUrl.split(',')
-								item.picUrl = env.filePublic + picUrlArr[0] + '?imageView2/2/w/750'
+								item.picUrl = env.filePublic + picUrlArr[2] + '?imageView2/2/w/750'
 							})
 							this.total = res.total
 							this.list = this.list.concat(res.rows)

+ 371 - 140
packagePrize/choice/index.vue

@@ -1,7 +1,6 @@
 	<template>
 	<view>
-		<u-navbar title="选择奖品" :border="true" :placeholder="true" :autoBack="true" bgColor="#fff" />
-		<view class="choice">
+		<!-- <view class="choice">
 			<view class="choice-title" v-if="!tipShow">恭喜你获得</view>
 			<view class="choice-all" v-if="total > 1 && !tipShow">以下奖品任选其一</view>
 			<view class="flex choice-list">
@@ -21,17 +20,17 @@
 						</view>
 					</view>
 				</view>
-			</view>
+			</view> -->
 			<!-- <view class="flex btn">
 				<view class="confirm" @click="confirmPrize" v-if="!tipShow">确认</view>
 			</view> -->
-		</view>
+		<!-- </view> -->
 
-		<view class="footer-fixed" v-if="!tipShow">
+		<!-- <view class="footer-fixed" v-if="!tipShow">
 			<view class="flex btn">
 				<button type="default" @click="confirmPrize">确认</button>
 			</view>
-		</view>
+		</view> -->
 
 		<u-popup :show="tipShow" :round="10" mode="center" :safeAreaInsetBottom="false">
 			<view class="null-prize">
@@ -40,7 +39,7 @@
 			</view>
 		</u-popup>
 
-		<u-popup :show="comfirmShow" :round="10" mode="center" :safeAreaInsetBottom="false">
+		<!-- <u-popup :show="comfirmShow" :round="10" mode="center" :safeAreaInsetBottom="false">
 			<view class="confirm-prize">
 				<view class="flex confirm-prize-info">
 					<image :src="actionInfo.picUrl" mode="aspectFill"></image>
@@ -57,14 +56,89 @@
 					<view class="confirm" @click="again">再来一张</view>
 				</view>
 			</view>
-		</u-popup>
+		</u-popup> -->
+		
+		<view class="choice">
+			<!-- 返回 -->
+			<view class="choice-navLeft flex" :style="{ top: statusHeight + 'px' }" @click="back">
+				<u-icon size="19" color="#fff" name="arrow-left"></u-icon>
+			</view>
+			<!-- 标题 -->
+			<view class="choice-title flex">
+				<image src="../../packagePrize/static/choice_title.png" mode="scaleToFill"></image>
+			</view>
+			<!-- 提示 -->
+			<view class="choice-tip flex" v-if="!comfirmShow">
+				<view class="choice-tip-content">以下奖品任选一件</view>
+			</view>
+			<!-- 奖品列表 -->
+			<view class="choice-list" v-if="!comfirmShow">
+				<view class="choice-list-item flex" v-for="(item, index) in prizeList" :key="index">
+					<view class="checkbox flex" :class="{ 'checkbox-action': actionIndex == index }" @click="selectPrize(index)">
+						<u-icon name="checkmark" color="#fff" size="14"></u-icon>
+					</view>
+					<view class="info flex">
+						<image :src="item.picUrl" mode="aspectFill"></image>
+						<view class="info-content flex">
+							<view class="info-content__title ells-one" v-if="item.prizeType && item.prizeType.value != 'coin'">{{ item.title }}</view>
+							<view class="info-content__title ells-one" v-else>盲豆</view>
+							<view class="info-content__price" v-if="item.prizeType && item.prizeType.value != 'coin'">¥{{ $numberFormat(item.value) }}</view>
+							<view class="info-content__price" v-else>{{ item.value }}颗</view>
+						</view>
+					</view>
+					<view class="detail" @click="toPrizeGoods(item)">查看</view>
+				</view>
+			</view>
+			<!-- 按钮 -->
+			<view class="footer-fixed flex" v-if="!comfirmShow">
+				<view class="footer-fixed-btn flex" @click="confirmPrize">
+					<image src="../../packagePrize/static/rolling_btn.png" mode="aspectFit"></image>
+					<view class="footer-fixed-btn-txt">确认</view>
+				</view>
+			</view>
+			
+			<view class="choice-box flex" v-if="comfirmShow">
+				<view class="choice-box-popup flex">
+					<view class="choice-box-popup__image flex">
+						<image :src="actionInfo.picUrl" mode="aspectFit"></image>
+					</view>
+				</view>
+			</view>
+			<view class="choice-info flex" v-if="comfirmShow">
+				<view class="choice-info-content">
+					<view class="choice-info-content-price" v-if="actionInfo.prizeType && actionInfo.prizeType.value != 'coin'"><text>¥</text>{{ $numberFormat(actionInfo.value) }}</view>
+					<view class="choice-info-content-price" v-else>{{ actionInfo.value }}颗</view>
+					<view class="choice-info-content-title" v-if="actionInfo.prizeType && actionInfo.prizeType.value != 'coin'">{{ actionInfo.title }}</view>
+					<view class="choice-info-content-title" v-else>盲豆</view>
+					<view class="choice-info-content-tip flex"  @click="toPrize(actionInfo.prizeType)">
+						<view class="txt">哇,去瞅瞅我的宝贝</view>
+					</view>
+				</view>
+			</view>
+			<view class="choice-btn flex" v-if="comfirmShow">
+				<view class="choice-btn-content flex"  @click="again">
+					<image src="../../packagePrize/static/rolling_btn.png" mode="aspectFit"></image>
+					<view class="choice-btn-content-txt">再来一张</view>
+				</view>
+			</view>
+		</view>
 		
+		<!-- 详情 -->
+		<u-popup :show="detailShow" :round="11" mode="bottom" @close="detailShow = false" :closeable="true">
+			<view class="prize-detail flex">
+				<view class="prize-detail-title">奖品详情</view>
+				<view class="prize-detail-content">
+					<u-parse :content="description" :selectable="true"></u-parse>
+				</view>
+			</view>
+		</u-popup>
 	</view>
 </template>
 
 <script>
 	import env from '../../config/env.js'
 	import $http from '@/utils/request.js'
+	import { formatRichText } from '@/utils/util.js'
 	export default {
 		data() {
 			return {
@@ -75,12 +149,21 @@
 				tipShow: false,
 				comfirmShow: false,
 				actionInfo: {},
-				type: ''
+				type: '',
+				
+				statusHeight: 30,
+				detailShow: false,
+				description: '',
 			};
 		},
 		onLoad(options) {
 			this.ticketId = options.id
 			this.type = options.type
+			
+			// #ifdef MP-WEIXIN
+			const res = uni.getMenuButtonBoundingClientRect()
+			this.statusHeight = res.top //胶囊距离顶部
+			// #endif
 		},
 		onShow() {
 			this.getPrizeList()
@@ -102,6 +185,19 @@
 							item.prizeType = JSON.parse(item.prizeType)
 						})
 						this.prizeList = res.data.prizeList
+						if(this.prizeList.length == 1) {
+							let item = this.prizeList[this.actionIndex]
+							this.actionInfo = item
+							$http.post('/api/v1/mp/user/ticket/cashPrize', {
+								ticketId: this.ticketId,
+								awardsId: item.awardsId,
+								prizeId: item.prizeId
+							}).then(res => {
+								if (res.code == 0) {
+									this.comfirmShow = true
+								}
+							})
+						}
 						this.ticketId = res.data.ticketId
 						this.total = this.prizeList.length
 					} else if (res.code == 1018) {
@@ -114,11 +210,7 @@
 				})
 			},
 
-			selectPrize(item, index) {
-				if (item.remainQty == 0) {
-					uni.$u.toast('该奖品已兑完!');
-					return
-				}
+			selectPrize(index) {
 				this.actionIndex = index
 			},
 
@@ -126,7 +218,6 @@
 				let _this = this
 				let item = _this.prizeList[_this.actionIndex]
 				_this.actionInfo = item
-				console.log(this.actionInfo)
 				if (_this.prizeList.length > 1) {
 					uni.showModal({
 						title: '提示',
@@ -193,37 +284,64 @@
 						url: '/packagePrize/prize/index?coupon=1'
 					})
 				}
-				if (data == 'coin') {
+				if (data.value == 'coin') {
 					uni.switchTab({
 						url: '/pages/core/index'
 					})
 				}
-				
 			},
-
+			
+			toPrizeGoods(item) {
+				if (item.prizeType.value == "goods") {
+					this.getGoodsDetail(item.refId)
+				}
+				//门店优惠券
+				if (item.prizeType.value == "coupon" || item.prizeType.value == "coupon_pkg") {
+					this.getGoodsDetail(425)
+				}
+				// 盲豆
+				if (item.prizeType.value == "coin") {
+					this.getGoodsDetail(424)
+				}
+			},
+			
+			getGoodsDetail(id) {
+				uni.showLoading({
+					title: '加载中'
+				});
+				$http.post('/api/v1/mp/user/exchange/goods/detail', {
+					noToken: true,
+					goodsId: id
+				}).then(res => {
+					uni.hideLoading();
+					if (res.code == 0) {
+						this.detailShow = true
+						// 处理富文本
+						const description = res.data.description.replaceAll(".jpg\"", ".jpg?imageView2/2/w/750\"")
+							.replaceAll(".jpeg\"", ".jpeg?imageView2/2/w/750\"").replaceAll(".png\"",
+								".png?imageView2/2/w/750\"");
+						this.description = formatRichText(description);
+					}
+				}).catch(() => {
+					uni.hideLoading();
+				})
+			},
+			
 			again() {
 				let _this = this
-				if (_this.type == 'onLine') {
-					uni.navigateBack({
-						delta: 1
-					})
-				} else if (_this.type == 'offLine') {
-					uni.scanCode({
-						scanType: ['qrCode'],
-						success(res) {
-							const url = res.result
-							let serialNo = url.substring(url.length - 21, url.length)
-							uni.redirectTo({
-								url: `/pages/lucky/index?id=${ serialNo }&type=offLine`
-							})
-						},
-						fail() {
-							uni.$u.toast('请扫二维码');
-						}
-					});
-				} else {
-					_this.toIndex()
-				}
+				uni.scanCode({
+					scanType: ['qrCode'],
+					success(res) {
+						const url = res.result
+						let serialNo = url.substring(url.length - 21, url.length)
+						uni.redirectTo({
+							url: `/pages/lucky/index?id=${ serialNo }&type=offLine`
+						})
+					},
+					fail() {
+						uni.$u.toast('请扫二维码');
+					}
+				});
 			},
 		}
 	}
@@ -231,135 +349,230 @@
 
 <style lang="scss" scoped>
 	.choice {
+		display: flex;
+		flex-direction: column;
+		position: relative;
 		width: 100%;
-		min-height: calc(100vh - 44px - var(--status-bar-height));
-		background: url(https://mp-public-1310078123.cos.ap-shanghai.myqcloud.com/openprize_bg.png) center center;
-		padding-bottom: 150rpx;
-
+		height: 100vh;
+		background: url(https://mp-public-1310078123.cos.ap-shanghai.myqcloud.com/v2/offline_prize_bkg.png) center center no-repeat;
+		background-size: 100vw 100vh;
+		overflow: hidden;
+		
+		// 返回
+		&-navLeft {
+			position: absolute;
+			left: 34rpx;
+			width: 66rpx;
+			height: 66rpx;
+			background-color: rgba(255, 255, 255, .36);
+			border-radius: 50%;
+		}
+		
+		// 标题
 		&-title {
-			padding-top: 100rpx;
-			font-size: 56rpx;
-			font-weight: bold;
-			text-align: center;
-			line-height: 84rpx;
-			margin-bottom: 12rpx;
+			padding-top: 15vh;
+			margin-bottom: 72rpx;
+			
+			image {
+				width: 484rpx;
+				height: 108rpx;
+			}
 		}
-
-		&-all {
-			text-align: center;
-			line-height: 40rpx;
+		
+		// 提示
+		&-tip {
+			&-content {
+				width: 50vw;
+				height: 56rpx;
+				line-height: 56rpx;
+				background: rgba(255, 211, 157, .44);
+				border-radius: 24rpx;
+				color: #FB900B;
+				font-size: 30rpx;
+				text-align: center;
+			}
 		}
-
+		
+		// 奖品列表
 		&-list {
-			justify-content: space-around;
-			flex-wrap: wrap;
-			padding: 60rpx;
-
+			flex: 1;
+			margin: 72rpx 48rpx 0;
+			padding-bottom: 200rpx;
+			overflow-y: auto;
+			
 			&-item {
-				position: relative;
-				width: 43%;
-				height: 440rpx;
-				margin-bottom: 40rpx;
-				background-color: #FFFFFF;
-				border-radius: 10rpx;
-
-				.item-info {
-					height: 100%;
-					display: flex;
-					flex-direction: column;
-					align-items: center;
-					border: 2px solid #FFFFFF;
-					border-radius: 10rpx;
-				}
-
-				.confirm {
-					background: none;
-					box-shadow: none;
-				}
-
-				.action-icon {
-					position: absolute;
-					bottom: -15rpx;
-					right: -15rpx;
-					width: 82rpx;
-					height: 82rpx;
-					line-height: 82rpx;
-					background-color: rgba(236, 122, 61, 100);
-					text-align: center;
-					box-shadow: 0px 4rpx 12rpx 0px rgba(0, 0, 0, 0.4);
+				justify-content: space-between;
+				background-color: #fff;
+				border-radius: 12rpx;
+				padding: 38rpx 24rpx;
+				margin-bottom: 54rpx;
+				
+				.checkbox {
+					width: 46rpx;
+					height: 46rpx;
+					border: 1px solid #F56D1B;
 					border-radius: 50%;
 				}
-
-				.action {
-					box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.4);
-					border: 2px solid rgba(236, 122, 61, 100);
+				
+				.checkbox-action {
+					background: #F56D1B;
 				}
-
-				.null {
-					box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.4);
-					border: 2px solid rgba(187, 187, 187, 54);
+				
+				.info {
+					margin: 0 30rpx;
+					flex: 1;
+					justify-content: flex-start;
+					
+					image {
+						width: 110rpx;
+						height: 110rpx;
+						margin-right: 34rpx;
+					}
+					
+					&-content {
+						height: 110rpx;
+						flex: 1;
+						align-items: flex-start;
+						flex-direction: column;
+						justify-content: space-between;
+						
+						&__title {
+							width: 100%;
+							font-size: 30rpx;
+						}
+						
+						&__price {
+							font-weight: bold;
+						}
+					}
 				}
-
-				.info-image {
-					width: 100%;
-					min-height: 70%;
-					background-color: #F8F8F8;
-					border-top-left-radius: 10rpx;
-					border-top-right-radius: 10rpx;
+				
+				.detail {
+					color: #F56D1B;
 				}
-
-				image {
-					width: 100%;
-					height: 80%;
+			}
+		}
+		
+		&-box {
+			margin-bottom: 34rpx;
+			
+			&-popup {
+				flex-direction: column;
+				width: 75vw;
+				height: 38vh;
+				background-color: #FFFFFF;
+				border-radius: 22rpx;
+				
+				&__image {
+					width: 65%;
+					height: 65%;
+					margin-bottom: 30rpx;
+					
+					image {
+						width: 100%;
+						height: 100%;
+					}
 				}
-
-				.title {
-					width: 100%;
-					font-size: 24rpx;
-					margin: 16rpx 0 0 10rpx;
-					color: #333;
-					overflow: hidden;
-					text-overflow: ellipsis;
-					display: -webkit-box;
-					-webkit-box-orient: vertical;
-					-webkit-line-clamp: 3;
+			}
+		}
+		
+		&-info {
+			margin-bottom: 34rpx;
+			
+			&-content {
+				width: 70vw;
+				
+				&-price {
+					text-align: center;
+					font-size: 40rpx;
+					line-height: 40rpx;
+					font-family: PingFang SC;
+					font-weight: bold;
+					color: #FFFFFF;
+					margin-bottom: 20rpx;
+					
+					text {
+						font-size: 28rpx;
+					}
 				}
-
-				.tip {
-					margin: 16rpx 0 0 10rpx;
-					font-size: 24rpx;
-					color: red;
+				
+				&-title {
+					text-align: center;
+					font-size: 36rpx;
+					line-height: 36rpx;
+					color: #FFFFFF;
+					margin-bottom: 40rpx;
+				}
+				
+				&-tip {
+					.txt {
+						padding: 10rpx 0;
+						width: 75%;
+						text-align: center;
+						background: rgba(255, 211, 157, .3);
+						border-radius: 30rpx;
+						font-size: 30rpx;
+						font-weight: 500;
+						color: #FC8D03;
+					}
 				}
 			}
 		}
-
-		.btn {
-			margin-top: 200rpx;
-
-			.confirm {
-				width: 400rpx;
-				height: 80rpx;
-				font-size: 36rpx;
-				line-height: 80rpx;
-				border-radius: 20rpx;
-				background-color: rgba(235, 112, 9, 100);
-				color: rgba(255, 255, 255, 100);
-				text-align: center;
+		
+		&-btn {
+			&-content {
+				position: relative;
+				width: 70vw;
+				
+				image {
+					width: 70vw;
+					height: 112rpx;
+				}
+				
+				&-txt {
+					position: absolute;
+					top: 0;
+					height: 112rpx;
+					line-height: 112rpx;
+					font-size: 30rpx;
+					text-align: center;
+					color: #FFFFFF;
+				}
 			}
 		}
 	}
-
+	
+	// 按钮
 	.footer-fixed {
 		position: fixed;
 		bottom: var(--window-bottom);
 		left: 0;
 		right: 0;
 		z-index: 11;
-		box-shadow: 0 -4rpx 40rpx 0 rgba(151, 151, 151, 0.24);
-		background: #fff;
 		// 设置ios刘海屏底部横线安全区域
 		padding-bottom: constant(safe-area-inset-bottom);
 		padding-bottom: env(safe-area-inset-bottom);
+		
+		&-btn {
+			padding: 0 0 20rpx;
+			position: relative;
+			width: 70vw;
+			
+			image {
+				width: 70vw;
+				height: 112rpx;
+			}
+			
+			&-txt {
+				position: absolute;
+				top: 0;
+				height: 112rpx;
+				line-height: 112rpx;
+				font-size: 30rpx;
+				text-align: center;
+				color: #FFFFFF;
+			}
+		}
 
 		.btn {
 			padding: 20rpx 0;
@@ -376,6 +589,24 @@
 			}
 		}
 	}
+	
+	.prize-detail {
+		flex-direction: column;
+		height: 60vh;
+
+		&-title {
+			padding: 40rpx 0;
+			text-align: center;
+			font-size: 34rpx;
+			line-height: 34rpx;
+			font-weight: bold;
+		}
+		
+		&-content {
+			flex: 1;
+			overflow-y: auto;
+		}
+	}
 
 	.null-prize {
 		display: flex;

+ 118 - 124
packagePrize/rolling/index.vue

@@ -8,9 +8,11 @@
 					<view class="rolling-prize-list-item flex" v-for="(item, index) in list" :key="index">
 						<view class="rolling-prize-list-item__items flex">
 							<view class="content flex" v-for="(items, indexs) in item" :key="indexs">
-								<image :src="items.url" mode="aspectFit"></image>
-								<view class="content-title ells-one">{{ items.title }}</view>
-								<view class="content-price">¥{{ $numberFormat(items.price) }}</view>
+								<image :src="items.picUrl" mode="aspectFit"></image>
+								<view class="content-title ells-one" v-if="items.prizeType && items.prizeType.value != 'coin'">{{ items.title }}</view>
+								<view class="content-title ells-one" v-else>盲豆</view>
+								<view class="content-price" v-if="items.prizeType && items.prizeType.value != 'coin'">¥{{ $numberFormat(items.value) }}</view>
+								<view class="content-price" v-else>{{ items.value }}颗</view>
 							</view>
 						</view>
 					</view>
@@ -19,9 +21,11 @@
 					<view class="rolling-prize-list-item flex" v-for="(item, index) in list" :key="index">
 						<view class="rolling-prize-list-item__items flex">
 							<view class="content flex" v-for="(items, indexs) in item" :key="indexs">
-								<image :src="items.url" mode="aspectFit"></image>
-								<view class="content-title ells-one">{{ items.title }}</view>
-								<view class="content-price">¥{{ $numberFormat(items.price) }}</view>
+								<image :src="items.picUrl" mode="aspectFit"></image>
+								<view class="content-title ells-one" v-if="items.prizeType && items.prizeType.value != 'coin'">{{ items.title }}</view>
+								<view class="content-title ells-one" v-else>盲豆</view>
+								<view class="content-price" v-if="items.prizeType && items.prizeType.value != 'coin'">¥{{ $numberFormat(items.value) }}</view>
+								<view class="content-price" v-else>{{ items.value }}颗</view>
 							</view>
 						</view>
 					</view>
@@ -30,7 +34,7 @@
 			
 			<!-- 按钮 -->
 			<view class="rolling-btn flex">
-				<view class="rolling-btn-content flex" :class="{ 'btn-stop': btnIng }" @click="stop">
+				<view class="rolling-btn-content flex" :class="{ 'btn-stop': btnIng }" @click="stop" v-show="btnShow">
 					<image src="../../static/ticketBox/ticket_btn_center.png" mode="scaleToFill"></image>
 					<view class="rolling-btn-content-title">停止滚动</view>
 				</view>
@@ -52,21 +56,26 @@
 			<view class="prize-box flex">
 				<view class="prize-box-popup flex">
 					<view class="prize-box-popup__image flex">
-						<image :src="prizeInfo.url" mode="aspectFit"></image>
+						<image :src="prizeInfo.picUrl" mode="aspectFit"></image>
 					</view>
-					<view class="prize-box-popup__tip">哇,去瞅瞅我的宝贝</view>
 				</view>
 			</view>
 			<view class="prize-info flex">
 				<view class="prize-info-content">
-					<view class="prize-info-content-price"><text>¥</text>{{ $numberFormat(prizeInfo.price) }}</view>
-					<view class="prize-info-content-title">{{ prizeInfo.title }}</view>
+					<view class="prize-info-content-price" v-if="prizeInfo.prizeType && prizeInfo.prizeType.value != 'coin'"><text>¥</text>{{ $numberFormat(prizeInfo.value) }}</view>
+					<view class="prize-info-content-price" v-else>{{ prizeInfo.value }}颗</view>
+					<view class="prize-info-content-title" v-if="prizeInfo.prizeType && prizeInfo.prizeType.value != 'coin'">{{ prizeInfo.title }}</view>
+					<view class="prize-info-content-title" v-else>盲豆</view>
+					<view class="prize-info-content-tip flex" v-if="isTry == 0" @click="toPrize(prizeInfo.prizeType)">
+						<view class="txt">哇,去瞅瞅我的宝贝</view>
+					</view>
 				</view>
 			</view>
 			<view class="prize-btn flex">
-				<view class="prize-btn-content flex">
+				<view class="prize-btn-content flex" @click="back">
 					<image src="../../packagePrize/static/rolling_btn.png" mode="aspectFit"></image>
-					<view class="prize-btn-content-txt">再来一张</view>
+					<view class="prize-btn-content-txt" v-if="isTry == 0">再来一张</view>
+					<view class="prize-btn-content-txt" v-else>来把真的</view>
 				</view>
 			</view>
 		</view>
@@ -84,107 +93,31 @@
 				num2: 0, // 动画持续时间
 				time: null, // 定时器
 				stopTime: null, //自动停止
-				list: [
-					[
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软显示(Miceosoft)日版Xbox Seies S', price: 2999 },
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软(Miceosoft)日版Xbox Seies S', price: 2999 },
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软(Miceosoft)日版Xbox Seies S', price: 2999 },
-					],
-					[
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软显示(Miceosoft)日版Xbox Seies S', price: 2999 },
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软(Miceosoft)日版Xbox Seies S', price: 2999 },
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软(Miceosoft)日版Xbox Seies S', price: 2999 },
-					],
-					[
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软显示(Miceosoft)日版Xbox Seies S', price: 2999 },
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软(Miceosoft)日版Xbox Seies S', price: 2999 },
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软(Miceosoft)日版Xbox Seies S', price: 2999 },
-					],
-					[
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软显示(Miceosoft)日版Xbox Seies S', price: 2999 },
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软(Miceosoft)日版Xbox Seies S', price: 2999 },
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软(Miceosoft)日版Xbox Seies S', price: 2999 },
-					],
-					[
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软显示(Miceosoft)日版Xbox Seies S', price: 2999 },
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软(Miceosoft)日版Xbox Seies S', price: 2999 },
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软(Miceosoft)日版Xbox Seies S', price: 2999 },
-					],
-					[
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软显示(Miceosoft)日版Xbox Seies S', price: 2999 },
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软(Miceosoft)日版Xbox Seies S', price: 2999 },
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软(Miceosoft)日版Xbox Seies S', price: 2999 },
-					],
-					[
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软显示(Miceosoft)日版Xbox Seies S', price: 2999 },
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软(Miceosoft)日版Xbox Seies S', price: 2999 },
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软(Miceosoft)日版Xbox Seies S', price: 2999 },
-					],
-					[
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软显示(Miceosoft)日版Xbox Seies S', price: 2999 },
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软(Miceosoft)日版Xbox Seies S', price: 2999 },
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软(Miceosoft)日版Xbox Seies S', price: 2999 },
-					],
-					[
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软显示(Miceosoft)日版Xbox Seies S', price: 2999 },
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软(Miceosoft)日版Xbox Seies S', price: 2999 },
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软(Miceosoft)日版Xbox Seies S', price: 2999 },
-					],
-					[
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软显示(Miceosoft)日版Xbox Seies S', price: 2999 },
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软(Miceosoft)日版Xbox Seies S', price: 2999 },
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软(Miceosoft)日版Xbox Seies S', price: 2999 },
-					],
-					[
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软显示(Miceosoft)日版Xbox Seies S', price: 2999 },
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软(Miceosoft)日版Xbox Seies S', price: 2999 },
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软(Miceosoft)日版Xbox Seies S', price: 2999 },
-					],
-					[
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软显示(Miceosoft)日版Xbox Seies S', price: 2999 },
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软(Miceosoft)日版Xbox Seies S', price: 2999 },
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软(Miceosoft)日版Xbox Seies S', price: 2999 },
-					],
-					[
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软显示(Miceosoft)日版Xbox Seies S', price: 2999 },
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软(Miceosoft)日版Xbox Seies S', price: 2999 },
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软(Miceosoft)日版Xbox Seies S', price: 2999 },
-					],
-					[
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软显示(Miceosoft)日版Xbox Seies S', price: 2999 },
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软(Miceosoft)日版Xbox Seies S', price: 2999 },
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软(Miceosoft)日版Xbox Seies S', price: 2999 },
-					],
-					[
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软显示(Miceosoft)日版Xbox Seies S', price: 2999 },
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软(Miceosoft)日版Xbox Seies S', price: 2999 },
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软(Miceosoft)日版Xbox Seies S', price: 2999 },
-					],
-					[
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软显示(Miceosoft)日版Xbox Seies S', price: 2999 },
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软(Miceosoft)日版Xbox Seies S', price: 2999 },
-						{ url: 'https://cdn.uviewui.com/uview/album/1.jpg', title: '微软(Miceosoft)日版Xbox Seies S', price: 2999 },
-					],
-				],
-				
-				prizeInfo: { 
-					url: 'https://cdn.uviewui.com/uview/album/4.jpg', 
-					title: '中奖了!!!', 
-					price: 9999 ,
-				},
+				list: [],
+				prizeInfo: {},
 				btnIng: false,
 				rollingShow: true,
 				statusHeight: 30,
+				btnShow: false,
+				
+				boxId: '',
+				isTry: null,
+				ticketId: '',
 			}
 		},
 		
-		onLoad() {
+		onLoad(options) {
 			// 创建动画实例
 			this.animation = uni.createAnimation()
 			// #ifdef MP-WEIXIN
 			const res = uni.getMenuButtonBoundingClientRect()
 			this.statusHeight = res.top //胶囊距离顶部
 			// #endif
+
+			if(options) {
+				this.boxId = options.boxId
+				this.isTry = Number(options.isTry)
+			}
 		},
 		
 		onUnload() {
@@ -193,10 +126,45 @@
 		},
 		
 		mounted() {
-			this.running()
+			this.getList()
 		},
 		
 		methods: {
+			getList() {
+				uni.showLoading({
+					title: '加载中'
+				});
+				let data = {
+					boxId: this.boxId,
+					isTry: this.isTry,
+					ticketId: this.ticketId
+				}
+				
+				$http.post('/api/v1/mp/user/ticket/autoCashPrize', data).then(res => {
+					if(res.code == 0) {
+						this.list = res.data.ticketAwardsPrizeList
+						this.list.forEach(item => {
+							item.forEach(ele => {
+								ele.picUrl = env.filePublic + ele.picUrl
+								ele.prizeType = JSON.parse(ele.prizeType)
+							})
+						})
+						this.prizeInfo = { 
+							...res.data,
+							picUrl: env.filePublic + res.data.picUrl,
+							prizeType: JSON.parse(res.data.prizeType)
+						}
+						setTimeout(()=> {
+							uni.hideLoading();
+							this.btnShow = true
+							this.running()
+						},500)
+					}
+				}).catch(() => {
+					uni.hideLoading();
+				})
+			},
+			
 			// 动画开始
 			running() {
 				// #ifdef H5
@@ -282,27 +250,27 @@
 				clearTimeout(this.stopTime)
 				this.animationData = {}
 				if (this.num2 == 0) {
-					this.list[3][1] = this.prizeInfo
+					this.list[3][1] = JSON.parse(JSON.stringify(this.prizeInfo))
 				} else if (this.num2 == 1) {
-					this.list[5][1] = this.prizeInfo
+					this.list[5][1] = JSON.parse(JSON.stringify(this.prizeInfo))
 				} else if (this.num2 == 2) {
-					this.list[7][1] = this.prizeInfo
+					this.list[7][1] = JSON.parse(JSON.stringify(this.prizeInfo))
 				} else if (this.num2 == 3) {
-					this.list[9][1] = this.prizeInfo
+					this.list[9][1] = JSON.parse(JSON.stringify(this.prizeInfo))
 				} else if (this.num2 == 4) {
-					this.list[11][1] = this.prizeInfo
+					this.list[11][1] = JSON.parse(JSON.stringify(this.prizeInfo))
 				} else if (this.num2 == 5) {
-					this.list[13][1] = this.prizeInfo
+					this.list[13][1] = JSON.parse(JSON.stringify(this.prizeInfo))
 				} else if (this.num2 == 6) {
-					this.list[15][1] = this.prizeInfo
+					this.list[15][1] = JSON.parse(JSON.stringify(this.prizeInfo))
 				} else if (this.num2 == 7) {
-					this.list[1][1] = this.prizeInfo
+					this.list[1][1] = JSON.parse(JSON.stringify(this.prizeInfo))
 				} else if (this.num2 == 8) {
 					// #ifdef MP-WEIXIN
-					this.list[1][1] = this.prizeInfo
+					this.list[1][1] = JSON.parse(JSON.stringify(this.prizeInfo))
 					// #endif
 					// #ifdef H5
-					this.list[3][1] = this.prizeInfo
+					this.list[3][1] = JSON.parse(JSON.stringify(this.prizeInfo))
 					// #endif
 				}
 				// #ifdef H5
@@ -344,6 +312,29 @@
 					delta: 1
 				})
 			},
+			
+			toPrize(data) {
+				if (data.value == 'goods') {
+					uni.redirectTo({
+						url: '/packagePrize/prize/index'
+					})
+				}
+				if (data.value == 'coupon') {
+					uni.redirectTo({
+						url: '/packagePrize/prize/index?coupon=1'
+					})
+				}
+				if (data.value == 'coupon_pkg') {
+					uni.redirectTo({
+						url: '/packagePrize/prize/index?coupon=1'
+					})
+				}
+				if (data.value == 'coin') {
+					uni.switchTab({
+						url: '/pages/core/index'
+					})
+				}
+			},
 		},
 	}
 </script>
@@ -530,17 +521,6 @@
 						height: 100%;
 					}
 				}
-				
-				&__tip {
-					padding: 4rpx 0;
-					width: 75%;
-					text-align: center;
-					background: rgba(255, 211, 157, .44);
-					border-radius: 24rpx;
-					font-size: 30rpx;
-					font-weight: 500;
-					color: #FB900B;
-				}
 			}
 		}
 		
@@ -569,6 +549,20 @@
 					font-size: 36rpx;
 					line-height: 36rpx;
 					color: #FFFFFF;
+					margin-bottom: 40rpx;
+				}
+				
+				&-tip {
+					.txt {
+						padding: 10rpx 0;
+						width: 75%;
+						text-align: center;
+						background: rgba(255, 211, 157, .3);
+						border-radius: 30rpx;
+						font-size: 30rpx;
+						font-weight: 500;
+						color: #FC8D03;
+					}
 				}
 			}
 		}

BIN
packagePrize/static/choice_title.png


+ 30 - 13
pages/index/index.vue

@@ -29,8 +29,8 @@
 					<swiper class="ticket-swiper" :current="ticketIndex" :autoplay="false" :circular="true" @change="changeTicket">
 						<swiper-item v-for="(item, index) in ticketList" :key="index" @click="toTicketBox(item)">
 							<view class="ticket-swiper-item flex">
-								<image class="box" :src="item.picUrl[1]" mode="scaleToFill"></image>
-								<image class="prize" :src="item.picUrl[0]" mode="scaleToFill"></image>
+								<image class="box" :src="item.picUrl[2]" mode="scaleToFill"></image>
+								<image class="prize" :src="item.picUrl[1]" mode="scaleToFill"></image>
 							</view>
 						</swiper-item>
 					</swiper>
@@ -56,9 +56,11 @@
 				<!-- 中奖概率 -->
 				<view class="chance flex">
 					<view class="chance-title">中奖概率:</view>
-					<view class="chance-content flex" v-for="(item, index) in ticketInfo.ticketAwardsLabelList" :key="index">
-						<image :src="item.picUrl" mode="scaleToFill"></image>
-						<text>{{ item.hitRate }}%</text>
+					<view class="chance-hitRate flex">
+						<view class="chance-hitRate-content flex" v-for="(item, index) in ticketInfo.ticketAwardsLabelList" :key="index">
+							<image :src="item.picUrl" mode="scaleToFill"></image>
+							<text>{{ item.hitRate }}%</text>
+						</view>
 					</view>
 				</view>
 				
@@ -75,7 +77,7 @@
 				
 				<!-- 刮开盲票 -->
 				<view class="ticket-btn flex">
-					<view class="ticket-btn-left flex">
+					<view class="ticket-btn-left flex" @click="toRollingGame">
 						<image src="../../static/index/index_btn_left.png" mode="scaleToFill"></image>
 						<view class="ticket-btn-left__title">试玩</view>
 					</view>
@@ -338,7 +340,7 @@
 						let info = {
 							...res.data,
 							...this.payInfo,
-							picUrl: this.payInfo.picUrl[2],
+							picUrl: this.payInfo.picUrl[0],
 							couponTitle: res.data && res.data.couponList && res.data.couponList.length && res
 								.data.couponList[0].title,
 							couponId: res.data && res.data.couponList && res.data.couponList.length && res.data
@@ -395,12 +397,18 @@
 				}
 				this.changeList()
 			},
+			
+			toRollingGame() {
+				uni.navigateTo({
+					url: `/packagePrize/rolling/index?boxId=${ this.ticketInfo.boxId }&isTry=1`
+				})
+			},
 
 			// 线上立即刮票成功,跳转到刮奖过程
 			toProcess(id) {
 				this.payShow = false
 				uni.navigateTo({
-					url: `/packageOperate/process/index?id=${ id }`
+					url: `/packagePrize/rolling/index?boxId=${ this.ticketInfo.boxId }&isTry=0`
 				})
 			},
 
@@ -676,7 +684,7 @@
 	
 	// 中奖概率
 	.chance {
-		justify-content: space-evenly;
+		justify-content: flex-start;
 		height: 44rpx;
 		margin: 0 34rpx 26rpx;
 		background-color: rgba(000, 000, 000, .36);
@@ -685,11 +693,20 @@
 		font-family: YouSheBiaoTiHei;
 		font-size: 14px;
 		
-		&-content {
+		&-title {
+			margin-left: 8rpx;
+		}
+		
+		&-hitRate {
+			flex: 1;
+			justify-content: space-evenly;
 			
-			image {
-				width: 56rpx;
-				height: 50rpx;
+			&-content {
+				
+				image {
+					width: 56rpx;
+					height: 50rpx;
+				}
 			}
 		}
 	}

+ 16 - 18
pages/ticketBox/detail.vue

@@ -32,9 +32,9 @@
 			
 			<!-- 奖品价格 -->
 			<view class="prize-price flex">
-				<view class="prize-price-present" v-if="prizeList[prizeIndex].prizeType != 'coin'">¥{{ $numberFormat(prizeList[prizeIndex].value) }}</view>
-				<view class="prize-price-present" v-else>{{ prizeList[prizeIndex].value }}颗</view>
-				<view class="prize-price-txt ells-one">{{ prizeList[prizeIndex].title }}</view>
+				<view class="prize-price-present" v-if="prizeInfo.prizeType != 'coin'">¥{{ $numberFormat(prizeInfo.value) }}</view>
+				<view class="prize-price-present" v-else>{{ prizeInfo.value }}颗</view>
+				<view class="prize-price-txt ells-one">{{ prizeInfo.title }}</view>
 				<view class="prize-price__ticket-price flex">
 					<image src="../../static/ticketBox/ticket_block.png" mode="scaleToFill"></image>
 					<view class="txt">¥{{ $numberFormat(info.salePrice) }} /个</view>
@@ -44,7 +44,7 @@
 			
 			<!-- 开启盲票 -->
 			<view class="ticket-btn flex">
-				<image class="ticket-btn-game" src="../../static/ticketBox/ticket_game.png" mode="scaleToFill"></image>
+				<image class="ticket-btn-game" src="../../static/ticketBox/ticket_game.png" mode="scaleToFill" @click="toRollingGame"></image>
 				<view class="ticket-btn-center flex" @click="exchange">
 					<image src="../../static/ticketBox/ticket_btn_center.png" mode="scaleToFill"></image>
 					<view class="ticket-btn-center-txt">开启盲票</view>
@@ -126,6 +126,7 @@
 				prizeIndex: 0,
 				contnetHeight: 0,
 				btnFixed: false,
+				prizeInfo: {}
 			};
 		},
 
@@ -174,6 +175,7 @@
 		methods: {
 			changePrizeSwiper({ detail }) {
 				this.prizeIndex = detail.current
+				this.prizeInfo = this.prizeList[detail.current]
 			},
 			
 			getDetail() {
@@ -193,13 +195,13 @@
 								return { ...item, picUrl: env.filePublic + item.picUrl }
 							})
 						}
-						console.log(this.info);
 						let prizeList = res.data.prizeList
 						prizeList.forEach(item => {
 							item.picUrl = env.filePublic + item.picUrl.split(',')[0] + '?imageView2/2/w/170'
 							item.awardsLabelPicUrl = env.filePublic + item.awardsLabelPicUrl
 						})
 						this.prizeList = prizeList
+						this.prizeInfo = this.prizeList[this.prizeIndex]
 					}
 				}).catch(() => {
 					uni.hideLoading();
@@ -217,7 +219,7 @@
 			toProcess(id) {
 				this.payShow = false
 				uni.navigateTo({
-					url: `/packageOperate/process/index?id=${ id }`
+					url: `/packagePrize/rolling/index?boxId=${ this.info.boxId }&isTry=0`
 				})
 			},
 
@@ -233,7 +235,7 @@
 						let info = {
 							...res.data,
 							...this.info,
-							picUrl: this.info.picUrl[2],
+							picUrl: this.info.picUrl[0],
 							couponTitle: res.data && res.data.couponList && res.data.couponList.length && res
 								.data.couponList[0].title,
 							couponId: res.data && res.data.couponList && res.data.couponList.length && res.data
@@ -244,6 +246,12 @@
 					}
 				})
 			},
+			
+			toRollingGame() {
+				uni.navigateTo({
+					url: `/packagePrize/rolling/index?boxId=${ this.info.boxId }&isTry=1`
+				})
+			},
 
 			toShare() {
 				if (!uni.getStorageSync('token')) {
@@ -270,7 +278,7 @@
 				})
 			},
 
-			toPrizeGoods(item) {
+			toPrizeGoods(item) { 
 				if (item.prizeType == "goods") {
 					uni.navigateTo({
 						url: `/packagePrize/goods/detail?id=${ item.refId }`
@@ -278,16 +286,6 @@
 				}
 				//门店优惠券
 				if (item.prizeType == "coupon" || item.prizeType == "coupon_pkg") {
-					// if (item.couponType == "1") {
-					// 	uni.navigateTo({
-					// 		url: `/packagePrize/goods/detail?id=426`
-					// 	})
-					// }
-					// if (item.couponType == "2") {
-					// 	uni.navigateTo({
-					// 		url: `/packagePrize/goods/detail?id=425`
-					// 	})
-					// }
 					uni.navigateTo({
 						url: `/packagePrize/goods/detail?id=425`
 					})

+ 135 - 98
utils/util.js

@@ -1,44 +1,44 @@
 // 日期格式化
 export function parseTime(time, pattern) {
-  if (arguments.length === 0 || !time) {
-    return null
-  }
-  const format = pattern || '{y}-{m}-{d} {h}:{i}:{s}'
-  let date
-  if (typeof time === 'object') {
-    date = time
-  } else {
-    if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) {
-      time = parseInt(time)
-    } else if (typeof time === 'string') {
-      time = time.replace(new RegExp(/-/gm), '/');
-    }
-    if ((typeof time === 'number') && (time.toString().length === 10)) {
-      time = time * 1000
-    }
-    date = new Date(time)
-  }
-  const formatObj = {
-    y: date.getFullYear(),
-    m: date.getMonth() + 1,
-    d: date.getDate(),
-    h: date.getHours(),
-    i: date.getMinutes(),
-    s: date.getSeconds(),
-    a: date.getDay()
-  }
-  const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
-    let value = formatObj[key]
-    // Note: getDay() returns 0 on Sunday
-    if (key === 'a') {
-      return ['日', '一', '二', '三', '四', '五', '六'][value]
-    }
-    if (result.length > 0 && value < 10) {
-      value = '0' + value
-    }
-    return value || 0
-  })
-  return time_str
+	if (arguments.length === 0 || !time) {
+		return null
+	}
+	const format = pattern || '{y}-{m}-{d} {h}:{i}:{s}'
+	let date
+	if (typeof time === 'object') {
+		date = time
+	} else {
+		if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) {
+			time = parseInt(time)
+		} else if (typeof time === 'string') {
+			time = time.replace(new RegExp(/-/gm), '/');
+		}
+		if ((typeof time === 'number') && (time.toString().length === 10)) {
+			time = time * 1000
+		}
+		date = new Date(time)
+	}
+	const formatObj = {
+		y: date.getFullYear(),
+		m: date.getMonth() + 1,
+		d: date.getDate(),
+		h: date.getHours(),
+		i: date.getMinutes(),
+		s: date.getSeconds(),
+		a: date.getDay()
+	}
+	const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
+		let value = formatObj[key]
+		// Note: getDay() returns 0 on Sunday
+		if (key === 'a') {
+			return ['日', '一', '二', '三', '四', '五', '六'][value]
+		}
+		if (result.length > 0 && value < 10) {
+			value = '0' + value
+		}
+		return value || 0
+	})
+	return time_str
 }
 
 
@@ -49,72 +49,109 @@ export function parseTime(time, pattern) {
  * @returns {Number}
  */
 export function floatAdd(a, b) {
-    var c, d, e;
-    if(undefined==a||null==a||""==a||isNaN(a)){a=0;}
-    if(undefined==b||null==b||""==b||isNaN(b)){b=0;}
-    try {
-        c = a.toString().split(".")[1].length;
-    } catch (f) {
-        c = 0;
-    }
-    try {
-        d = b.toString().split(".")[1].length;
-    } catch (f) {
-        d = 0;
-    }
-    e = Math.pow(10, Math.max(c, d));
-    return  (floatMul(a, e) + floatMul(b, e)) / e;
+	var c, d, e;
+	if (undefined == a || null == a || "" == a || isNaN(a)) {
+		a = 0;
+	}
+	if (undefined == b || null == b || "" == b || isNaN(b)) {
+		b = 0;
+	}
+	try {
+		c = a.toString().split(".")[1].length;
+	} catch (f) {
+		c = 0;
+	}
+	try {
+		d = b.toString().split(".")[1].length;
+	} catch (f) {
+		d = 0;
+	}
+	e = Math.pow(10, Math.max(c, d));
+	return (floatMul(a, e) + floatMul(b, e)) / e;
 }
 
 //除法去除精度损失
 export function accDiv(arg1, arg2) {
-  if(!arg1 || !arg2){
-    if(arg2 == 0){
-      return Infinity
-    }
-    return arg1/arg2
-  }
-	var t1 = 0, t2 = 0, r1, r2;
-	try { t1 = arg1.toString().split(".")[1].length } catch (e) { }
-	try { t2 = arg2.toString().split(".")[1].length } catch (e) { }
-  r1 = Number(arg1.toString().replace(".", ""));
-  r2 = Number(arg2.toString().replace(".", ""));
-  if(r2==0){
-    return Infinity;
-  }else{
-    return (r1 / r2) * Math.pow(10, t2 - t1);
+	if (!arg1 || !arg2) {
+		if (arg2 == 0) {
+			return Infinity
+		}
+		return arg1 / arg2
+	}
+	var t1 = 0,
+		t2 = 0,
+		r1, r2;
+	try {
+		t1 = arg1.toString().split(".")[1].length
+	} catch (e) {}
+	try {
+		t2 = arg2.toString().split(".")[1].length
+	} catch (e) {}
+	r1 = Number(arg1.toString().replace(".", ""));
+	r2 = Number(arg2.toString().replace(".", ""));
+	if (r2 == 0) {
+		return Infinity;
+	} else {
+		return (r1 / r2) * Math.pow(10, t2 - t1);
 	}
 }
 
 export function numberFormat(number, decimals = 2, dec_point = '.', thousands_sep = ',') {
-  /*
-    * 参数说明:
-    * number:要格式化的数字
-    * decimals:保留几位小数
-    * dec_point:小数点符号
-    * thousands_sep:千分位符号
-    * */
-   number = accDiv(number,100)
-   number = (number + '').replace(/[^0-9+-Ee.]/g, '');
-   var n = !isFinite(+number) ? 0 : +number,
-	   prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
-	   sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
-	   dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
-	   s = '',
-	   toFixedFix = function (n, prec) {
+	/*
+	 * 参数说明:
+	 * number:要格式化的数字
+	 * decimals:保留几位小数
+	 * dec_point:小数点符号
+	 * thousands_sep:千分位符号
+	 * */
+	number = accDiv(number, 100)
+	number = (number + '').replace(/[^0-9+-Ee.]/g, '');
+	var n = !isFinite(+number) ? 0 : +number,
+		prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
+		sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
+		dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
+		s = '',
+		toFixedFix = function(n, prec) {
 
-		   var k = Math.pow(10, prec);
-		   return '' + Math.round(n * k) / k;
-	   };
-   s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
-   var re = /(-?\d+)(\d{3})/;
-   while (re.test(s[0])) {
-	   s[0] = s[0].replace(re, "$1" + sep + "$2");
-   }
-   if ((s[1] || '').length < prec) {
-	   s[1] = s[1] || '';
-	   s[1] += new Array(prec - s[1].length + 1).join('0');
-   }
+			var k = Math.pow(10, prec);
+			return '' + Math.round(n * k) / k;
+		};
+	s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
+	var re = /(-?\d+)(\d{3})/;
+	while (re.test(s[0])) {
+		s[0] = s[0].replace(re, "$1" + sep + "$2");
+	}
+	if ((s[1] || '').length < prec) {
+		s[1] = s[1] || '';
+		s[1] += new Array(prec - s[1].length + 1).join('0');
+	}
+
+	return s.join(dec);
+}
 
-   return s.join(dec);
-}
+/**
+ * 处理富文本里的图片宽度自适应
+ * 1.去掉img标签里的style、width、height属性
+ * 2.img标签添加style属性:max-width:100%;height:auto
+ * 3.修改所有style里的width属性为max-width:100%
+ * 4.去掉<br/>标签
+ * @param html
+ * @returns {void|string|*}
+ */
+export function formatRichText(html) { //控制小程序中图片大小
+	let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
+		match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
+		match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
+		match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
+		return match;
+	});
+	newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
+		match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi,
+			'max-width:100%;');
+		return match;
+	});
+	newContent = newContent.replace(/<br[^>]*\/>/gi, '');
+	newContent = newContent.replace(/\<img/gi,
+		'<img style="max-width:100%;height:auto;font-size: 0;margin-top: -5px;"');
+	return newContent;
+}