order.vue 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941
  1. <template>
  2. <view class="ezy-order-page">
  3. <view class="icon-title-navBar-box">
  4. <view @click="goBack" class="nav-bar-icon"></view>
  5. <text class="nav-bar-title">我的订单</text>
  6. </view>
  7. <view class="ezy-tab-border">
  8. <uni-segmented-control :current="dingdanData.current" :values="dingdanData.items" active-color="#3A7FE9"
  9. @clickItem="onChangeTab" class="ezy-tab-box" />
  10. <view>
  11. <view v-if="dingdanData.current == 0">
  12. <scroll-view scroll-y="true" refresher-enabled="true" @scrolltolower="onScrolltolower"
  13. :refresher-triggered="dingdanData.quanbu.loading" :refresher-threshold="50"
  14. refresher-background="transparent" @refresherrefresh="onRefresh" class="order-scroll-view">
  15. <!--数学-->
  16. <uni-list>
  17. <uni-list-item v-for="(item,index) in dingdanData.quanbu.list" :key="index"
  18. class="order-list-item">
  19. <template v-slot:body>
  20. <view class="order-item-head">
  21. <view class="order-name-box">
  22. <icon></icon><text>鹅状元自营</text>
  23. </view>
  24. <view>
  25. <text>不支持退订</text>
  26. <text v-if="item.status ==2" class="pay-status">已付款</text>
  27. <text v-if="item.status ==3" class="pay-status">已关闭</text>
  28. <text v-if="item.status ==1" class="pay-status">待付款</text>
  29. </view>
  30. </view>
  31. <view class="order-content-box" @click="goDao(item2,index2)"
  32. v-for="(item2,index2) in item.cardList" :key="index2">
  33. <!-- 需要改成从接口获取的 wgy-->
  34. <img class="content-img" :src="item2.cover">
  35. <view class="content-body-box">
  36. <view class="content-name">{{item2.cardName}}</view>
  37. <view class="content-text">{{item2.intro}}</view>
  38. <!-- 未付款数据对一下 是否有课程包明细 wgy-->
  39. <view class="content-money-box">
  40. <view class="order-kcb-btn" v-if="item2.type ==1"
  41. @click.stop="detailBtn(item2,index2)">课程包明细<icon></icon>
  42. </view>
  43. <text class="content-yuanjia">¥{{item.money}}</text>
  44. </view>
  45. </view>
  46. </view>
  47. <view class="content-heji" v-if="item.cardList.length>1">合计:¥{{item.money}}</view>
  48. <view v-if="item.status !=2" class="order-bottom-box">
  49. <view class="pay-status-box"
  50. v-if="payType =='weixin'&&currentPlatform =='android'"
  51. @click="switchPayWay">
  52. <icon class="wx-icon"></icon>微信
  53. </view>
  54. <view class="pay-status-box"
  55. v-if="payType =='zhifubao'&&currentPlatform =='android'"
  56. @click="switchPayWay">
  57. <icon class="zfb-icon"></icon>支付宝
  58. </view>
  59. <view class="pay-status-box apple-status-box" v-if="currentPlatform =='ios'">
  60. <icon class="apple-icon"></icon>
  61. </view>
  62. <view v-if="currentPlatform =='android'" class="pay-btn"
  63. @touchstart="creatOrder(item.cardList,index)">立即支付
  64. </view>
  65. <view v-if="currentPlatform =='ios'" class="pay-btn"
  66. @touchstart="creatOrderIos(item.cardList,index,item.id)">立即支付
  67. </view>
  68. </view>
  69. </template>
  70. </uni-list-item>
  71. <uni-load-more :status="dingdanData.quanbu.state" @click="getMore(0)"
  72. :contentText="dingdanData.quanbu.contentText">
  73. </uni-load-more>
  74. </uni-list>
  75. </scroll-view>
  76. </view>
  77. <view v-if="dingdanData.current == 1">
  78. <scroll-view scroll-y="true" refresher-enabled="true" @scrolltolower="onScrolltolower"
  79. :refresher-triggered="dingdanData.daiFukuan.loading" :refresher-threshold="50"
  80. refresher-background="transparent" @refresherrefresh="onRefresh" class="order-scroll-view">
  81. <!--数学-->
  82. <uni-list>
  83. <uni-list-item v-for="(item,index) in dingdanData.daiFukuan.list" :key="index"
  84. class="order-list-item">
  85. <template v-slot:body>
  86. <view class="order-item-head">
  87. <view class="order-name-box">
  88. <icon></icon><text>鹅状元自营</text>
  89. </view>
  90. <view>
  91. <text>不支持退订</text>
  92. <text v-if="item.status ==2" class="pay-status">已付款</text>
  93. <text v-if="item.status ==3" class="pay-status">已关闭</text>
  94. <text v-if="item.status ==1" class="pay-status">待付款</text>
  95. </view>
  96. </view>
  97. <view class="order-content-box" v-for="(item2,index2) in item.cardList"
  98. :key="index2">
  99. <!-- 需要改成从接口获取的 wgy-->
  100. <img class="content-img" :src="item2.cover">
  101. <view class="content-body-box">
  102. <view class="content-name">{{item2.cardName}}</view>
  103. <view class="content-text">{{item2.intro}}</view>
  104. <!-- 未付款数据对一下 是否有课程包明细 wgy-->
  105. <view class="content-money-box">
  106. <view class="order-kcb-btn" v-if="item2.type ==1"
  107. @click="detailBtn(item2,index2)">课程包明细<icon></icon>
  108. </view>
  109. <text class="content-yuanjia">¥{{item.money}}</text>
  110. </view>
  111. </view>
  112. </view>
  113. <view class="content-heji" v-if="item.cardList.length>1">合计:¥{{item.money}}</view>
  114. <view v-if="item.status !=2" class="order-bottom-box">
  115. <view class="pay-status-box"
  116. v-if="payType =='weixin'&&currentPlatform =='android'"
  117. @click="switchPayWay">
  118. <icon class="wx-icon"></icon>微信
  119. </view>
  120. <view class="pay-status-box"
  121. v-if="payType =='zhifubao'&&currentPlatform =='android'"
  122. @click="switchPayWay">
  123. <icon class="zfb-icon"></icon>支付宝
  124. </view>
  125. <view class="pay-status-box apple-status-box" v-if="currentPlatform =='ios'">
  126. <icon class="apple-icon"></icon>
  127. </view>
  128. <view v-if="currentPlatform =='android'" class="pay-btn"
  129. @touchstart="creatOrder(item.cardList,index)">立即支付
  130. </view>
  131. <view v-if="currentPlatform =='ios'" class="pay-btn"
  132. @touchstart="creatOrderIos(item.cardList,index,item.id)">立即支付
  133. </view>
  134. </view>
  135. </template>
  136. </uni-list-item>
  137. <uni-load-more :status="dingdanData.daiFukuan.state" @click="getMore(1)"
  138. :contentText="dingdanData.daiFukuan.contentText">
  139. </uni-load-more>
  140. </uni-list>
  141. </scroll-view>
  142. </view>
  143. <view v-if="dingdanData.current == 2">
  144. <scroll-view scroll-y="true" refresher-enabled="true" @scrolltolower="onScrolltolower"
  145. :refresher-triggered="dingdanData.yiFukuan.loading" :refresher-threshold="50"
  146. refresher-background="transparent" @refresherrefresh="onRefresh" class="order-scroll-view">
  147. <!--数学-->
  148. <uni-list>
  149. <uni-list-item v-for="(item,index) in dingdanData.yiFukuan.list" :key="index"
  150. class="order-list-item">
  151. <template v-slot:body>
  152. <view class="order-item-head">
  153. <view class="order-name-box">
  154. <icon></icon><text>鹅状元自营</text>
  155. </view>
  156. <view>
  157. <text>不支持退订</text>
  158. <text v-if="item.status ==2" class="pay-status">已付款</text>
  159. <text v-if="item.status ==3" class="pay-status">已关闭</text>
  160. <text v-if="item.status ==1" class="pay-status">待付款</text>
  161. </view>
  162. </view>
  163. <view class="order-content-box" @click="goDao(item2,index2)"
  164. v-for="(item2,index2) in item.cardList" :key="index2">
  165. <!-- 需要改成从接口获取的 wgy-->
  166. <img class="content-img" :src="item2.cover">
  167. <view class="content-body-box">
  168. <view class="content-name">{{item2.cardName}}</view>
  169. <view class="content-text">{{item2.intro}}</view>
  170. <!-- 未付款数据对一下 是否有课程包明细 wgy-->
  171. <view class="content-money-box">
  172. <view class="order-kcb-btn" v-if="item2.type ==1"
  173. @click="detailBtn(item2,index2)">课程包明细<icon></icon>
  174. </view>
  175. <text class="content-yuanjia">¥{{item.money}}</text>
  176. </view>
  177. </view>
  178. </view>
  179. <view class="content-heji" v-if="item.cardList.length>1">合计:¥{{item.money}}</view>
  180. <view v-if="item.status !=2" class="order-bottom-box">
  181. <view class="pay-status-box"
  182. v-if="payType =='weixin'&&currentPlatform =='android'"
  183. @click="switchPayWay">
  184. <icon class="wx-icon"></icon>微信
  185. </view>
  186. <view class="pay-status-box"
  187. v-if="payType =='zhifubao'&&currentPlatform =='android'"
  188. @click="switchPayWay">
  189. <icon class="zfb-icon"></icon>支付宝
  190. </view>
  191. <view class="pay-status-box apple-status-box" v-if="currentPlatform =='ios'">
  192. <icon class="apple-icon"></icon>
  193. </view>
  194. <view v-if="currentPlatform =='android'" class="pay-btn"
  195. @touchstart="creatOrder(item.cardList,index)">立即支付
  196. </view>
  197. <view v-if="currentPlatform =='ios'" class="pay-btn"
  198. @touchstart="creatOrderIos(item.cardList,index,item.id)">立即支付
  199. </view>
  200. </view>
  201. </template>
  202. </uni-list-item>
  203. <uni-load-more :status="dingdanData.yiFukuan.state" @click="getMore(2)"
  204. :contentText="dingdanData.yiFukuan.contentText">
  205. </uni-load-more>
  206. </uni-list>
  207. </scroll-view>
  208. </view>
  209. </view>
  210. </view>
  211. <product-dialog ref="mallProductPopup"></product-dialog>
  212. <CustomTabBar></CustomTabBar>
  213. </view>
  214. </template>
  215. <script setup>
  216. import {
  217. reactive,
  218. ref
  219. } from "vue";
  220. import {
  221. orderAdd,
  222. orderPayAli,
  223. orderPayWx,
  224. orderPayApple,
  225. getOrderList,
  226. orderInfo,
  227. orderCheck
  228. } from "@/api/order.js"
  229. import {
  230. onLoad
  231. } from "@dcloudio/uni-app";
  232. import {
  233. toast,
  234. debounce,
  235. getUserIdentity
  236. } from "@/utils/common";
  237. import cacheManager from '@/utils/cacheManager.js';
  238. import CustomTabBar from '@/components/custom-tabbar/custom-tabbar.vue';
  239. import payComponents from '@/components/payComponents/index.vue';
  240. import productDialog from './productDialog.vue'
  241. const mallProductPopup = ref(null);
  242. const payComponentsRef = ref(null);
  243. const showPayWay = ref(true)
  244. let currentPlatform = ref('android')
  245. const payType = ref('weixin');
  246. let orderId = ref('');
  247. let productId = ref(null)
  248. let iapChannel = ref(null)
  249. let quantity = ref(1)
  250. let channel = ref('')
  251. let appleFlag = ref('')
  252. function switchPayWay() {
  253. payType.value = payType.value == 'weixin' ? 'zhifubao' : 'weixin'
  254. }
  255. function detailBtn(data, index) {
  256. mallProductPopup.value.detailShow(data.levelList);
  257. }
  258. const dingdanData = reactive({
  259. items: ['全部', '待付款', '已付款'],
  260. current: 0,
  261. quanbu: {
  262. page: 0,
  263. list: [],
  264. loading: false,
  265. state: 'more',
  266. contentText: {
  267. contentdown: '查看更多',
  268. contentrefresh: '加载中',
  269. contentnomore: '没有更多'
  270. }
  271. },
  272. daiFukuan: {
  273. page: 0,
  274. list: [],
  275. loading: false,
  276. state: 'more',
  277. contentText: {
  278. contentdown: '查看更多',
  279. contentrefresh: '加载中',
  280. contentnomore: '没有更多'
  281. }
  282. },
  283. yiFukuan: {
  284. page: 0,
  285. list: [],
  286. loading: false,
  287. state: 'more',
  288. contentText: {
  289. contentdown: '查看更多',
  290. contentrefresh: '加载中',
  291. contentnomore: '没有更多'
  292. }
  293. },
  294. })
  295. function goDao(data, index) {
  296. console.log('data', data);
  297. console.log('index', index);
  298. if (data.type == 0 && data.levelList.length == 1) {
  299. cacheManager.updateObject('auth', {
  300. typeId: data.levelList[0].typeId,
  301. levelId: data.levelList[0].levelId,
  302. subjectId: data.levelList[0].subjectId,
  303. currentZhang: 0
  304. })
  305. cacheManager.remove('daoPageCache')
  306. uni.redirectTo({
  307. url: `/pages/study/index`
  308. })
  309. }
  310. }
  311. function genggaiVip(data) {
  312. uni.hideLoading();
  313. const localList = cacheManager.get('auth').levelIdList || []
  314. const mergeList = [...new Set([...localList, ...data.levelIdList])]
  315. cacheManager.updateObject('auth', {
  316. levelIdList: mergeList
  317. })
  318. toast("支付成功")
  319. dingdanData.current = 2
  320. getMore(2)
  321. // if (formPage.value == 'my') {
  322. // uni.redirectTo({
  323. // url: '/pages/my/index'
  324. // })
  325. // } else {
  326. // uni.redirectTo({
  327. // url: '/pages/study/index'
  328. // })
  329. // }
  330. }
  331. const creatOrderIos = debounce((data, index, orderId) => {
  332. console.log('data', data[0].cardId);
  333. console.log('index', index);
  334. console.log('orderId', orderId);
  335. return
  336. uni.showLoading({
  337. title: '',
  338. mask: true
  339. });
  340. const productMap = {
  341. 4: 'ezySxJstxL1', //计算特训 L1
  342. 6: 'ezySxTjmtL1', //图解母题 L1
  343. 7: 'ezySxJstxL2', //计算特训 L2
  344. 8: 'ezySxJstxL3', //计算特训 L3
  345. 9: 'ezySxJstxL4', //计算特训 L4
  346. 10: 'ezySxJstxL5', //计算特训 L5
  347. 11: 'ezySxJstxL6', //计算特训 L6
  348. 12: 'ezySxTjmtL2', //图解母题 L2
  349. 13: 'ezySxTjmtL3', //图解母题 L3
  350. 14: 'ezySxTjmtL4', //图解母题 L4
  351. 15: 'ezySxTjmtL5', //图解母题 L5
  352. 16: 'ezySxTjmtL6', //图解母题 L6
  353. 22: 'ezySxTjmtL1L6', //图解母题 L1-6
  354. 23: 'ezyYyZrpdL1', //自然拼读 L1
  355. 24: 'ezyYyZrpdL2', //自然拼读 L2
  356. 25: 'ezyYyZrpdL3', //自然拼读 L3
  357. 26: 'ezyYyZrpdL4', //自然拼读 L4
  358. 27: 'ezyYyZrpdL5', //自然拼读 L5
  359. 28: 'ezyYyZrpdL1L5', //自然拼读 L1-l5
  360. 29: ' ezySxJstxL1L6' //计算特训 L1-L6
  361. };
  362. const firstId = data.length > 0 ? data[0].cardId : null;
  363. if (firstId) {
  364. productId.value = productMap[firstId]
  365. console.log('productId.value', productId.value);
  366. } else {
  367. toast("无对应产品Id,请练习管理员")
  368. uni.hideLoading();
  369. return false
  370. }
  371. setTimeout(() => {
  372. uni.hideLoading();
  373. }, 1000)
  374. orderId.value = orderId
  375. if (!orderId.value) {
  376. toast(
  377. "无orderId!"
  378. )
  379. return false
  380. }
  381. // 测试ios 1元
  382. applePay()
  383. }, 500)
  384. function applePaySuccess(data) {
  385. uni.showLoading({
  386. title: '开通中',
  387. mask: true
  388. });
  389. let req = {
  390. "id": orderId.value,
  391. "paynum": data.transactionIdentifier,
  392. "receipt": data.transactionReceipt
  393. }
  394. console.log('reqreq', req);
  395. orderPayApple(req).then(res => {
  396. if (res.code == 0 && res.data) {
  397. iapChannel.finishTransaction(data.transactionIdentifier)
  398. console.log('resiapChanneliapChanneliapChannel', res);
  399. orderCheck({
  400. id: orderId.value
  401. }).then(res3 => {
  402. console.log('res3', res3);
  403. if (res3.code == 0 && res3.data.success) {
  404. genggaiVip(res3.data)
  405. } else {
  406. setTimeout(() => {
  407. orderCheck({
  408. id: orderId.value
  409. }).then(res4 => {
  410. if (res4.code == 0 && res4.data.success) {
  411. genggaiVip(res4.data)
  412. } else {
  413. toast(
  414. "开通失败,请联系管理员!"
  415. )
  416. uni
  417. .hideLoading();
  418. return false
  419. }
  420. }).catch(() => {
  421. uni.hideLoading();
  422. toast("check接口报错")
  423. return false
  424. })
  425. }, 5000)
  426. }
  427. }).catch(() => {
  428. uni.hideLoading();
  429. toast("check接口报错")
  430. return false
  431. })
  432. } else {
  433. iapChannel.finishTransaction(data.transactionIdentifier)
  434. uni.hideLoading();
  435. toast("苹果内购失败")
  436. console.log('orderPayApple失败');
  437. return false
  438. }
  439. })
  440. }
  441. function applePay() {
  442. console.log('123123');
  443. if (!productId.value) {
  444. uni.showToast({
  445. title: '苹果内购ID缺失,请选择其它支付方式或联系客服',
  446. icon: "none"
  447. });
  448. return false;
  449. }
  450. uni.showLoading({
  451. title: '正在支付中...'
  452. });
  453. try {
  454. plus.payment.getChannels(function(channels) { //判读项目支付通道开通情况
  455. for (var i in channels) {
  456. iapChannel = channels[i];
  457. // 获取 id 为 'appleiap' 的 channel
  458. console.info("支付通道", iapChannel)
  459. if (iapChannel.id === 'appleiap') { //开通了app应用内支付,在manifest.josn中设置,开通后需打自定议基座
  460. // ids 数组中的项为 App Store Connect 配置的内购买项目产品ID(productId)
  461. var ids = [productId.value];
  462. // iap 为应用内支付对象
  463. iapChannel.requestOrder(ids, function(e) {
  464. // 获取订单信息成功回调方法
  465. console.log('requestOrder success: ' + JSON.stringify(e));
  466. uni.requestPayment({
  467. provider: 'appleiap',
  468. orderInfo: {
  469. productid: productId.value, //产品id,来自于苹果
  470. quantity: quantity.value, //产品数量
  471. manualFinishTransaction: true
  472. },
  473. success: (e) => {
  474. uni.hideLoading();
  475. // toast("苹果内购成功")
  476. console.info("苹果内购成功", e)
  477. applePaySuccess(e)
  478. //e.payment.orderNo = that.orderNo
  479. //支付成功回调,前端调用后台接口
  480. },
  481. fail: (e) => {
  482. uni.hideLoading();
  483. toast("苹果内购失败")
  484. console.info("苹果内购失败", e)
  485. },
  486. })
  487. },
  488. function(e) {
  489. // 获取订单信息失败回调方法
  490. console.log('requestOrder failed: ' + JSON.stringify(e));
  491. });
  492. } else {
  493. console.log('不支持苹果支付')
  494. }
  495. }
  496. },
  497. function(e) {
  498. console.log("获取iap支付通道失败:" + e.message);
  499. });
  500. } catch (e) {
  501. uni.showModal({
  502. title: "init",
  503. content: e.message,
  504. showCancel: false
  505. });
  506. } finally {
  507. uni.hideLoading();
  508. }
  509. }
  510. function wxPay() {
  511. orderPayWx({
  512. id: orderId.value
  513. }).then(res2 => {
  514. uni.hideLoading();
  515. console.log('res2', res2);
  516. if (res2.code != 0) {
  517. return false
  518. }
  519. uni.requestPayment({
  520. "provider": "wxpay",
  521. "orderInfo": {
  522. "appid": res2.data.appid, // 应用ID(AppID)
  523. "partnerid": res2.data.partnerId, // 商户号(PartnerID)
  524. "prepayid": res2.data.prepayId, // 预支付交易会话ID
  525. "package": res2.data.packageVal, // 固定值
  526. "noncestr": res2.data.nonceStr, // 随机字符串
  527. "timestamp": res2.data.timestamp, // 时间戳(单位:秒)
  528. "sign": res2.data.sign // 签名,这里用的 MD5 签名
  529. }, //此处为服务器返回的订单信息字符串
  530. success: function(res) {
  531. //var rawdata = JSON.parse(res.rawdata);
  532. // console.log('res',res);
  533. // console.log('支付成功');
  534. // console.log('rawdata', rawdata);
  535. uni.showLoading({
  536. title: '开通中,请稍后...'
  537. });
  538. orderCheck({
  539. id: orderId.value
  540. }).then(res3 => {
  541. console.log('res3', res3);
  542. if (res3.code == 0 && res3.data.success) {
  543. genggaiVip(res3.data)
  544. } else {
  545. setTimeout(() => {
  546. orderCheck({
  547. id: orderId.value
  548. }).then(res4 => {
  549. if (res4.code == 0 && res4.data.success) {
  550. genggaiVip(res4.data)
  551. } else {
  552. toast(
  553. "开通失败,请联系管理员!"
  554. )
  555. uni
  556. .hideLoading();
  557. return false
  558. }
  559. }).catch(() => {
  560. uni.hideLoading();
  561. toast("check接口报错")
  562. return false
  563. })
  564. }, 5000)
  565. }
  566. }).catch(() => {
  567. uni.hideLoading();
  568. toast("check接口报错")
  569. return false
  570. })
  571. },
  572. fail: function(err) {
  573. uni.hideLoading();
  574. // toast('支付失败:' + JSON.stringify(err));
  575. console.log('支付失败:' + JSON.stringify(err));
  576. }
  577. });
  578. }).catch((error) => {
  579. uni.hideLoading();
  580. console.log(error);
  581. })
  582. }
  583. function aliApy() {
  584. orderPayAli({
  585. id: orderId.value
  586. }).then(res2 => {
  587. console.log('res2', res2);
  588. uni.hideLoading();
  589. if (res2.code != 0) {
  590. return false
  591. }
  592. uni.requestPayment({
  593. "provider": "alipay",
  594. "orderInfo": res2.data.text, //此处为服务器返回的订单信息字符串
  595. success: function(res) {
  596. // var rawdata = JSON.parse(res.rawdata);
  597. // console.log('支付成功');
  598. // console.log('rawdata', rawdata);
  599. uni.showLoading({
  600. title: '开通中,请稍后...'
  601. });
  602. orderCheck({
  603. id: orderId.value
  604. }).then(res3 => {
  605. if (res3.code == 0 && res3.data.success) {
  606. genggaiVip(res3.data)
  607. } else {
  608. setTimeout(() => {
  609. orderCheck({
  610. id: orderId.value
  611. }).then(res4 => {
  612. if (res4.code ==
  613. 0 && res4.data.success) {
  614. genggaiVip(res4.data)
  615. } else {
  616. toast(
  617. "开通失败,请联系管理员!"
  618. )
  619. uni
  620. .hideLoading();
  621. return false
  622. }
  623. }).catch(() => {
  624. uni.hideLoading();
  625. toast("check接口报错")
  626. return false
  627. })
  628. }, 5000)
  629. }
  630. }).catch(() => {
  631. uni.hideLoading();
  632. toast("check接口报错")
  633. return false
  634. })
  635. },
  636. fail: function(err) {
  637. console.log('支付失败:' + JSON.stringify(err));
  638. uni.hideLoading();
  639. }
  640. });
  641. })
  642. }
  643. const creatOrder = debounce((data, index) => {
  644. uni.showLoading({
  645. title: '',
  646. mask: true
  647. });
  648. if (payType.value == 'weixin') {
  649. orderId.value = data.id
  650. wxPay()
  651. } else {
  652. orderId.value = data.id
  653. aliApy()
  654. }
  655. }, 500)
  656. function onChangeTab(e) {
  657. if (dingdanData.current !== e.currentIndex) {
  658. dingdanData.current = e.currentIndex;
  659. if (dingdanData.current == 0) {
  660. dingdanData.quanbu.page = 0
  661. } else if (dingdanData.current == 1) {
  662. dingdanData.daiFukuan.page = 0
  663. } else if (dingdanData.current == 2) {
  664. dingdanData.yiFukuan.page = 0
  665. }
  666. refreshData(dingdanData.current);
  667. }
  668. }
  669. function onScrolltolower() {
  670. getMore(dingdanData.current)
  671. }
  672. function refreshData(code) {
  673. const opt = {
  674. page: 1,
  675. size: 10, // 固定查询10条
  676. status: code
  677. }
  678. if (code == 0) {
  679. dingdanData.quanbu.list = [];
  680. // 数学
  681. dingdanData.quanbu.state = 'loading';
  682. dingdanData.quanbu.page++;
  683. opt.page = dingdanData.quanbu.page;
  684. } else if (code == 1) {
  685. dingdanData.daiFukuan.list = [];
  686. // 英语
  687. dingdanData.daiFukuan.state = 'loading';
  688. dingdanData.daiFukuan.page++;
  689. opt.page = dingdanData.daiFukuan.page;
  690. } else if (code == 2) {
  691. dingdanData.yiFukuan.list = [];
  692. // 英语
  693. dingdanData.yiFukuan.state = 'loading';
  694. dingdanData.yiFukuan.page++;
  695. opt.page = dingdanData.yiFukuan.page;
  696. }
  697. getOrderList(opt).then(res => {
  698. if (code == 0) {
  699. dingdanData.quanbu.list = dingdanData.quanbu.list.concat(res.data.data);
  700. dingdanData.quanbu.loading = false;
  701. } else if (code == 1) {
  702. dingdanData.daiFukuan.list = dingdanData.daiFukuan.list.concat(res.data.data);
  703. dingdanData.daiFukuan.loading = false;
  704. } else if (code == 2) {
  705. dingdanData.yiFukuan.list = dingdanData.yiFukuan.list.concat(res.data.data);
  706. dingdanData.yiFukuan.loading = false;
  707. }
  708. if (code == 0) {
  709. if (res.data.total > dingdanData.quanbu.list.length) {
  710. // 数学
  711. dingdanData.quanbu.state = 'more';
  712. dingdanData.quanbu.loading = false;
  713. } else {
  714. // 数学
  715. dingdanData.quanbu.state = 'no-more';
  716. dingdanData.quanbu.loading = false;
  717. }
  718. } else if (code == 1) {
  719. if (res.data.total > dingdanData.daiFukuan.list.length) {
  720. // 英语
  721. dingdanData.daiFukuan.state = 'more';
  722. dingdanData.daiFukuan.loading = false;
  723. } else {
  724. // 英语
  725. dingdanData.daiFukuan.state = 'no-more';
  726. dingdanData.daiFukuan.loading = false;
  727. }
  728. } else if (code == 2) {
  729. if (res.data.total > dingdanData.yiFukuan.list.length) {
  730. // 英语
  731. dingdanData.yiFukuan.state = 'more';
  732. dingdanData.yiFukuan.loading = false;
  733. } else {
  734. // 英语
  735. dingdanData.yiFukuan.state = 'no-more';
  736. dingdanData.yiFukuan.loading = false;
  737. }
  738. }
  739. }).catch(err => {
  740. if (code == 0) {
  741. // 数学
  742. dingdanData.quanbu.state = 'more';
  743. dingdanData.quanbu.loading = false;
  744. } else if (code == 1) {
  745. // 英语
  746. dingdanData.daiFukuan.state = 'more';
  747. dingdanData.daiFukuan.loading = false;
  748. } else if (code == 2) {
  749. // 英语
  750. dingdanData.yiFukuan.state = 'more';
  751. dingdanData.yiFukuan.loading = false;
  752. }
  753. })
  754. }
  755. function onRefresh() {
  756. if (dingdanData.current == 0) {
  757. dingdanData.quanbu.page = 0;
  758. dingdanData.quanbu.list = [];
  759. dingdanData.quanbu.loading = true;
  760. } else if (dingdanData.current == 1) {
  761. dingdanData.daiFukuan.page = 0;
  762. dingdanData.daiFukuan.list = [];
  763. dingdanData.daiFukuan.loading = true;
  764. } else if (dingdanData.current == 2) {
  765. dingdanData.yiFukuan.page = 0;
  766. dingdanData.yiFukuan.list = [];
  767. dingdanData.yiFukuan.loading = true;
  768. }
  769. refreshData(dingdanData.current);
  770. }
  771. function getMore(code) {
  772. const opt = {
  773. page: 1,
  774. size: 10, // 固定查询10条
  775. status: Number(code) // 前台索引加1为学科cardId
  776. }
  777. if (code == 0) {
  778. if (dingdanData.quanbu.state == 'no-more') {
  779. return;
  780. }
  781. // 数学
  782. dingdanData.quanbu.state = 'loading';
  783. dingdanData.quanbu.page++;
  784. opt.page = dingdanData.quanbu.page;
  785. } else if (code == 1) {
  786. if (dingdanData.daiFukuan.state == 'no-more') {
  787. return;
  788. }
  789. dingdanData.daiFukuan.state = 'loading';
  790. dingdanData.daiFukuan.page++;
  791. opt.page = dingdanData.daiFukuan.page;
  792. } else if (code == 2) {
  793. if (dingdanData.yiFukuan.state == 'no-more') {
  794. return;
  795. }
  796. dingdanData.yiFukuan.state = 'loading';
  797. dingdanData.yiFukuan.page++;
  798. opt.page = dingdanData.yiFukuan.page;
  799. }
  800. getOrderList(opt).then(res => {
  801. if (code == 0) {
  802. dingdanData.quanbu.list = dingdanData.quanbu.list.concat(res.data.data);
  803. dingdanData.quanbu.loading = false;
  804. } else if (code == 1) {
  805. dingdanData.daiFukuan.list = dingdanData.daiFukuan.list.concat(res.data.data);
  806. dingdanData.daiFukuan.loading = false;
  807. } else if (code == 2) {
  808. dingdanData.yiFukuan.list = dingdanData.yiFukuan.list.concat(res.data.data);
  809. dingdanData.yiFukuan.loading = false;
  810. }
  811. if (code == 0) {
  812. if (res.data.total > dingdanData.quanbu.list.length) {
  813. // 数学
  814. dingdanData.quanbu.state = 'more';
  815. dingdanData.quanbu.state_text = '加载更多';
  816. dingdanData.quanbu.loading = false;
  817. } else {
  818. // 数学
  819. dingdanData.quanbu.state = 'no-more';
  820. dingdanData.quanbu.state_text = '没有更多啦';
  821. dingdanData.quanbu.loading = false;
  822. }
  823. } else if (code == 1) {
  824. if (res.data.total > dingdanData.daiFukuan.list.length) {
  825. // 英语
  826. dingdanData.daiFukuan.state = 'more';
  827. dingdanData.daiFukuan.state_text = '加载更多';
  828. dingdanData.daiFukuan.loading = false;
  829. } else {
  830. // 英语
  831. dingdanData.daiFukuan.state = 'no-more';
  832. dingdanData.daiFukuan.state_text = '没有更多啦';
  833. dingdanData.daiFukuan.loading = false;
  834. }
  835. } else if (code == 2) {
  836. if (res.data.total > dingdanData.yiFukuan.list.length) {
  837. // 英语
  838. dingdanData.yiFukuan.state = 'more';
  839. dingdanData.yiFukuan.state_text = '加载更多';
  840. dingdanData.yiFukuan.loading = false;
  841. } else {
  842. // 英语
  843. dingdanData.yiFukuan.state = 'no-more';
  844. dingdanData.yiFukuan.state_text = '没有更多啦';
  845. dingdanData.yiFukuan.loading = false;
  846. }
  847. }
  848. }).catch(err => {
  849. if (code == 0) {
  850. // 数学
  851. dingdanData.quanbu.state = 'more';
  852. dingdanData.quanbu.state_text = '加载更多';
  853. dingdanData.quanbu.loading = false;
  854. } else if (code == 1) {
  855. // 英语
  856. dingdanData.daiFukuan.state = 'more';
  857. dingdanData.daiFukuan.state_text = '加载更多';
  858. dingdanData.daiFukuan.loading = false;
  859. } else if (code == 2) {
  860. // 英语
  861. dingdanData.yiFukuan.state = 'more';
  862. dingdanData.yiFukuan.state_text = '加载更多';
  863. dingdanData.yiFukuan.loading = false;
  864. }
  865. })
  866. }
  867. function goBack() {
  868. uni.redirectTo({
  869. url: '/pages/my/index'
  870. })
  871. }
  872. const isIOSorAndroid = () => {
  873. const systemInfo = uni.getSystemInfoSync();
  874. console.log('systemInfo', systemInfo);
  875. if (systemInfo.platform == 'ios') {
  876. return currentPlatform.value = 'ios'
  877. } else {
  878. return currentPlatform.value = 'android'
  879. }
  880. }
  881. onLoad((options) => {
  882. dingdanData.current = Number(options.status) || dingdanData.current
  883. getMore(dingdanData.current);
  884. isIOSorAndroid()
  885. })
  886. </script>
  887. <style>
  888. </style>