infoPage.vue 16 KB

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