takePhoto.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. // pages/takePhoto/takePhoto.js
  2. import { postApi, getApi } from "../../apis/api";
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. terminalServices: [], // 码头服务列表
  9. terminalSearchWords: "", // 搜索关键词
  10. loading: false, // 加载状态
  11. waterLevels: [], // 水位数据
  12. demolitionPolicy: [], // 拆解政策
  13. shipbuildingPolicy: [], // 造船政策
  14. shipAnnualInspection: [],
  15. shipCertificate: [],
  16. shipCrewCertificate: [],
  17. certOperationContact: [],
  18. palletList: [
  19. {
  20. id: 5,
  21. cargoName: "222",
  22. loadPortName: "2",
  23. dischargePortName: "3",
  24. cargoTons: 4,
  25. contactName: "5",
  26. contactPhone: "13666666666",
  27. status: 1,
  28. releaseTime: "2025/05/08 19:52:33",
  29. createTime: "2025/05/07 23:36:26",
  30. },
  31. {
  32. id: 6,
  33. cargoName: "测试1",
  34. loadPortName: "上海",
  35. dischargePortName: "张家港",
  36. cargoTons: 111,
  37. contactName: "11",
  38. contactPhone: "11111111111",
  39. status: 1,
  40. releaseTime: "2025/05/08 19:52:14",
  41. createTime: "2025/05/08 11:06:03",
  42. },
  43. ],
  44. palletListSearchWords: "", // 货盘搜索关键词
  45. },
  46. /**
  47. * 生命周期函数--监听页面加载
  48. */
  49. onLoad(options) {
  50. this.getTerminalServices();
  51. this.getWaterLevel();
  52. this.getNewEnergyPolicy();
  53. this.getIntelligentService();
  54. this.getPalletList();
  55. },
  56. /**
  57. * 生命周期函数--监听页面初次渲染完成
  58. */
  59. onReady() {},
  60. /**
  61. * 生命周期函数--监听页面显示
  62. */
  63. onShow() {
  64. if (typeof this.getTabBar === "function" && this.getTabBar()) {
  65. this.getTabBar().setData({
  66. selected: 0,
  67. });
  68. }
  69. },
  70. /**
  71. * 生命周期函数--监听页面隐藏
  72. */
  73. onHide() {},
  74. /**
  75. * 生命周期函数--监听页面卸载
  76. */
  77. onUnload() {},
  78. /**
  79. * 页面相关事件处理函数--监听用户下拉动作
  80. */
  81. onPullDownRefresh() {},
  82. /**
  83. * 页面上拉触底事件的处理函数
  84. */
  85. onReachBottom() {},
  86. /**
  87. * 用户点击右上角分享
  88. */
  89. onShareAppMessage() {},
  90. /**
  91. * 获取码头服务数据
  92. */
  93. getTerminalServices(terminalSearchWords = "") {
  94. this.setData({
  95. loading: true,
  96. });
  97. postApi("/pallet/terminal/services", {
  98. searchWords: terminalSearchWords,
  99. })
  100. .then((res) => {
  101. if (res.data && res.data.status === 0) {
  102. this.setData({
  103. terminalServices: res.data.result || [],
  104. loading: false,
  105. });
  106. } else {
  107. this.setData({
  108. loading: false,
  109. });
  110. wx.showToast({
  111. title: res.data.msg || "获取数据失败",
  112. icon: "none",
  113. });
  114. }
  115. })
  116. .catch((res) => {
  117. console.log(res);
  118. this.setData({
  119. loading: false,
  120. });
  121. wx.showToast({
  122. title: "网络请求失败",
  123. icon: "none",
  124. });
  125. });
  126. },
  127. /**
  128. * 搜索码头服务
  129. */
  130. searchTerminalServices() {
  131. this.getTerminalServices(this.data.terminalSearchWords);
  132. },
  133. /**
  134. * 输入框内容变化事件
  135. */
  136. onSearchInput(e) {
  137. this.setData({
  138. terminalSearchWords: e.detail.value,
  139. });
  140. },
  141. /**
  142. * 拨打电话
  143. */
  144. makePhoneCall(e) {
  145. const phone = e.currentTarget.dataset.phone;
  146. if (phone) {
  147. wx.makePhoneCall({
  148. phoneNumber: phone,
  149. });
  150. } else {
  151. wx.showToast({
  152. title: "电话号码不存在",
  153. icon: "none",
  154. });
  155. }
  156. },
  157. async getWaterLevel() {
  158. let { data } = await getApi("/pallet/water/level");
  159. if (data.status === 0) {
  160. // 判断data.result是数组内对象waterLevelFluctuation字段的第一个字符如果是负号,新增change字段的值为down,如果是正号,新增change字段的值为up,如果是0,新增change字段的值为zero
  161. data.result.forEach((item) => {
  162. if (item.waterLevelFluctuation[0] === "-") {
  163. item.change = "falling";
  164. item.changeIcon = "↓";
  165. }
  166. if (item.waterLevelFluctuation[0] === "+") {
  167. item.change = "rising";
  168. item.changeIcon = "↑";
  169. }
  170. if (item.waterLevelFluctuation[0] === "0") {
  171. item.change = "stable";
  172. }
  173. });
  174. this.setData({
  175. waterLevels: data.result,
  176. });
  177. } else {
  178. this.setData({
  179. waterLevels: [],
  180. });
  181. wx.showToast({
  182. title: data.msg,
  183. icon: "none",
  184. });
  185. }
  186. },
  187. async getNewEnergyPolicy() {
  188. let { data } = await getApi("/pallet/new/energy/subsidy/policy");
  189. if (data.status === 0) {
  190. this.setData({
  191. demolitionPolicy: data.result.demolitionPolicy,
  192. shipbuildingPolicy: data.result.shipbuildingPolicy,
  193. });
  194. } else {
  195. this.setData({
  196. demolitionPolicy: [],
  197. shipbuildingPolicy: [],
  198. });
  199. wx.showToast({
  200. title: data.msg,
  201. icon: "none",
  202. });
  203. }
  204. },
  205. // intelligent/service获取智能服务
  206. async getIntelligentService() {
  207. let { data } = await postApi("/pallet/intelligent/service", {});
  208. if (data.status === 0) {
  209. this.setData(data.result);
  210. } else {
  211. this.setData({
  212. shipAnnualInspection: [],
  213. shipCertificate: [],
  214. shipCrewCertificate: [],
  215. certOperationContact: [],
  216. });
  217. wx.showToast({
  218. title: data.msg,
  219. });
  220. }
  221. },
  222. /**
  223. * 获取货盘列表数据
  224. */
  225. async getPalletList(palletListSearchWords = "") {
  226. this.setData({
  227. loading: true,
  228. });
  229. try {
  230. let { data } = await postApi("/pallet/list", {
  231. searchWords: palletListSearchWords,
  232. });
  233. if (data && data.status === 0) {
  234. this.setData({
  235. palletList: data.result || [],
  236. loading: false,
  237. });
  238. } else {
  239. this.setData({
  240. loading: false,
  241. palletList: [],
  242. });
  243. wx.showToast({
  244. title: data.msg || "获取数据失败",
  245. icon: "none",
  246. });
  247. }
  248. } catch (error) {
  249. console.log(error);
  250. this.setData({
  251. loading: false,
  252. });
  253. wx.showToast({
  254. title: "网络请求失败",
  255. icon: "none",
  256. });
  257. }
  258. },
  259. /**
  260. * 搜索货盘列表
  261. */
  262. searchPalletList() {
  263. this.getPalletList(this.data.palletListSearchWords);
  264. },
  265. /**
  266. * 货盘搜索输入框内容变化事件
  267. */
  268. onPalletSearchInput(e) {
  269. this.setData({
  270. palletListSearchWords: e.detail.value,
  271. });
  272. },
  273. });