You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

185 lines
6.2 KiB

  1. const app = getApp()
  2. const navigationBarHeight = (getApp().statusBarHeight + 44) + "px"
  3. const config = require("../../config/config")
  4. const util = require("../../utils/util");
  5. const Http = require("../../utils/HttpBasics.js");
  6. Page({
  7. data: {
  8. navigationBarHeight,
  9. imgHttps: app.globalData.imgHttps,
  10. pitch: 1,//选中支付类型
  11. orderLsit: [],//订单列表
  12. pageNum: 1,
  13. noDAtaFlag:false,
  14. statusLsit: [
  15. {
  16. value: 0,
  17. name: "待支付"
  18. },
  19. {
  20. value: 1,
  21. name: "已支付"
  22. }
  23. ],
  24. },
  25. goClass(e){
  26. let id = e.currentTarget.dataset.id
  27. let title = e.currentTarget.dataset.title
  28. tt.navigateTo({
  29. url: `/pages/classDetails/classDetails?id=${id}&title=${title}` // 指定页面的url
  30. });
  31. },
  32. setPitch(e) {
  33. let index = e.currentTarget.dataset.index
  34. this.setData({
  35. pitch: index,
  36. pageNum:1
  37. })
  38. this.getOrder()
  39. },
  40. goPay(e){
  41. let id = e.currentTarget.dataset.id
  42. Http.post({//拿orderInfo
  43. url: config.api.pay,
  44. data: {
  45. orderId: id
  46. }
  47. }).then(item => {
  48. let _this = this
  49. tt.pay({
  50. service: 5,
  51. orderInfo: {
  52. order_id: item.data.orderId,
  53. order_token: item.data.token,
  54. },
  55. success(res) {
  56. if (res.code === 0) {
  57. tt.showToast({
  58. title: '支付成功!', // 内容
  59. });
  60. tt.request({
  61. url: Http.address + config.api.ifPayOk, // 目标服务器url
  62. method: "post",
  63. headers: {
  64. "Content-Type": "application/json;charset=UTF-8",
  65. token: app.globalData.token
  66. },
  67. data: {
  68. code: 0,
  69. orderId: id
  70. },
  71. success: (res) => {
  72. _this.getOrder()
  73. },
  74. fail: (err) => {
  75. tt.showToast({
  76. title: err.message, // 内容
  77. icon: "none"
  78. });
  79. console.log("我失败; err", err);
  80. _this.getOrder()
  81. }
  82. });
  83. // 支付成功处理逻辑,只有res.code=0时,才表示支付成功
  84. // 但是最终状态要以商户后端结果为准
  85. } else if (res.code === 1) {
  86. tt.showToast({
  87. title: '支付超时', // 内容
  88. icon: "none"
  89. });
  90. } else if (res.code === 2) {
  91. tt.showToast({
  92. title: '支付失败', // 内容
  93. icon: "none"
  94. });
  95. } else if (res.code === 3) {
  96. tt.showToast({
  97. title: '支付关闭', // 内容
  98. icon: "none"
  99. });
  100. } else if (res.code === 4) {
  101. tt.showToast({
  102. title: '支付取消', // 内容
  103. icon: "none"
  104. });
  105. } else if (res.code === 9) {
  106. tt.showToast({
  107. title: '订单状态开发者自行获取', // 内容
  108. icon: "none"
  109. });
  110. }
  111. },
  112. fail(res) {
  113. // handle fail
  114. },
  115. })
  116. }).catch(err => {
  117. tt.showToast({
  118. title: err.message?err.message:err.data, // 内容
  119. icon: "none"
  120. });
  121. })
  122. },
  123. getOrder() {//查询订单
  124. //ORDER_STATUS_PENDING_PAYMENT(0, "待付款"),
  125. // ORDER_STATUS_PAYMENT_ING(1,"支付中"),
  126. // ORDER_STATUS_PAYMENT_SUCCESS(2, "已支付"),
  127. // ORDER_STATUS_OVERTIME_CANCEL(3, "已取消"),
  128. // ORDER_STATUS_PENDING_REFUND(4, "待退款"),
  129. // ORDER_STATUS_REFUND_SUCCESS(5,"已退款"),
  130. // ORDER_STATUS_REFUND_FAILD(6, "退款失败"),
  131. let tempArr = []
  132. if (this.data.pitch == 0) {//待付款
  133. tempArr.push(...[0, 1, 3])
  134. } else {//已支付
  135. tempArr.push(...[2, 4, 5, 6])
  136. }
  137. Http.get({
  138. url: config.api.getOrderLsit,
  139. data: {
  140. pageNum: this.data.pageNum,
  141. pageSize: 6,
  142. statusS: tempArr
  143. }
  144. }).then(res => {
  145. let arr = res.data.list
  146. arr.map(item=>{
  147. item.createDate = util.formatTime(item.createDate, "yyyy-MM-dd hh:mm:ss")
  148. })
  149. if(this.data.pageNum>1){
  150. let tempLsit = this.data.orderLsit
  151. let tempArrLsit = [...tempLsit,...arr]
  152. this.setData({
  153. orderLsit:tempArrLsit,
  154. noDAtaFlag:tempArrLsit.length==0?true: false,
  155. })
  156. }else{
  157. this.setData({
  158. orderLsit:arr,
  159. noDAtaFlag:arr.length==0?true: false,
  160. })
  161. }
  162. }).catch(err=>{
  163. tt.showToast({
  164. title: err.message, // 内容
  165. icon: "none"
  166. });
  167. })
  168. },
  169. onLoad() {
  170. this.getOrder()
  171. },
  172. onSshow(){
  173. this.getOrder()
  174. },
  175. onReachBottom(){
  176. console.log("到底了");
  177. this.setData({
  178. pageNum:this.data.pageNum +1
  179. })
  180. this.getOrder()
  181. }
  182. })