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. 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. is_draft: 2
  130. },
  131. success: function (res) {
  132. if (res.code == 0) {
  133. var list = that.data.list
  134. var touchBottom = that.data.touchBottom
  135. list[index] = list[index].concat(res.data);
  136. if (res.data.length <= 0) {
  137. touchBottom[index] = true;
  138. }
  139. that.setData({
  140. touchBottom,
  141. list,
  142. isSearch: false
  143. })
  144. }
  145. }
  146. })
  147. },
  148. switchTab: function (e) {
  149. var index = e.currentTarget.dataset.index
  150. this.setData({
  151. tabIndex: index
  152. })
  153. wx.pageScrollTo({
  154. scrollTop: 0,
  155. duration: 300
  156. })
  157. this.search()
  158. },
  159. onChange: function (e) {
  160. var name = e.currentTarget.dataset.name
  161. this.setData({
  162. [name]: e.detail.value
  163. })
  164. },
  165. /**
  166. * 生命周期函数--监听页面初次渲染完成
  167. */
  168. onReady: function () {
  169. },
  170. /**
  171. * 生命周期函数--监听页面显示
  172. */
  173. onShow: function () {
  174. },
  175. /**
  176. * 生命周期函数--监听页面隐藏
  177. */
  178. onHide: function () {
  179. },
  180. /**
  181. * 生命周期函数--监听页面卸载
  182. */
  183. onUnload: function () {
  184. },
  185. /**
  186. * 页面相关事件处理函数--监听用户下拉动作
  187. */
  188. onPullDownRefresh: function () {
  189. },
  190. /**
  191. * 页面上拉触底事件的处理函数
  192. */
  193. onReachBottom: function () {
  194. var index = this.data.tabIndex
  195. if(!this.data.isSearch && !this.data.touchBottom[index]) {
  196. var pages = this.data.pages
  197. pages[index] = pages[index] + 1;
  198. this.setData({
  199. pages
  200. })
  201. this.getList()
  202. }
  203. if(this.data.touchBottom[index]) {
  204. util.error('没有更多数据了')
  205. }
  206. },
  207. /**
  208. * 用户点击右上角分享
  209. */
  210. onShareAppMessage: function () {
  211. }
  212. })