payment.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <template>
  2. <uni-popup ref="popup" type="bottom" :mask-click="false">
  3. <view class="pay">
  4. <view class="pay_close" @click="$refs.popup.close()">
  5. <image src="https://www.chaomangdao.com/image/home/guanbi@2x.png" mode=""></image>
  6. </view>
  7. <view class="pay_head">支付</view>
  8. <view class="pay_shop flexs">
  9. <view class="pay_shop_img">
  10. <view class="pay_shop_img_top">
  11. <view class="pay_shop_img_left">
  12. <image :src="boxMessage.image" mode="aspectFill"></image>
  13. </view>
  14. <view class="pay_shop_img_right">
  15. <image :src="item" mode="aspectFill" v-for="(item,index) in boxMessage.right" :key="index"></image>
  16. </view>
  17. </view>
  18. <view class="pay_shop_img_bot">
  19. <image :src="item" mode="aspectFill" v-for="(item,index) in boxMessage.bot" :key="index"></image>
  20. </view>
  21. </view>
  22. <view class="pay_shop_main">
  23. <view class="pay_shop_name">{{ boxMessage.box_name }}</view>
  24. <view class="pay_shop_price flex">
  25. <view class="pay_shop_price_l">{{ boxMessage.coin_amount }}金币</view>
  26. <view class="pay_shop_price_btn center" v-if="boxMessage.coin_not_enough">金额不足</view>
  27. </view>
  28. </view>
  29. </view>
  30. <view class="pay_attention">{{ boxMessage.notice }}</view>
  31. <view class="pay_contant flexs">
  32. <image @click="isConsent = !isConsent" :src="isConsent ? '/static/image/publice/xuanzhong1@2x.png' : '/static/image/publice/weixuanzhong1@2x.png' " mode=""></image>
  33. <text @click="goBuyer">我已阅读并同意《喵喵开盒买家须知》</text>
  34. </view>
  35. <view class="pay_ul flex">
  36. <button class="pay_gold" @click="goldPay" v-if="!boxMessage.coin_not_enough" hover-class="hover-view" :disabled="!payFlag">金币支付</button>
  37. <button v-else class="pay_ul_btn" @click="recharge()" hover-class="hover-view">立即充值</button>
  38. <!--button class="pay_ul_btn" @click="patternIndex(index)" hover-class="hover-view" v-for="(item,index) in 2" :key="index">{{ index == 0 ? '微信支付'+ boxMessage.rmb_amount +'金币' : '支付宝支付'+ boxMessage.rmb_amount +'金币' }}</button-->
  39. <button class="pay_ul_btn" @click="balance()" hover-class="hover-view">余额支付</button>
  40. <!-- <button class="pay_ul_btn" @click="cashPay()" hover-class="hover-view">现金支付</button> -->
  41. </view>
  42. </view>
  43. </uni-popup>
  44. </template>
  45. <script>
  46. export default {
  47. name:"payment",
  48. props:{
  49. //盒子id
  50. boxId: Number,
  51. //支付页面
  52. payPage: String
  53. },
  54. data() {
  55. return {
  56. isConsent: true,//是否同意
  57. boxMessage: {} ,//盒子详情
  58. payFlag: true, //支付锁 防止重复点击
  59. payUrls: {}//支付链接
  60. };
  61. },
  62. methods: {
  63. /**
  64. * 打开页面
  65. *
  66. * @param {Object} type 开盒类型 1:试玩 其他:正式开盒
  67. * @param {Object} num 数量 1 5 9
  68. */
  69. open (type, num){
  70. this.isConsent = true
  71. this.$api[type == 1 ? 'haveATry' : 'createOrder']({
  72. box_id: this.boxId,
  73. num: num,
  74. msg: type == 1 ? '试玩' : '创建订单中',
  75. }).then( ({code, data}) => {
  76. if (code === 1) {
  77. //创建订单成功
  78. if (type != 1) {
  79. //缓存订单id
  80. uni.setStorageSync('order_id', data.order_id)
  81. //正式开盒
  82. this.$emit("create-success")
  83. data.right = []
  84. data.bot = []
  85. data.image = data.images[0]
  86. data.images.forEach((item,index)=>{
  87. if (index > 0 && index < 3) {
  88. data.right.push(item)
  89. }
  90. if (index > 2) {
  91. data.bot.push(item)
  92. }
  93. })
  94. this.boxMessage = data
  95. //支付链接
  96. this.payUrls.alipay = data.alipay
  97. this.payUrls.wechat = data.wechat
  98. this.$refs.popup.open()
  99. } else {
  100. //返回结果
  101. this.$emit("show-result", data)
  102. }
  103. }
  104. })
  105. },
  106. //买家须知
  107. goBuyer () {
  108. uni.navigateTo({url:'/pagesA/pages/buyer'})
  109. },
  110. //金币支付
  111. goldPay () {
  112. if (!this.isConsent) return uni.showToast({title:'请阅读并勾选买家须知',icon:'none'})
  113. if (!this.payFlag) return
  114. this.payFlag = false
  115. //访问后台支付
  116. this.$api.coinPay({order_id: this.boxMessage.order_id}).then(({code, data}) => {
  117. //解除支付锁
  118. this.payFlag = true
  119. if (code === 1) {
  120. //关闭弹窗
  121. this.$refs.popup.close()
  122. //返回结果
  123. this.$emit("show-result", data.prize)
  124. }
  125. })
  126. },
  127. //余额支付
  128. balance () {
  129. if (!this.isConsent) return uni.showToast({title:'请阅读并勾选买家须知',icon:'none'})
  130. if (!this.payFlag) return
  131. this.payFlag = false
  132. //访问后台支付
  133. this.$api.cmoneyPay({order_id: this.boxMessage.order_id}).then(({code, data}) => {
  134. //解除支付锁
  135. this.payFlag = true
  136. if (code === 1) {
  137. //关闭弹窗
  138. this.$refs.popup.close()
  139. //返回结果
  140. this.$emit("show-result", data.prize)
  141. }
  142. })
  143. },
  144. //去充值
  145. recharge () {
  146. if (!this.isConsent) return uni.showToast({title:'请阅读并勾选买家须知',icon:'none'})
  147. uni.navigateTo({url:'/pages/me/recharge'})
  148. },
  149. //现金支付
  150. cashPay(){
  151. if (!this.isConsent) return uni.showToast({title:'请阅读并勾选买家须知',icon:'none'})
  152. if (!this.payFlag) return
  153. this.payFlag = false
  154. uni.navigateTo({
  155. url:`/pages/tabbar/cashPay/cashPay?alipay=${this.payUrls.alipay}&wechat=${this.payUrls.wechat}&payPage=${this.payPage}`,
  156. complete: () => {
  157. this.payFlag = true
  158. }
  159. })
  160. }
  161. }
  162. }
  163. </script>
  164. <style lang="scss">
  165. .pay {
  166. background: #FFFFFF;
  167. border-radius: 20rpx 20rpx 0rpx 0rpx;
  168. padding: 0 50rpx 32rpx 50rpx;
  169. position: relative;
  170. .pay_close {
  171. top: 30rpx;
  172. right: 30rpx;
  173. width: 44rpx;
  174. height: 44rpx;
  175. position: absolute;
  176. }
  177. .pay_head {
  178. text-align: center;
  179. font-size: 30rpx;
  180. font-weight: bold;
  181. padding: 40rpx 0 50rpx 0;
  182. }
  183. .pay_shop {
  184. margin-bottom: 40rpx;
  185. .pay_shop_main {
  186. display: flex;
  187. flex: 1;
  188. height: 200rpx;
  189. flex-direction: column;
  190. justify-content: space-around;
  191. }
  192. .pay_shop_img {
  193. width: 200rpx;
  194. height: 200rpx;
  195. padding: 12rpx;
  196. .pay_shop_img_top {
  197. display: flex;
  198. margin-bottom: 12rpx;
  199. .pay_shop_img_left {
  200. image {
  201. width: 114rpx;
  202. height: 114rpx;
  203. border-radius: 6rpx;
  204. }
  205. margin-right: 12rpx;
  206. }
  207. .pay_shop_img_right {
  208. image {
  209. width: 51rpx;
  210. height: 51rpx;
  211. &:first-child {
  212. margin-bottom: 12rpx;
  213. }
  214. border-radius: 6rpx;
  215. }
  216. }
  217. }
  218. .pay_shop_img_bot {
  219. display: flex;
  220. justify-content: flex-end;
  221. image {
  222. width: 51rpx;
  223. height: 51rpx;
  224. margin-left: 12rpx;
  225. &:first-child {
  226. margin-left: 0;
  227. }
  228. border-radius: 6rpx;
  229. }
  230. }
  231. margin-right: 30rpx;
  232. }
  233. .pay_shop_name {
  234. font-size: 28rpx;
  235. }
  236. .pay_shop_price_l {
  237. color: #CF271B;
  238. font-size: 30rpx;
  239. }
  240. .pay_shop_price_btn {
  241. width: 183rpx;
  242. height: 50rpx;
  243. color: #FA7E48;
  244. font-size: 30rpx;
  245. font-weight: bold;
  246. background: rgba(246, 175, 50, 0.5);
  247. border-radius: 25rpx;
  248. }
  249. }
  250. .pay_attention {
  251. color: #666666;
  252. }
  253. .pay_contant {
  254. margin: 24rpx 0 59rpx 0;
  255. image {
  256. width: 32rpx;
  257. height: 32rpx;
  258. margin-right: 10rpx;
  259. }
  260. text {
  261. font-size: 26rpx;
  262. }
  263. }
  264. .pay_gold {
  265. width: 310rpx;
  266. height: 78rpx;
  267. font-size: 26rpx;
  268. background: -webkit-linear-gradient(60deg, #ffc8de 0%, #ff67a4 100%);
  269. border-radius: 39rpx;
  270. }
  271. .pay_ul_btn {
  272. width: 310rpx;
  273. height: 78rpx;
  274. font-size: 26rpx;
  275. background: -webkit-linear-gradient(60deg, #ffc8de 0%, #ff67a4 100%);
  276. border-radius: 39rpx;
  277. &:last-child {
  278. background: -webkit-linear-gradient(0deg, #89f7fe 0%, #66a6ff 100%);
  279. }
  280. }
  281. }
  282. </style>