takePhoto.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. // pages/takePhoto/takePhoto.js
  2. import { postApi, getApi } from "../../apis/api";
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. terminalServices: [], // 码头服务列表
  9. searchWords: "", // 搜索关键词
  10. loading: false, // 加载状态
  11. waterLevels: [], // 水位数据
  12. demolitionPolicy: [], // 拆解政策
  13. shipbuildingPolicy: [], // 造船政策
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad(options) {
  19. this.getTerminalServices();
  20. this.getWaterLevel();
  21. this.getNewEnergyPolicy();
  22. },
  23. /**
  24. * 生命周期函数--监听页面初次渲染完成
  25. */
  26. onReady() {},
  27. /**
  28. * 生命周期函数--监听页面显示
  29. */
  30. onShow() {
  31. if (typeof this.getTabBar === "function" && this.getTabBar()) {
  32. this.getTabBar().setData({
  33. selected: 0,
  34. });
  35. }
  36. },
  37. /**
  38. * 生命周期函数--监听页面隐藏
  39. */
  40. onHide() {},
  41. /**
  42. * 生命周期函数--监听页面卸载
  43. */
  44. onUnload() {},
  45. /**
  46. * 页面相关事件处理函数--监听用户下拉动作
  47. */
  48. onPullDownRefresh() {},
  49. /**
  50. * 页面上拉触底事件的处理函数
  51. */
  52. onReachBottom() {},
  53. /**
  54. * 用户点击右上角分享
  55. */
  56. onShareAppMessage() {},
  57. /**
  58. * 获取码头服务数据
  59. */
  60. getTerminalServices(searchWords = "") {
  61. this.setData({
  62. loading: true,
  63. });
  64. postApi("/pallet/terminal/services", {
  65. searchWords: searchWords,
  66. })
  67. .then((res) => {
  68. if (res.data && res.data.status === 0) {
  69. this.setData({
  70. terminalServices: res.data.result || [],
  71. loading: false,
  72. });
  73. } else {
  74. this.setData({
  75. loading: false,
  76. });
  77. wx.showToast({
  78. title: res.data.msg || "获取数据失败",
  79. icon: "none",
  80. });
  81. }
  82. })
  83. .catch((res) => {
  84. console.log(res);
  85. this.setData({
  86. loading: false,
  87. });
  88. wx.showToast({
  89. title: "网络请求失败",
  90. icon: "none",
  91. });
  92. });
  93. },
  94. /**
  95. * 搜索码头服务
  96. */
  97. searchTerminalServices() {
  98. this.getTerminalServices(this.data.searchWords);
  99. },
  100. /**
  101. * 输入框内容变化事件
  102. */
  103. onSearchInput(e) {
  104. this.setData({
  105. searchWords: e.detail.value,
  106. });
  107. },
  108. /**
  109. * 拨打电话
  110. */
  111. makePhoneCall(e) {
  112. const phone = e.currentTarget.dataset.phone;
  113. if (phone) {
  114. wx.makePhoneCall({
  115. phoneNumber: phone,
  116. });
  117. } else {
  118. wx.showToast({
  119. title: "电话号码不存在",
  120. icon: "none",
  121. });
  122. }
  123. },
  124. async getWaterLevel() {
  125. let { data } = await getApi("/pallet/water/level");
  126. if (data.status === 0) {
  127. // 判断data.result是数组内对象waterLevelFluctuation字段的第一个字符如果是负号,新增change字段的值为down,如果是正号,新增change字段的值为up,如果是0,新增change字段的值为zero
  128. data.result.forEach((item) => {
  129. if (item.waterLevelFluctuation[0] === "-") {
  130. item.change = "falling";
  131. item.changeIcon = "↓";
  132. }
  133. if (item.waterLevelFluctuation[0] === "+") {
  134. item.change = "rising";
  135. item.changeIcon = "↑";
  136. }
  137. if (item.waterLevelFluctuation[0] === "0") {
  138. item.change = "stable";
  139. }
  140. });
  141. this.setData({
  142. waterLevels: data.result,
  143. });
  144. } else {
  145. this.setData({
  146. waterLevels: [],
  147. });
  148. wx.showToast({
  149. title: data.msg,
  150. icon: "none",
  151. });
  152. }
  153. },
  154. async getNewEnergyPolicy() {
  155. let { data } = await getApi("/pallet/new/energy/subsidy/policy");
  156. if (data.status === 0) {
  157. this.setData({
  158. demolitionPolicy: data.result.demolitionPolicy,
  159. shipbuildingPolicy: data.result.shipbuildingPolicy,
  160. });
  161. } else {
  162. this.setData({
  163. demolitionPolicy: [],
  164. shipbuildingPolicy: [],
  165. });
  166. wx.showToast({
  167. title: data.msg,
  168. icon: "none",
  169. });
  170. }
  171. },
  172. });