| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- // pages/takePhoto/takePhoto.js
- import { postApi, getApi } from "../../apis/api";
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- terminalServices: [], // 码头服务列表
- searchWords: "", // 搜索关键词
- loading: false, // 加载状态
- waterLevels: [], // 水位数据
- demolitionPolicy: [], // 拆解政策
- shipbuildingPolicy: [], // 造船政策
- shipAnnualInspection: [],
- shipCertificate: [],
- shipCrewCertificate: [],
- certOperationContact: [],
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- this.getTerminalServices();
- this.getWaterLevel();
- this.getNewEnergyPolicy();
- this.getIntelligentService();
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {},
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- if (typeof this.getTabBar === "function" && this.getTabBar()) {
- this.getTabBar().setData({
- selected: 0,
- });
- }
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {},
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {},
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {},
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {},
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {},
- /**
- * 获取码头服务数据
- */
- getTerminalServices(searchWords = "") {
- this.setData({
- loading: true,
- });
- postApi("/pallet/terminal/services", {
- searchWords: searchWords,
- })
- .then((res) => {
- if (res.data && res.data.status === 0) {
- this.setData({
- terminalServices: res.data.result || [],
- loading: false,
- });
- } else {
- this.setData({
- loading: false,
- });
- wx.showToast({
- title: res.data.msg || "获取数据失败",
- icon: "none",
- });
- }
- })
- .catch((res) => {
- console.log(res);
- this.setData({
- loading: false,
- });
- wx.showToast({
- title: "网络请求失败",
- icon: "none",
- });
- });
- },
- /**
- * 搜索码头服务
- */
- searchTerminalServices() {
- this.getTerminalServices(this.data.searchWords);
- },
- /**
- * 输入框内容变化事件
- */
- onSearchInput(e) {
- this.setData({
- searchWords: e.detail.value,
- });
- },
- /**
- * 拨打电话
- */
- makePhoneCall(e) {
- const phone = e.currentTarget.dataset.phone;
- if (phone) {
- wx.makePhoneCall({
- phoneNumber: phone,
- });
- } else {
- wx.showToast({
- title: "电话号码不存在",
- icon: "none",
- });
- }
- },
- async getWaterLevel() {
- let { data } = await getApi("/pallet/water/level");
- if (data.status === 0) {
- // 判断data.result是数组内对象waterLevelFluctuation字段的第一个字符如果是负号,新增change字段的值为down,如果是正号,新增change字段的值为up,如果是0,新增change字段的值为zero
- data.result.forEach((item) => {
- if (item.waterLevelFluctuation[0] === "-") {
- item.change = "falling";
- item.changeIcon = "↓";
- }
- if (item.waterLevelFluctuation[0] === "+") {
- item.change = "rising";
- item.changeIcon = "↑";
- }
- if (item.waterLevelFluctuation[0] === "0") {
- item.change = "stable";
- }
- });
- this.setData({
- waterLevels: data.result,
- });
- } else {
- this.setData({
- waterLevels: [],
- });
- wx.showToast({
- title: data.msg,
- icon: "none",
- });
- }
- },
- async getNewEnergyPolicy() {
- let { data } = await getApi("/pallet/new/energy/subsidy/policy");
- if (data.status === 0) {
- this.setData({
- demolitionPolicy: data.result.demolitionPolicy,
- shipbuildingPolicy: data.result.shipbuildingPolicy,
- });
- } else {
- this.setData({
- demolitionPolicy: [],
- shipbuildingPolicy: [],
- });
- wx.showToast({
- title: data.msg,
- icon: "none",
- });
- }
- },
- // intelligent/service获取智能服务
- async getIntelligentService() {
- let { data } = await postApi("/pallet/intelligent/service", {});
- if (data.status === 0) {
- this.setData(data.result);
- } else {
- this.setData({
- shipAnnualInspection: [],
- shipCertificate: [],
- shipCrewCertificate: [],
- certOperationContact: [],
- });
- wx.showToast({
- title: data.msg,
- });
- }
- },
- });
|