index.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import GoodApi from '../../../../services/good'
  2. import checkauth from '../../../../utils/checkauth'
  3. import Navi from '../../../../utils/navi'
  4. // pages/mine/myorder/confirm/index.ts
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. addrId: -1,
  11. address: {} as any,
  12. items: [] as any[],
  13. // pay: {} as any,
  14. // price: {} as any,
  15. wait: false,
  16. },
  17. behaviors: [checkauth],
  18. init() {
  19. this.setData({
  20. wait: true,
  21. })
  22. GoodApi.PreviewOrder({
  23. addrId: this.data.addrId,
  24. })
  25. .then((rsp) => {
  26. if (rsp.result) {
  27. this.setData({
  28. ...rsp.result,
  29. wait: false,
  30. })
  31. }
  32. })
  33. .catch(() => {
  34. this.setData({
  35. wait: false,
  36. })
  37. })
  38. },
  39. /**
  40. * 生命周期函数--监听页面加载
  41. */
  42. //@ts-ignore
  43. onLoad(query: { addrId: number }) {
  44. const { addrId } = query
  45. this.setData({
  46. addrId,
  47. })
  48. },
  49. /**
  50. * 生命周期函数--监听页面初次渲染完成
  51. */
  52. onReady() {},
  53. /**
  54. * 生命周期函数--监听页面显示
  55. */
  56. onShow() {
  57. const self = this
  58. //@ts-ignore
  59. this.afterAuth(() => {
  60. self.init()
  61. })
  62. },
  63. /**
  64. * 生命周期函数--监听页面隐藏
  65. */
  66. onHide() {},
  67. /**
  68. * 生命周期函数--监听页面卸载
  69. */
  70. onUnload() {},
  71. /**
  72. * 页面相关事件处理函数--监听用户下拉动作
  73. */
  74. onPullDownRefresh() {},
  75. /**
  76. * 页面上拉触底事件的处理函数
  77. */
  78. onReachBottom() {},
  79. /**
  80. * 用户点击右上角分享
  81. */
  82. onShareAppMessage() {},
  83. userAddr(addr: any) {
  84. this.setData({
  85. addrId: addr.id,
  86. address: {
  87. id: addr.id,
  88. name: addr.detailAddress,
  89. phone: addr.phone,
  90. detailAddress: addr.detailAddress,
  91. },
  92. })
  93. },
  94. gotoAddr() {
  95. Navi.navigateTo({
  96. url: '/pages/mine/myaddr/list/index?mode=choose&id=' + this.data.addrId,
  97. })
  98. },
  99. onConfirm() {
  100. const { items, pay = { mode: '' }, addrId } = this.data as any
  101. const bag: WxGoodComOrderDto = {
  102. addrId,
  103. items,
  104. couponId: undefined,
  105. payMode: pay.mode,
  106. expectMode: undefined,
  107. expectDate: undefined,
  108. }
  109. this.setData({
  110. wait: true,
  111. })
  112. GoodApi.MakeOrder(bag)
  113. .then((rsp) => {
  114. var reg = new RegExp('^\\d+$')
  115. debugger
  116. if (rsp.result && reg.test(rsp.result)) {
  117. this.setData(
  118. {
  119. wait: false,
  120. },
  121. () => {
  122. Navi.redirectTo({
  123. url: '/pages/mine/myorder/result/index?orderCode=' + rsp.result,
  124. })
  125. },
  126. )
  127. }
  128. })
  129. .catch((e) => {
  130. this.setData({
  131. wait: false,
  132. })
  133. })
  134. },
  135. })