cp-pay.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <template>
  2. <view class="pages-box">
  3. <view class="topup-listbtn-box">
  4. <view class="topup-listbtn-items" v-for="(item,index) in resultList" :key="index">
  5. <view :class="selected == item.id ? 'select_class' :'' " @click="select_items(item.id,item.price)">
  6. <view class="">{{item.title}}</view>
  7. <view class="" style="margin-top: 10rpx;">({{item.desc}})</view>
  8. <view class="" style="margin-top: 10rpx;">
  9. ¥<span style="font-size: 36rpx;font-weight: bold;">{{item.price}}</span>
  10. </view>
  11. <view class="" style="margin-top: 10rpx;"><span style="text-decoration:line-through;">¥{{item.original_price}}</span></view>
  12. </view>
  13. </view>
  14. </view>
  15. <view class="zf-fs-box">
  16. <text>支付方式:</text>
  17. <text>微信</text>
  18. </view>
  19. <view class="pages-btn" hover-class="hover-btn" @click="submitReview">确认协议并支付¥{{pay_text}}</view>
  20. <view class="checkbox-view">
  21. <checkbox-group @change="bindChange">
  22. <label class="checkbox">
  23. <checkbox value="1" :checked="checked"/>
  24. <text>开通前请阅读</text>
  25. </label>
  26. </checkbox-group>
  27. <text class="lable-text" @click="openPrivacyContract">《服务协议》</text>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. export default {
  33. data() {
  34. return {
  35. selected: 1,
  36. pay_text: '',
  37. sel_info: null,
  38. checked: true,
  39. tempFilePaths: '',
  40. resultList: [],
  41. order_id: ''
  42. }
  43. },
  44. created() {
  45. },
  46. onLoad(option) {
  47. this.tempFilePaths = option.tempFilePaths;
  48. this.getPrice();
  49. },
  50. methods: {
  51. select_items(n,t){
  52. this.selected = n;
  53. this.pay_text = t;
  54. },
  55. getPrice(){
  56. let that = this;
  57. that.$request.getPrice({}).then( res =>{
  58. console.log(res)
  59. if(res.code == 0){
  60. let resultList = res.data.result;
  61. let selected = that.selected;
  62. resultList.forEach( ele =>{
  63. if(ele.id == selected){
  64. that.pay_text = ele.price;
  65. that.sel_info = ele;
  66. }
  67. })
  68. that.resultList = resultList;
  69. }else{
  70. uni.showToast({
  71. title: res.message,
  72. icon: "none",
  73. })
  74. }
  75. }).catch( e =>{
  76. console.log(e)
  77. })
  78. },
  79. submitReview(){
  80. let that = this;
  81. let tempFilePaths = JSON.parse(that.tempFilePaths).tempFilePath;
  82. console.log(tempFilePaths)
  83. wx.uploadFile({
  84. url: 'https://ocr.lfwhzb.com/api/review',
  85. filePath: tempFilePaths,
  86. name: 'file',
  87. header: {
  88. token: uni.getStorageSync('token')
  89. },
  90. formData: { pay_id: that.selected },
  91. success(res) {
  92. let data = JSON.parse(res.data);
  93. if(data.code == 0){
  94. that.order_id = data.data.order_id;
  95. that.reviewPay(data.data.order_id);
  96. }else{
  97. uni.showToast({
  98. title: data.message,
  99. icon:"none"
  100. })
  101. }
  102. },
  103. fail(err) {
  104. console.log('上传失败:', err);
  105. }
  106. });
  107. // that.$request.submitReview({
  108. // file: that.file,
  109. // pay_id: that.selected,
  110. // }).then( res =>{
  111. // console.log(res)
  112. // if(res.code == 0){
  113. // that.order_id = res.data.order_id;
  114. // that.reviewPay(res.data.order_id);
  115. // }else{
  116. // uni.showToast({
  117. // title: res.message,
  118. // icon: "none",
  119. // })
  120. // }
  121. // }).catch( e =>{
  122. // console.log(e)
  123. // })
  124. },
  125. // 支付
  126. reviewPay(o){
  127. let that = this;
  128. that.$request.reviewPay({
  129. order_id: o,
  130. }).then( res =>{
  131. console.log(res)
  132. if(res.code == 0){
  133. let data = res.data;
  134. uni.requestPayment({
  135. "appId": data.appId, // 微信开放平台 - 应用 - AppId,注意和微信小程序、公众号 AppId 可能不一致
  136. "nonceStr": data.nonceStr, // 随机字符串
  137. "package": data.package, // 固定值
  138. "timeStamp": data.timeStamp, // 时间戳(单位:秒)
  139. "signType": data.signType, //签名类型
  140. "paySign": data.paySign ,// 签名,这里用的 MD5/RSA 签名
  141. success(res) {
  142. uni.showToast({
  143. title: '支付成功',
  144. icon: 'success'
  145. })
  146. setTimeout(() =>{
  147. uni.navigateTo({
  148. url:'../user/cp-cg'
  149. })
  150. },1000)
  151. },
  152. fail(e) {
  153. console.log(e)
  154. uni.showToast({
  155. title: '支付报错',
  156. icon: 'none'
  157. })
  158. }
  159. })
  160. }else{
  161. uni.showToast({
  162. title: res.message,
  163. icon: "none",
  164. })
  165. }
  166. }).catch( e =>{
  167. console.log(e)
  168. uni.showToast({
  169. title: e,
  170. icon: 'none'
  171. })
  172. })
  173. }
  174. }
  175. }
  176. </script>
  177. <style scoped>
  178. .pages-box{
  179. padding: 40rpx;
  180. box-sizing: border-box;
  181. }
  182. .topup-listbtn-box{
  183. padding: 10rpx 20rpx;
  184. box-sizing: border-box;
  185. display: flex;
  186. flex-wrap: wrap;
  187. align-items: center;
  188. }
  189. .topup-listbtn-box>view.topup-listbtn-items{
  190. width: 50%;
  191. padding: 15rpx;
  192. font-size: 28rpx;
  193. box-sizing: border-box;
  194. }
  195. .topup-listbtn-items>view{
  196. text-align: center;
  197. height: auto;
  198. border-radius: 8px;
  199. font-size: 28rpx;
  200. padding: 20rpx 0;
  201. box-shadow: 0 0 20rpx 2rpx #00000020;
  202. }
  203. .topup-listbtn-items>.select_class{
  204. background: #95bf7f;
  205. color: #fff;
  206. }
  207. .zf-fs-box{
  208. width: 462rpx;
  209. margin: 0 auto;
  210. margin-top: 160rpx;
  211. padding: 20rpx 30rpx 10rpx 0;
  212. box-sizing: border-box;
  213. display: flex;
  214. align-items: center;
  215. justify-content: space-between;
  216. }
  217. .pages-btn{
  218. width: 480rpx;
  219. height: 74rpx;
  220. line-height: 74rpx;
  221. text-align: center;
  222. background: #95bf7f;
  223. color: #fff;
  224. border-radius: 20px;
  225. margin: 10rpx auto;
  226. box-shadow: 0 0 20rpx 2rpx #00000020;
  227. }
  228. .hover-btn{
  229. opacity: 0.8;
  230. }
  231. .checkbox-view{
  232. width: 480rpx;
  233. margin: 0 auto;
  234. margin-top: 20rpx;
  235. font-size: 30rpx;
  236. color: #333;
  237. display: flex;
  238. align-items: center;
  239. }
  240. .checkbox{
  241. display: flex;
  242. align-items: center;
  243. }
  244. .lable-text{
  245. color: blue;
  246. }
  247. .checkbox checkbox{
  248. transform: scale(0.7);
  249. }
  250. </style>