index.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. is_draft: 2
  120. },
  121. success: function (res) {
  122. if (res.code == 0) {
  123. var list = that.data.list
  124. var touchBottom = that.data.touchBottom
  125. list[index] = list[index].concat(res.data);
  126. if (res.data.length <= 0) {
  127. touchBottom[index] = true;
  128. }
  129. that.setData({
  130. touchBottom,
  131. list,
  132. isSearch: false
  133. })
  134. }
  135. }
  136. })
  137. },
  138. switchTab: function (e) {
  139. var index = e.currentTarget.dataset.index
  140. this.setData({
  141. tabIndex: index
  142. })
  143. wx.pageScrollTo({
  144. scrollTop: 0,
  145. duration: 300
  146. })
  147. this.search()
  148. },
  149. onChange: function (e) {
  150. var name = e.currentTarget.dataset.name
  151. this.setData({
  152. [name]: e.detail.value
  153. })
  154. },
  155. onDropChange: function(e) {
  156. var name = e.currentTarget.dataset.name
  157. this.setData({
  158. [name]: e.detail
  159. })
  160. if(name == 'work_point_id') {
  161. this.search()
  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. })