| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433 |
- import { uploadFile } from "../../utils/upload";
- import { subMsg } from "../../utils/wxUtils";
- import { postApi, getApi } from "../../apis/api";
- Page({
- data: {
- sign: "https://frontend-1255802371.cos.ap-shanghai.myqcloud.com/sign.png",
- avater_exp:
- "https://frontend-1255802371.cos.ap-shanghai.myqcloud.com/miniapp-static/avatar-icon.jpg?sign=f5c66c94d189436f82353eb48cb01f08&t=1634538864",
- cameraIcon:
- "https://frontend-1255802371.cos.ap-shanghai.myqcloud.com/miniapp-static/camera-icon.png?sign=11a65871a2800cd04ecaa8991687fccd&t=1634607415",
- newCameraIcon:
- "https://frontend-1255802371.cos.ap-shanghai.myqcloud.com/miniapp-static/camera.png?sign=ad0fe8bead6a46cb20f45f792d4bed67&t=1645502416",
- userName: "",
- phone: "",
- shipName: "",
- shipMmsi: "",
- authModal: false,
- modalText: "位置",
- shipId: "",
- locked: false,
- certs: [],
- contacts: [],
- oilPriceList: [],
- },
- async getCerts() {
- let { data } = await postApi("/ship/cert/list", {
- userId: wx.getStorageSync("userId"),
- });
- if (data.status === 0) {
- this.setData({
- certs: data.result,
- });
- } else {
- this.setData({
- certs: [],
- });
- wx.showToast({
- title: data.msg,
- icon: "none",
- });
- }
- },
- async getContacts() {
- let { data } = await getApi("/ship/cert/operation/contacts");
- if (data.status === 0) {
- this.setData({
- contacts: data.result,
- });
- } else {
- this.setData({
- contacts: [],
- });
- wx.showToast({
- title: data.msg,
- icon: "none",
- });
- }
- },
- makePhoneCall(e) {
- wx.makePhoneCall({
- phoneNumber: e.currentTarget.dataset.phone,
- });
- },
- copy(e) {
- wx.setClipboardData({
- data: e.currentTarget.dataset.phone,
- success(res) {
- wx.showToast({
- title: "复制成功",
- });
- },
- });
- },
- async getOilPriceList() {
- let { data } = await postApi("/fuel/list", {});
- if (data.status === 0) {
- this.setData({
- oilPriceList: data.result.map((item, index) => {
- return {
- id: index,
- latitude: item.fuelShipLatitude,
- longitude: item.fuelShipLongitude,
- iconPath:
- "https://frontend-1255802371.cos.ap-shanghai.myqcloud.com/miniapp-static%2Fgas-station.png",
- width: 40,
- height: 40,
- ...item,
- callout: {
- content: item.vendorName,
- display: "ALWAYS",
- bgColor: "none",
- },
- };
- }),
- });
- } else {
- this.setData({
- oilPriceList: [],
- });
- wx.showToast({
- title: data.msg,
- icon: "none",
- });
- }
- },
- openSetting() {
- this.setData({
- authModal: false,
- });
- wx.openSetting({
- complete: (e) => {
- console.log(e);
- if (e.authSetting["scope.writePhotosAlbum"]) {
- if (wx.getStorageSync("cacheImage")) {
- wx.saveImageToPhotosAlbum({
- filePath: wx.getStorageSync("cacheImage"),
- success: (e) => {
- wx.showToast({
- title: "保存成功!",
- });
- wx.removeStorageSync("cacheImage");
- },
- complete: (e) => {
- console.log(e);
- },
- });
- }
- }
- },
- });
- },
- takeBill() {
- if (this.data.locked) return;
- wx.redirectTo({
- url: "/pages/takeBill/takeBill",
- });
- },
- async registerShip() {
- if (!this.checkout()) return;
- let res = await postApi("/user/wx/register", {
- userId: wx.getStorageSync("userId"),
- shipName: this.data.shipName,
- shipMmsi: this.data.shipMmsi,
- });
- if (res.data.status == 0) {
- let { shipInfo, userInfo } = res.data.result;
- let data = {
- ...shipInfo,
- ...userInfo,
- };
- Object.keys(data).forEach(function (key) {
- wx.setStorageSync(key, data[key]);
- });
- wx.showToast({
- title: res.data.msg,
- });
- this.setData({
- ...data,
- });
- } else {
- wx.showToast({
- title: res.data.msg,
- });
- }
- },
- checkout() {
- if (!this.data.shipName) {
- wx.showToast({
- title: "请输入船名!",
- icon: "error",
- });
- return;
- }
- if (!this.data.shipMmsi) {
- wx.showToast({
- title: "请输入MMSI!",
- icon: "error",
- });
- return;
- }
- return true;
- },
- 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;
- },
- });
- },
- async msg() {
- let res = await subMsg();
- },
- async checkCheckStatus() {
- let { data } = await postApi("/user/wx/checkin/status", {
- userId: wx.getStorageSync("userId"),
- });
- this.setData(data.result);
- },
- async check() {
- 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("/user/wx/checkin", {
- userId: wx.getStorageSync("userId"),
- latitude,
- longitude,
- });
- this.setData(data.result);
- if (data.status == 0) {
- wx.showToast({
- title: data.msg,
- icon: "success",
- duration: 2000,
- mask: true,
- });
- }
- },
- complete: (e) => {
- wx.hideLoading({});
- this.data.locked = false;
- },
- });
- },
- onShow() {
- if (typeof this.getTabBar === "function" && this.getTabBar()) {
- this.getTabBar().setData({
- selected: 0,
- });
- }
- let userName = wx.getStorageSync("userName");
- let userId = wx.getStorageSync("userId");
- let phone = wx.getStorageSync("phone");
- let shipId = wx.getStorageSync("shipId");
- if (userId && shipId) this.checkCheckStatus();
- this.getCerts();
- this.getContacts();
- this.getOilPriceList();
- this.setData({
- userName,
- phone,
- userId,
- shipId,
- });
- },
- });
|