order.vue 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946
  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. if (data.type == 0 && data.levelList.length == 1) {
  297. cacheManager.updateObject('auth', {
  298. typeId: data.levelList[0].typeId,
  299. levelId: data.levelList[0].levelId,
  300. subjectId: data.levelList[0].subjectId,
  301. })
  302. if (data.levelList[0].subjectId == 2 && data.levelIdList[0].typeId == 1) {
  303. cacheManager.remove('zhangInfo')
  304. uni.redirectTo({
  305. url: `/pages/selectVersion/selectVersion`
  306. })
  307. } else {
  308. cacheManager.remove('zhangInfo')
  309. uni.redirectTo({
  310. url: `/pages/study/index`
  311. })
  312. }
  313. }
  314. }
  315. function genggaiVip(data) {
  316. uni.hideLoading();
  317. const localList = cacheManager.get('auth').levelIdList || []
  318. const mergeList = [...new Set([...localList, ...data.levelIdList])]
  319. cacheManager.updateObject('auth', {
  320. levelIdList: mergeList
  321. })
  322. toast("支付成功")
  323. dingdanData.current = 2
  324. getMore(2)
  325. // if (formPage.value == 'my') {
  326. // uni.redirectTo({
  327. // url: '/pages/my/index'
  328. // })
  329. // } else {
  330. // uni.redirectTo({
  331. // url: '/pages/study/index'
  332. // })
  333. // }
  334. }
  335. const creatOrderIos = debounce((data, index, orderId) => {
  336. console.log('data', data[0].cardId);
  337. console.log('index', index);
  338. console.log('orderId', orderId);
  339. uni.showLoading({
  340. title: '',
  341. mask: true
  342. });
  343. const productMap = {
  344. 4: 'ezySxJstxL1', //计算特训 L1
  345. 6: 'ezySxTjmtL1', //图解母题 L1
  346. 7: 'ezySxJstxL2', //计算特训 L2
  347. 8: 'ezySxJstxL3', //计算特训 L3
  348. 9: 'ezySxJstxL4', //计算特训 L4
  349. 10: 'ezySxJstxL5', //计算特训 L5
  350. 11: 'ezySxJstxL6', //计算特训 L6
  351. 12: 'ezySxTjmtL2', //图解母题 L2
  352. 13: 'ezySxTjmtL3', //图解母题 L3
  353. 14: 'ezySxTjmtL4', //图解母题 L4
  354. 15: 'ezySxTjmtL5', //图解母题 L5
  355. 16: 'ezySxTjmtL6', //图解母题 L6
  356. 22: 'ezySxTjmtL1L6', //图解母题 L1-6
  357. 23: 'ezyYyZrpdL1', //自然拼读 L1
  358. 24: 'ezyYyZrpdL2', //自然拼读 L2
  359. 25: 'ezyYyZrpdL3', //自然拼读 L3
  360. 26: 'ezyYyZrpdL4', //自然拼读 L4
  361. 27: 'ezyYyZrpdL5', //自然拼读 L5
  362. 28: 'ezyYyZrpdL1L5', //自然拼读 L1-l5
  363. 29: ' ezySxJstxL1L6', //计算特训 L1-L6
  364. 30: ' ezySxTjmtL3L6', //图解母题L3-L6
  365. 31: ' ezySxTjmtL5L6' //图解母题L5-L6
  366. };
  367. const firstId = data.length > 0 ? data[0].cardId : null;
  368. if (firstId) {
  369. productId.value = productMap[firstId]
  370. console.log('productId.value', productId.value);
  371. } else {
  372. toast("无对应产品Id,请练习管理员")
  373. uni.hideLoading();
  374. return false
  375. }
  376. setTimeout(() => {
  377. uni.hideLoading();
  378. }, 1000)
  379. orderId.value = orderId
  380. if (!orderId.value) {
  381. toast(
  382. "无orderId!"
  383. )
  384. return false
  385. }
  386. // 测试ios 1元
  387. applePay()
  388. }, 500)
  389. function applePaySuccess(data) {
  390. uni.showLoading({
  391. title: '开通中',
  392. mask: true
  393. });
  394. let req = {
  395. "id": orderId.value,
  396. "paynum": data.transactionIdentifier,
  397. "receipt": data.transactionReceipt
  398. }
  399. console.log('reqreq', req);
  400. orderPayApple(req).then(res => {
  401. if (res.code == 0 && res.data) {
  402. iapChannel.finishTransaction(data.transactionIdentifier)
  403. console.log('resiapChanneliapChanneliapChannel', res);
  404. orderCheck({
  405. id: orderId.value
  406. }).then(res3 => {
  407. console.log('res3', res3);
  408. if (res3.code == 0 && res3.data.success) {
  409. genggaiVip(res3.data)
  410. } else {
  411. setTimeout(() => {
  412. orderCheck({
  413. id: orderId.value
  414. }).then(res4 => {
  415. if (res4.code == 0 && res4.data.success) {
  416. genggaiVip(res4.data)
  417. } else {
  418. toast(
  419. "开通失败,请联系管理员!"
  420. )
  421. uni
  422. .hideLoading();
  423. return false
  424. }
  425. }).catch(() => {
  426. uni.hideLoading();
  427. toast("check接口报错")
  428. return false
  429. })
  430. }, 5000)
  431. }
  432. }).catch(() => {
  433. uni.hideLoading();
  434. toast("check接口报错")
  435. return false
  436. })
  437. } else {
  438. iapChannel.finishTransaction(data.transactionIdentifier)
  439. uni.hideLoading();
  440. toast("失败")
  441. console.log('orderPayApple失败');
  442. return false
  443. }
  444. })
  445. }
  446. function applePay() {
  447. console.log('123123');
  448. if (!productId.value) {
  449. uni.showToast({
  450. title: '产品错误,请联系客服',
  451. icon: "none"
  452. });
  453. return false;
  454. }
  455. uni.showLoading({
  456. title: '正在支付中...'
  457. });
  458. try {
  459. plus.payment.getChannels(function(channels) { //判读项目支付通道开通情况
  460. for (var i in channels) {
  461. iapChannel = channels[i];
  462. // 获取 id 为 'appleiap' 的 channel
  463. console.info("支付通道", iapChannel)
  464. if (iapChannel.id === 'appleiap') { //开通了app应用内支付,在manifest.josn中设置,开通后需打自定议基座
  465. // ids 数组中的项为 App Store Connect 配置的内购买项目产品ID(productId)
  466. var ids = [productId.value];
  467. // iap 为应用内支付对象
  468. iapChannel.requestOrder(ids, function(e) {
  469. // 获取订单信息成功回调方法
  470. console.log('requestOrder success: ' + JSON.stringify(e));
  471. uni.requestPayment({
  472. provider: 'appleiap',
  473. orderInfo: {
  474. productid: productId.value, //产品id,来自于苹果
  475. quantity: quantity.value, //产品数量
  476. manualFinishTransaction: true
  477. },
  478. success: (e) => {
  479. uni.hideLoading();
  480. // toast("苹果内购成功")
  481. applePaySuccess(e)
  482. //e.payment.orderNo = that.orderNo
  483. //支付成功回调,前端调用后台接口
  484. },
  485. fail: (e) => {
  486. uni.hideLoading();
  487. toast("失败或取消支付")
  488. },
  489. })
  490. },
  491. function(e) {
  492. // 获取订单信息失败回调方法
  493. console.log('requestOrder failed: ' + JSON.stringify(e));
  494. });
  495. } else {
  496. console.log('不支持苹果支付')
  497. }
  498. }
  499. },
  500. function(e) {
  501. console.log("获取iap支付通道失败:" + e.message);
  502. });
  503. } catch (e) {
  504. uni.showModal({
  505. title: "init",
  506. content: e.message,
  507. showCancel: false
  508. });
  509. } finally {
  510. uni.hideLoading();
  511. }
  512. }
  513. function wxPay() {
  514. orderPayWx({
  515. id: orderId.value
  516. }).then(res2 => {
  517. uni.hideLoading();
  518. console.log('res2', res2);
  519. if (res2.code != 0) {
  520. return false
  521. }
  522. uni.requestPayment({
  523. "provider": "wxpay",
  524. "orderInfo": {
  525. "appid": res2.data.appid, // 应用ID(AppID)
  526. "partnerid": res2.data.partnerId, // 商户号(PartnerID)
  527. "prepayid": res2.data.prepayId, // 预支付交易会话ID
  528. "package": res2.data.packageVal, // 固定值
  529. "noncestr": res2.data.nonceStr, // 随机字符串
  530. "timestamp": res2.data.timestamp, // 时间戳(单位:秒)
  531. "sign": res2.data.sign // 签名,这里用的 MD5 签名
  532. }, //此处为服务器返回的订单信息字符串
  533. success: function(res) {
  534. //var rawdata = JSON.parse(res.rawdata);
  535. // console.log('res',res);
  536. // console.log('支付成功');
  537. // console.log('rawdata', rawdata);
  538. uni.showLoading({
  539. title: '开通中,请稍后...'
  540. });
  541. orderCheck({
  542. id: orderId.value
  543. }).then(res3 => {
  544. console.log('res3', res3);
  545. if (res3.code == 0 && res3.data.success) {
  546. genggaiVip(res3.data)
  547. } else {
  548. setTimeout(() => {
  549. orderCheck({
  550. id: orderId.value
  551. }).then(res4 => {
  552. if (res4.code == 0 && res4.data.success) {
  553. genggaiVip(res4.data)
  554. } else {
  555. toast(
  556. "开通失败,请联系管理员!"
  557. )
  558. uni
  559. .hideLoading();
  560. return false
  561. }
  562. }).catch(() => {
  563. uni.hideLoading();
  564. toast("check接口报错")
  565. return false
  566. })
  567. }, 5000)
  568. }
  569. }).catch(() => {
  570. uni.hideLoading();
  571. toast("check接口报错")
  572. return false
  573. })
  574. },
  575. fail: function(err) {
  576. uni.hideLoading();
  577. // toast('支付失败:' + JSON.stringify(err));
  578. console.log('支付失败:' + JSON.stringify(err));
  579. }
  580. });
  581. }).catch((error) => {
  582. uni.hideLoading();
  583. console.log(error);
  584. })
  585. }
  586. function aliApy() {
  587. orderPayAli({
  588. id: orderId.value
  589. }).then(res2 => {
  590. console.log('res2', res2);
  591. uni.hideLoading();
  592. if (res2.code != 0) {
  593. return false
  594. }
  595. uni.requestPayment({
  596. "provider": "alipay",
  597. "orderInfo": res2.data.text, //此处为服务器返回的订单信息字符串
  598. success: function(res) {
  599. // var rawdata = JSON.parse(res.rawdata);
  600. // console.log('支付成功');
  601. // console.log('rawdata', rawdata);
  602. uni.showLoading({
  603. title: '开通中,请稍后...'
  604. });
  605. orderCheck({
  606. id: orderId.value
  607. }).then(res3 => {
  608. if (res3.code == 0 && res3.data.success) {
  609. genggaiVip(res3.data)
  610. } else {
  611. setTimeout(() => {
  612. orderCheck({
  613. id: orderId.value
  614. }).then(res4 => {
  615. if (res4.code ==
  616. 0 && res4.data.success) {
  617. genggaiVip(res4.data)
  618. } else {
  619. toast(
  620. "开通失败,请联系管理员!"
  621. )
  622. uni
  623. .hideLoading();
  624. return false
  625. }
  626. }).catch(() => {
  627. uni.hideLoading();
  628. toast("check接口报错")
  629. return false
  630. })
  631. }, 5000)
  632. }
  633. }).catch(() => {
  634. uni.hideLoading();
  635. toast("check接口报错")
  636. return false
  637. })
  638. },
  639. fail: function(err) {
  640. console.log('支付失败:' + JSON.stringify(err));
  641. uni.hideLoading();
  642. }
  643. });
  644. })
  645. }
  646. const creatOrder = debounce((data, index) => {
  647. uni.showLoading({
  648. title: '',
  649. mask: true
  650. });
  651. if (payType.value == 'weixin') {
  652. orderId.value = data.id
  653. wxPay()
  654. } else {
  655. orderId.value = data.id
  656. aliApy()
  657. }
  658. }, 500)
  659. function onChangeTab(e) {
  660. if (dingdanData.current !== e.currentIndex) {
  661. dingdanData.current = e.currentIndex;
  662. if (dingdanData.current == 0) {
  663. dingdanData.quanbu.page = 0
  664. } else if (dingdanData.current == 1) {
  665. dingdanData.daiFukuan.page = 0
  666. } else if (dingdanData.current == 2) {
  667. dingdanData.yiFukuan.page = 0
  668. }
  669. refreshData(dingdanData.current);
  670. }
  671. }
  672. function onScrolltolower() {
  673. getMore(dingdanData.current)
  674. }
  675. function refreshData(code) {
  676. const opt = {
  677. page: 1,
  678. size: 10, // 固定查询10条
  679. status: code
  680. }
  681. if (code == 0) {
  682. dingdanData.quanbu.list = [];
  683. // 数学
  684. dingdanData.quanbu.state = 'loading';
  685. dingdanData.quanbu.page++;
  686. opt.page = dingdanData.quanbu.page;
  687. } else if (code == 1) {
  688. dingdanData.daiFukuan.list = [];
  689. // 英语
  690. dingdanData.daiFukuan.state = 'loading';
  691. dingdanData.daiFukuan.page++;
  692. opt.page = dingdanData.daiFukuan.page;
  693. } else if (code == 2) {
  694. dingdanData.yiFukuan.list = [];
  695. // 英语
  696. dingdanData.yiFukuan.state = 'loading';
  697. dingdanData.yiFukuan.page++;
  698. opt.page = dingdanData.yiFukuan.page;
  699. }
  700. getOrderList(opt).then(res => {
  701. if (code == 0) {
  702. dingdanData.quanbu.list = dingdanData.quanbu.list.concat(res.data.data);
  703. dingdanData.quanbu.loading = false;
  704. } else if (code == 1) {
  705. dingdanData.daiFukuan.list = dingdanData.daiFukuan.list.concat(res.data.data);
  706. dingdanData.daiFukuan.loading = false;
  707. } else if (code == 2) {
  708. dingdanData.yiFukuan.list = dingdanData.yiFukuan.list.concat(res.data.data);
  709. dingdanData.yiFukuan.loading = false;
  710. }
  711. if (code == 0) {
  712. if (res.data.total > dingdanData.quanbu.list.length) {
  713. // 数学
  714. dingdanData.quanbu.state = 'more';
  715. dingdanData.quanbu.loading = false;
  716. } else {
  717. // 数学
  718. dingdanData.quanbu.state = 'no-more';
  719. dingdanData.quanbu.loading = false;
  720. }
  721. } else if (code == 1) {
  722. if (res.data.total > dingdanData.daiFukuan.list.length) {
  723. // 英语
  724. dingdanData.daiFukuan.state = 'more';
  725. dingdanData.daiFukuan.loading = false;
  726. } else {
  727. // 英语
  728. dingdanData.daiFukuan.state = 'no-more';
  729. dingdanData.daiFukuan.loading = false;
  730. }
  731. } else if (code == 2) {
  732. if (res.data.total > dingdanData.yiFukuan.list.length) {
  733. // 英语
  734. dingdanData.yiFukuan.state = 'more';
  735. dingdanData.yiFukuan.loading = false;
  736. } else {
  737. // 英语
  738. dingdanData.yiFukuan.state = 'no-more';
  739. dingdanData.yiFukuan.loading = false;
  740. }
  741. }
  742. }).catch(err => {
  743. if (code == 0) {
  744. // 数学
  745. dingdanData.quanbu.state = 'more';
  746. dingdanData.quanbu.loading = false;
  747. } else if (code == 1) {
  748. // 英语
  749. dingdanData.daiFukuan.state = 'more';
  750. dingdanData.daiFukuan.loading = false;
  751. } else if (code == 2) {
  752. // 英语
  753. dingdanData.yiFukuan.state = 'more';
  754. dingdanData.yiFukuan.loading = false;
  755. }
  756. })
  757. }
  758. function onRefresh() {
  759. if (dingdanData.current == 0) {
  760. dingdanData.quanbu.page = 0;
  761. dingdanData.quanbu.list = [];
  762. dingdanData.quanbu.loading = true;
  763. } else if (dingdanData.current == 1) {
  764. dingdanData.daiFukuan.page = 0;
  765. dingdanData.daiFukuan.list = [];
  766. dingdanData.daiFukuan.loading = true;
  767. } else if (dingdanData.current == 2) {
  768. dingdanData.yiFukuan.page = 0;
  769. dingdanData.yiFukuan.list = [];
  770. dingdanData.yiFukuan.loading = true;
  771. }
  772. refreshData(dingdanData.current);
  773. }
  774. function getMore(code) {
  775. const opt = {
  776. page: 1,
  777. size: 10, // 固定查询10条
  778. status: Number(code) // 前台索引加1为学科cardId
  779. }
  780. if (code == 0) {
  781. if (dingdanData.quanbu.state == 'no-more') {
  782. return;
  783. }
  784. // 数学
  785. dingdanData.quanbu.state = 'loading';
  786. dingdanData.quanbu.page++;
  787. opt.page = dingdanData.quanbu.page;
  788. } else if (code == 1) {
  789. if (dingdanData.daiFukuan.state == 'no-more') {
  790. return;
  791. }
  792. dingdanData.daiFukuan.state = 'loading';
  793. dingdanData.daiFukuan.page++;
  794. opt.page = dingdanData.daiFukuan.page;
  795. } else if (code == 2) {
  796. if (dingdanData.yiFukuan.state == 'no-more') {
  797. return;
  798. }
  799. dingdanData.yiFukuan.state = 'loading';
  800. dingdanData.yiFukuan.page++;
  801. opt.page = dingdanData.yiFukuan.page;
  802. }
  803. getOrderList(opt).then(res => {
  804. if (code == 0) {
  805. dingdanData.quanbu.list = dingdanData.quanbu.list.concat(res.data.data);
  806. dingdanData.quanbu.loading = false;
  807. } else if (code == 1) {
  808. dingdanData.daiFukuan.list = dingdanData.daiFukuan.list.concat(res.data.data);
  809. dingdanData.daiFukuan.loading = false;
  810. } else if (code == 2) {
  811. dingdanData.yiFukuan.list = dingdanData.yiFukuan.list.concat(res.data.data);
  812. dingdanData.yiFukuan.loading = false;
  813. }
  814. if (code == 0) {
  815. if (res.data.total > dingdanData.quanbu.list.length) {
  816. // 数学
  817. dingdanData.quanbu.state = 'more';
  818. dingdanData.quanbu.state_text = '加载更多';
  819. dingdanData.quanbu.loading = false;
  820. } else {
  821. // 数学
  822. dingdanData.quanbu.state = 'no-more';
  823. dingdanData.quanbu.state_text = '没有更多啦';
  824. dingdanData.quanbu.loading = false;
  825. }
  826. } else if (code == 1) {
  827. if (res.data.total > dingdanData.daiFukuan.list.length) {
  828. // 英语
  829. dingdanData.daiFukuan.state = 'more';
  830. dingdanData.daiFukuan.state_text = '加载更多';
  831. dingdanData.daiFukuan.loading = false;
  832. } else {
  833. // 英语
  834. dingdanData.daiFukuan.state = 'no-more';
  835. dingdanData.daiFukuan.state_text = '没有更多啦';
  836. dingdanData.daiFukuan.loading = false;
  837. }
  838. } else if (code == 2) {
  839. if (res.data.total > dingdanData.yiFukuan.list.length) {
  840. // 英语
  841. dingdanData.yiFukuan.state = 'more';
  842. dingdanData.yiFukuan.state_text = '加载更多';
  843. dingdanData.yiFukuan.loading = false;
  844. } else {
  845. // 英语
  846. dingdanData.yiFukuan.state = 'no-more';
  847. dingdanData.yiFukuan.state_text = '没有更多啦';
  848. dingdanData.yiFukuan.loading = false;
  849. }
  850. }
  851. }).catch(err => {
  852. if (code == 0) {
  853. // 数学
  854. dingdanData.quanbu.state = 'more';
  855. dingdanData.quanbu.state_text = '加载更多';
  856. dingdanData.quanbu.loading = false;
  857. } else if (code == 1) {
  858. // 英语
  859. dingdanData.daiFukuan.state = 'more';
  860. dingdanData.daiFukuan.state_text = '加载更多';
  861. dingdanData.daiFukuan.loading = false;
  862. } else if (code == 2) {
  863. // 英语
  864. dingdanData.yiFukuan.state = 'more';
  865. dingdanData.yiFukuan.state_text = '加载更多';
  866. dingdanData.yiFukuan.loading = false;
  867. }
  868. })
  869. }
  870. function goBack() {
  871. uni.redirectTo({
  872. url: '/pages/my/index'
  873. })
  874. }
  875. const isIOSorAndroid = () => {
  876. const systemInfo = uni.getSystemInfoSync();
  877. console.log('systemInfo', systemInfo);
  878. if (systemInfo.platform == 'ios') {
  879. return currentPlatform.value = 'ios'
  880. } else {
  881. return currentPlatform.value = 'android'
  882. }
  883. }
  884. onLoad((options) => {
  885. dingdanData.current = Number(options.status) || dingdanData.current
  886. getMore(dingdanData.current);
  887. isIOSorAndroid()
  888. })
  889. </script>
  890. <style>
  891. </style>