gasUse.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. <!--气瓶使用-->
  2. <template>
  3. <view id="gasRecycle">
  4. <view class="title">{{form.gasName}}-{{form.levelName}}({{form.sizeName}})</view>
  5. <view class="register_li">
  6. <view class="register_li_min">
  7. <view>余量:</view>
  8. <input v-model="form.gasPressure" disabled type="text" style="color: #D60000;">
  9. </view>
  10. <view class="register_li_min">
  11. <view>学院:</view>
  12. <input v-model="form.collegeName" disabled type="text" >
  13. </view>
  14. <view class="register_li_min" style="border: none;">
  15. <view>实验地点:</view>
  16. <input v-model="form.subjectName" disabled type="text" >
  17. </view>
  18. </view>
  19. <view class="register_li2">
  20. <view class="period" v-if="pageType==0">
  21. <view class="period_l"><i>*</i>开始时间</view>
  22. <view class="period_r">
  23. <picker mode="multiSelector" @change="changeDateTime" @columnchange="changeDateTimeColumn" :range="dateTimeArray">
  24. <input class="picker-text" disabled type="text" v-model="form.usageStartTime" placeholder="开始时间">
  25. </picker>
  26. </view>
  27. </view>
  28. <view class="period" v-if="pageType==0">
  29. <view class="period_l"><i>*</i>结束时间</view>
  30. <view class="period_r">
  31. <picker mode="multiSelector" @change="changeDateTime2" @columnchange="changeDateTimeColumn" :range="dateTimeArray">
  32. <input class="picker-text" disabled type="text" v-model="form.usageEndTime" placeholder="结束时间">
  33. </picker>
  34. </view>
  35. </view>
  36. <view class="register_li_min" v-if="pageType==0">
  37. <view>*</view>
  38. <view>使用时长:</view>
  39. <input v-model="form.usageTime+usageTimeUnit" placeholder="--" disabled type="text" >
  40. </view>
  41. <view class="register_li_min" v-if="pageType==0">
  42. <view>*</view>
  43. <view>当前压力:</view>
  44. <input v-model="form.currentPressure" @change="calculateAmountFun()" placeholder="请输入当前压力值" type="text" >
  45. </view>
  46. <view class="register_li_min" v-if="pageType==0">
  47. <view>*</view>
  48. <view>本次使用量:</view>
  49. <input v-model="form.usageAmount" placeholder="--" type="text" >
  50. </view>
  51. <view class="up-img-box">
  52. <view class="asterisk">*</view>
  53. <view class="title-view">气表照片:</view>
  54. <view class="img-max-box">
  55. <view class="img-box" v-for="(item,index) in imgList" :key="index">
  56. <img class="img-data" :src="baseUrl+item">
  57. <img class="position-img" src="@/pages_manage/images/icon_ssp_closure.png" @click="delImg(index)">
  58. </view>
  59. <img class="add-button" src="@/pages_manage/images/icon_07.png" @click="selectImage" v-if="imgList.length<1">
  60. <img class="add-button" src="@/pages_manage/images/Version3.0/img_sydj_sltp.png" >
  61. </view>
  62. </view>
  63. </view>
  64. <view class="btn" v-if="pageType==0">
  65. <view class="btn_l" @click="handleClick('gasApply')">气瓶出库</view>
  66. <view class="btn_r" @click="submitForm(1)">登记完成</view>
  67. </view>
  68. <view v-if="pageType==1" class="sub_btn" @click="submitForm(2)">提交余量不符并使用</view>
  69. </view>
  70. </template>
  71. <script>
  72. import { useRegisterDetail,useRegisterAdd,airbottleStockFindByBeaconTag,airbottleUsageRecordAdd} from '@/api/index.js'
  73. import { config } from '@/api/request/config.js'
  74. import { dateTimePicker,getMonthDay} from '@/api/../component/date.js'
  75. export default {
  76. name: "gasRecycle",
  77. data() {
  78. return {
  79. baseUrl:config.base_url,
  80. pageType:0,//0气瓶使用 1余量不符
  81. //列表请求参数
  82. getData:{
  83. pageNum:1,
  84. pageSize:20,
  85. isCg:0,
  86. zgStatus:"",
  87. getType:true,
  88. nullDataType:true,
  89. },
  90. userType:uni.getStorageSync('userType'),
  91. gasBottleLevel:uni.getStorageSync('gasBottleLevel'),// 气瓶级别
  92. gasBottleSpecification:uni.getStorageSync('gasBottleSpecification'), // 气瓶规格
  93. form:{
  94. location:'10map'
  95. },
  96. dataList:[],
  97. imgList:[],
  98. specificationName:{},
  99. currentStatus:null,
  100. beaconTag:'',
  101. //时间年月日时分秒
  102. dateTime: null,
  103. dateTimeArray: null,
  104. startYear: 0,
  105. endYear: 0,
  106. timeStr:'',
  107. usageTimeUnit:'分钟',
  108. currentDate:'',//开始时间默认当前时间
  109. }
  110. },
  111. onLoad(option) {
  112. this.currentDateStartFun()
  113. this.currentDateFun()
  114. this.initTime()
  115. if(option.beaconTag){
  116. this.beaconTag=option.beaconTag;
  117. }
  118. },
  119. onShow() {
  120. },
  121. mounted(){
  122. this.getInfo()
  123. },
  124. methods: {
  125. currentDateFun(){
  126. let date = new Date(); //Fri Oct 29 2021 16:37:56 GMT+0800 (CST)
  127. this.startYear= date.getFullYear(); //获取完整的年份(4位)
  128. this.endYear= date.getFullYear()+70;
  129. },
  130. //当前时间年月日时分
  131. currentDateStartFun(){
  132. var self = this;
  133. let yy = new Date().getFullYear();
  134. let mm = new Date().getMonth()+1;
  135. let dd = new Date().getDate();
  136. let hh = new Date().getHours();
  137. let mf = new Date().getMinutes()<10 ? '0'+new Date().getMinutes() : new Date().getMinutes();
  138. let ss = new Date().getSeconds()<10 ? '0'+new Date().getSeconds() : new Date().getSeconds();
  139. self.currentDate=yy+'-'+mm+'-'+dd+' '+hh+':'+mf;
  140. },
  141. initTime(){
  142. let date = new Date();
  143. let endYear = date.getFullYear();
  144. // 获取完整的年月日 时分秒,以及默认显示的数组
  145. let obj = dateTimePicker(this.startYear, this.endYear);
  146. // 精确到分的处理,将数组的秒去掉
  147. // let lastArray = obj.dateTimeArray.pop();
  148. // let lastTime = obj.dateTime.pop();
  149. this.dateTimeArray=obj.dateTimeArray
  150. this.dateTime=obj.dateTime
  151. },
  152. durationFun(){
  153. let self=this;
  154. let duration=new Date(self.form.usageEndTime).getTime()-new Date(self.form.usageStartTime).getTime()
  155. let minutes = parseInt(duration/(1000 * 60))
  156. this.$set(this.form,'usageTime',minutes);
  157. },
  158. //开始时间
  159. changeDateTime(e) {
  160. this.dateTime = e.detail.value;
  161. let start= this.createTimeStr(this.dateTimeArray,this.dateTime);
  162. if(new Date(start).getTime()>new Date(this.form.usageEndTime).getTime()){
  163. uni.showToast({
  164. title: '结束时间不能小于开始时间',
  165. icon:"none",
  166. mask:true,
  167. duration: 2000
  168. });
  169. }else{
  170. this.form.usageStartTime= start;
  171. }
  172. //ios时间不能用'-'解析成时间戳
  173. },
  174. //结束时间
  175. changeDateTime2(e) {
  176. this.dateTime = e.detail.value;
  177. let end= this.createTimeStr(this.dateTimeArray,this.dateTime);
  178. if(new Date(this.form.usageStartTime).getTime()>new Date(end).getTime()){
  179. uni.showToast({
  180. title: '结束时间不能小于开始时间',
  181. icon:"none",
  182. mask:true,
  183. duration: 2000
  184. });
  185. }else{
  186. this.form.usageEndTime= end
  187. //ios时间不能用'-'解析成时间戳
  188. this.durationFun();//使用时长
  189. }
  190. },
  191. /*年,月切换时重新更新计算*/
  192. changeDateTimeColumn(e) {
  193. //let {id} = e.target;
  194. let {column,value} = e.detail;
  195. if(column==0 || column==1){
  196. //直接修改数组下标视图不更新,用深拷贝之后替换数组
  197. let dateTime = JSON.parse(JSON.stringify(this.dateTime));
  198. let dateTimeArray = JSON.parse(JSON.stringify(this.dateTimeArray));
  199. dateTime[column] = value;
  200. dateTimeArray[2] = getMonthDay(dateTimeArray[0][dateTime[0]], dateTimeArray[1][dateTime[1]]);
  201. this.dateTime = dateTime;
  202. this.dateTimeArray = dateTimeArray;
  203. }
  204. },
  205. createTimeStr(dateTimeArray,dateTime){
  206. let timeStr = dateTimeArray[0][dateTime[0]]+'-'+dateTimeArray[1][dateTime[1]]+'-'+dateTimeArray[2][dateTime[2]]+' '+dateTimeArray[3][dateTime[3]]+":"+dateTimeArray[4][dateTime[4]];
  207. return timeStr
  208. },
  209. //点击事件
  210. handleClick(doType) {
  211. let _this=this;
  212. if(doType=='inconformity'){//余量不符
  213. _this.pageType=1;
  214. }else if(doType=='gasApply'){//气瓶出库
  215. uni.redirectTo({
  216. url:'/pages/gasBottle/gasOutstock/gasOutstock?id='+this.form.id
  217. })
  218. }
  219. },
  220. //输入当前压力值后计算本次使用量
  221. calculateAmountFun(){
  222. let num=parseInt(this.form.gasPressure)-parseInt(this.form.currentPressure)
  223. if(num<=0){
  224. num=0;
  225. }
  226. this.$set(this.form,'usageAmount',num)
  227. },
  228. // //开始时间选中事件
  229. // startChange(form,e){
  230. // if(new Date(e.target.value).getTime()>new Date(this.form.endTime).getTime()){
  231. // uni.showToast({
  232. // title: '结束时间不能小于开始时间',
  233. // icon:"none",
  234. // mask:true,
  235. // duration: 2000
  236. // });
  237. // }else{
  238. // this.$set(this.form,'startTime',e.target.value);
  239. // }
  240. // },
  241. // //结束时间选中事件
  242. // endChange(form,e){
  243. // if(new Date(this.form.startTime).getTime()>new Date(e.target.value).getTime()){
  244. // uni.showToast({
  245. // title: '结束时间不能小于开始时间',
  246. // icon:"none",
  247. // mask:true,
  248. // duration: 2000
  249. // });
  250. // }else{
  251. // this.$set(this.form,'endTime',e.target.value);
  252. // }
  253. // },
  254. // 图片上传
  255. selectImage(index) {
  256. let self = this;
  257. if(self.imgList.length>1){
  258. uni.showToast({
  259. title: '最多上传1张图片',
  260. icon:"none",
  261. mask:true,
  262. duration: 2000
  263. });
  264. return
  265. }
  266. wx.chooseImage({
  267. count: 1,
  268. sizeType: ["original", "compressed"],
  269. sourceType: ["album", "camera"],
  270. success: function(res) {
  271. let tempFilePaths = res.tempFilePaths[0];
  272. self.uploadImg(tempFilePaths,index);
  273. }
  274. });
  275. },
  276. async uploadImg(tempFilePaths,index){
  277. var self = this;
  278. uni.showLoading({
  279. title: '上传中',
  280. mask: true
  281. });
  282. uni.uploadFile({
  283. url: config.base_url+'/base/file/upload', //仅为示例,非真实的接口地址
  284. header:{'Authorization':uni.getStorageSync('token')},
  285. filePath: tempFilePaths,
  286. name: 'file',
  287. formData: {
  288. 'user': 'test'
  289. },
  290. success: (uploadFileRes) => {
  291. let res = JSON.parse(uploadFileRes.data);
  292. if(res.code == 200){
  293. self.imgList.push(res.data.url);
  294. }else{
  295. uni.showToast({
  296. title: res.msg,
  297. icon:"none",
  298. mask:true,
  299. duration: 2000
  300. });
  301. }
  302. },
  303. fail: err => {},
  304. complete: () => {
  305. uni.hideLoading()
  306. }
  307. });
  308. },
  309. //删除图片
  310. delImg(index){
  311. this.imgList.splice(index,1);
  312. },
  313. async getInfo(){
  314. let self=this;
  315. const {data} = await airbottleStockFindByBeaconTag({BeaconTag:self.beaconTag});
  316. if(data.code==200){
  317. for(let b=0;b<this.gasBottleSpecification.length;b++){
  318. if(this.gasBottleSpecification[b].dictValue==data.data.size){
  319. data.data.sizeName=this.gasBottleSpecification[b].dictLabel
  320. }
  321. }
  322. for(let t=0;t<this.gasBottleLevel.length;t++){
  323. if(this.gasBottleLevel[t].dictValue==data.data.level){
  324. data.data.levelName=this.gasBottleLevel[t].dictLabel
  325. }
  326. }
  327. self.form=data.data;
  328. this.$set(this.form,'usageStartTime',self.currentDate);
  329. console.log(self.currentDate)
  330. }
  331. },
  332. //提交
  333. async submitForm(type){
  334. let _this = this;
  335. if(_this.imgList.length<=0){
  336. uni.showToast({
  337. title: '请选择气表图片!',
  338. icon:"none",
  339. mask:true,
  340. duration: 2000
  341. });
  342. return
  343. }
  344. this.$set(this.form,'stcokId',this.form.id);
  345. this.$set(this.form,'id','');
  346. this.$set(this.form,'usageImg',this.imgList.join(','));
  347. this.$set(this.form,'gasPressure',this.form.currentPressure);
  348. const {data} = await airbottleUsageRecordAdd(this.form);
  349. if(data.code == 200){
  350. uni.showToast({
  351. title: '提交成功',
  352. icon:"none",
  353. mask:true,
  354. duration: 2000
  355. });
  356. setTimeout(function(){
  357. uni.redirectTo({
  358. url: '/pages/gasBottle/gasManage/gasManage'
  359. });
  360. },2000);
  361. }
  362. },
  363. }
  364. }
  365. </script>
  366. <style lang="stylus" scoped>
  367. #gasRecycle {
  368. height: auto;
  369. width: 100%;
  370. flex :1;
  371. display flex;
  372. flex-direction column;
  373. overflow hidden;
  374. padding-bottom: 220rpx;
  375. .title{
  376. width: 750rpx;
  377. height: 100rpx;
  378. background: #FFFFFF;
  379. font-size: 28rpx;
  380. font-family: PingFang SC;
  381. font-weight: 500;
  382. color: #333333;
  383. line-height: 100rpx;
  384. padding-left: 40rpx;
  385. }
  386. .register_li{
  387. background #fff;
  388. border-radius:20rpx;
  389. margin:20rpx 20rpx 0;
  390. padding:20rpx 0;
  391. box-sizing: border-box;
  392. .register_li_min{
  393. margin:0 26rpx;
  394. display flex;
  395. align-items center;
  396. border-bottom: 1px solid #F5F5F5;
  397. .icon_img{
  398. width: 30rpx;
  399. height: 30rpx;
  400. margin-right: 12rpx;
  401. }
  402. view{
  403. //width:140rpx;
  404. font-size: 28rpx;
  405. font-family: PingFang SC;
  406. font-weight: 500;
  407. color: #999999;
  408. line-height: 100rpx;
  409. }
  410. >input{
  411. flex:1;
  412. text-align: right;
  413. font-size: 24rpx;
  414. font-family: PingFang SC;
  415. font-weight: 500;
  416. color: #333333;
  417. }
  418. .inconformity{
  419. font-size: 24rpx;
  420. font-family: PingFang SC;
  421. font-weight: 500;
  422. color: #D60000;
  423. margin-left: 40rpx;
  424. }
  425. }
  426. }
  427. .register_li2{
  428. background #fff;
  429. border-radius:20rpx;
  430. margin:20rpx 20rpx 0;
  431. padding:20rpx 0;
  432. box-sizing: border-box;
  433. .period{
  434. display: flex;
  435. justify-content: flex-start;
  436. align-items: center;
  437. margin: 0 26rpx;
  438. border-bottom: 1px solid #f5f5f5;
  439. .period_l{
  440. width: 146rpx;
  441. font-size: 30rpx;
  442. font-family: PingFang SC-Medium, PingFang SC;
  443. font-weight: 400;
  444. color: #333333;
  445. line-height: 42rpx;
  446. text-align: left;
  447. >i{
  448. display: inline-block;
  449. color: #f00;
  450. line-height: 28rpx;
  451. margin-right: 12rpx;
  452. }
  453. }
  454. .period_r{
  455. width: 490rpx;
  456. height: 80rpx;
  457. border-radius: 10rpx;
  458. display: flex;
  459. justify-content: flex-start;
  460. align-items: center;
  461. .picker-text{
  462. font-size: 30rpx;
  463. font-family: PingFang SC-Medium, PingFang SC;
  464. font-weight: 400;
  465. color: #999;
  466. line-height: 80rpx;
  467. width: 516rpx;
  468. text-align: right;
  469. }
  470. // .picker-text2{
  471. // font-size: 30rpx;
  472. // font-family: PingFang SC-Medium, PingFang SC;
  473. // font-weight: 400;
  474. // color: #333;
  475. // line-height: 80rpx;
  476. // width: 230rpx;
  477. // text-align: center;
  478. // }
  479. }
  480. }
  481. .register_li_min{
  482. margin:0 26rpx;
  483. display flex;
  484. align-items center;
  485. border-bottom: 1px solid #F5F5F5;
  486. .icon_img{
  487. width: 30rpx;
  488. height: 30rpx;
  489. margin-right: 12rpx;
  490. }
  491. view:nth-child(1){
  492. color:red;
  493. line-height:28rpx;
  494. margin-right: 12rpx;
  495. }
  496. view{
  497. //width:140rpx;
  498. font-size: 28rpx;
  499. font-family: PingFang SC;
  500. font-weight: 500;
  501. color: #333333;
  502. line-height: 100rpx;
  503. }
  504. >input{
  505. flex:1;
  506. text-align: right;
  507. font-size: 24rpx;
  508. font-family: PingFang SC;
  509. font-weight: 500;
  510. color: #999999;
  511. }
  512. }
  513. /* 照片 */
  514. .up-img-box{
  515. display flex
  516. margin:34rpx 26rpx;
  517. .asterisk{
  518. padding-top:30rpx;
  519. color:red;
  520. line-height:28rpx;
  521. margin-right: 12rpx;
  522. }
  523. .title-view{
  524. width:150rpx;
  525. line-height:80rpx;
  526. font-size: 30rpx;
  527. color:#333;
  528. }
  529. .img-max-box{
  530. width:480rpx;
  531. display: flex;
  532. .img-box{
  533. display inline-block
  534. height:150rpx;
  535. width:150rpx;
  536. position relative
  537. margin:0 20rpx 20rpx 0;
  538. .img-data{
  539. height:150rpx;
  540. width:150rpx;
  541. }
  542. .position-img{
  543. position absolute
  544. right:0;
  545. top:0;
  546. width:36rpx;
  547. height:36rpx;
  548. }
  549. }
  550. .add-button{
  551. display inline-block
  552. height:150rpx;
  553. width:150rpx;
  554. margin-right: 20rpx;
  555. }
  556. }
  557. }
  558. }
  559. /* 按钮 */
  560. .btn{
  561. display: flex;
  562. position: fixed;
  563. bottom: 40rpx;
  564. left: 50rpx;
  565. .btn_l{
  566. width: 324rpx;
  567. height: 100rpx;
  568. background: #F28E26;
  569. border-radius: 50rpx 0rpx 0rpx 50rpx;
  570. font-size: 28rpx;
  571. font-family: PingFang SC;
  572. font-weight: 500;
  573. color: #FFFFFF;
  574. line-height: 100rpx;
  575. text-align: center;
  576. }
  577. .btn_r{
  578. width: 324rpx;
  579. height: 100rpx;
  580. background: #0183FA;
  581. border-radius: 0rpx 50rpx 50rpx 0rpx;
  582. font-size: 28rpx;
  583. font-family: PingFang SC;
  584. font-weight: 500;
  585. color: #FFFFFF;
  586. line-height: 100rpx;
  587. text-align: center;
  588. }
  589. }
  590. /* 按钮 */
  591. .sub_btn{
  592. width: 650rpx;
  593. height: 100rpx;
  594. background: #0183FA;
  595. border-radius: 20rpx;
  596. font-size: 28rpx;
  597. font-family: PingFang SC;
  598. font-weight: 500;
  599. color: #FFFFFF;
  600. line-height: 100rpx;
  601. text-align: center;
  602. margin-left: 50rpx;
  603. position: fixed;
  604. bottom:30rpx;
  605. z-index: 1000;
  606. }
  607. /* 空 */
  608. .empty{
  609. background #fff;
  610. border-radius:20rpx;
  611. margin:20rpx 20rpx 0;
  612. padding:20rpx 0;
  613. box-sizing: border-box;
  614. >img{
  615. width: 100rpx;
  616. height: 100rpx;
  617. margin-top: 124rpx;
  618. margin-left: 300rpx;
  619. }
  620. >view{
  621. font-size: 28rpx;
  622. font-family: PingFang SC;
  623. font-weight: 500;
  624. color: #333333;
  625. line-height: 30rpx;
  626. text-align: center;
  627. margin-top: 42rpx;
  628. padding-bottom: 106rpx;
  629. }
  630. }
  631. }
  632. </style>