|
|
@@ -99,7 +99,10 @@
|
|
|
<view class="shade-text-box">
|
|
|
<view>关机时间</view>
|
|
|
<view>
|
|
|
- <uni-datetime-picker :start="timeApplication" @change="timePickerChange()" return-type="timestamp" v-model="shadeDataA.data4">{{timestampToStr(shadeDataA.data4)}}</uni-datetime-picker>
|
|
|
+ <uni-datetime-picker
|
|
|
+ :hide-second="true"
|
|
|
+ :start="timeApplication" @change="timePickerChange()"
|
|
|
+ return-type="timestamp" v-model="shadeDataA.data4">{{timestampToStr(shadeDataA.data4)}}</uni-datetime-picker>
|
|
|
</view>
|
|
|
</view>
|
|
|
|
|
|
@@ -107,7 +110,7 @@
|
|
|
<view>使用总时长</view>
|
|
|
<view>{{shadeDataA.data5}}</view>
|
|
|
</view>
|
|
|
- <view class="shade-button" @click="submitButton(1)">确定</view>
|
|
|
+ <view class="shade-button" @click="submitButton(1)">登记使用</view>
|
|
|
</view>
|
|
|
<!-- 结束 -->
|
|
|
<view class="shade-box" v-if="shadeType == 2">
|
|
|
@@ -121,23 +124,23 @@
|
|
|
</view>
|
|
|
<view class="shade-text-box">
|
|
|
<view>开机时间</view>
|
|
|
- <view>{{shadeDataB.data3}}</view>
|
|
|
+ <view>{{timestampToStr(shadeDataB.data3)}}</view>
|
|
|
</view>
|
|
|
<view class="shade-text-box">
|
|
|
<view>关机时间</view>
|
|
|
- <view>{{shadeDataB.data4}}</view>
|
|
|
+ <view>{{timestampToStr(shadeDataB.data4)}}</view>
|
|
|
</view>
|
|
|
<view class="shade-text-box">
|
|
|
<view>使用总时长</view>
|
|
|
<view>{{shadeDataB.data5}}</view>
|
|
|
</view>
|
|
|
- <view class="shade-button">确定</view>
|
|
|
+ <view class="shade-button" @click="submitButton(2)">结束使用</view>
|
|
|
</view>
|
|
|
<!-- 查看 -->
|
|
|
<view class="shade-box-c" v-if="shadeType == 3">
|
|
|
<view class="shade-text-title">当前设备已被【{{shadeDataC.data1}}】登记使用,</view>
|
|
|
<view class="shade-text-title">开机时间:{{shadeDataC.data2}}</view>
|
|
|
- <view class="shade-text-title">如有疑问请联系:{{shadeDataC.data3}}</view>
|
|
|
+ <!-- <view class="shade-text-title">如有疑问请联系:{{shadeDataC.data3}}</view> -->
|
|
|
</view>
|
|
|
<view class="shade-box" v-if="shadeType == 4">
|
|
|
<view class="text-box">
|
|
|
@@ -151,7 +154,7 @@
|
|
|
|
|
|
<script>
|
|
|
import {
|
|
|
- mpDeviceDetail,
|
|
|
+ mpDeviceDetail,mpDeviceUsageStart,mpDeviceUsageEnd
|
|
|
} from '@/pages_equipmentUtilization/api/index.js'
|
|
|
import { config } from '@/api/request/config.js'
|
|
|
export default {
|
|
|
@@ -204,7 +207,7 @@
|
|
|
}
|
|
|
},
|
|
|
mounted() {
|
|
|
- this.mpDeviceDetail(this.equipmentId);
|
|
|
+ this.mpDeviceDetail();
|
|
|
},
|
|
|
methods: {
|
|
|
pickerChange(val){
|
|
|
@@ -212,11 +215,11 @@
|
|
|
this.$set(this,'pickerIndex',val.mp.detail.value);
|
|
|
},
|
|
|
//获取设备信息
|
|
|
- async mpDeviceDetail(id) {
|
|
|
+ async mpDeviceDetail() {
|
|
|
let self = this;
|
|
|
const {
|
|
|
data
|
|
|
- } = await mpDeviceDetail({id:id});
|
|
|
+ } = await mpDeviceDetail({id:this.equipmentId});
|
|
|
if (data.code == 200) {
|
|
|
this.$set(this,'newData',data.data);
|
|
|
}
|
|
|
@@ -257,17 +260,34 @@
|
|
|
data5:'0天0小时0分',
|
|
|
});
|
|
|
this.$set(this,'shadeType',1);
|
|
|
- }else if(this.newData.runStatus != 0 || this.newData.currentUserId != this.userId){
|
|
|
+ }else if(this.newData.runStatus != 0 && this.newData.currentUserId != this.userId){
|
|
|
//别人使用中
|
|
|
+ this.$set(this,'shadeDataC',{
|
|
|
+ data1:this.newData.currentUserName,
|
|
|
+ data2:this.newData.currentStartTime,
|
|
|
+ // data3:this.toTimestamp(this.newData.currentStartTime),
|
|
|
+ });
|
|
|
this.$set(this,'shadeType',3);
|
|
|
- }else if(this.newData.runStatus != 0 || this.newData.currentUserId == this.userId){
|
|
|
+ }else if(this.newData.runStatus != 0 && this.newData.currentUserId == this.userId){
|
|
|
//自己使用中
|
|
|
+ const now = new Date();
|
|
|
+ now.setSeconds(0, 0); // 将秒和毫秒都设为0
|
|
|
+ const timestamp = now.getTime()
|
|
|
+ this.$set(this,'timeApplication',timestamp);
|
|
|
+ this.$set(this,'shadeDataB',{
|
|
|
+ data1:this.newData.currentUserName,
|
|
|
+ data2:this.newData.usageType == 0?'自用':'对外服务',
|
|
|
+ data3:this.toTimestamp(this.newData.currentStartTime),
|
|
|
+ data4:this.timeApplication,
|
|
|
+ data5:this.formatTimeDiff(this.toTimestamp(this.newData.currentStartTime),this.timeApplication),
|
|
|
+ });
|
|
|
this.$set(this,'shadeType',2);
|
|
|
}
|
|
|
},
|
|
|
offShade(){
|
|
|
this.$set(this,'shadeType',0);
|
|
|
},
|
|
|
+ //时间戳格式化
|
|
|
timestampToStr(timestamp) {
|
|
|
const date = new Date(timestamp); // 传入毫秒级时间戳
|
|
|
const year = date.getFullYear();
|
|
|
@@ -278,6 +298,21 @@
|
|
|
// 注意:这里没有拼接秒
|
|
|
return `${year}-${month}-${day} ${hours}:${minutes}`;
|
|
|
},
|
|
|
+ //时间格式转时间戳
|
|
|
+ toTimestamp(dateStr, isUTC = false) {
|
|
|
+ // 假设 dateStr 格式为 "YYYY-MM-DD HH:mm:ss"
|
|
|
+ const [datePart, timePart] = dateStr.split(' ');
|
|
|
+ const [year, month, day] = datePart.split('-').map(Number);
|
|
|
+ const [hour, minute, second] = timePart.split(':').map(Number);
|
|
|
+ if (isUTC) {
|
|
|
+ // 返回 UTC 时间戳
|
|
|
+ return Date.UTC(year, month - 1, day, hour, minute, second);
|
|
|
+ } else {
|
|
|
+ // 返回本地时间戳
|
|
|
+ return new Date(year, month - 1, day, hour, minute, second).getTime();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ //开始时间-结束时间-相差时间
|
|
|
formatTimeDiff(timestamp1, timestamp2) {
|
|
|
// 计算绝对差值(毫秒)
|
|
|
const diffMs = Math.abs(timestamp1 - timestamp2);
|
|
|
@@ -295,12 +330,13 @@
|
|
|
if (minutes > 0 || parts.length === 0) parts.push(minutes + '分'); // 确保至少显示“0分”
|
|
|
return parts.join('');
|
|
|
},
|
|
|
+ //登记-结束时间选择
|
|
|
timePickerChange(){
|
|
|
if(this.shadeDataA.data4>this.shadeDataA.data3){
|
|
|
this.$set(this.shadeDataA,'data5',this.formatTimeDiff(this.shadeDataA.data3,this.shadeDataA.data4));
|
|
|
}else{
|
|
|
uni.showToast({
|
|
|
- title: '开机时间与关机时间不能相等',
|
|
|
+ title: '请检查关机时间',
|
|
|
icon:"none",
|
|
|
mask:true,
|
|
|
duration: 2000
|
|
|
@@ -308,8 +344,86 @@
|
|
|
}
|
|
|
|
|
|
},
|
|
|
+ //确定按钮
|
|
|
submitButton(type){
|
|
|
- console.log('shadeDataA',this.shadeDataA)
|
|
|
+ let self = this;
|
|
|
+ if(type == 1){
|
|
|
+ if(this.shadeDataA.data4>this.shadeDataA.data3){
|
|
|
+ uni.showModal({
|
|
|
+ content: '确认提交?',
|
|
|
+ cancelColor: "#999",
|
|
|
+ confirmColor: "#0183FA",
|
|
|
+ success: function(res) {
|
|
|
+ if (res.confirm) {
|
|
|
+ self.mpDeviceUsageStart()
|
|
|
+ } else if (res.cancel) {}
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ uni.showToast({
|
|
|
+ title: '请检查关机时间',
|
|
|
+ icon:"none",
|
|
|
+ mask:true,
|
|
|
+ duration: 2000
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }else if(type == 2){
|
|
|
+ uni.showModal({
|
|
|
+ content: '确认提交?',
|
|
|
+ cancelColor: "#999",
|
|
|
+ confirmColor: "#0183FA",
|
|
|
+ success: function(res) {
|
|
|
+ if (res.confirm) {
|
|
|
+ self.mpDeviceUsageEnd()
|
|
|
+ } else if (res.cancel) {}
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ //登记使用
|
|
|
+ async mpDeviceUsageStart() {
|
|
|
+ let self = this;
|
|
|
+ let obj = {
|
|
|
+ deviceId:this.equipmentId,
|
|
|
+ usageType:this.pickerList[this.pickerIndex]=='自用'?0:1,
|
|
|
+ startTime:this.timestampToStr(this.shadeDataA.data3)+':00',
|
|
|
+ expectedEndTime:this.timestampToStr(this.shadeDataA.data4)+':00',
|
|
|
+ }
|
|
|
+ const {
|
|
|
+ data
|
|
|
+ } = await mpDeviceUsageStart(obj);
|
|
|
+ if (data.code == 200) {
|
|
|
+ this.$set(this,'shadeType',0);
|
|
|
+ this.mpDeviceDetail();
|
|
|
+ uni.showToast({
|
|
|
+ mask: true,
|
|
|
+ icon: "none",
|
|
|
+ position: "center",
|
|
|
+ title: data.message,
|
|
|
+ duration: 2000
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ //结束使用
|
|
|
+ async mpDeviceUsageEnd() {
|
|
|
+ let self = this;
|
|
|
+ let obj = {
|
|
|
+ deviceId:this.newData.currentUsageId,
|
|
|
+ }
|
|
|
+ const {
|
|
|
+ data
|
|
|
+ } = await mpDeviceUsageEnd(obj);
|
|
|
+ if (data.code == 200) {
|
|
|
+ this.$set(this,'shadeType',0);
|
|
|
+ this.mpDeviceDetail();
|
|
|
+ uni.showToast({
|
|
|
+ mask: true,
|
|
|
+ icon: "none",
|
|
|
+ position: "center",
|
|
|
+ title: data.message,
|
|
|
+ duration: 2000
|
|
|
+ });
|
|
|
+ }
|
|
|
},
|
|
|
},
|
|
|
}
|