pay-popup.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <template>
  2. <view>
  3. <u-popup :show="payShow" mode="bottom" round="17" @close="close" :closeable="true" overlayOpacity="0.5"
  4. @touchmove.prevent.stop>
  5. <view class="choiceShow-wrap">
  6. <!-- 盲票信息 -->
  7. <view class="flex goods">
  8. <view class="flex image-wrap">
  9. <image :src="payInfo.picUrl" mode="aspectFit"></image>
  10. </view>
  11. <view class="info">
  12. <view class="info-title">{{ payInfo.title }}</view>
  13. <view class="info-stock">¥{{ $numberFormat( payInfo.orderAmt ) }}</view>
  14. </view>
  15. </view>
  16. <!-- 推广员信息 -->
  17. <view class="flex coupon" @click="toPromoters" v-if="promoterNum > 0">
  18. <view class="flex coupon-left">
  19. <image src="../../static/public/promoter.png" mode="scaleToFill"></image>
  20. <view class="txt">盲票天使</view>
  21. </view>
  22. <view class="coupon-right flex">
  23. <view class="txt coupon-right-color" v-if="promoters && promoters.name">
  24. {{`${ promoters.name } ( ${promoters.workNo} ) `}}
  25. </view>
  26. <view class="txt" v-else>选择盲票天使,运气更好哦</view>
  27. <image src="../../static/public/public_right_arrow.png" mode="scaleToFill"></image>
  28. </view>
  29. </view>
  30. <!-- 优惠券信息 -->
  31. <view class="flex coupon" @click="toCoupon">
  32. <view class="flex coupon-left">
  33. <image src="../../static/public/public_coupon.png" mode="scaleToFill"></image>
  34. <view class="txt">优惠券</view>
  35. </view>
  36. <view class="coupon-right flex">
  37. <view class="txt coupon-right-color" v-if="$numberFormat(payInfo.discountAmt) != 0">
  38. -¥{{ $numberFormat(payInfo.discountAmt)}}</view>
  39. <view class="txt" v-else-if="total != 0">{{ total }}张可用</view>
  40. <view class="txt" v-else>暂无可用优惠券</view>
  41. <image src="../../static/public/public_right_arrow.png" mode="scaleToFill"></image>
  42. </view>
  43. </view>
  44. <view class="flex agreement">
  45. <view class="checked">
  46. <u-checkbox-group>
  47. <u-checkbox :value="checked" :checked="checked" shape="circle" activeColor="#F9822C"
  48. @change="changeChecked"></u-checkbox>
  49. </u-checkbox-group>
  50. </view>
  51. <view class="txt" @click="toRule">同意《商品购买协议》</text></view>
  52. </view>
  53. <view class="flex btn">
  54. <view class="flex btn-left">
  55. <view class="title">应付:</view>
  56. <view class="flex price">¥{{ $numberFormat(payInfo.payAmt) }}</view>
  57. </view>
  58. <view class="btn-right">
  59. <view class="confirm" @click="pay">立即支付</view>
  60. </view>
  61. </view>
  62. </view>
  63. </u-popup>
  64. <auth :auth-show="authShow" @close="authShow = false" />
  65. </view>
  66. </template>
  67. <script>
  68. import $http from '@/utils/request.js'
  69. import appId from '@/config/appId.js'
  70. import Auth from '../../components/auth/auth.vue'
  71. export default {
  72. name: "pay-popup",
  73. components: {
  74. Auth,
  75. },
  76. props: {
  77. payShow: {
  78. type: [Boolean],
  79. default: false
  80. },
  81. payInfo: {
  82. type: [Object],
  83. default: {}
  84. },
  85. },
  86. data() {
  87. return {
  88. checked: true,
  89. authShow: false,
  90. total: 0,
  91. promoters: {
  92. channelId: "", //id
  93. name: "", //名字
  94. workNo: "" //工号
  95. },
  96. promoterNum: 0, //推广员
  97. siteId: "", // 门店id
  98. };
  99. },
  100. created() {
  101. if (this.payInfo.promoter) {
  102. this.promoters = this.payInfo.promoter
  103. }
  104. this.getTotal()
  105. if (this.payInfo.channelId) {
  106. this.getPromoterNum()
  107. }
  108. },
  109. mounted() {
  110. let that = this
  111. uni.$on('promoters', function(data) {
  112. that.promoters = data
  113. that.payInfo.promoter = data
  114. })
  115. },
  116. methods: {
  117. getTotal() {
  118. $http.post(`/api/v1/mp/user/ticket/order/coupon/listPage`, {}).then(
  119. res => {
  120. if (res.code == 0) {
  121. this.total = res.total
  122. }
  123. }).catch(() => {})
  124. },
  125. getPromoterNum() {
  126. $http.post(`/api/v1/mp/channel/promoter/list?pageNum=1&pageSize=20`, {
  127. channelId: this.payInfo.channelId,
  128. }).then(res => {
  129. if (res.code == 0) {
  130. this.promoterNum = res.total
  131. }
  132. }).catch(() => {})
  133. },
  134. changeChecked(e) {
  135. this.checked = e
  136. },
  137. toPromoters() {
  138. let index = ''
  139. if (this.payInfo.promoter) {
  140. index = this.payInfo.promoter.channelId
  141. } else {
  142. index = 0
  143. }
  144. uni.navigateTo({
  145. url: `/packageGoods/promoters/index?channelId=${ this.payInfo.channelId }&index=${ index }`
  146. })
  147. },
  148. toCoupon() {
  149. if(this.payInfo && this.payInfo.siteId){
  150. uni.navigateTo({
  151. url: `/packageGoods/coupon/index?channelId=${ this.payInfo.channelId }&couponId=${ this.payInfo.couponId }&boxId=${ this.payInfo.boxId }&ticketId=${ this.payInfo.ticketId }&siteId=${ this.payInfo.siteId }`
  152. })
  153. }else{
  154. uni.navigateTo({
  155. url: `/packageGoods/coupon/index?channelId=${ this.payInfo.channelId }&couponId=${ this.payInfo.couponId }&boxId=${ this.payInfo.boxId }&ticketId=${ this.payInfo.ticketId }`
  156. })
  157. }
  158. },
  159. toRule() {
  160. uni.navigateTo({
  161. url: '/packageOther/rule/purchase'
  162. })
  163. },
  164. close() {
  165. this.$emit('close')
  166. },
  167. success(id) {
  168. this.$emit('success', id)
  169. },
  170. pay() {
  171. let _this = this
  172. let payIng = false
  173. if (!this.checked) {
  174. uni.$u.toast('请同意《盲票产品规则》');
  175. return
  176. }
  177. uni.showLoading({
  178. title: '支付中'
  179. });
  180. if (payIng) return
  181. let suid = uni.getStorageSync('shareUid')
  182. $http.post('/api/v1/mp/user/ticket/order/submit', {
  183. promoterId: this.promoters && this.promoters.channelId ? this.promoters.channelId : null,
  184. suid: suid !== 'undefined' && suid !== undefined ? suid : null,
  185. type: uni.getStorageSync('shareType')
  186. }).then(res => {
  187. uni.hideLoading();
  188. payIng = true
  189. if (res.code == 0) {
  190. if (res.data.needPay == 1) {
  191. // #ifdef MP-ALIPAY
  192. let data = {
  193. orderId: res.data.orderId,
  194. payType: 1,
  195. appSource: appId
  196. }
  197. // #endif
  198. // #ifdef MP-WEIXIN
  199. let data = {
  200. orderId: res.data.orderId,
  201. payType: 2,
  202. appSource: appId
  203. }
  204. // #endif
  205. // #ifdef H5
  206. let data = {
  207. orderId: res.data.orderId,
  208. payType: 3,
  209. appSource: appId
  210. }
  211. // #endif
  212. $http.post('/api/v1/mp/user/ticket/order/pay', data).then(ele => {
  213. if (ele.code == 0) {
  214. // #ifdef MP-ALIPAY
  215. my.tradePay({
  216. tradeNO: ele.data.pay_info,
  217. success: (resu) => {
  218. if (resu.resultCode == '9000') {
  219. uni.showToast({
  220. title: '支付成功',
  221. icon: 'success',
  222. duration: 2000
  223. })
  224. _this.success(res.data.orderId) //跳转抽奖详情页
  225. } else {
  226. payIng = false
  227. _this.close()
  228. }
  229. },
  230. fail: (resu) => {
  231. payIng = false
  232. _this.close()
  233. }
  234. })
  235. // #endif
  236. // #ifdef MP-WEIXIN
  237. uni.requestPayment({
  238. timeStamp: ele.data.timeStamp,
  239. nonceStr: ele.data.nonceStr,
  240. package: ele.data.package,
  241. signType: ele.data.signType,
  242. paySign: ele.data.paySign,
  243. success() {
  244. uni.showToast({
  245. title: '支付成功',
  246. icon: 'success',
  247. duration: 2000
  248. })
  249. _this.success(res.data.orderId)
  250. },
  251. fail() {
  252. payIng = false
  253. _this.close()
  254. }
  255. })
  256. // #endif
  257. // #ifdef H5
  258. let data = ele.data
  259. _this.close()
  260. sessionStorage.setItem('viewUrlData', JSON.stringify(data))
  261. uni.navigateTo({
  262. url: `/pages/index/payExternal?orderId=${ res.data.orderId }`
  263. })
  264. // uni.navigateTo({
  265. // url: `/pages/index/payExternal?viewUrl=${ encodeURIComponent(JSON.stringify(data)) }&orderId=${ res.data.orderId }`
  266. // })
  267. // #endif
  268. } else if (ele.code == 1005) {
  269. _this.authShow = true
  270. } else if (ele.code == 1026) {
  271. _this.authShow = true
  272. } else {
  273. payIng = false
  274. _this.close()
  275. uni.$u.toast('支付失败');
  276. }
  277. }).catch(() => {
  278. payIng = false
  279. _this.close()
  280. uni.$u.toast('支付异常');
  281. })
  282. } else {
  283. uni.showToast({
  284. title: '支付成功',
  285. icon: 'success',
  286. duration: 2000
  287. })
  288. _this.success(res.data.orderId)
  289. }
  290. } else if (res.code == 1020) {
  291. payIng = false
  292. _this.close()
  293. uni.$u.toast(res.msg);
  294. } else {
  295. payIng = false
  296. _this.close()
  297. uni.$u.toast(res.msg);
  298. }
  299. }).catch(() => {
  300. uni.hideLoading();
  301. payIng = false
  302. uni.$u.toast('订单创建失败');
  303. })
  304. },
  305. },
  306. }
  307. </script>
  308. <style lang="scss" scoped>
  309. .coupon-right-color {
  310. font-size: 32rpx;
  311. line-height: 44rpx;
  312. color: rgba(235, 112, 9, 100);
  313. }
  314. </style>
  315. <style lang="scss" scoped>
  316. .choiceShow-wrap {
  317. min-height: 400rpx;
  318. padding: 34rpx;
  319. // 盲票信息
  320. .goods {
  321. justify-content: flex-start;
  322. margin-bottom: 60rpx;
  323. .image-wrap {
  324. width: 220rpx;
  325. height: 220rpx;
  326. border-radius: 10rpx;
  327. overflow: hidden;
  328. image {
  329. width: 100%;
  330. height: 100%;
  331. }
  332. }
  333. .info {
  334. flex: 1;
  335. display: flex;
  336. height: 220rpx;
  337. flex-direction: column;
  338. justify-content: space-around;
  339. padding-left: 34rpx;
  340. &-title {
  341. font-size: 36rpx;
  342. line-height: 36rpx;
  343. font-weight: bold;
  344. }
  345. &-stock {
  346. font-size: 26rpx;
  347. color: #FF4208;
  348. }
  349. }
  350. }
  351. // 优惠券
  352. .coupon {
  353. justify-content: space-between;
  354. height: 40rpx;
  355. margin-bottom: 46rpx;
  356. &-left {
  357. image {
  358. width: 48rpx;
  359. height: 40rpx;
  360. margin-right: 18rpx;
  361. }
  362. .txt {
  363. font-size: 30rpx;
  364. font-weight: bold;
  365. }
  366. }
  367. &-right {
  368. height: 40rpx;
  369. image {
  370. width: 12rpx;
  371. height: 22rpx;
  372. margin-left: 14rpx;
  373. }
  374. .txt {
  375. line-height: 26rpx;
  376. font-size: 26rpx;
  377. color: #666666;
  378. }
  379. }
  380. }
  381. // 同意协议
  382. .agreement {
  383. justify-content: flex-start;
  384. margin-bottom: 56rpx;
  385. .txt {
  386. font-size: 26rpx;
  387. color: #666666;
  388. }
  389. }
  390. // 支付按钮
  391. .btn {
  392. justify-content: space-between;
  393. &-left {
  394. .title {
  395. font-size: 13px;
  396. font-weight: 500;
  397. }
  398. .price {
  399. font-size: 30rpx;
  400. font-weight: bold;
  401. color: #FF4208;
  402. }
  403. }
  404. &-right {
  405. .confirm {
  406. width: 414rpx;
  407. height: 88rpx;
  408. line-height: 88rpx;
  409. background: #FA822C;
  410. border-radius: 44rpx;
  411. font-size: 36rpx;
  412. color: #fff;
  413. text-align: center;
  414. }
  415. }
  416. }
  417. }
  418. </style>