index.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. // pages/order/index.js
  2. import http from '../../utils/http'
  3. import util from '../../utils/util'
  4. import api from '../../utils/api'
  5. import Dialog from '../../miniprogram_npm/@vant/weapp/dialog/dialog';
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. id: -1,
  12. project: null,
  13. tabs: ['全部订单', '待审核', '已审核', '已完成', '已驳回'],
  14. statuses: ['', 'checking', 'checked', 'pass', 'reject'],
  15. list: [
  16. [],
  17. [],
  18. [],
  19. [],
  20. []
  21. ],
  22. pages: [1, 1, 1, 1, 1],
  23. tabIndex: 0,
  24. touchBottom: [false, false, false, false, false],
  25. work_points: [],
  26. work_point_id: '',
  27. pointIndex: -1,
  28. isSearch: false,
  29. role: '',
  30. // list|check
  31. type: 'list'
  32. },
  33. /**
  34. * 生命周期函数--监听页面加载
  35. */
  36. onLoad: function (options) {
  37. var id = options.id ? options.id : 1
  38. var type = options.type ? options.type : 'list'
  39. var tabIndex = options.index ? options.index : 0
  40. this.setData({
  41. id,
  42. type,
  43. tabIndex
  44. })
  45. api.getProject(this)
  46. api.getByName(this, 'work-points/get', 'work_points', {type: 'drop_menu'});
  47. api.getByName(this, 'orders/getRole', 'role', {id: id});
  48. this.getList();
  49. },
  50. doAction: function(e) {
  51. var type = e.currentTarget.dataset.type
  52. if(type == 'edit' || type == 'detail') {
  53. this.navigate(e)
  54. } else if(type == 'confirm') {
  55. var that = this
  56. var order = e.currentTarget.dataset.order
  57. Dialog.confirm({
  58. title: '提示',
  59. message: '确定订单吗',
  60. })
  61. .then(() => {
  62. that.submitCheck(order)
  63. })
  64. }
  65. },
  66. submitCheck(order) {
  67. var that = this
  68. http({
  69. url: 'orders/check',
  70. data: {
  71. id: order.id,
  72. type: 'confirm',
  73. remark: order.remark
  74. },
  75. success: function (res) {
  76. if (res.code == 0) {
  77. that.search()
  78. }
  79. }
  80. })
  81. },
  82. navigate: function(e) {
  83. wx.navigateTo({
  84. url: e.currentTarget.dataset.url,
  85. })
  86. },
  87. search() {
  88. this.setData({
  89. list: [
  90. [],
  91. [],
  92. [],
  93. [],
  94. []
  95. ],
  96. pages: [1, 1, 1, 1, 1],
  97. touchBottom: [false, false, false, false, false],
  98. isSearch: true
  99. })
  100. this.getList()
  101. },
  102. getList: function () {
  103. var index = this.data.tabIndex
  104. var touchBottom = this.data.touchBottom[index]
  105. if (touchBottom) return false;
  106. var status = this.data.statuses[index]
  107. var page = this.data.pages[index]
  108. var that = this
  109. var work_point_id = this.data.work_point_id
  110. http({
  111. url: 'orders/get',
  112. data: {
  113. project_id: this.data.id,
  114. status: status,
  115. page: page,
  116. work_point_id: work_point_id,
  117. keyword: this.data.keyword,
  118. type: 1
  119. },
  120. success: function (res) {
  121. if (res.code == 0) {
  122. var list = that.data.list
  123. var touchBottom = that.data.touchBottom
  124. list[index] = list[index].concat(res.data);
  125. if (res.data.length <= 0) {
  126. touchBottom[index] = true;
  127. }
  128. that.setData({
  129. touchBottom,
  130. list,
  131. isSearch: false
  132. })
  133. }
  134. }
  135. })
  136. },
  137. switchTab: function (e) {
  138. var index = e.currentTarget.dataset.index
  139. this.setData({
  140. tabIndex: index
  141. })
  142. wx.pageScrollTo({
  143. scrollTop: 0,
  144. duration: 300
  145. })
  146. this.search()
  147. },
  148. onChange: function (e) {
  149. var name = e.currentTarget.dataset.name
  150. this.setData({
  151. [name]: e.detail.value
  152. })
  153. },
  154. onDropChange: function(e) {
  155. var name = e.currentTarget.dataset.name
  156. this.setData({
  157. [name]: e.detail
  158. })
  159. if(name == 'work_point_id') {
  160. this.search()
  161. }
  162. },
  163. /**
  164. * 生命周期函数--监听页面初次渲染完成
  165. */
  166. onReady: function () {
  167. },
  168. /**
  169. * 生命周期函数--监听页面显示
  170. */
  171. onShow: function () {
  172. },
  173. /**
  174. * 生命周期函数--监听页面隐藏
  175. */
  176. onHide: function () {
  177. },
  178. /**
  179. * 生命周期函数--监听页面卸载
  180. */
  181. onUnload: function () {
  182. },
  183. /**
  184. * 页面相关事件处理函数--监听用户下拉动作
  185. */
  186. onPullDownRefresh: function () {
  187. },
  188. /**
  189. * 页面上拉触底事件的处理函数
  190. */
  191. onReachBottom: function () {
  192. var index = this.data.tabIndex
  193. if(!this.data.isSearch && !this.data.touchBottom[index]) {
  194. var pages = this.data.pages
  195. pages[index] = pages[index] + 1;
  196. this.setData({
  197. pages
  198. })
  199. this.getList()
  200. }
  201. if(this.data.touchBottom[index]) {
  202. util.error('没有更多数据了')
  203. }
  204. },
  205. /**
  206. * 用户点击右上角分享
  207. */
  208. onShareAppMessage: function () {
  209. }
  210. })