addPage.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. <!-- 称重登记-新增 -->
  2. <template>
  3. <view class="weighingRegistrationAddPage">
  4. <view class="weighingRegistrationAddPage-center-box">
  5. <view class="text-title-p">基础信息</view>
  6. <view class="content-box" style="padding-bottom:20rpx;">
  7. <view class="sub-picker-box">
  8. <view class="title-box-1" style="width:220rpx;">报备单编号:</view>
  9. <view class="text-p-1">{{addForm.newdata1}}</view>
  10. </view>
  11. <view class="sub-picker-box">
  12. <view class="title-box-1" style="width:220rpx;">实验室:</view>
  13. <view class="text-p-1">{{addForm.newdata2}}</view>
  14. </view>
  15. <view class="sub-picker-box">
  16. <view class="title-box-1" style="width:220rpx;">上门回收日期:</view>
  17. <view class="text-p-1">{{addForm.newdata3}}</view>
  18. </view>
  19. <view class="sub-picker-box">
  20. <view class="title-box-1" style="width:220rpx;">废物种类:</view>
  21. <view class="text-p-1">{{addForm.newdata4}}</view>
  22. </view>
  23. <view class="sub-picker-box">
  24. <view class="title-box-1" style="width:220rpx;">报备人:</view>
  25. <view class="text-p-1">{{addForm.newdata5}}</view>
  26. </view>
  27. <view class="sub-picker-box">
  28. <view class="title-box-1" style="width:220rpx;">报备时间:</view>
  29. <view class="text-p-1">{{addForm.newdata6}}</view>
  30. </view>
  31. </view>
  32. <view class="text-title-p">称重登记</view>
  33. <view class="content-box">
  34. <view class="for-content-box" v-for="(item,index) in addForm.formData4" :key="index">
  35. <view class="sub-picker-box">
  36. <view class="mark-box">*</view>
  37. <view class="title-box">类型:</view>
  38. <view class="picker-box">
  39. <picker @change="(val)=>forChange(index,val)" :value="item.forData3" :range="item.forList" :range-key="'label'">
  40. <view class="picker-p" :class="item.forData1?'check-picker-p':''">{{item.forData1?item.forData2:'请选择危废类型'}}</view>
  41. </picker>
  42. </view>
  43. <img class="right-button" v-if="addForm.formData4[1]"
  44. @click="reductionItemButton(index)"
  45. :src="imagesUrl('commonality/icon_zgsq_jian.png')">
  46. </view>
  47. <view class="sub-picker-box">
  48. <view class="mark-box">*</view>
  49. <view class="title-box">数量:</view>
  50. <view class="reduction-button" @click="reductionAdd(1,index)">-</view>
  51. <input class="input-p" type="digit" maxlength="10" @input="(val)=>handleInput(index,val)" v-model="item.forData4">
  52. <view class="add-button" @click="reductionAdd(2,index)">+</view>
  53. <view class="unit-p">{{item.forData1?item.forData5:''}}</view>
  54. </view>
  55. </view>
  56. <view class="add-item-button" v-if="this.addForm.formData4.length < this.dialogOptionForList.length"
  57. @click="addItemButton()">补充其他未报备类型</view>
  58. <view class="sub-picker-box">
  59. <view class="mark-box"></view>
  60. <view class="title-box">图片:</view>
  61. <view class="explain-box">可拍摄称重凭据或回收人员照片,最多可上传3张</view>
  62. </view>
  63. <view class="sub-picker-box">
  64. <view class="img-list-box" v-if="addForm.imgList[0]">
  65. <view class="for-img-box" v-for="(img,imgIndex) in addForm.imgList" :key="imgIndex" >
  66. <p @click="delImg(imgIndex)">x</p>
  67. <img :src="baseUrl+img">
  68. </view>
  69. </view>
  70. <view class="img-up-p" @click="selectImage()" v-if="!addForm.imgList[2]">+</view>
  71. </view>
  72. <view class="sub-picker-box" style="padding-bottom:50rpx;">
  73. </view>
  74. </view>
  75. <view class="submit-button">登记完成,提交</view>
  76. </view>
  77. </view>
  78. </template>
  79. <script>
  80. import { config } from '@/api/request/config.js'
  81. import {
  82. demo1,
  83. demo2
  84. } from '@/pages_hazardousWasteRecycling/api/index.js'
  85. export default {
  86. data() {
  87. return {
  88. baseUrl:config.base_url,
  89. addForm:{
  90. newdata1:'HW202510400001',
  91. newdata2:'植物营养实验室(A201)',
  92. newdata3:'2025-11-05(星期四)',
  93. newdata4:'4',
  94. newdata5:'王二小(2020110010)',
  95. newdata6:'2025-11-04 10:10:09',
  96. formData4:[],
  97. imgList:[],
  98. },
  99. subList: [
  100. { subId: 1, subName: "实验室1" },
  101. { subId: 2, subName: "实验室2" },
  102. { subId: 3, subName: "实验室3" },
  103. ],
  104. dialogOptionList:[],
  105. dialogOptionForList:[
  106. {value:'1',label:'数据1',dict:'斤'},
  107. {value:'2',label:'数据2',dict:'公斤'},
  108. {value:'3',label:'数据3',dict:'升'},
  109. {value:'4',label:'数据4',dict:'毫升'},
  110. {value:'5',label:'数据5',dict:'公升'},
  111. {value:'6',label:'数据6',dict:'克'},
  112. ],
  113. }
  114. },
  115. onLoad(option) {
  116. },
  117. onShow() {
  118. },
  119. mounted() {
  120. this.initialize(1);
  121. },
  122. methods: {
  123. //初始化
  124. initialize(type){
  125. let self = this;
  126. if(type == 1){
  127. //无数据-初始化
  128. for(let i=0;i<self.dialogOptionForList.length;i++){
  129. if(i<4){
  130. let obj = {
  131. forData1:self.dialogOptionForList[i].value,
  132. forData2:self.dialogOptionForList[i].label,
  133. forData3:i,
  134. forData4:0,
  135. forData5:self.dialogOptionForList[i].dict,
  136. forList:self.dialogOptionForList,
  137. }
  138. self.addForm.formData4.push(JSON.parse(JSON.stringify(obj)))
  139. }
  140. }
  141. this.filtrateList();
  142. }else if(type == 2){
  143. //有数据-初始化
  144. }
  145. },
  146. //选中实验室
  147. subChange(e) {
  148. this.$set(this.addForm,'subId',this.subList[e.detail.value].subId);
  149. this.$set(this.addForm,'subName',this.subList[e.detail.value].subName);
  150. this.$set(this.addForm,'subIndex',e.detail.value);
  151. },
  152. //选中类型
  153. forChange(index,e){
  154. this.$set(this.addForm.formData4[index],'forData1',this.addForm.formData4[index].forList[e.detail.value].value);
  155. this.$set(this.addForm.formData4[index],'forData2',this.addForm.formData4[index].forList[e.detail.value].label);
  156. this.$set(this.addForm.formData4[index],'forData5',this.addForm.formData4[index].forList[e.detail.value].dict);
  157. this.$set(this.addForm.formData4[index],'forData3',e.detail.value);
  158. this.filtrateList();
  159. },
  160. //单位值加减
  161. reductionAdd(type,index){
  162. if(type == 1){
  163. //减
  164. if(this.addForm.formData4[index].forData4>=1){
  165. this.$set(this.addForm.formData4[index],'forData4',this.addForm.formData4[index].forData4-1);
  166. }
  167. }else if(type == 2){
  168. //加
  169. if(this.addForm.formData4[index].forData4<9999){
  170. this.$set(this.addForm.formData4[index],'forData4',this.addForm.formData4[index].forData4+1);
  171. }
  172. }
  173. },
  174. //添加类型
  175. addItemButton(){
  176. if(this.addForm.formData4.length>= this.dialogOptionForList.length){
  177. uni.showToast({
  178. title: '没有更多类型可添加',
  179. icon: "none",
  180. mask: true,
  181. duration: 2000
  182. });
  183. return
  184. }
  185. this.addForm.formData4.push({
  186. forData1:'',
  187. forData2:'',
  188. forData3:'',
  189. forData4:0,
  190. forData5:'',
  191. forList:[],
  192. })
  193. this.filtrateList();
  194. },
  195. //删除类型
  196. reductionItemButton(index){
  197. let self = this;
  198. uni.showModal({
  199. // title: '确认要退出吗?',
  200. content: '确认删除该类型?',
  201. cancelColor: "#999",
  202. confirmColor: "#0183FA",
  203. success: function(res) {
  204. if (res.confirm) {
  205. self.addForm.formData4.splice(index,1);
  206. self.filtrateList();
  207. } else if (res.cancel) {}
  208. }
  209. });
  210. },
  211. // 图片上传
  212. selectImage() {
  213. let self = this;
  214. wx.chooseImage({
  215. count: 1,
  216. sizeType: ["original", "compressed"],
  217. sourceType: ["album", "camera"],
  218. success: function(res) {
  219. let tempFilePaths = res.tempFilePaths[0];
  220. self.uploadImg(tempFilePaths);
  221. }
  222. });
  223. },
  224. async uploadImg(tempFilePaths){
  225. var self = this;
  226. uni.showLoading({
  227. title: '上传中',
  228. mask: true
  229. });
  230. uni.uploadFile({
  231. url: config.base_url + '/system/file/upload', //仅为示例,非真实的接口地址
  232. header:{'Authorization':uni.getStorageSync('token')},
  233. filePath: tempFilePaths,
  234. name: 'file',
  235. formData: {
  236. 'user': 'test'
  237. },
  238. success: (uploadFileRes) => {
  239. let res = JSON.parse(uploadFileRes.data);
  240. if(res.code == 200){
  241. self.addForm.imgList.push(res.data.url)
  242. }else{
  243. uni.showToast({
  244. title: res.msg,
  245. icon:"none",
  246. mask:true,
  247. duration: 2000
  248. });
  249. }
  250. },
  251. fail: err => {},
  252. complete: () => {
  253. uni.hideLoading()
  254. }
  255. });
  256. },
  257. //删除图片
  258. delImg(index){
  259. let self = this;
  260. uni.showModal({
  261. // title: '确认要退出吗?',
  262. content: '确认删除该图片?',
  263. cancelColor: "#999",
  264. confirmColor: "#0183FA",
  265. success: function(res) {
  266. if (res.confirm) {
  267. self.addForm.imgList.splice(index,1);
  268. } else if (res.cancel) {}
  269. }
  270. });
  271. },
  272. // 小数点后两位
  273. handleInput(index,e){
  274. // 一定要加nextTick,否则特殊情况的更改不生效【如:000时,更改为0】
  275. this.$nextTick(() => {
  276. let value = e.detail.value
  277. // 如果当前输入为空,直接允许清空
  278. if (!value) {
  279. this.addForm.formData4[index].forData4 = ''
  280. } else if (value?.charAt(0) === '0' && value.charAt(1) && value.charAt(1) !== '.') {
  281. // // 1. 当第一位为0时,只能输入小数点【第二位必须是小数点】
  282. value = '0'
  283. }
  284. value = value.replace(/[^\d.]/g, '') // 清除"数字"和"."以外的字符
  285. value = value.replace(/\.{2,}/g, '.') // 只保留第一个. 清除多余的
  286. value = value.match(/^\d*(\.?\d{0,2})/g)[0] || '' // 保留2位小数
  287. this.addForm.formData4[index].forData4 = value
  288. })
  289. },
  290. //匹配数据
  291. filtrateList(){
  292. let self = this;
  293. let forList = JSON.parse(JSON.stringify(this.dialogOptionForList));
  294. let newList = JSON.parse(JSON.stringify(this.dialogOptionForList));
  295. for(let i=0;i<forList.length;i++){
  296. let num = 0;
  297. for(let o=0;o<self.addForm.formData4.length;o++){
  298. if(forList[i].value == self.addForm.formData4[o].forData1){
  299. num++
  300. break
  301. }
  302. }
  303. if(num!=0){
  304. forList.splice(i,1);
  305. i--
  306. }
  307. }
  308. for(let i=0;i<self.addForm.formData4.length;i++){
  309. let list = [];
  310. if(self.addForm.formData4[i].forData1){
  311. for(let o=0;o<newList.length;o++){
  312. if(self.addForm.formData4[i].forData1 == newList[o].value){
  313. list.push(newList[o]);
  314. }
  315. }
  316. }
  317. list = list.concat(forList)
  318. self.$set(self.addForm.formData4[i],'forList',JSON.parse(JSON.stringify(list)));
  319. }
  320. },
  321. },
  322. }
  323. </script>
  324. <style lang="stylus" scoped>
  325. .weighingRegistrationAddPage{
  326. height: 100%;
  327. display flex;
  328. flex:1;
  329. flex-direction column;
  330. overflow: hidden;
  331. .weighingRegistrationAddPage-top-box{
  332. height:380rpx;
  333. }
  334. .weighingRegistrationAddPage-center-box{
  335. flex:1;
  336. overflow-y: scroll;
  337. overflow-x: hidden
  338. display flex;
  339. flex-direction column;
  340. }
  341. .text-title-p{
  342. font-size:32rpx;
  343. color:#0183FA;
  344. line-height:80rpx;
  345. margin:0 20rpx;
  346. }
  347. .content-box{
  348. margin:0 20rpx;
  349. background-color: #fff;
  350. border-radius:10rpx;
  351. padding:20rpx 20rpx 0 10rpx;
  352. .for-content-box{
  353. .right-button{
  354. margin-top:8rpx;
  355. margin-left:20rpx;
  356. width:50rpx;
  357. height:50rpx;
  358. }
  359. }
  360. .sub-picker-box{
  361. display: flex;
  362. padding:10rpx;
  363. .mark-box{
  364. width:17rpx;
  365. color:red;
  366. margin-left:10rpx;
  367. height:60rpx;
  368. line-height:60rpx;
  369. margin-bottom:20rpx;
  370. }
  371. .title-box-1{
  372. width:100rpx;
  373. margin:0 10rpx;
  374. height:40rpx;
  375. line-height:40rpx;
  376. }
  377. .text-p-1{
  378. flex:1;
  379. height:40rpx;
  380. line-height:40rpx;
  381. }
  382. .title-box{
  383. width:100rpx;
  384. margin:0 10rpx;
  385. height:60rpx;
  386. line-height:60rpx;
  387. }
  388. .text-p{
  389. flex:1;
  390. text-align: right;
  391. height:60rpx;
  392. line-height:60rpx;
  393. }
  394. .picker-box{
  395. height:60rpx;
  396. flex:1;
  397. border:1rpx solid #dedede;
  398. border-radius:10rpx;
  399. .picker-p{
  400. padding:0 20rpx;
  401. color:#666;
  402. line-height:60rpx;
  403. }
  404. .check-picker-p{
  405. }
  406. }
  407. .reduction-button{
  408. width:60rpx;
  409. height:60rpx;
  410. border:1rpx solid #0183FA;
  411. color:#0183FA;
  412. text-align: center;
  413. font-size:30rpx;
  414. line-height:58rpx;
  415. border-radius:6rpx;
  416. font-size:34rpx;
  417. font-weight:700;
  418. }
  419. .input-p{
  420. width:140rpx;
  421. height:60rpx;
  422. height:60rpx;
  423. text-align: center;
  424. border:1rpx solid #dedede;
  425. border-radius:6rpx;
  426. margin:0 20rpx;
  427. }
  428. .add-button{
  429. width:60rpx;
  430. height:60rpx;
  431. border:1rpx solid #0183FA;
  432. color:#0183FA;
  433. text-align: center;
  434. font-size:30rpx;
  435. line-height:58rpx;
  436. border-radius:6rpx;
  437. font-size:34rpx;
  438. font-weight:700;
  439. }
  440. .unit-p{
  441. text-align: center;
  442. flex:1;
  443. height:62rpx;
  444. line-height:60rpx;
  445. font-size:30rpx;
  446. }
  447. .input-text-p{
  448. flex:1;
  449. height:185rpx;
  450. border:1rpx solid #dedede;
  451. border-radius:6rpx;
  452. padding:20rpx;
  453. margin-right:70rpx;
  454. margin-bottom:30rpx;
  455. }
  456. .explain-box{
  457. flex:1;
  458. height:32rpx;
  459. line-height:30rpx;
  460. font-size:28rpx;
  461. color:#999;
  462. }
  463. .img-list-box{
  464. display: flex;
  465. .for-img-box{
  466. position: relative;
  467. width:200rpx;
  468. height:200rpx;
  469. margin-left:18rpx;
  470. p{
  471. position: absolute;
  472. top:0;
  473. right:0;
  474. border-radius:50%;
  475. width:40rpx;
  476. height:40rpx;
  477. line-height:38rpx;
  478. text-align: center;
  479. color:#fff;
  480. background-color: #FF6A6A;
  481. }
  482. img{
  483. display: inline-block;
  484. width:200rpx;
  485. height:200rpx;
  486. }
  487. }
  488. }
  489. .img-up-p{
  490. width:200rpx;
  491. height:200rpx;
  492. margin-left:18rpx;
  493. line-height:200rpx;
  494. text-align: center;
  495. border:1rpx solid #999;
  496. border-radius:10rpx;
  497. color:#999;
  498. line-height:200rpx;
  499. font-size:50rpx;
  500. }
  501. }
  502. .add-item-button{
  503. width:588rpx;
  504. line-height:80rpx;
  505. height:80rpx;
  506. margin:0 50rpx 20rpx;
  507. background-color: #fff;
  508. border:1rpx solid #0183FA;
  509. color:#0183FA;
  510. font-size:30rpx;
  511. text-align: center;
  512. border-radius:6rpx;
  513. }
  514. }
  515. .submit-button{
  516. width:650rpx;
  517. line-height:80rpx;
  518. height:80rpx;
  519. margin:20rpx 50rpx 60rpx;
  520. background-color: #0183FA;
  521. color:#fff;
  522. font-size:30rpx;
  523. text-align: center;
  524. border-radius:6rpx;
  525. }
  526. }
  527. </style>