index.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. // pages/car/index.js
  2. const app = getApp()
  3. var startPoint
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. str:' ',
  10. str2: ' ',
  11. //按钮位置参数
  12. safeAreaHeight: 0, //底部安全区域的高度
  13. buttonTop: 0,
  14. buttonLeft: 0,
  15. windowHeight: '',
  16. windowWidth: '',
  17. loginStatus: wx.getStorageSync('loginStatus') ? wx.getStorageSync('loginStatus') : false,
  18. roleCodeList: wx.getStorageSync('roleCodeList') ? wx.getStorageSync('roleCodeList') : [],
  19. searchVal: '',
  20. //分页
  21. limit: 10,
  22. requestStatu: '加载中...',
  23. page: 1,
  24. totalPages: 1,
  25. more: false,
  26. nomore: '',
  27. resData:[],
  28. },
  29. /**
  30. * 生命周期函数--监听页面加载
  31. */
  32. onLoad(options) {
  33. this.setData({
  34. safeAreaHeight: app.globalData.windowInfo.screenHeight - app.globalData.systemInfo.safeArea.bottom
  35. })
  36. //获取页面高度设置新增按钮的初始位置
  37. var that = this;
  38. wx.getSystemInfo({
  39. success: function (res) {
  40. // 高度,宽度 单位为px
  41. that.setData({
  42. windowHeight: res.windowHeight, //屏幕宽度、高度
  43. windowWidth: res.windowWidth,
  44. buttonTop: res.windowHeight * 0.8 - that.data.safeAreaHeight-50, //这里定义按钮的初始位置
  45. buttonLeft: res.windowWidth * 0.80, //这里定义按钮的初始位置
  46. })
  47. }
  48. })
  49. },
  50. /**
  51. * 生命周期函数--监听页面初次渲染完成
  52. */
  53. onReady() {
  54. },
  55. /**
  56. * 生命周期函数--监听页面显示
  57. */
  58. onShow() {
  59. this.setData({
  60. requestStatu:'加载中...',
  61. loginStatus: wx.getStorageSync('loginStatus') ? wx.getStorageSync('loginStatus') : false
  62. })
  63. if (wx.getStorageSync('loginStatus')) {
  64. this.getListFun();
  65. }
  66. },
  67. //搜索框请求S
  68. onChange(e) {
  69. this.setData({
  70. searchVal: e.detail,
  71. });
  72. },
  73. onSearch: function (event) {
  74. this.setData({
  75. searchVal: event.detail
  76. })
  77. this.getListFun();
  78. },
  79. onCancel: function () {
  80. this.setData({})
  81. },
  82. toSearch: function (event) {
  83. this.getListFun();
  84. },
  85. //列表
  86. getListFun: function () {
  87. this.setData({
  88. page: 1
  89. })
  90. let params = {
  91. current : this.data.page,
  92. size : this.data.limit,
  93. shipNumber: this.data.searchVal
  94. }
  95. app.request.pageFirst({
  96. url: app.API.shipPage,
  97. page: this,
  98. params: params,
  99. })
  100. },
  101. //页面跳转
  102. toLink: function (e) {
  103. let { url } = e.currentTarget.dataset
  104. wx.navigateTo({
  105. url: url
  106. })
  107. },
  108. //删除
  109. delFun: function (e) {
  110. let _this = this
  111. let { id, shipNumber } = e.currentTarget.dataset
  112. wx.showModal({
  113. title: '提示!',
  114. content: `删除【${shipNumber}】后不可恢复。确定要删除吗?`,
  115. confirmColor: '#FF5B5B',
  116. success: function (res) {
  117. if (res.confirm) {
  118. app.request.POST({
  119. url: app.API.shipDelete,
  120. params: [{
  121. id: id
  122. }],
  123. page: _this,
  124. isLoadingTxt: '删除中...',
  125. successFun: true
  126. }).then(res => {
  127. wx.showToast({
  128. title: '删除成功',
  129. icon: 'success',
  130. duration: 1000,
  131. mask: true
  132. })
  133. _this.getListFun(); //刷新列表
  134. })
  135. } else if (res.cancel) {
  136. }
  137. }
  138. })
  139. },
  140. //启用关闭车辆
  141. changeStatus: function (e) {
  142. let _this = this
  143. let { id, shipNumber, status } = e.currentTarget.dataset
  144. let text = status== '1'?'开启':'关闭'
  145. wx.showModal({
  146. title: '提示!',
  147. content: `${text}【${shipNumber}】船舶?`,
  148. confirmColor: '#FF5B5B',
  149. success: function (res) {
  150. if (res.confirm) {
  151. app.request.POST({
  152. url: app.API.shipEdit,
  153. params: {
  154. id: id,
  155. status:status
  156. },
  157. page: _this,
  158. isLoadingTxt: '操作中...',
  159. successFun: true
  160. }).then(res => {
  161. wx.showToast({
  162. title: '操作成功',
  163. icon: 'success',
  164. duration: 1000,
  165. mask: true
  166. })
  167. _this.getListFun(); //刷新列表
  168. })
  169. } else if (res.cancel) {
  170. }
  171. }
  172. })
  173. },
  174. //业务员进行确认
  175. comform: function (e) {
  176. let _this = this
  177. let { id, orderNumber } = e.currentTarget.dataset
  178. wx.showModal({
  179. title: '提示!',
  180. content: `确认【${orderNumber}】后不可取消。确定现在确认订单吗?`,
  181. confirmColor: '#FF5B5B',
  182. success: function (res) {
  183. if (res.confirm) {
  184. app.request.POST({
  185. url: app.API.orderConfirm,
  186. params: {
  187. id: id
  188. },
  189. page: _this,
  190. isLoadingTxt: '确认中...',
  191. successFun: true
  192. }).then(res => {
  193. wx.showToast({
  194. title: '确认成功',
  195. icon: 'success',
  196. duration: 1000,
  197. mask: true
  198. })
  199. _this.getListFun(); //刷新列表
  200. })
  201. } else if (res.cancel) {
  202. }
  203. }
  204. })
  205. },
  206. // 单选
  207. dangerStatusChange: function (e) {
  208. this.setData({
  209. [e.currentTarget.dataset.radiotype]: e.detail.value
  210. })
  211. if (e.detail.value == '1') {
  212. this.setData({
  213. appointmentReason: ''
  214. })
  215. }
  216. },
  217. //结束
  218. endFun: function (e) {
  219. let _this = this
  220. let { id, orderNumber } = e.currentTarget.dataset
  221. wx.showModal({
  222. title: '提示!',
  223. content: `结束【${orderNumber}】订单后不可取消。确定现在结束订单吗?`,
  224. confirmColor: '#FF5B5B',
  225. success: function (res) {
  226. if (res.confirm) {
  227. app.request.POST({
  228. url: app.API.orderEnd,
  229. params: {
  230. id: id
  231. },
  232. page: _this,
  233. isLoadingTxt: '操作中...',
  234. successFun: true
  235. }).then(res => {
  236. wx.showToast({
  237. title: '结束成功',
  238. icon: 'success',
  239. duration: 1000,
  240. mask: true
  241. })
  242. _this.getListFun(); //刷新列表
  243. })
  244. } else if (res.cancel) {
  245. }
  246. }
  247. })
  248. },
  249. //扫码预约申请
  250. changeAdd() {
  251. wx.navigateTo({
  252. url: 'add'
  253. })
  254. },
  255. /**
  256. * 生命周期函数--监听页面隐藏
  257. */
  258. onHide() {
  259. },
  260. /**
  261. * 生命周期函数--监听页面卸载
  262. */
  263. onUnload() {
  264. },
  265. /**
  266. * 页面相关事件处理函数--监听用户下拉动作
  267. */
  268. onPullDownRefresh: function () {
  269. this.setData({
  270. searchVal: ''
  271. })
  272. if (wx.getStorageSync('loginStatus')) {
  273. this.getListFun();
  274. } else {
  275. wx.stopPullDownRefresh();
  276. }
  277. },
  278. /**
  279. * 页面上拉触底事件的处理函数
  280. */
  281. onReachBottom: function () {
  282. this.data.page++;
  283. let params = {
  284. current : this.data.page,
  285. size : this.data.limit,
  286. shipNumber: this.data.searchVal
  287. }
  288. app.request.pageOther({
  289. url: app.API.bizvehicleList,
  290. page: this,
  291. params: params,
  292. loadType: true //加载类型,是否是下拉加载
  293. });
  294. },
  295. //以下是按钮拖动事件
  296. buttonStart: function (e) {
  297. startPoint = e.touches[0] //获取拖动开始点
  298. },
  299. buttonMove: function (e) {
  300. var endPoint = e.touches[e.touches.length - 1] //获取拖动结束点
  301. //计算在X轴上拖动的距离和在Y轴上拖动的距离
  302. var translateX = endPoint.clientX - startPoint.clientX
  303. var translateY = endPoint.clientY - startPoint.clientY
  304. startPoint = endPoint //重置开始位置
  305. var buttonTop = this.data.buttonTop + translateY
  306. var buttonLeft = this.data.buttonLeft + translateX
  307. //判断是移动否超出屏幕
  308. if (buttonLeft + 50 >= this.data.windowWidth) {
  309. buttonLeft = this.data.windowWidth - 50;
  310. }
  311. if (buttonLeft <= 0) {
  312. buttonLeft = 0;
  313. }
  314. if (buttonTop <= this.data.filterHeight) {
  315. buttonTop = this.data.filterHeight
  316. }
  317. if (buttonTop + 50 + 48 + this.data.safeAreaHeight >= this.data.windowHeight) {
  318. buttonTop = this.data.windowHeight - 50 - 48 - this.data.safeAreaHeight;
  319. }
  320. this.setData({
  321. buttonTop: buttonTop,
  322. buttonLeft: buttonLeft
  323. })
  324. },
  325. buttonEnd: function (e) {},
  326. /**
  327. * 用户点击右上角分享
  328. */
  329. onShareAppMessage() {
  330. }
  331. })