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