infoPage.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. <template>
  2. <view class="equipmentInformationInfoPage">
  3. <view class="info-max-box">
  4. <img class="left-img" v-if="imageUrls[0]" :src="baseUrl+imageUrls[0]">
  5. <img class="left-img" v-if="!imageUrls[0]" src="">
  6. <view class="right-box">
  7. <view>设备分类:{{newData.categoryName}}</view>
  8. <view>设备名称:{{newData.deviceName}}</view>
  9. <view>设备编号:{{newData.deviceCode}}</view>
  10. <view>设备状态:{{newData.deviceStatusName}}</view>
  11. </view>
  12. </view>
  13. <view class="text-max-box">
  14. <img src="">
  15. <view>类型</view>
  16. <view>{{newData.deviceType}}</view>
  17. </view>
  18. <view class="text-max-box">
  19. <img src="">
  20. <view>品牌</view>
  21. <view>{{newData.brand}}</view>
  22. </view>
  23. <view class="text-max-box">
  24. <img src="">
  25. <view>设备原值(元)</view>
  26. <view>{{newData.price}}</view>
  27. </view>
  28. <view class="text-title-box">参数用途</view>
  29. <view class="text-max-box">
  30. <img src="">
  31. <view>设备用途</view>
  32. <view class="colorA" @click="lookText(1)">查看</view>
  33. </view>
  34. <view class="text-max-box">
  35. <img src="">
  36. <view>技术参数</view>
  37. <view class="colorA" @click="lookText(2)">查看</view>
  38. </view>
  39. <view class="text-max-box">
  40. <img src="">
  41. <view>备注</view>
  42. <view class="colorA" @click="lookText(3)">查看</view>
  43. </view>
  44. <view class="text-title-box">设备归属</view>
  45. <view class="text-max-box">
  46. <img src="">
  47. <view>设备管理员</view>
  48. <view>{{newData.adminDisplay}}</view>
  49. </view>
  50. <view class="text-max-box">
  51. <img src="">
  52. <view>管理部门</view>
  53. <view>{{newData.manageDeptName}}</view>
  54. </view>
  55. <view class="text-max-box">
  56. <img src="">
  57. <view>存放位置</view>
  58. <view>{{newData.location}}</view>
  59. </view>
  60. <view class="text-title-box">厂家产地</view>
  61. <view class="text-max-box">
  62. <img src="">
  63. <view>单位</view>
  64. <view>{{newData.unit}}</view>
  65. </view>
  66. <view class="text-max-box">
  67. <img src="">
  68. <view>生产厂家</view>
  69. <view>{{newData.manufacturer}}</view>
  70. </view>
  71. <view class="text-max-box">
  72. <img src="">
  73. <view>产地</view>
  74. <view>{{newData.originPlace}}</view>
  75. </view>
  76. <view class="bottom-button" @click="onShade()">登记使用信息</view>
  77. <view class="shade-max-big-box" v-if="shadeType == 1||shadeType == 2||shadeType == 3||shadeType == 4">
  78. <view class="shade-top-flex" @click="offShade()"></view>
  79. <view class="shade-big-box">
  80. <view class="shade-title-box" v-if="shadeType == 1||shadeType == 2||shadeType == 3">登记使用信息</view>
  81. <view class="shade-title-box" v-if="shadeType == 4">{{shadeDataD.data1}}</view>
  82. <!-- 登记 -->
  83. <view class="shade-box" v-if="shadeType == 1">
  84. <view class="shade-text-box">
  85. <view>使用人</view>
  86. <view>{{shadeDataA.data1}}</view>
  87. </view>
  88. <view class="shade-text-box">
  89. <view>使用类型</view>
  90. <!-- <view>{{shadeDataA.data2}}</view> -->
  91. <picker @change="pickerChange" :value="pickerIndex" :range="pickerList">
  92. <view style="width:400rpx;text-align:right;">{{pickerList[pickerIndex]}}</view>
  93. </picker>
  94. </view>
  95. <view class="shade-text-box">
  96. <view>开机时间</view>
  97. <view>{{timestampToStr(shadeDataA.data3)}}</view>
  98. </view>
  99. <view class="shade-text-box">
  100. <view>关机时间</view>
  101. <view>
  102. <uni-datetime-picker
  103. :hide-second="true"
  104. :start="timeApplication" @change="timePickerChange()"
  105. return-type="timestamp" v-model="shadeDataA.data4">{{timestampToStr(shadeDataA.data4)}}</uni-datetime-picker>
  106. </view>
  107. </view>
  108. <view class="shade-text-box">
  109. <view>使用总时长</view>
  110. <view>{{shadeDataA.data5}}</view>
  111. </view>
  112. <view class="shade-button" @click="submitButton(1)">登记使用</view>
  113. </view>
  114. <!-- 结束 -->
  115. <view class="shade-box" v-if="shadeType == 2">
  116. <view class="shade-text-box">
  117. <view>使用人</view>
  118. <view>{{shadeDataB.data1}}</view>
  119. </view>
  120. <view class="shade-text-box">
  121. <view>使用类型</view>
  122. <view>{{shadeDataB.data2}}</view>
  123. </view>
  124. <view class="shade-text-box">
  125. <view>开机时间</view>
  126. <view>{{timestampToStr(shadeDataB.data3)}}</view>
  127. </view>
  128. <view class="shade-text-box">
  129. <view>关机时间</view>
  130. <view>{{timestampToStr(shadeDataB.data4)}}</view>
  131. </view>
  132. <view class="shade-text-box">
  133. <view>使用总时长</view>
  134. <view>{{shadeDataB.data5}}</view>
  135. </view>
  136. <view class="shade-button" @click="submitButton(2)">结束使用</view>
  137. </view>
  138. <!-- 查看 -->
  139. <view class="shade-box-c" v-if="shadeType == 3">
  140. <view class="shade-text-title">当前设备已被【{{shadeDataC.data1}}】登记使用,</view>
  141. <view class="shade-text-title">开机时间:{{shadeDataC.data2}}</view>
  142. <!-- <view class="shade-text-title">如有疑问请联系:{{shadeDataC.data3}}</view> -->
  143. </view>
  144. <view class="shade-box" v-if="shadeType == 4">
  145. <view class="text-box">
  146. {{shadeDataD.data2}}
  147. </view>
  148. </view>
  149. </view>
  150. </view>
  151. </view>
  152. </template>
  153. <script>
  154. import {
  155. mpDeviceDetail,mpDeviceUsageStart,mpDeviceUsageEnd
  156. } from '@/pages_equipmentUtilization/api/index.js'
  157. import { config } from '@/api/request/config.js'
  158. export default {
  159. props: {
  160. equipmentId: {},
  161. },
  162. data() {
  163. return {
  164. shadeType:0,
  165. baseUrl:config.base_url,
  166. userId: uni.getStorageSync('userId'),
  167. newData:{
  168. categoryName:'',
  169. deviceCode:'',
  170. deviceName:'',
  171. deviceStatusName:'',
  172. deviceType:'',
  173. brand:'',
  174. price:'',
  175. adminDisplay:'',
  176. manageDeptName:'',
  177. location:'',
  178. unit:'',
  179. manufacturer:'',
  180. originPlace:'',
  181. purpose:'',
  182. techParams:'',
  183. remark:'',
  184. },
  185. shadeDataA:{},
  186. shadeDataB:{
  187. data1:'张工',
  188. data2:'自用',
  189. data3:'2026-01-25 15:30',
  190. data4:'2026-01-25 15:30',
  191. data5:'3天2小时15分',
  192. },
  193. shadeDataC:{
  194. data1:'张工',
  195. data2:'2026-01-25 15:30',
  196. data3:'010-88888888',
  197. },
  198. shadeDataD:{
  199. data1:'张工',
  200. data2:'2026-01-25 15:30',
  201. },
  202. pickerList:['自用','对外服务'],
  203. pickerIndex:0,
  204. timeApplication:null,
  205. }
  206. },
  207. mounted() {
  208. this.mpDeviceDetail();
  209. },
  210. methods: {
  211. pickerChange(val){
  212. console.log('val',val.mp.detail.value);
  213. this.$set(this,'pickerIndex',val.mp.detail.value);
  214. },
  215. //获取设备信息
  216. async mpDeviceDetail() {
  217. let self = this;
  218. const {
  219. data
  220. } = await mpDeviceDetail({id:this.equipmentId});
  221. if (data.code == 200) {
  222. this.$set(this,'newData',data.data);
  223. }
  224. },
  225. lookText(type){
  226. if(type == 1){
  227. this.$set(this,'shadeDataD',{
  228. data1:'设备用途',
  229. data2:this.newData.purpose,
  230. });
  231. }else if(type == 2){
  232. this.$set(this,'shadeDataD',{
  233. data1:'技术参数',
  234. data2:this.newData.techParams,
  235. });
  236. }else if(type == 3){
  237. this.$set(this,'shadeDataD',{
  238. data1:'备注',
  239. data2:this.newData.remark,
  240. });
  241. }
  242. this.$set(this,'shadeType',4);
  243. },
  244. onShade(){
  245. //判断 登记时1 退订2 已占用3
  246. if(this.newData.runStatus == 0){
  247. //无人使用
  248. const now = new Date();
  249. now.setSeconds(0, 0); // 将秒和毫秒都设为0
  250. const timestamp = now.getTime()
  251. this.$set(this,'timeApplication',timestamp);
  252. this.$set(this,'pickerIndex',0);
  253. this.$set(this,'shadeDataA',{
  254. data1:uni.getStorageSync('user-name'),
  255. data2:null,
  256. data3:this.timeApplication,
  257. data4:this.timeApplication,
  258. data5:'0天0小时0分',
  259. });
  260. this.$set(this,'shadeType',1);
  261. }else if(this.newData.runStatus != 0 && this.newData.currentUserId != this.userId){
  262. //别人使用中
  263. this.$set(this,'shadeDataC',{
  264. data1:this.newData.currentUserName,
  265. data2:this.newData.currentStartTime,
  266. // data3:this.toTimestamp(this.newData.currentStartTime),
  267. });
  268. this.$set(this,'shadeType',3);
  269. }else if(this.newData.runStatus != 0 && this.newData.currentUserId == this.userId){
  270. //自己使用中
  271. const now = new Date();
  272. now.setSeconds(0, 0); // 将秒和毫秒都设为0
  273. const timestamp = now.getTime()
  274. this.$set(this,'timeApplication',timestamp);
  275. this.$set(this,'shadeDataB',{
  276. data1:this.newData.currentUserName,
  277. data2:this.newData.usageType == 0?'自用':'对外服务',
  278. data3:this.toTimestamp(this.newData.currentStartTime),
  279. data4:this.timeApplication,
  280. data5:this.formatTimeDiff(this.toTimestamp(this.newData.currentStartTime),this.timeApplication),
  281. });
  282. this.$set(this,'shadeType',2);
  283. }
  284. },
  285. offShade(){
  286. this.$set(this,'shadeType',0);
  287. },
  288. //时间戳格式化
  289. timestampToStr(timestamp) {
  290. const date = new Date(timestamp); // 传入毫秒级时间戳
  291. const year = date.getFullYear();
  292. const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始,需+1
  293. const day = String(date.getDate()).padStart(2, '0');
  294. const hours = String(date.getHours()).padStart(2, '0');
  295. const minutes = String(date.getMinutes()).padStart(2, '0');
  296. // 注意:这里没有拼接秒
  297. return `${year}-${month}-${day} ${hours}:${minutes}`;
  298. },
  299. //时间格式转时间戳
  300. toTimestamp(dateStr, isUTC = false) {
  301. // 假设 dateStr 格式为 "YYYY-MM-DD HH:mm:ss"
  302. const [datePart, timePart] = dateStr.split(' ');
  303. const [year, month, day] = datePart.split('-').map(Number);
  304. const [hour, minute, second] = timePart.split(':').map(Number);
  305. if (isUTC) {
  306. // 返回 UTC 时间戳
  307. return Date.UTC(year, month - 1, day, hour, minute, second);
  308. } else {
  309. // 返回本地时间戳
  310. return new Date(year, month - 1, day, hour, minute, second).getTime();
  311. }
  312. },
  313. //开始时间-结束时间-相差时间
  314. formatTimeDiff(timestamp1, timestamp2) {
  315. // 计算绝对差值(毫秒)
  316. const diffMs = Math.abs(timestamp1 - timestamp2);
  317. // 转换为总分钟数(向下取整)
  318. const totalMinutes = Math.floor(diffMs / (1000 * 60));
  319. // 计算天、小时、分钟
  320. const days = Math.floor(totalMinutes / (60 * 24));
  321. const remainingMinutes = totalMinutes % (60 * 24);
  322. const hours = Math.floor(remainingMinutes / 60);
  323. const minutes = remainingMinutes % 60;
  324. // 构建输出字符串
  325. const parts = [];
  326. if (days > 0) parts.push(days + '天');
  327. if (hours > 0) parts.push(hours + '小时');
  328. if (minutes > 0 || parts.length === 0) parts.push(minutes + '分'); // 确保至少显示“0分”
  329. return parts.join('');
  330. },
  331. //登记-结束时间选择
  332. timePickerChange(){
  333. if(this.shadeDataA.data4>this.shadeDataA.data3){
  334. this.$set(this.shadeDataA,'data5',this.formatTimeDiff(this.shadeDataA.data3,this.shadeDataA.data4));
  335. }else{
  336. uni.showToast({
  337. title: '请检查关机时间',
  338. icon:"none",
  339. mask:true,
  340. duration: 2000
  341. });
  342. }
  343. },
  344. //确定按钮
  345. submitButton(type){
  346. let self = this;
  347. if(type == 1){
  348. if(this.shadeDataA.data4>this.shadeDataA.data3){
  349. uni.showModal({
  350. content: '确认提交?',
  351. cancelColor: "#999",
  352. confirmColor: "#0183FA",
  353. success: function(res) {
  354. if (res.confirm) {
  355. self.mpDeviceUsageStart()
  356. } else if (res.cancel) {}
  357. }
  358. });
  359. }else{
  360. uni.showToast({
  361. title: '请检查关机时间',
  362. icon:"none",
  363. mask:true,
  364. duration: 2000
  365. });
  366. }
  367. }else if(type == 2){
  368. uni.showModal({
  369. content: '确认提交?',
  370. cancelColor: "#999",
  371. confirmColor: "#0183FA",
  372. success: function(res) {
  373. if (res.confirm) {
  374. self.mpDeviceUsageEnd()
  375. } else if (res.cancel) {}
  376. }
  377. });
  378. }
  379. },
  380. //登记使用
  381. async mpDeviceUsageStart() {
  382. let self = this;
  383. let obj = {
  384. deviceId:this.equipmentId,
  385. usageType:this.pickerList[this.pickerIndex]=='自用'?0:1,
  386. startTime:this.timestampToStr(this.shadeDataA.data3)+':00',
  387. expectedEndTime:this.timestampToStr(this.shadeDataA.data4)+':00',
  388. }
  389. const {
  390. data
  391. } = await mpDeviceUsageStart(obj);
  392. if (data.code == 200) {
  393. this.$set(this,'shadeType',0);
  394. this.mpDeviceDetail();
  395. uni.showToast({
  396. mask: true,
  397. icon: "none",
  398. position: "center",
  399. title: data.message,
  400. duration: 2000
  401. });
  402. }
  403. },
  404. //结束使用
  405. async mpDeviceUsageEnd() {
  406. let self = this;
  407. let obj = {
  408. deviceId:this.newData.currentUsageId,
  409. }
  410. const {
  411. data
  412. } = await mpDeviceUsageEnd(obj);
  413. if (data.code == 200) {
  414. this.$set(this,'shadeType',0);
  415. this.mpDeviceDetail();
  416. uni.showToast({
  417. mask: true,
  418. icon: "none",
  419. position: "center",
  420. title: data.message,
  421. duration: 2000
  422. });
  423. }
  424. },
  425. },
  426. }
  427. </script>
  428. <style lang="stylus" scoped>
  429. .equipmentInformationInfoPage {
  430. height: 100%;
  431. flex:1;
  432. display:flex;
  433. flex-direction:column;
  434. background-color: #fff;
  435. overflow: scroll;
  436. .info-max-box{
  437. display: flex;
  438. .left-img{
  439. width:200rpx;
  440. height:200rpx;
  441. display: inline-block;
  442. border:1rpx solid #dedede;
  443. margin:40rpx 20rpx 20rpx 20rpx;
  444. }
  445. .right-box{
  446. flex:1;
  447. margin:40rpx 20rpx 20rpx 0;
  448. view{
  449. width: 480rpx;
  450. display:block;
  451. overflow:hidden;
  452. text-overflow:ellipsis;
  453. white-space:nowrap;
  454. margin-bottom:14rpx;
  455. }
  456. }
  457. }
  458. .text-max-box{
  459. display: flex;
  460. border-bottom: 1rpx solid #f2f2f2;
  461. line-height:80rpx;
  462. padding: 0 40rpx;
  463. img{
  464. width:40rpx;
  465. height:40rpx;
  466. display: inline-block;
  467. }
  468. view:nth-child(2){
  469. flex:1;
  470. }
  471. view:nth-child(3){
  472. }
  473. .colorA{
  474. color:#0183FA;
  475. }
  476. }
  477. .text-title-box{
  478. line-height:80rpx;
  479. background-color: #f2f2f2;
  480. padding: 0 30rpx;
  481. }
  482. .bottom-button{
  483. width:300rpx;
  484. line-height:80rpx;
  485. text-align: center;
  486. margin:60rpx auto;
  487. color:#fff;
  488. background-color: #0183FA;
  489. border-radius:6rpx;
  490. }
  491. .shade-max-big-box{
  492. position: absolute;
  493. top:0;
  494. left:0;
  495. width:100%;
  496. height:100%;
  497. background-color: rgba(0,0,0,0.3)
  498. display: flex;
  499. flex-direction: column;
  500. .shade-top-flex{
  501. flex:1;
  502. }
  503. .shade-big-box{
  504. background-color: #fff;
  505. .shade-title-box{
  506. font-weight:900;
  507. padding-right:20rpx;
  508. width:300rpx;
  509. border-bottom-right-radius: 40rpx
  510. background-color: #0183FA;
  511. color:#fff;
  512. text-align: center;
  513. line-height:60rpx;
  514. }
  515. .shade-box{
  516. padding:20rpx 0 100rpx;
  517. .shade-text-box{
  518. display: flex;
  519. border-bottom:1rpx solid #f2f2f2;
  520. line-height:80rpx;
  521. padding:0 30rpx;
  522. view:nth-child(1){
  523. flex:1;
  524. }
  525. view:nth-child(1){
  526. flex:3;
  527. }
  528. }
  529. .shade-button{
  530. width:300rpx;
  531. line-height:80rpx;
  532. text-align: center;
  533. background-color: #0183FA;
  534. border-radius:8rpx;
  535. color:#fff;
  536. margin:40rpx auto 0;
  537. }
  538. .text-box{
  539. padding:60rpx 40rpx 200rpx;
  540. }
  541. }
  542. .shade-box-c{
  543. padding:120rpx 0 200rpx;
  544. .shade-text-title{
  545. text-align-last: center;
  546. line-height: 60rpx;
  547. }
  548. }
  549. }
  550. }
  551. }
  552. </style>