|
|
@@ -1,10 +1,17 @@
|
|
|
// 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, // 加载状态
|
|
|
@@ -53,6 +60,7 @@ Page({
|
|
|
this.getNewEnergyPolicy();
|
|
|
this.getIntelligentService();
|
|
|
this.getPalletList();
|
|
|
+ this.getCheckinStatus();
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
@@ -285,4 +293,250 @@ Page({
|
|
|
palletListSearchWords: e.detail.value,
|
|
|
});
|
|
|
},
|
|
|
+ /**
|
|
|
+ * 获取签到状态
|
|
|
+ */
|
|
|
+ async getCheckinStatus() {
|
|
|
+ try {
|
|
|
+ let { data } = await getApi("/checkin/wx/checkin/status");
|
|
|
+ if (data && data.status === 0) {
|
|
|
+ this.setData(data.result);
|
|
|
+ } else {
|
|
|
+ wx.showToast({
|
|
|
+ title: data.msg || "获取签到状态失败",
|
|
|
+ icon: "none",
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.log(error);
|
|
|
+ wx.showToast({
|
|
|
+ title: "网络请求失败",
|
|
|
+ icon: "none",
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ async onSignIn() {
|
|
|
+ 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.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.data.locked) return;
|
|
|
+ wx.redirectTo({
|
|
|
+ url: "/pages/takeBill/takeBill",
|
|
|
+ });
|
|
|
+ },
|
|
|
});
|