pay.vue 8.4 KB

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