抖音小程序C端
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

205 строки
5.8 KiB

  1. const app = getApp()
  2. const navigationBarHeight = (getApp().statusBarHeight + 50) + "px"
  3. const Http = require("../../utils/HttpBasics");
  4. let config = require("../../config/config.js");
  5. const util = require("../../utils/util")
  6. Page({
  7. data: {
  8. navigationBarHeight,
  9. ifPay:true,
  10. orderId:"",
  11. detailObj:{},
  12. createDate:"",
  13. mystatus: '',
  14. },
  15. updetail(){
  16. Http.get({
  17. url:config.api.orderDetail,
  18. data:{
  19. orderId: this.data.orderId
  20. }
  21. }).then(res=>{
  22. console.log(res);
  23. let createDate = util.formatTime(res.data.createDate, "yyyy-MM-dd hh:mm:ss");
  24. this.setData({
  25. detailObj:res.data,
  26. createDate: createDate
  27. })
  28. }).catch(err => {
  29. tt.showToast({
  30. title: err.message ? err.message : err.data, // 内容
  31. icon: "none"
  32. });
  33. })
  34. },
  35. /**
  36. * 支付订单更新
  37. */
  38. payOrderUpdate(orderId, payOrderId, status, reason, type, _this, composeOrderType) {
  39. let that = this;
  40. Http.post({
  41. url: config.api.payOrderUpdate,
  42. data: {
  43. payOrderId: payOrderId,
  44. composeOrderId: orderId,
  45. status: status,
  46. reason: reason
  47. }
  48. }).then(res => {
  49. tt.hideLoading();
  50. if(!type&&type!="free"){
  51. tt.showToast({
  52. title: "购买成功",
  53. duration: 2000,
  54. mask: false,
  55. success: function () {
  56. tt.showLoading({
  57. title: "加载中..."
  58. });
  59. setTimeout(function () {
  60. tt.hideLoading();
  61. }, 1600);
  62. setTimeout(() => {
  63. let url = ""
  64. if (_this.data.orderFlag){
  65. tt.redirectTo({
  66. url: `/pages/detailOrder/detailOrder?orderId=${orderId}&dingdan=order`
  67. });
  68. }else{
  69. tt.redirectTo({
  70. url: `/pages/detailOrder/detailOrder?orderId=${orderId}`
  71. });
  72. }
  73. }, 1600);
  74. }
  75. });
  76. } else if (type == 'free'){
  77. tt.redirectTo({
  78. url: `/pages/detailOrder/detailOrder?orderId=${orderId}`
  79. });
  80. }
  81. }).catch(err => {
  82. console.log(err);
  83. if (!type) {
  84. setTimeout(function () {
  85. _this.payOrderUpdate(orderId, payOrderId, status, reason, type, _this, composeOrderType);
  86. }, 2000)
  87. }
  88. })
  89. },
  90. powerDrawer: function (e) {
  91. let that = this;
  92. console.log(e)
  93. // couponOrderStatus
  94. // 0 未使用
  95. // 1 已使用
  96. // 2 已过期
  97. // 3 已经退款
  98. if (that.data.mystatus == "" || that.data.mystatus == undefined) {
  99. tt.navigateTo({
  100. url: `/pages/orderquanma/orderquanma?quancode=${
  101. e.currentTarget.dataset.quancode
  102. }&title=${e.currentTarget.dataset.title}&subtitle=${
  103. e.currentTarget.dataset.subtitle
  104. }&remark=${e.currentTarget.dataset.remark}&couponorderstatus=${
  105. e.currentTarget.dataset.couponorderstatus}&validstatus=${e.currentTarget.dataset.validstatus}
  106. &contentType=${that.data.contentType}`
  107. });
  108. } else {
  109. tt.navigateTo({
  110. url: `/pages/orderquanma/orderquanma?quancode=${
  111. e.currentTarget.dataset.quancode
  112. }&title=${e.currentTarget.dataset.title}&subtitle=${
  113. e.currentTarget.dataset.subtitle
  114. }&remark=${e.currentTarget.dataset.remark}&couponorderstatus=${
  115. that.data.mystatus}&validstatus=${e.currentTarget.dataset.validstatus}
  116. &contentType=${that.data.contentType}`
  117. });
  118. }
  119. },
  120. gotopay() {
  121. let that = this;
  122. Http.get({//判断是否授权抖音
  123. url: config.api.checkPhoneStatus,
  124. }).then(res => {
  125. Http.post({
  126. url: config.api.payOrderCreate,
  127. data: {
  128. orderId: that.data.detailObj.id,
  129. composeOrderType: that.data.detailObj.composeOrderType
  130. }
  131. }).then(payres => {
  132. tt.hideLoading();
  133. tt.pay({
  134. service: 5,
  135. orderInfo: {
  136. order_id: payres.data.orderId,
  137. order_token: payres.data.token,
  138. },
  139. success(suRes) {
  140. if(suRes.code==0){
  141. tt.showLoading({
  142. title: '订单正在处理中...',
  143. })
  144. that.payOrderUpdate(that.data.detailObj.id,payres.data.outOrderNo,1,"","",that,that.data.detailObj.composeOrderType)
  145. } else if (res.code === 1) {
  146. tt.showToast({
  147. title: '支付超时', // 内容
  148. icon: "none"
  149. });
  150. } else if (res.code === 2) {
  151. tt.showToast({
  152. title: '支付失败', // 内容
  153. icon: "none"
  154. });
  155. } else if (res.code === 3) {
  156. tt.showToast({
  157. title: '支付关闭', // 内容
  158. icon: "none"
  159. });
  160. } else if (res.code === 4) {
  161. tt.showToast({
  162. title: '支付取消', // 内容
  163. icon: "none"
  164. });
  165. } else if (res.code === 9) {
  166. tt.showToast({
  167. title: '订单状态开发者自行获取', // 内容
  168. icon: "none"
  169. });
  170. }
  171. },
  172. fail(res) {
  173. console.log(123);
  174. // handle fail
  175. },
  176. })
  177. }).catch(err => {
  178. tt.showToast({
  179. title: err.message ? err.message : err.data, // 内容
  180. icon: "none"
  181. });
  182. })
  183. })
  184. // .catch(err => {
  185. // if (err.code == 11005) {
  186. // this.setData({
  187. // showPhoem: true
  188. // })
  189. // }
  190. // })
  191. },
  192. onLoad: function (options) {
  193. console.log(options.orderId);
  194. this.setData({
  195. orderId:options.orderId
  196. })
  197. this.updetail()
  198. }
  199. })