payVid.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <template>
  2. <view class="pagecon">
  3. <view class="conwarp">
  4. <view class="gdHead dffs">
  5. <view class="head flex1">{{ goodInfo.title }}</view>
  6. <text v-for="(item, index) in goodInfo.tags.split('|')" class="desc">{{ item }}</text>
  7. </view>
  8. <view class="subtit textgrey fontssm">{{ goodInfo.desc }}</view>
  9. </view>
  10. <view v-if="!hidePay" class="conwarp">
  11. <view class="gdHead"><view class="head textgrey">选择支付方式</view></view>
  12. <view class="monBox">
  13. <view @click="selHandle(1)" class="payInfo bb dfsb">
  14. <image class="payicon" src="/static/img/pro/paywx.png" mode=""></image>
  15. <view class="flex1"><text class="blank fontmid">微信支付</text></view>
  16. <image class="payselicon" :src="pay_type == 1 ? '/static/img/pro/chenggong.png' : '/static/img/pro/wxz.png'" mode=""></image>
  17. </view>
  18. <view @click="selHandle(2)" class="payInfo bb dfsb">
  19. <image class="payicon" src="/static/img/pro/payxd.png" mode=""></image>
  20. <view class="dffd flex1">
  21. <text class="blank fontmid">学豆支付</text>
  22. <view class="textgrey fontssm">
  23. 剩余学豆:
  24. <text class="prosecond fontssm">{{ userInfo.userInfo.bean || 0 }}</text>
  25. </view>
  26. </view>
  27. <image class="payselicon" :src="pay_type == 2 ? '/static/img/pro/chenggong.png' : '/static/img/pro/wxz.png'" mode=""></image>
  28. </view>
  29. <!-- <view class="payInfo bb dfsb">
  30. <image class="payicon" src="/static/img/pro/payyh.png" mode=""></image>
  31. <view class="dffd flex1">
  32. <text class="blank fontmid">使用优惠券 -{{ coupon.reduce || 0 }}</text>
  33. <view @click.stop="nextTo" class="textgrey fontssm dffs">
  34. 查看当前可使用的优惠券
  35. <u-icon name="arrow-down" color="#999" size="14"></u-icon>
  36. </view>
  37. </view>
  38. </view> -->
  39. </view>
  40. </view>
  41. <view class="fixBox dffs">
  42. <view class="fontbase">应付:</view>
  43. <text class=" prosecond">{{ ordInfo.order_amount }} </text>
  44. <text class="fontsm flex1"> 会员折扣{{ userInfo.userInfo.jing_discount || 0 }}折</text>
  45. <view @click="creatOrd()" class="clickbtn fontmid"> 确定购买 </view>
  46. </view>
  47. <pay-password-keyboard :showPass="payShow" @close="payShow = false" @getPass="balancePay"></pay-password-keyboard>
  48. </view>
  49. </template>
  50. <script>
  51. import videoList from '@/pages/index/components/wordlist.vue';
  52. import payPasswordKeyboard from '@/components/pay-password-keyboard/pay-password-keyboard.vue';
  53. import { mapState } from 'vuex';
  54. export default {
  55. components: {
  56. videoList,
  57. payPasswordKeyboard
  58. },
  59. data() {
  60. return {
  61. hidePay: false, //如果选择下载并且 价格为0 隐藏支付方式
  62. id: '',
  63. goodInfo: { tags: '' },
  64. // pay_type: 1, //2微信 1 学豆
  65. pay_type: 1, //1=微信 2=学豆
  66. payShow: false, //支付密码
  67. coupon: { reduce: 0 },
  68. ordInfo:'',
  69. ordId: ''
  70. };
  71. },
  72. computed: {
  73. ...mapState({ userInfo: state => state.userInfo })
  74. },
  75. async onLoad(opt) {
  76. this.goodInfo = JSON.parse(opt.item);
  77. console.log(this.goodInfo);
  78. await this.$store.dispatch('getUserInfo');
  79. await this.getInfo();
  80. },
  81. methods: {
  82. selHandle(val) {
  83. console.log(val);
  84. if (val == 2 && this.userInfo.userInfo.level_time == 0) {
  85. this.$api.toast('请先开通会员');
  86. setTimeout(res => {
  87. uni.navigateTo({
  88. url: '/pages/user/mine/member'
  89. });
  90. }, 600);
  91. } else {
  92. this.pay_type = val;
  93. this.getInfo();
  94. }
  95. },
  96. /**
  97. * 请求数据只是为了代码不那么乱
  98. * 分次请求未作整合
  99. */
  100. async getInfo() {
  101. let url = 'video_order/outInfo';
  102. this.$api
  103. .request(url, {
  104. video_id: this.goodInfo.id,
  105. pay_type: this.pay_type,
  106. })
  107. .then(res => {
  108. if (res.code == '200') {
  109. this.ordInfo = res.data;
  110. }
  111. });
  112. },
  113. // 选择优惠券
  114. nextTo() {
  115. if (this.pay_type == 1) return this.$api.toast('余额支付不能使用优惠券');
  116. uni.navigateTo({
  117. url: '/pages/user/coupon/myCoup?money=' + this.money
  118. });
  119. },
  120. // 学豆支付
  121. balancePay(val) {
  122. this.payShow = false;
  123. console.log(val);
  124. this.$api
  125. .request('user/checkMd', {
  126. pay_pass: val
  127. })
  128. .then(data => {
  129. if (data.code == 200) {
  130. this.emitHandle();
  131. } else {
  132. this.$api.toast(data.msg);
  133. }
  134. });
  135. },
  136. // 点击支付
  137. creatOrd() {
  138. // return;
  139. let url = 'video_order/create';
  140. if ( this.ordInfo.order_amount <= 0) {
  141. this.pay_type = 3;
  142. }
  143. this.$api
  144. .request(url, {
  145. video_id: this.goodInfo.id,
  146. coupon_id: this.coupon.id || '',
  147. pay_type: this.pay_type
  148. })
  149. .then(data => {
  150. if (data.code == 200) {
  151. this.ordId = data.data;
  152. if (this.pay_type == 1) {
  153. this.emitHandle();
  154. } else if (this.pay_type == 2) {
  155. this.payShow = true;
  156. } else {
  157. this.emitHandle();
  158. }
  159. } else {
  160. this.$api.toast(data.msg);
  161. }
  162. });
  163. },
  164. // 点击支付
  165. emitHandle() {
  166. // return;
  167. let url = 'payment/videoPay';
  168. this.$api
  169. .request(url, {
  170. order_id: this.ordId || '',
  171. pay_type: this.pay_type
  172. })
  173. .then(data => {
  174. if (this.pay_type != 1) {
  175. this.$api.toast(data.msg);
  176. if (data.code == 200) {
  177. setTimeout(res => {
  178. uni.navigateTo({
  179. url: '/pages/user/mine/buy'
  180. });
  181. }, 600);
  182. }
  183. } else {
  184. if (data.code && data.code != 200) {
  185. this.$api.toast(data.msg || '获取支付信息失败');
  186. return;
  187. }
  188. console.log(data);
  189. const orderInfo = data;
  190. const { timeStamp, nonceStr, paySign } = orderInfo;
  191. const payParams = {
  192. provider: 'wxpay',
  193. orderInfo: data,
  194. timeStamp,
  195. nonceStr,
  196. package: orderInfo.package,
  197. signType: 'MD5',
  198. paySign,
  199. success: e => {
  200. this.$api.toast('支付成功');
  201. setTimeout(res => {
  202. uni.navigateTo({
  203. url: '/pages/user/mine/buy'
  204. });
  205. }, 600);
  206. },
  207. fail: err => {
  208. if (err.errMsg.indexOf('取消') > -1 || err.errMsg.indexOf('cancel') > 1 || err.errMsg.indexOf('-2') > -1) {
  209. this.$api.toast('取消支付');
  210. } else {
  211. this.$api.toast('支付遇到错误,请稍候重试');
  212. console.log(err);
  213. }
  214. }
  215. };
  216. uni.requestPayment(payParams);
  217. }
  218. });
  219. }
  220. }
  221. };
  222. </script>
  223. <style lang="scss" scoped>
  224. .pagecon {
  225. padding-bottom: 100rpx;
  226. .conwarp {
  227. background-color: #fff;
  228. padding: 26rpx 30rpx 39rpx;
  229. border-radius: 16rpx;
  230. margin-bottom: 20rpx;
  231. .gdHead {
  232. line-height: 58rpx;
  233. margin-bottom: 16rpx;
  234. .head {
  235. font-size: 34rpx;
  236. font-family: PingFangSC-Medium, PingFang SC;
  237. font-weight: 600;
  238. color: #333333;
  239. line-height: 48rpx;
  240. }
  241. .desc {
  242. background: #f89638;
  243. border-radius: 5rpx;
  244. font-size: 18rpx;
  245. height: 32rpx;
  246. line-height: 32rpx;
  247. padding: 0rpx 8rpx;
  248. display: inline-block;
  249. color: #fff;
  250. margin-left: 10rpx;
  251. &:nth-of-type(2) {
  252. background: #7fc06e;
  253. }
  254. &:nth-of-type(3) {
  255. background: #75b2c4;
  256. }
  257. &:nth-of-type(4) {
  258. background: #8875c0;
  259. }
  260. }
  261. }
  262. }
  263. .monBox {
  264. margin-top: 20rpx;
  265. background-color: #fff;
  266. .payInfo {
  267. padding: 35rpx 0;
  268. .payicon {
  269. width: 68rpx;
  270. height: 68rpx;
  271. }
  272. .flex1 {
  273. margin: 0 15rpx;
  274. }
  275. .fontmid {
  276. flex: 1;
  277. }
  278. .payselicon {
  279. width: 32rpx;
  280. height: 32rpx;
  281. }
  282. }
  283. }
  284. .fixBox {
  285. justify-content: flex-end;
  286. font-size: 32rpx;
  287. padding: 0 30rpx;
  288. .prosecond {
  289. // text-align: right;
  290. // flex: 1;
  291. text {
  292. font-size: 28rpx;
  293. color: $prosecond;
  294. }
  295. font-size: 42rpx;
  296. font-family: DIN-Regular, DIN;
  297. font-weight: 400;
  298. }
  299. .clickbtn {
  300. margin: 0 0 0 20rpx;
  301. width: 214rpx;
  302. height: 80rpx;
  303. line-height: 80rpx;
  304. background: #ed742f;
  305. border-radius: 40rpx;
  306. }
  307. }
  308. }
  309. </style>