gasUse.vue 16 KB

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