王智慧 3 anni fa
parent
commit
39d0fee1f7

+ 144 - 1
miniprogram/pages/securityCheck/securityCheck.js

@@ -2,11 +2,154 @@
 import {
   postApi
 } from "../../apis/api"
+import {
+  apiUrl
+} from "../../apis/apiConfig"
+
+import {
+  isImage
+} from "../../utils/utils"
 Page({
   data: {
+    list: [],
+    loginStatus: wx.getStorageSync('userId')
+  },
+  async login() {
+    if (!wx.getStorageSync('openId')) return
+    let res1 = await postApi("/user/wx/openId/login", {
+      openId: wx.getStorageSync('openId')
+    })
+    if (res1.data.status == 0) {
+      let data = {
+        ...res1.data.result.userInfo,
+        ...res1.data.result.shipInfo,
+      }
+      Object.keys(data).forEach(function (key) {
+        wx.setStorageSync(key, data[key])
+      })
+      this.setData({
+        loginStatus: true
+      })
+      this.getList()
+    } else {
+      wx.navigateTo({
+        url: '/pages/takePhoto/takePhoto',
+      })
 
+    }
   },
-  onLoad(options) {
+  async getList() {
+    if (!wx.getStorageSync('userId')) {
+      wx.showToast({
+        title: '尚未登录',
+        icon: 'error'
+      })
+      return
+    }
+    let {
+      data
+    } = await postApi('/security/check/list', {
+      userId: wx.getStorageSync('userId'),
+      shipId: wx.getStorageSync('shipId')
+    })
+    wx.stopPullDownRefresh()
+    if (data.status == 0) {
+      for (let i of data.result) {
+        i.isImage = isImage(i.fileKey)
+      }
+      this.setData({
+        list: data.result
+      })
+    } else {
+      this.setData({
+        list: []
+      })
+    }
+  },
+  uploadMedia(e) {
+    let {
+      id: itemId
+    } = e.currentTarget.dataset
+    wx.showLoading({
+      title: '高精度定位中...'
+    })
+    wx.getLocation({
+      type: 'gcj02',
+      isHighAccuracy: true,
+      success: e => {
+        let {
+          latitude,
+          longitude
+        } = e
+        wx.chooseMedia({
+          count: 1,
+          mediaType: ['image', 'video'],
+          sourceType: ['album', 'camera'],
+          sizeType: ['original', 'compressed'],
+          success: e => {
+            console.log("获取媒体成功!", e)
+            let filePath = e.tempFiles[0].tempFilePath
+            wx.showLoading({
+              title: '正在上传...'
+            })
+            wx.uploadFile({
+              url: `${apiUrl}/security/check/upload/file`,
+              filePath,
+              name: 'file',
+              formData: {
+                itemId,
+                userId: wx.getStorageSync('userId'),
+                location: `${longitude},${latitude}`
+              },
+              success: async e => {
+                let data = JSON.parse(e.data)
+                if (data.status == 0) {
+                  this.getList()
+                  wx.showToast({
+                    title: data.msg,
+                    duration: 1500
+                  })
+                } else {
+                  wx.showToast({
+                    title: data.msg,
+                    icon: "error",
+                    duration: 2000
+                  })
+                }
+
+              },
+              fail: err => {
+                wx.showToast({
+                  title: data.msg,
+                  icon: "error",
+                  duration: 2000
+                })
+              }
+            })
+          },
+          fail: e => {
+            console.log("失败1", e)
+          }
+        })
+      },
+      fail: e => {
+        this.setData({
+          authModal: true,
+          modalText: "位置信息"
+        })
+      },
+      complete: e => {
+        wx.hideLoading({
+          success: (res) => {},
+        })
+      }
+    })
+  },
+  onPullDownRefresh() {
+    this.getList()
 
   },
+  onLoad(options) {
+    this.getList()
+  },
 })

+ 2 - 1
miniprogram/pages/securityCheck/securityCheck.json

@@ -1,3 +1,4 @@
 {
-  "usingComponents": {}
+  "usingComponents": {},
+  "enablePullDownRefresh": true
 }

+ 10 - 2
miniprogram/pages/securityCheck/securityCheck.wxml

@@ -1,2 +1,10 @@
-<view class="tac" style="color:#777;font-size: 50rpx;margin-top: 20vh;">安检</view>
-<view class="tac" style="color:#777;font-size: 50rpx;margin-top: 20vh;">建设中...</view>
+<view wx:if="{{loginStatus}}" class="box mb30" wx:for="{{list}}" wx:key="id">
+  <view class="title mb10">{{item.checkItemName}}</view>
+  <view wx:if="{{item.viewUrl}}">
+    <image wx:if="{{item.isImage}}" class="img" src="{{item.viewUrl}}"></image>
+    <video wx:else class="img" src="{{item.viewUrl}}"></video>
+  </view>
+  <view bindtap="uploadMedia" data-id="{{item.id}}" class="take-photo retake mb10" wx:else="">拍照</view>
+  <view class="next retake" bindtap="uploadMedia" data-id="{{item.id}}" wx:if="{{item.viewUrl}}">重拍</view>
+</view>
+<view wx:if="{{!loginStatus}}" bindtap="login" class="go">登录</view>

+ 46 - 1
miniprogram/pages/securityCheck/securityCheck.wxss

@@ -1 +1,46 @@
-/* pages/securityCheck/securityCheck.wxss */
+/* pages/securityCheck/securityCheck.wxss */
+.box {
+  padding: 30rpx;
+  border-bottom: 2rpx solid #ddd;
+  padding-bottom: 30px;
+}
+
+.title {
+  font-size: 32rpx;
+  color: #555;
+  margin-bottom: 20px;
+}
+
+.img {
+  display: block;
+  margin: 20rpx auto;
+}
+
+
+.retake {
+  width: 530rpx !important;
+  height: 80rpx;
+  background: linear-gradient(270deg, #0089FD 0%, #43A9FF 100%);
+  border-radius: 20rpx;
+  text-align: center;
+  line-height: 80rpx;
+  font-size: 30rpx;
+  font-family: PingFangSC-Medium, PingFang SC;
+  font-weight: 500;
+  color: #FFFFFF;
+  margin: 0 auto;
+}
+
+
+.go {
+  width: 70vw;
+  height: 12vw;
+  line-height: 12vw;
+  font-size: 5vw;
+  text-align: center;
+  background: #3e94f6;
+  color: #fff;
+  border-radius: 6vw;
+  margin: 0 auto;
+  margin-top: 80vh;
+}

+ 9 - 0
miniprogram/utils/utils.js

@@ -0,0 +1,9 @@
+function isImage(url) {
+  let imgArr = ["jpg", "jpeg", "png", "gif"];
+  let lastIndex = url.lastIndexOf(".");
+  return imgArr.indexOf(url.substring(lastIndex + 1, url.length)) != -1;
+}
+
+module.exports = {
+  isImage
+}