infoPage.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  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.runStatus == 0){
  251. //无人使用
  252. const now = new Date();
  253. now.setSeconds(0, 0); // 将秒和毫秒都设为0
  254. const timestamp = now.getTime()
  255. this.$set(this,'timeApplication',timestamp);
  256. this.$set(this,'pickerIndex',0);
  257. this.$set(this,'shadeDataA',{
  258. data1:uni.getStorageSync('user-name'),
  259. data2:null,
  260. data3:this.timeApplication,
  261. data4:this.timeApplication,
  262. data5:'0天0小时0分',
  263. });
  264. this.$set(this,'shadeType',1);
  265. }else if(this.newData.runStatus != 0 && this.newData.currentUserId != this.userId){
  266. //别人使用中
  267. this.$set(this,'shadeDataC',{
  268. data1:this.newData.currentUserName,
  269. data2:this.newData.currentStartTime,
  270. // data3:this.toTimestamp(this.newData.currentStartTime),
  271. });
  272. this.$set(this,'shadeType',3);
  273. }else if(this.newData.runStatus != 0 && this.newData.currentUserId == this.userId){
  274. //自己使用中
  275. const now = new Date();
  276. now.setSeconds(0, 0); // 将秒和毫秒都设为0
  277. const timestamp = now.getTime()
  278. this.$set(this,'timeApplication',timestamp);
  279. this.$set(this,'shadeDataB',{
  280. data1:this.newData.currentUserName,
  281. data2:this.newData.usageType == 0?'自用':'对外服务',
  282. data3:this.toTimestamp(this.newData.currentStartTime),
  283. data4:this.timeApplication,
  284. data5:this.formatTimeDiff(this.toTimestamp(this.newData.currentStartTime),this.timeApplication),
  285. });
  286. this.$set(this,'shadeType',2);
  287. }
  288. },
  289. offShade(){
  290. this.$set(this,'shadeType',0);
  291. },
  292. //时间戳格式化
  293. timestampToStr(timestamp) {
  294. const date = new Date(timestamp); // 传入毫秒级时间戳
  295. const year = date.getFullYear();
  296. const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始,需+1
  297. const day = String(date.getDate()).padStart(2, '0');
  298. const hours = String(date.getHours()).padStart(2, '0');
  299. const minutes = String(date.getMinutes()).padStart(2, '0');
  300. // 注意:这里没有拼接秒
  301. return `${year}-${month}-${day} ${hours}:${minutes}`;
  302. },
  303. //时间格式转时间戳
  304. toTimestamp(dateStr, isUTC = false) {
  305. // 假设 dateStr 格式为 "YYYY-MM-DD HH:mm:ss"
  306. const [datePart, timePart] = dateStr.split(' ');
  307. const [year, month, day] = datePart.split('-').map(Number);
  308. const [hour, minute, second] = timePart.split(':').map(Number);
  309. if (isUTC) {
  310. // 返回 UTC 时间戳
  311. return Date.UTC(year, month - 1, day, hour, minute, second);
  312. } else {
  313. // 返回本地时间戳
  314. return new Date(year, month - 1, day, hour, minute, second).getTime();
  315. }
  316. },
  317. //开始时间-结束时间-相差时间
  318. formatTimeDiff(timestamp1, timestamp2) {
  319. // 计算绝对差值(毫秒)
  320. const diffMs = Math.abs(timestamp1 - timestamp2);
  321. // 转换为总分钟数(向下取整)
  322. const totalMinutes = Math.floor(diffMs / (1000 * 60));
  323. // 计算天、小时、分钟
  324. const days = Math.floor(totalMinutes / (60 * 24));
  325. const remainingMinutes = totalMinutes % (60 * 24);
  326. const hours = Math.floor(remainingMinutes / 60);
  327. const minutes = remainingMinutes % 60;
  328. // 构建输出字符串
  329. const parts = [];
  330. if (days > 0) parts.push(days + '天');
  331. if (hours > 0) parts.push(hours + '小时');
  332. if (minutes > 0 || parts.length === 0) parts.push(minutes + '分'); // 确保至少显示“0分”
  333. return parts.join('');
  334. },
  335. //登记-结束时间选择
  336. timePickerChange(){
  337. if(this.shadeDataA.data4>this.shadeDataA.data3){
  338. this.$set(this.shadeDataA,'data5',this.formatTimeDiff(this.shadeDataA.data3,this.shadeDataA.data4));
  339. }else{
  340. uni.showToast({
  341. title: '请检查关机时间',
  342. icon:"none",
  343. mask:true,
  344. duration: 2000
  345. });
  346. }
  347. },
  348. //确定按钮
  349. submitButton(type){
  350. let self = this;
  351. if(type == 1){
  352. if(this.shadeDataA.data4>this.shadeDataA.data3){
  353. uni.showModal({
  354. content: '确认提交?',
  355. cancelColor: "#999",
  356. confirmColor: "#0183FA",
  357. success: function(res) {
  358. if (res.confirm) {
  359. self.mpDeviceUsageStart()
  360. } else if (res.cancel) {}
  361. }
  362. });
  363. }else{
  364. uni.showToast({
  365. title: '请检查关机时间',
  366. icon:"none",
  367. mask:true,
  368. duration: 2000
  369. });
  370. }
  371. }else if(type == 2){
  372. uni.showModal({
  373. content: '确认提交?',
  374. cancelColor: "#999",
  375. confirmColor: "#0183FA",
  376. success: function(res) {
  377. if (res.confirm) {
  378. self.mpDeviceUsageEnd()
  379. } else if (res.cancel) {}
  380. }
  381. });
  382. }
  383. },
  384. //登记使用
  385. async mpDeviceUsageStart() {
  386. let self = this;
  387. let obj = {
  388. deviceId:this.equipmentId,
  389. usageType:this.pickerList[this.pickerIndex]=='自用'?0:1,
  390. startTime:this.timestampToStr(this.shadeDataA.data3)+':00',
  391. expectedEndTime:this.timestampToStr(this.shadeDataA.data4)+':00',
  392. }
  393. const {
  394. data
  395. } = await mpDeviceUsageStart(obj);
  396. if (data.code == 200) {
  397. this.$set(this,'shadeType',0);
  398. this.mpDeviceDetail();
  399. uni.showToast({
  400. mask: true,
  401. icon: "none",
  402. position: "center",
  403. title: data.message,
  404. duration: 2000
  405. });
  406. }
  407. },
  408. //结束使用
  409. async mpDeviceUsageEnd() {
  410. let self = this;
  411. let obj = {
  412. deviceId:this.newData.currentUsageId,
  413. }
  414. const {
  415. data
  416. } = await mpDeviceUsageEnd(obj);
  417. if (data.code == 200) {
  418. this.$set(this,'shadeType',0);
  419. this.mpDeviceDetail();
  420. uni.showToast({
  421. mask: true,
  422. icon: "none",
  423. position: "center",
  424. title: data.message,
  425. duration: 2000
  426. });
  427. }
  428. },
  429. },
  430. }
  431. </script>
  432. <style lang="stylus" scoped>
  433. .equipmentInformationInfoPage {
  434. height: 100%;
  435. flex:1;
  436. display:flex;
  437. flex-direction:column;
  438. background-color: #fff;
  439. overflow: scroll;
  440. .info-max-box{
  441. display: flex;
  442. .left-img{
  443. width:200rpx;
  444. height:200rpx;
  445. display: inline-block;
  446. border:1rpx solid #dedede;
  447. margin:40rpx 20rpx 20rpx 20rpx;
  448. }
  449. .right-box{
  450. flex:1;
  451. margin:40rpx 20rpx 20rpx 0;
  452. view{
  453. width: 480rpx;
  454. display:block;
  455. overflow:hidden;
  456. text-overflow:ellipsis;
  457. white-space:nowrap;
  458. margin-bottom:14rpx;
  459. }
  460. }
  461. }
  462. .text-max-box{
  463. display: flex;
  464. border-bottom: 1rpx solid #f2f2f2;
  465. line-height:80rpx;
  466. padding: 0 40rpx;
  467. img{
  468. width:40rpx;
  469. height:40rpx;
  470. display: inline-block;
  471. }
  472. view:nth-child(2){
  473. flex:1;
  474. }
  475. view:nth-child(3){
  476. }
  477. .colorA{
  478. color:#0183FA;
  479. }
  480. }
  481. .text-title-box{
  482. line-height:80rpx;
  483. background-color: #f2f2f2;
  484. padding: 0 30rpx;
  485. }
  486. .bottom-button{
  487. width:300rpx;
  488. line-height:80rpx;
  489. text-align: center;
  490. margin:60rpx auto;
  491. color:#fff;
  492. background-color: #0183FA;
  493. border-radius:6rpx;
  494. }
  495. .shade-max-big-box{
  496. position: absolute;
  497. top:0;
  498. left:0;
  499. width:100%;
  500. height:100%;
  501. background-color: rgba(0,0,0,0.3)
  502. display: flex;
  503. flex-direction: column;
  504. .shade-top-flex{
  505. flex:1;
  506. }
  507. .shade-big-box{
  508. background-color: #fff;
  509. .shade-title-box{
  510. font-weight:900;
  511. padding-right:20rpx;
  512. width:300rpx;
  513. border-bottom-right-radius: 40rpx
  514. background-color: #0183FA;
  515. color:#fff;
  516. text-align: center;
  517. line-height:60rpx;
  518. }
  519. .shade-box{
  520. padding:20rpx 0 100rpx;
  521. .shade-text-box{
  522. display: flex;
  523. border-bottom:1rpx solid #f2f2f2;
  524. line-height:80rpx;
  525. padding:0 30rpx;
  526. view:nth-child(1){
  527. flex:1;
  528. }
  529. view:nth-child(1){
  530. flex:3;
  531. }
  532. }
  533. .shade-button{
  534. width:300rpx;
  535. line-height:80rpx;
  536. text-align: center;
  537. background-color: #0183FA;
  538. border-radius:8rpx;
  539. color:#fff;
  540. margin:40rpx auto 0;
  541. }
  542. .text-box{
  543. padding:60rpx 40rpx 200rpx;
  544. }
  545. }
  546. .shade-box-c{
  547. padding:120rpx 0 200rpx;
  548. .shade-text-title{
  549. text-align-last: center;
  550. line-height: 60rpx;
  551. }
  552. }
  553. }
  554. }
  555. }
  556. </style>