index.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // pages/order/index.js
  2. import http from '../../utils/http'
  3. import util from '../../utils/util'
  4. import api from '../../utils/api'
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. id: -1,
  11. project: null,
  12. tabs: ['全部订单', '待审核', '已审核', '已完成', '已驳回'],
  13. statuses: ['', 'checking', 'checked', 'pass', 'reject'],
  14. list: [
  15. [],
  16. [],
  17. [],
  18. [],
  19. []
  20. ],
  21. pages: [1, 1, 1, 1, 1],
  22. tabIndex: 0,
  23. touchBottom: [false, false, false, false, false],
  24. work_points: [],
  25. pointIndex: -1
  26. },
  27. /**
  28. * 生命周期函数--监听页面加载
  29. */
  30. onLoad: function (options) {
  31. var id = options.id ? options.id : 1
  32. this.setData({
  33. id
  34. })
  35. api.getProject(this)
  36. api.getByName(this, 'work-points/get', 'work_points');
  37. this.getList();
  38. },
  39. search() {
  40. this.setData({
  41. list: [
  42. [],
  43. [],
  44. [],
  45. [],
  46. []
  47. ],
  48. pages: [1, 1, 1, 1, 1],
  49. touchBottom: [false, false, false, false, false],
  50. })
  51. this.getList()
  52. },
  53. getList: function () {
  54. var index = this.data.tabIndex
  55. var touchBottom = this.data.touchBottom[index]
  56. if (touchBottom) return false;
  57. var status = this.data.statuses[index]
  58. var page = this.data.pages[index]
  59. var that = this
  60. var pointIndex = this.data.pointIndex
  61. var work_point_id = pointIndex >= 0 ? this.data.work_points[pointIndex].id : 0
  62. http({
  63. url: 'orders/get',
  64. data: {
  65. project_id: this.data.id,
  66. status: status,
  67. page: page,
  68. work_point_id: work_point_id
  69. },
  70. success: function (res) {
  71. if (res.code == 0) {
  72. var list = that.data.list
  73. var touchBottom = that.data.touchBottom
  74. list[index] = list[index].concat(res.data);
  75. if (res.data.length <= 0) {
  76. touchBottom[index] = true;
  77. }
  78. that.setData({
  79. touchBottom,
  80. list
  81. })
  82. }
  83. }
  84. })
  85. },
  86. switchTab: function (e) {
  87. var index = e.currentTarget.dataset.index
  88. this.setData({
  89. tabIndex: index
  90. })
  91. },
  92. onChange: function (e) {
  93. var name = e.currentTarget.dataset.name
  94. this.setData({
  95. [name]: e.detail.value
  96. })
  97. },
  98. /**
  99. * 生命周期函数--监听页面初次渲染完成
  100. */
  101. onReady: function () {
  102. },
  103. /**
  104. * 生命周期函数--监听页面显示
  105. */
  106. onShow: function () {
  107. },
  108. /**
  109. * 生命周期函数--监听页面隐藏
  110. */
  111. onHide: function () {
  112. },
  113. /**
  114. * 生命周期函数--监听页面卸载
  115. */
  116. onUnload: function () {
  117. },
  118. /**
  119. * 页面相关事件处理函数--监听用户下拉动作
  120. */
  121. onPullDownRefresh: function () {
  122. },
  123. /**
  124. * 页面上拉触底事件的处理函数
  125. */
  126. onReachBottom: function () {
  127. },
  128. /**
  129. * 用户点击右上角分享
  130. */
  131. onShareAppMessage: function () {
  132. }
  133. })