电速宝
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. const api = require('../../api/index.js');
  2. Page({
  3. data: {
  4. tabsindex:"",
  5. driverlist:[],
  6. selected:1,
  7. userdata:[],
  8. pageNum: 1, // 当前页码
  9. pageSize: 10, // 每页条数
  10. loading: false, // 加载中状态(防止重复请求)
  11. noMoreData: false, // 是否无更多数据
  12. },
  13. onLoad() {
  14. // this.getdriver()
  15. this.setData({
  16. userdata:wx.getStorageSync('user')
  17. })
  18. wx.$on('wsMessage', this.toolWsMessage);
  19. },
  20. onUnload() {
  21. // 页面卸载时,取消订阅!
  22. wx.$off('wsMessage', this.toolWsMessage);
  23. },
  24. /**
  25. * 处理接收到的 WebSocket 消息
  26. * @param {Object} message 从 app.js 广播过来的消息对象
  27. */
  28. toolWsMessage(message) {
  29. console.log('Other Page 收到 WebSocket 消息:', message);
  30. // 根据消息类型进行不同的处
  31. switch (message.api) {
  32. case '/sysworkorder/selectworkorderlist':
  33. // 在这里可以更新地图、刷新UI等
  34. if (message.type==1) {
  35. this.getdriver()
  36. }
  37. break;
  38. case 'trajectoryInit':
  39. // 处理初始轨迹数据
  40. break;
  41. case 'heartbeatReply':
  42. // 心跳回复,通常不需要UI处理
  43. break;
  44. default:
  45. // 处理其他类型的消息
  46. break;
  47. }
  48. },
  49. onselected(e){
  50. console.log(e.currentTarget.dataset.index);
  51. this.setData({
  52. selected:e.currentTarget.dataset.index
  53. })
  54. this.getdriver()
  55. },
  56. getdriver(){
  57. // 设置加载中状态
  58. this.setData({ loading: true });
  59. let data ={
  60. }
  61. if (this.data.userdata.operationRole==4) {
  62. data ={
  63. workorderId:'',
  64. workorderName:'',
  65. addressId:'',
  66. driverId:'',
  67. carId:'',
  68. customerId:'',
  69. settlementType:'',
  70. workorderType:this.data.tabsindex,
  71. chargedischargeType:this.data.selected,
  72. pageNum: this.data.pageNum,
  73. pageSize: this.data.pageSize,
  74. }
  75. }else if(this.data.userdata.operationRole==5){
  76. data ={
  77. workorderId:'',
  78. workorderName:'',
  79. addressId:'',
  80. driverId:'',
  81. carId:'',
  82. customerId:'',
  83. settlementType:'',
  84. workorderType:this.data.tabsindex,
  85. chargedischargeType:1,
  86. pageNum: this.data.pageNum,
  87. pageSize: this.data.pageSize,
  88. }
  89. }else if(this.data.userdata.operationRole==6){
  90. data ={
  91. workorderId:'',
  92. workorderName:'',
  93. addressId:'',
  94. driverId:'',
  95. carId:'',
  96. customerId:'',
  97. settlementType:'',
  98. workorderType:this.data.tabsindex,
  99. chargedischargeType:2,
  100. pageNum: this.data.pageNum,
  101. pageSize: this.data.pageSize,
  102. }
  103. }
  104. if((this.data.userdata.operationRole==6||this.data.userdata.operationRole==5)&&this.data.selected==2){
  105. data ={
  106. workorderId:'',
  107. workorderName:'',
  108. addressId:'',
  109. driverId:'',
  110. carId:'',
  111. customerId:'',
  112. settlementType:this.data.tabsindex,
  113. workorderType:3,
  114. chargedischargeType:this.data.userdata.operationRole==5?1:2,
  115. pageNum: this.data.pageNum,
  116. pageSize: this.data.pageSize,
  117. }
  118. }
  119. api.request(`/sysworkorder/selectworkorderlist`, 'post',data,{ isPublic: false })
  120. .then((res) => {
  121. console.log(res.data);
  122. if (res.code==200) {
  123. const data = res.data.list; //data(当前页数据)
  124. const total = res.data.total; // total(总条数)
  125. console.log(data);
  126. // 拼接新数据
  127. const newList = this.data.pageNum === 1 ? data : [...this.data.driverlist, ...data];
  128. console.log(newList);
  129. // 判断是否有更多数据
  130. const noMoreData = newList.length >= total;
  131. // const noMoreData = false;
  132. this.setData({
  133. driverlist: newList,
  134. noMoreData:noMoreData,
  135. });
  136. // 无论成功失败,结束加载状态
  137. this.setData({ loading: false });
  138. // this.setData({
  139. // driverlist:data.data
  140. // })
  141. }
  142. // wx.navigateTo({
  143. // url: '/pages/map/index',
  144. // })
  145. })
  146. .catch((err) => {
  147. wx.showToast({
  148. title: '加载失败',
  149. icon: 'none',
  150. });
  151. // 失败时页码回退(避免下次触底页码错误)
  152. this.setData({ pageNum: this.data.pageNum - 1 });
  153. // 无论成功失败,结束加载状态
  154. this.setData({ loading: false });
  155. console.error('请求失败:', err);
  156. });
  157. },
  158. // 选项卡
  159. onTabsChange(e){
  160. console.log(e.detail.value);
  161. this.setData({
  162. tabsindex:e.detail.value,
  163. })
  164. this.getdriver()
  165. // this.gitreview()
  166. },
  167. details(e){
  168. console.log(e.currentTarget.dataset.id);
  169. wx.navigateTo({
  170. url: `/package-map/pages/map/index?id=${e.currentTarget.dataset.id}`,
  171. })
  172. },
  173. onShow() {
  174. this.getdriver()
  175. },
  176. /**
  177. * 页面相关事件处理函数--监听用户下拉动作
  178. */
  179. onPullDownRefresh() {
  180. this.getdriver()
  181. console.log('监听用户下拉动作');
  182. },
  183. /**
  184. * 监听页面触底事件
  185. */
  186. onReachBottom() {
  187. console.log(this.data.loading);
  188. console.log(this.data.noMoreData);
  189. // 防止重复加载(加载中/无更多数据时不触发)
  190. if (this.data.loading || this.data.noMoreData) return;
  191. // 页码+1
  192. this.setData({ pageNum: this.data.pageNum + 1 });
  193. // 加载下一页数据
  194. this.getdriver()
  195. }
  196. });
  197. //