家政小程序
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.

index.js 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. const $ = global;
  2. const orderTexts = [
  3. '已预约,等待处理',
  4. '未付款',
  5. '已付款'
  6. ]
  7. new $.Page({
  8. data: {
  9. services: [],
  10. goods: []
  11. },
  12. onShow() {
  13. this.init();
  14. },
  15. init() {
  16. $.request('my/orders', 'GET', {}).then((res) => {
  17. const services = []
  18. const goods = []
  19. if (res.data && res.data.length > 0) {
  20. res.data.forEach(e => {
  21. e.orderText = orderTexts[e.status];
  22. if (e.order_type == 'product_order') {
  23. if (e.status == 0)
  24. e.orderText = '待付款';
  25. goods.push(e);
  26. } else {
  27. services.push(e);
  28. }
  29. });
  30. this.setData({
  31. services,
  32. goods
  33. });
  34. }
  35. });
  36. },
  37. toPay(e) {
  38. const _this = this;
  39. const {
  40. id,
  41. type
  42. } = e.target.dataset;
  43. if (id && type) {
  44. $.wx.showToast({
  45. title: '支付中'
  46. }, 'loading');
  47. $.request('payments/pay', 'POST', {
  48. order_id: id,
  49. order_type: type
  50. }).then((res) => {
  51. if (res.msg) {
  52. const {
  53. timestamp,
  54. paySign,
  55. nonceStr
  56. } = res.msg;
  57. const pck = res.msg.package;
  58. wx.requestPayment({
  59. timeStamp: timestamp + '',
  60. nonceStr,
  61. package: pck,
  62. signType: 'MD5',
  63. paySign,
  64. success(res) {
  65. console.log('支付成功', res);
  66. $.wx.hideToast('loading');
  67. _this.init();
  68. },
  69. fail() {
  70. $.wx.showToast({
  71. title: '支付失败'
  72. });
  73. }
  74. });
  75. }
  76. });
  77. }
  78. },
  79. addComment(e) {
  80. const {
  81. id,
  82. type
  83. } = e.target.dataset;
  84. if (id) {
  85. $.router.goto({
  86. path: '/pages/addComment/index',
  87. query: {
  88. id,
  89. type
  90. }
  91. });
  92. }
  93. }
  94. });