| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515 |
- // pages/takePhoto/takePhoto.js
- import { uploadFile } from "../../utils/upload";
- import { postApi, getApi } from "../../apis/api";
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- checkinStatus: 0, // 签到状态
- checkinDatetime: "",
- checkinDesc: "",
- shipOwnerId: 0,
- locked: false, // 锁定状态
- terminalServices: [], // 码头服务列表
- terminalSearchWords: "", // 搜索关键词
- loading: false, // 加载状态
- waterLevels: [], // 水位数据
- demolitionPolicy: [], // 拆解政策
- shipbuildingPolicy: [], // 造船政策
- shipAnnualInspection: [],
- shipCertificate: [],
- shipCrewCertificate: [],
- certOperationContact: [],
- palletList: [
- {
- id: 5,
- cargoName: "222",
- loadPortName: "2",
- dischargePortName: "3",
- cargoTons: 4,
- contactName: "5",
- contactPhone: "13666666666",
- status: 1,
- releaseTime: "2025/05/08 19:52:33",
- createTime: "2025/05/07 23:36:26",
- },
- {
- id: 6,
- cargoName: "测试1",
- loadPortName: "上海",
- dischargePortName: "张家港",
- cargoTons: 111,
- contactName: "11",
- contactPhone: "11111111111",
- status: 1,
- releaseTime: "2025/05/08 19:52:14",
- createTime: "2025/05/08 11:06:03",
- },
- ],
- palletListSearchWords: "", // 货盘搜索关键词
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- this.getTerminalServices();
- this.getWaterLevel();
- this.getNewEnergyPolicy();
- this.getIntelligentService();
- this.getPalletList();
- this.getCheckinStatus();
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {},
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- if (typeof this.getTabBar === "function" && this.getTabBar()) {
- this.getTabBar().setData({
- selected: 0,
- });
- }
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {},
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {},
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {},
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {},
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {},
- /**
- * 获取码头服务数据
- */
- getTerminalServices(terminalSearchWords = "") {
- this.setData({
- loading: true,
- });
- postApi("/pallet/terminal/services", {
- searchWords: terminalSearchWords,
- })
- .then((res) => {
- if (res.data && res.data.status === 0) {
- this.setData({
- terminalServices: res.data.result || [],
- loading: false,
- });
- } else {
- this.setData({
- loading: false,
- });
- }
- })
- .catch((res) => {
- this.setData({
- loading: false,
- });
- });
- },
- /**
- * 搜索码头服务
- */
- searchTerminalServices() {
- this.getTerminalServices(this.data.terminalSearchWords);
- },
- /**
- * 输入框内容变化事件
- */
- onSearchInput(e) {
- this.setData({
- terminalSearchWords: 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: [],
- });
- }
- },
- 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: [],
- });
- }
- },
- // 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: [],
- });
- }
- },
- /**
- * 获取货盘列表数据
- */
- async getPalletList(palletListSearchWords = "") {
- this.setData({
- loading: true,
- });
- try {
- let { data } = await postApi("/pallet/list", {
- searchWords: palletListSearchWords,
- });
- if (data && data.status === 0) {
- this.setData({
- palletList: data.result || [],
- loading: false,
- });
- } else {
- this.setData({
- loading: false,
- palletList: [],
- });
- }
- } catch (error) {
- console.log(error);
- this.setData({
- loading: false,
- });
- }
- },
- /**
- * 搜索货盘列表
- */
- searchPalletList() {
- this.getPalletList(this.data.palletListSearchWords);
- },
- /**
- * 货盘搜索输入框内容变化事件
- */
- onPalletSearchInput(e) {
- this.setData({
- palletListSearchWords: e.detail.value,
- });
- },
- /**
- * 获取签到状态
- */
- async getCheckinStatus() {
- try {
- let { data } = await getApi("/checkin/wx/checkin/status");
- if (data && data.status === 0) {
- this.setData(data.result);
- }
- } catch (error) {}
- },
- checkToken() {
- if (!wx.getStorageSync("accessToken")) {
- wx.showToast({
- title: "尚未登录,正在体验",
- icon: "none",
- });
- return false;
- }
- return true;
- },
- async onSignIn() {
- if (!this.checkToken()) return;
- if (this.data.checkinStatus == 1) return;
- if (this.data.locked) {
- wx.showLoading({
- title: "高精度定位中...",
- });
- return;
- }
- this.data.locked = true;
- wx.getLocation({
- type: "gcj02",
- isHighAccuracy: true,
- success: async (e) => {
- let { latitude, longitude } = e;
- let { data } = await postApi("/checkin", {
- latitude,
- longitude,
- });
- this.setData(data.result);
- if (data.status == 0) {
- wx.showToast({
- title: data.msg,
- icon: "success",
- duration: 2000,
- mask: true,
- });
- // 更新签到状态
- this.getCheckinStatus();
- }
- },
- complete: (e) => {
- wx.hideLoading({});
- this.data.locked = false;
- },
- });
- },
- async takePhoto(e) {
- if (!this.checkToken()) return;
- if (this.data.locked) {
- wx.showLoading({
- title: "高精度定位中...",
- });
- return;
- }
- this.data.locked = true;
- let { mediatype } = e.currentTarget.dataset;
- wx.getLocation({
- type: "gcj02",
- isHighAccuracy: true,
- success: (e) => {
- let { latitude, longitude } = e;
- console.log("获取定位成功!", e);
- this.data.latitude = latitude;
- this.data.longitude = longitude;
- wx.setStorageSync("latitude", latitude);
- wx.setStorageSync("longitude", longitude);
- wx.chooseMedia({
- mediaType: ["image"],
- sourceType: ["camera"],
- success: (e) => {
- console.log("获取媒体成功!", e);
- let src = e.tempFiles[0].tempFilePath;
- if (e.type == "video") {
- wx.showLoading({
- title: "正在压缩...",
- });
- wx.compressVideo({
- src,
- quality: "high",
- bitrate: "",
- fps: "",
- resolution: "",
- success: async (e) => {
- if (wx.getStorageSync("userName")) {
- wx.showLoading({
- title: "正在上传...",
- });
- let res = await uploadFile(e.tempFilePath, {
- type: 4,
- userId: wx.getStorageSync("userId"),
- location: `${this.data.longitude},${this.data.latitude}`,
- });
- if (res.status == 0) {
- console.log(res);
- wx.showToast({
- title: res.msg,
- });
- wx.redirectTo({
- url: "/pages/takePhoto/success/success",
- });
- } else {
- wx.showToast({
- title: res.msg,
- });
- }
- } else {
- // 新用户视频
- wx.hideLoading({
- success: (res) => {},
- });
- console.log("新用户视频", e);
- wx.setStorageSync("type", 2);
- wx.setStorageSync("file", e.tempFilePath);
- wx.redirectTo({
- url: `/pages/newCachePage/newCachePage`,
- });
- }
- },
- fail: (e) => {
- console.log(e);
- },
- });
- } else {
- wx.compressImage({
- src,
- quality: 80, // 压缩质量
- success: async (e) => {
- console.log("图片压缩成功!", e);
- wx.hideLoading({
- success: (res) => {},
- });
- if (wx.getStorageSync("userName")) {
- wx.showLoading({
- title: "正在上传...",
- });
- let postData = {
- type: mediatype,
- userId: wx.getStorageSync("userId"),
- };
- if (mediatype == 3) {
- postData.location = `${this.data.longitude},${this.data.latitude}`;
- } else {
- postData.location = "";
- }
- let res = await uploadFile(e.tempFilePath, postData);
- console.log("上传结束", res);
- if (res.status == 0) {
- wx.showToast({
- title: res.msg,
- });
- wx.setStorageSync("shareImageUrl", res.result.viewUrl);
- console.log(wx.getStorageSync("shareImageUrl"));
- wx.downloadFile({
- url: res.result.viewUrl,
- success: (e) => {
- console.log("下载调用!", e);
- wx.setStorageSync("cacheImage", e.tempFilePath);
- if (mediatype == 3) {
- wx.saveImageToPhotosAlbum({
- filePath: e.tempFilePath,
- success: (e) => {
- if (e.errMsg == "saveImageToPhotosAlbum:ok") {
- wx.showToast({
- title: "保存成功!",
- });
- wx.removeStorageSync("cacheImage");
- }
- },
- fail: (e) => {
- console.log("失败4", e);
- this.setData({
- authModal: true,
- modalText: "文件存储",
- });
- },
- });
- }
- wx.redirectTo({
- url: "/pages/takePhoto/success/success",
- });
- },
- fail: (e) => {
- console.log("失败3", e);
- },
- });
- } else {
- wx.showToast({
- title: res.msg,
- });
- }
- } else {
- // 新用户图片
- console.log("新用户图片", e);
- wx.setStorageSync("type", 1);
- wx.setStorageSync("file", e.tempFilePath);
- wx.redirectTo({
- url: `/pages/newCachePage/newCachePage`,
- });
- }
- },
- fail: (e) => {
- console.log("失败2", e);
- },
- });
- }
- },
- fail: (e) => {
- console.log("失败1", e);
- },
- });
- },
- fail: (e) => {
- this.setData({
- authModal: true,
- modalText: "位置信息",
- });
- },
- complete: (e) => {
- wx.hideLoading({
- success: (res) => {},
- });
- this.data.locked = false;
- },
- });
- },
- takeBill() {
- if (!this.checkToken()) return;
- if (this.data.locked) return;
- wx.redirectTo({
- url: "/pages/takeBill/takeBill",
- });
- },
- });
|