gasUse.vue 18 KB

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