index.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. // pages/order-list/index.js
  2. let app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. statusType: ["全部", "待支付", "待确认", "已确认"],
  9. currentType:0,
  10. tabClass:["","","",""]
  11. },
  12. statusTap(e){
  13. let index = e.currentTarget.dataset.index
  14. this.setData({
  15. currentType: index
  16. })
  17. this.onShow()
  18. },
  19. //取消
  20. toQuxiao(e){
  21. let orderId = e.currentTarget.dataset.id
  22. let that = this
  23. let postData = {
  24. oid: orderId
  25. }
  26. postData.status = '已取消'
  27. wx.request({
  28. url: app.data.resturl + '/orderstate.action',
  29. data: postData,
  30. method: 'post',
  31. header: {
  32. 'content-type': 'application/x-www-form-urlencoded'
  33. },
  34. success:(res)=>{
  35. let code = res.data;
  36. if(code=='yes'){
  37. let postData = {
  38. openid: app.globalData.openid
  39. }
  40. postData.status = '已取消'
  41. wx.request({
  42. url: app.data.resturl + '/olist.action',
  43. data: postData,
  44. method: 'post',
  45. header: {
  46. 'content-type': 'application/x-www-form-urlencoded'
  47. },
  48. success: (res) => {
  49. that.setData({
  50. orderList: res.data.dlist
  51. });
  52. that.setData({
  53. currentType: 0
  54. })
  55. }
  56. })
  57. }
  58. }
  59. })
  60. },
  61. //支付
  62. toPay(e) {
  63. let orderId = e.currentTarget.dataset.id
  64. let that = this
  65. let postData = {
  66. oid: orderId
  67. }
  68. postData.status = '待接单'
  69. wx.request({
  70. url: app.data.resturl + '/orderstate.action',
  71. data: postData,
  72. method: 'post',
  73. header: {
  74. 'content-type': 'application/x-www-form-urlencoded'
  75. },
  76. success: (res) => {
  77. let code = res.data;
  78. if (code == 'yes') {
  79. let postData = {
  80. openid: app.globalData.openid
  81. }
  82. postData.status = '待接单'
  83. wx.request({
  84. url: app.data.resturl + '/olist.action',
  85. data: postData,
  86. method: 'post',
  87. header: {
  88. 'content-type': 'application/x-www-form-urlencoded'
  89. },
  90. success: (res) => {
  91. that.setData({
  92. orderList: res.data.dlist
  93. });
  94. that.setData({
  95. currentType: 2
  96. })
  97. }
  98. })
  99. }
  100. }
  101. })
  102. },
  103. //删除
  104. toDel(e) {
  105. let orderId = e.currentTarget.dataset.id
  106. let that = this
  107. let postData = {
  108. oid: orderId
  109. }
  110. wx.request({
  111. url: app.data.resturl + '/delOrder.action',
  112. data: postData,
  113. method: 'post',
  114. header: {
  115. 'content-type': 'application/x-www-form-urlencoded'
  116. },
  117. success: (res) => {
  118. let code = res.data;
  119. if (code == 'yes') {
  120. let postData = {
  121. openid: app.globalData.openid
  122. }
  123. wx.request({
  124. url: app.data.resturl + '/olist.action',
  125. data: postData,
  126. method: 'post',
  127. header: {
  128. 'content-type': 'application/x-www-form-urlencoded'
  129. },
  130. success: (res) => {
  131. that.setData({
  132. orderList: res.data.dlist
  133. });
  134. that.setData({
  135. currentType: 0
  136. })
  137. }
  138. })
  139. }
  140. }
  141. })
  142. },
  143. orderDetail(e) {
  144. wx.navigateTo({
  145. url: '/pages/order-details/index?id=' + e.currentTarget.dataset.id
  146. })
  147. },
  148. /**
  149. * 生命周期函数--监听页面初次渲染完成
  150. */
  151. onReady: function () {
  152. },
  153. onShow: function () {
  154. let that = this
  155. wx.showLoading()
  156. let postData = {
  157. openid: app.globalData.openid
  158. }
  159. if (this.data.currentType == 1){
  160. postData.status = '待支付'
  161. }
  162. if (this.data.currentType == 2){
  163. postData.status = '待接单'
  164. }
  165. if (this.data.currentType == 3) {
  166. postData.status = '已接单'
  167. }
  168. postData.openid = app.globalData.openid
  169. wx.request({
  170. url: app.data.resturl + '/olist.action',
  171. data: postData,
  172. method: 'post',
  173. header: {
  174. 'content-type': 'application/x-www-form-urlencoded'
  175. },
  176. success:(res)=>{
  177. wx.hideLoading()
  178. that.setData({
  179. orderList: res.data.dlist
  180. })
  181. }
  182. })
  183. },
  184. /**
  185. * 生命周期函数--监听页面隐藏
  186. */
  187. onHide: function () {
  188. },
  189. /**
  190. * 生命周期函数--监听页面卸载
  191. */
  192. onUnload: function () {
  193. },
  194. /**
  195. * 页面相关事件处理函数--监听用户下拉动作
  196. */
  197. onPullDownRefresh: function () {
  198. },
  199. /**
  200. * 页面上拉触底事件的处理函数
  201. */
  202. onReachBottom: function () {
  203. },
  204. /**
  205. * 用户点击右上角分享
  206. */
  207. onShareAppMessage: function () {
  208. }
  209. })