infoPage.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. <template>
  2. <view class="equipmentInformationInfoPage">
  3. <view class="info-max-box">
  4. <img class="left-img" v-if="newData.imageUrls[0]" :src="baseUrl+newData.imageUrls[0]">
  5. <img class="left-img" v-if="!newData.imageUrls[0]" :src="imagesUrl('commonality/chemicalsInfoNull.png')">
  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?newData.deviceType:'-'}}</view>
  17. </view>
  18. <view class="text-max-box">
  19. <img src="">
  20. <view>品牌</view>
  21. <view>{{newData.brand?newData.brand:'-'}}</view>
  22. </view>
  23. <view class="text-max-box">
  24. <img src="">
  25. <view>设备原值(元)</view>
  26. <view>{{newData.price?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?newData.adminDisplay:'-'}}</view>
  49. </view>
  50. <view class="text-max-box">
  51. <img src="">
  52. <view>管理部门</view>
  53. <view>{{newData.manageDeptName?newData.manageDeptName:'-'}}</view>
  54. </view>
  55. <view class="text-max-box">
  56. <img src="">
  57. <view>存放位置</view>
  58. <view>{{newData.location?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?newData.unit:'-'}}</view>
  65. </view>
  66. <view class="text-max-box">
  67. <img src="">
  68. <view>生产厂家</view>
  69. <view>{{newData.manufacturer?newData.manufacturer:'-'}}</view>
  70. </view>
  71. <view class="text-max-box">
  72. <img src="">
  73. <view>产地</view>
  74. <view>{{newData.originPlace?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" style="max-height: 500rpx;overflow-y: scroll;">
  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. imageUrls:[],
  169. categoryName:'',
  170. deviceCode:'',
  171. deviceName:'',
  172. deviceStatusName:'',
  173. deviceType:'',
  174. brand:'',
  175. price:'',
  176. adminDisplay:'',
  177. manageDeptName:'',
  178. location:'',
  179. unit:'',
  180. manufacturer:'',
  181. originPlace:'',
  182. purpose:'',
  183. techParams:'',
  184. remark:'',
  185. },
  186. shadeDataA:{},
  187. shadeDataB:{
  188. data1:'',
  189. data2:'',
  190. data3:'',
  191. data4:'',
  192. data5:'',
  193. },
  194. shadeDataC:{
  195. data1:'',
  196. data2:'',
  197. data3:'',
  198. },
  199. shadeDataD:{
  200. data1:'',
  201. data2:'',
  202. },
  203. pickerList:['自用','对外服务'],
  204. pickerIndex:0,
  205. timeApplication:null,
  206. }
  207. },
  208. mounted() {
  209. this.mpDeviceDetail();
  210. },
  211. methods: {
  212. pickerChange(val){
  213. console.log('val',val.mp.detail.value);
  214. this.$set(this,'pickerIndex',val.mp.detail.value);
  215. },
  216. //获取设备信息
  217. async mpDeviceDetail() {
  218. let self = this;
  219. const {
  220. data
  221. } = await mpDeviceDetail({id:this.equipmentId});
  222. if (data.code == 200) {
  223. if(!data.data.imageUrls){
  224. data.data.imageUrls = [];
  225. }
  226. this.$set(this,'newData',data.data);
  227. }
  228. },
  229. lookText(type){
  230. if(type == 1){
  231. this.$set(this,'shadeDataD',{
  232. data1:'设备用途',
  233. data2:this.newData.purpose?this.newData.purpose:'未配置设备用途',
  234. });
  235. }else if(type == 2){
  236. this.$set(this,'shadeDataD',{
  237. data1:'技术参数',
  238. data2:this.newData.techParams?this.newData.techParams:'未配置技术参数',
  239. });
  240. }else if(type == 3){
  241. this.$set(this,'shadeDataD',{
  242. data1:'备注',
  243. data2:this.newData.remark?this.newData.remark:'未配置备注',
  244. });
  245. }
  246. this.$set(this,'shadeType',4);
  247. },
  248. onShade(){
  249. //判断 登记时1 退订2 已占用3
  250. if(this.newData.deviceStatus == 1){
  251. //维护
  252. uni.showToast({
  253. title: '设备维护中,如有疑问请联系管理员.',
  254. icon:"none",
  255. mask:true,
  256. duration: 2000
  257. });
  258. return
  259. }else if(this.newData.deviceStatus == 2){
  260. //报废
  261. uni.showToast({
  262. title: '设备已报废,如有疑问请联系管理员.',
  263. icon:"none",
  264. mask:true,
  265. duration: 2000
  266. });
  267. return
  268. }
  269. if(this.newData.runStatus == 0){
  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,'pickerIndex',0);
  276. this.$set(this,'shadeDataA',{
  277. data1:uni.getStorageSync('user-name'),
  278. data2:null,
  279. data3:this.timeApplication,
  280. data4:this.timeApplication,
  281. data5:'0天0小时0分',
  282. });
  283. this.$set(this,'shadeType',1);
  284. }else if(this.newData.runStatus == 1 && this.newData.currentUserId != this.userId){
  285. //别人使用中
  286. this.$set(this,'shadeDataC',{
  287. data1:this.newData.currentUserName,
  288. data2:this.newData.currentStartTime,
  289. // data3:this.toTimestamp(this.newData.currentStartTime),
  290. });
  291. this.$set(this,'shadeType',3);
  292. }else if(this.newData.runStatus == 1 && this.newData.currentUserId == this.userId){
  293. //自己使用中
  294. const now = new Date();
  295. now.setSeconds(0, 0); // 将秒和毫秒都设为0
  296. const timestamp = now.getTime()
  297. this.$set(this,'timeApplication',timestamp);
  298. this.$set(this,'shadeDataB',{
  299. data1:this.newData.currentUserName,
  300. data2:this.newData.usageType == 0?'自用':'对外服务',
  301. data3:this.toTimestamp(this.newData.currentStartTime),
  302. data4:this.timeApplication,
  303. data5:this.formatTimeDiff(this.toTimestamp(this.newData.currentStartTime),this.timeApplication),
  304. });
  305. this.$set(this,'shadeType',2);
  306. }
  307. },
  308. offShade(){
  309. this.$set(this,'shadeType',0);
  310. },
  311. //时间戳格式化
  312. timestampToStr(timestamp) {
  313. const date = new Date(timestamp); // 传入毫秒级时间戳
  314. const year = date.getFullYear();
  315. const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始,需+1
  316. const day = String(date.getDate()).padStart(2, '0');
  317. const hours = String(date.getHours()).padStart(2, '0');
  318. const minutes = String(date.getMinutes()).padStart(2, '0');
  319. // 注意:这里没有拼接秒
  320. return `${year}-${month}-${day} ${hours}:${minutes}`;
  321. },
  322. //时间格式转时间戳
  323. toTimestamp(dateStr, isUTC = false) {
  324. // 假设 dateStr 格式为 "YYYY-MM-DD HH:mm:ss"
  325. const [datePart, timePart] = dateStr.split(' ');
  326. const [year, month, day] = datePart.split('-').map(Number);
  327. const [hour, minute, second] = timePart.split(':').map(Number);
  328. if (isUTC) {
  329. // 返回 UTC 时间戳
  330. return Date.UTC(year, month - 1, day, hour, minute, second);
  331. } else {
  332. // 返回本地时间戳
  333. return new Date(year, month - 1, day, hour, minute, second).getTime();
  334. }
  335. },
  336. //开始时间-结束时间-相差时间
  337. formatTimeDiff(timestamp1, timestamp2) {
  338. // 计算绝对差值(毫秒)
  339. const diffMs = Math.abs(timestamp1 - timestamp2);
  340. // 转换为总分钟数(向下取整)
  341. const totalMinutes = Math.floor(diffMs / (1000 * 60));
  342. // 计算天、小时、分钟
  343. const days = Math.floor(totalMinutes / (60 * 24));
  344. const remainingMinutes = totalMinutes % (60 * 24);
  345. const hours = Math.floor(remainingMinutes / 60);
  346. const minutes = remainingMinutes % 60;
  347. // 构建输出字符串
  348. const parts = [];
  349. if (days > 0) parts.push(days + '天');
  350. if (hours > 0) parts.push(hours + '小时');
  351. if (minutes > 0 || parts.length === 0) parts.push(minutes + '分'); // 确保至少显示“0分”
  352. return parts.join('');
  353. },
  354. //登记-结束时间选择
  355. timePickerChange(){
  356. if(this.shadeDataA.data4>this.shadeDataA.data3){
  357. this.$set(this.shadeDataA,'data5',this.formatTimeDiff(this.shadeDataA.data3,this.shadeDataA.data4));
  358. }else{
  359. uni.showToast({
  360. title: '请检查关机时间',
  361. icon:"none",
  362. mask:true,
  363. duration: 2000
  364. });
  365. }
  366. },
  367. //确定按钮
  368. submitButton(type){
  369. let self = this;
  370. if(type == 1){
  371. if(this.shadeDataA.data4>this.shadeDataA.data3){
  372. uni.showModal({
  373. content: '确认提交?',
  374. cancelColor: "#999",
  375. confirmColor: "#0183FA",
  376. success: function(res) {
  377. if (res.confirm) {
  378. self.mpDeviceUsageStart()
  379. } else if (res.cancel) {}
  380. }
  381. });
  382. }else{
  383. uni.showToast({
  384. title: '请检查关机时间',
  385. icon:"none",
  386. mask:true,
  387. duration: 2000
  388. });
  389. }
  390. }else if(type == 2){
  391. uni.showModal({
  392. content: '确认提交?',
  393. cancelColor: "#999",
  394. confirmColor: "#0183FA",
  395. success: function(res) {
  396. if (res.confirm) {
  397. self.mpDeviceUsageEnd()
  398. } else if (res.cancel) {}
  399. }
  400. });
  401. }
  402. },
  403. //登记使用
  404. async mpDeviceUsageStart() {
  405. let self = this;
  406. let obj = {
  407. deviceId:this.equipmentId,
  408. usageType:this.pickerList[this.pickerIndex]=='自用'?0:1,
  409. startTime:this.timestampToStr(this.shadeDataA.data3)+':00',
  410. expectedEndTime:this.timestampToStr(this.shadeDataA.data4)+':00',
  411. }
  412. const {
  413. data
  414. } = await mpDeviceUsageStart(obj);
  415. if (data.code == 200) {
  416. this.$set(this,'shadeType',0);
  417. this.mpDeviceDetail();
  418. uni.showToast({
  419. mask: true,
  420. icon: "none",
  421. position: "center",
  422. title: data.message,
  423. duration: 2000
  424. });
  425. }
  426. },
  427. //结束使用
  428. async mpDeviceUsageEnd() {
  429. let self = this;
  430. let obj = {
  431. deviceId:this.newData.currentUsageId,
  432. }
  433. const {
  434. data
  435. } = await mpDeviceUsageEnd(obj);
  436. if (data.code == 200) {
  437. this.$set(this,'shadeType',0);
  438. this.mpDeviceDetail();
  439. uni.showToast({
  440. mask: true,
  441. icon: "none",
  442. position: "center",
  443. title: data.message,
  444. duration: 2000
  445. });
  446. }
  447. },
  448. },
  449. }
  450. </script>
  451. <style lang="stylus" scoped>
  452. .equipmentInformationInfoPage {
  453. height: 100%;
  454. flex:1;
  455. display:flex;
  456. flex-direction:column;
  457. background-color: #fff;
  458. overflow: scroll;
  459. .info-max-box{
  460. display: flex;
  461. .left-img{
  462. width:200rpx;
  463. height:200rpx;
  464. display: inline-block;
  465. border:1rpx solid #dedede;
  466. margin:40rpx 20rpx 20rpx 20rpx;
  467. }
  468. .right-box{
  469. flex:1;
  470. margin:40rpx 20rpx 20rpx 0;
  471. view{
  472. width: 480rpx;
  473. display:block;
  474. overflow:hidden;
  475. text-overflow:ellipsis;
  476. white-space:nowrap;
  477. margin-bottom:14rpx;
  478. }
  479. }
  480. }
  481. .text-max-box{
  482. display: flex;
  483. border-bottom: 1rpx solid #f2f2f2;
  484. line-height:80rpx;
  485. padding: 0 40rpx;
  486. img{
  487. width:40rpx;
  488. height:40rpx;
  489. display: inline-block;
  490. }
  491. view:nth-child(2){
  492. flex:1;
  493. }
  494. view:nth-child(3){
  495. }
  496. .colorA{
  497. color:#0183FA;
  498. }
  499. }
  500. .text-title-box{
  501. line-height:80rpx;
  502. background-color: #f2f2f2;
  503. padding: 0 30rpx;
  504. }
  505. .bottom-button{
  506. width:300rpx;
  507. line-height:80rpx;
  508. text-align: center;
  509. margin:60rpx auto;
  510. color:#fff;
  511. background-color: #0183FA;
  512. border-radius:6rpx;
  513. }
  514. .shade-max-big-box{
  515. position: absolute;
  516. top:0;
  517. left:0;
  518. width:100%;
  519. height:100%;
  520. background-color: rgba(0,0,0,0.3)
  521. display: flex;
  522. flex-direction: column;
  523. .shade-top-flex{
  524. flex:1;
  525. }
  526. .shade-big-box{
  527. background-color: #fff;
  528. .shade-title-box{
  529. font-weight:900;
  530. padding-right:20rpx;
  531. width:300rpx;
  532. border-bottom-right-radius: 40rpx
  533. background-color: #0183FA;
  534. color:#fff;
  535. text-align: center;
  536. line-height:60rpx;
  537. }
  538. .shade-box{
  539. padding:20rpx 0 100rpx;
  540. .shade-text-box{
  541. display: flex;
  542. border-bottom:1rpx solid #f2f2f2;
  543. line-height:80rpx;
  544. padding:0 30rpx;
  545. view:nth-child(1){
  546. flex:1;
  547. }
  548. view:nth-child(1){
  549. flex:3;
  550. }
  551. }
  552. .shade-button{
  553. width:300rpx;
  554. line-height:80rpx;
  555. text-align: center;
  556. background-color: #0183FA;
  557. border-radius:8rpx;
  558. color:#fff;
  559. margin:40rpx auto 0;
  560. }
  561. .text-box{
  562. padding:60rpx 40rpx 200rpx;
  563. }
  564. }
  565. .shade-box-c{
  566. padding:120rpx 0 200rpx;
  567. .shade-text-title{
  568. text-align-last: center;
  569. line-height: 60rpx;
  570. }
  571. }
  572. }
  573. }
  574. }
  575. </style>