pay-popup.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  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. };
  98. },
  99. created() {
  100. if (this.payInfo.promoter) {
  101. this.promoters = this.payInfo.promoter
  102. }
  103. this.getTotal()
  104. if (this.payInfo.channelId) {
  105. this.getPromoterNum()
  106. }
  107. },
  108. mounted() {
  109. let that = this
  110. uni.$on('promoters', function(data) {
  111. that.promoters = data
  112. that.payInfo.promoter = data
  113. })
  114. },
  115. methods: {
  116. getTotal() {
  117. $http.post(`/api/v1/mp/user/ticket/order/coupon/listPage`, {}).then(
  118. res => {
  119. if (res.code == 0) {
  120. this.total = res.total
  121. }
  122. }).catch(() => {})
  123. },
  124. getPromoterNum() {
  125. $http.post(`/api/v1/mp/channel/promoter/list?pageNum=1&pageSize=20`, {
  126. channelId: this.payInfo.channelId,
  127. }).then(res => {
  128. if (res.code == 0) {
  129. this.promoterNum = res.total
  130. }
  131. }).catch(() => {})
  132. },
  133. changeChecked(e) {
  134. this.checked = e
  135. },
  136. toPromoters() {
  137. let index = ''
  138. if (this.payInfo.promoter) {
  139. index = this.payInfo.promoter.channelId
  140. } else {
  141. index = 0
  142. }
  143. uni.navigateTo({
  144. url: `/packageGoods/promoters/index?channelId=${ this.payInfo.channelId }&index=${ index }`
  145. })
  146. },
  147. toCoupon() {
  148. uni.navigateTo({
  149. url: `/packageGoods/coupon/index?channelId=${ this.payInfo.channelId }&couponId=${ this.payInfo.couponId }&boxId=${ this.payInfo.boxId }&ticketId=${ this.payInfo.ticketId }`
  150. })
  151. },
  152. toRule() {
  153. uni.navigateTo({
  154. url: '/packageOther/rule/purchase'
  155. })
  156. },
  157. close() {
  158. this.$emit('close')
  159. },
  160. success(id) {
  161. this.$emit('success', id)
  162. },
  163. pay() {
  164. let _this = this
  165. let payIng = false
  166. if (!this.checked) {
  167. uni.$u.toast('请同意《盲票产品规则》');
  168. return
  169. }
  170. uni.showLoading({
  171. title: '支付中'
  172. });
  173. if (payIng) return
  174. let suid = uni.getStorageSync('shareUid')
  175. $http.post('/api/v1/mp/user/ticket/order/submit', {
  176. promoterId: this.promoters && this.promoters.channelId ? this.promoters.channelId : null,
  177. suid: suid !== 'undefined' && suid !== undefined ? suid : null,
  178. type: uni.getStorageSync('shareType')
  179. }).then(res => {
  180. uni.hideLoading();
  181. payIng = true
  182. if (res.code == 0) {
  183. if (res.data.needPay == 1) {
  184. // #ifdef MP-ALIPAY
  185. let data = {
  186. orderId: res.data.orderId,
  187. payType: 1,
  188. appSource: appId
  189. }
  190. // #endif
  191. // #ifdef MP-WEIXIN
  192. let data = {
  193. orderId: res.data.orderId,
  194. payType: 2,
  195. appSource: appId
  196. }
  197. // #endif
  198. // #ifdef H5
  199. let data = {
  200. orderId: res.data.orderId,
  201. payType: 3,
  202. appSource: appId
  203. }
  204. // #endif
  205. $http.post('/api/v1/mp/user/ticket/order/pay', data).then(ele => {
  206. if (ele.code == 0) {
  207. // #ifdef MP-ALIPAY
  208. my.tradePay({
  209. tradeNO: ele.data.pay_info,
  210. success: (resu) => {
  211. if (resu.resultCode == '9000') {
  212. uni.showToast({
  213. title: '支付成功',
  214. icon: 'success',
  215. duration: 2000
  216. })
  217. _this.success(res.data.orderId) //跳转抽奖详情页
  218. } else {
  219. payIng = false
  220. _this.close()
  221. }
  222. },
  223. fail: (resu) => {
  224. payIng = false
  225. _this.close()
  226. }
  227. })
  228. // #endif
  229. // #ifdef MP-WEIXIN
  230. uni.requestPayment({
  231. timeStamp: ele.data.timeStamp,
  232. nonceStr: ele.data.nonceStr,
  233. package: ele.data.package,
  234. signType: ele.data.signType,
  235. paySign: ele.data.paySign,
  236. success() {
  237. uni.showToast({
  238. title: '支付成功',
  239. icon: 'success',
  240. duration: 2000
  241. })
  242. _this.success(res.data.orderId)
  243. },
  244. fail() {
  245. payIng = false
  246. _this.close()
  247. }
  248. })
  249. // #endif
  250. // #ifdef H5
  251. // localStorage.removeItem('callbackHTML');
  252. // localStorage.setItem('callbackHTML',ele.data.payUrl);
  253. let data = ele.data
  254. uni.navigateTo({
  255. url: `/pages/index/payExternal?viewUrl=${ encodeURIComponent(JSON.stringify(data)) }`
  256. })
  257. // let formData = new FormData()
  258. // Object.keys(ele.data).forEach(key => {
  259. // formData.append(key,ele.data[key])
  260. // })
  261. // uni.request({
  262. // url: 'https://openapi.ysepay.com/gateway.do',
  263. // header: {
  264. // 'Content-Type': 'application/x-www-form-urlencoded',
  265. // },
  266. // data: ele.data,
  267. // method: 'GET',
  268. // success: (_res) => {
  269. // console.log(_res);
  270. // },
  271. // fail: (err) => {
  272. // console.log(err);
  273. // }
  274. // })
  275. // #endif
  276. } else if (ele.code == 1005) {
  277. _this.authShow = true
  278. } else if (ele.code == 1026) {
  279. _this.authShow = true
  280. } else {
  281. payIng = false
  282. _this.close()
  283. uni.$u.toast('支付失败');
  284. }
  285. }).catch(() => {
  286. payIng = false
  287. _this.close()
  288. uni.$u.toast('支付异常');
  289. })
  290. } else {
  291. uni.showToast({
  292. title: '支付成功',
  293. icon: 'success',
  294. duration: 2000
  295. })
  296. _this.success(res.data.orderId)
  297. }
  298. } else if (res.code == 1020) {
  299. payIng = false
  300. _this.close()
  301. uni.$u.toast(res.msg);
  302. } else {
  303. payIng = false
  304. _this.close()
  305. uni.$u.toast(res.msg);
  306. }
  307. }).catch(() => {
  308. uni.hideLoading();
  309. payIng = false
  310. uni.$u.toast('订单创建失败');
  311. })
  312. },
  313. },
  314. }
  315. </script>
  316. <style lang="scss" scoped>
  317. .coupon-right-color {
  318. font-size: 32rpx;
  319. line-height: 44rpx;
  320. color: rgba(235, 112, 9, 100);
  321. }
  322. </style>
  323. <style lang="scss" scoped>
  324. .choiceShow-wrap {
  325. min-height: 400rpx;
  326. padding: 34rpx;
  327. // 盲票信息
  328. .goods {
  329. justify-content: flex-start;
  330. margin-bottom: 60rpx;
  331. .image-wrap {
  332. width: 220rpx;
  333. height: 220rpx;
  334. border-radius: 10rpx;
  335. overflow: hidden;
  336. image {
  337. width: 100%;
  338. height: 100%;
  339. }
  340. }
  341. .info {
  342. flex: 1;
  343. display: flex;
  344. height: 220rpx;
  345. flex-direction: column;
  346. justify-content: space-around;
  347. padding-left: 34rpx;
  348. &-title {
  349. font-size: 36rpx;
  350. line-height: 36rpx;
  351. font-weight: bold;
  352. }
  353. &-stock {
  354. font-size: 26rpx;
  355. color: #FF4208;
  356. }
  357. }
  358. }
  359. // 优惠券
  360. .coupon {
  361. justify-content: space-between;
  362. height: 40rpx;
  363. margin-bottom: 46rpx;
  364. &-left {
  365. image {
  366. width: 48rpx;
  367. height: 40rpx;
  368. margin-right: 18rpx;
  369. }
  370. .txt {
  371. font-size: 30rpx;
  372. font-weight: bold;
  373. }
  374. }
  375. &-right {
  376. height: 40rpx;
  377. image {
  378. width: 12rpx;
  379. height: 22rpx;
  380. margin-left: 14rpx;
  381. }
  382. .txt {
  383. line-height: 26rpx;
  384. font-size: 26rpx;
  385. color: #666666;
  386. }
  387. }
  388. }
  389. // 同意协议
  390. .agreement {
  391. justify-content: flex-start;
  392. margin-bottom: 56rpx;
  393. .txt {
  394. font-size: 26rpx;
  395. color: #666666;
  396. }
  397. }
  398. // 支付按钮
  399. .btn {
  400. justify-content: space-between;
  401. &-left {
  402. .title {
  403. font-size: 13px;
  404. font-weight: 500;
  405. }
  406. .price {
  407. font-size: 30rpx;
  408. font-weight: bold;
  409. color: #FF4208;
  410. }
  411. }
  412. &-right {
  413. .confirm {
  414. width: 414rpx;
  415. height: 88rpx;
  416. line-height: 88rpx;
  417. background: #FA822C;
  418. border-radius: 44rpx;
  419. font-size: 36rpx;
  420. color: #fff;
  421. text-align: center;
  422. }
  423. }
  424. }
  425. }
  426. </style>