takePhoto.js 4.6 KB

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