yuyue.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. <template>
  2. <view class="content">
  3. <view class="content-form">
  4. <!-- <view class="content-detail">
  5. <view class="detail-text">
  6. <u-image src="/static/pop_icon_warning.png" width="32" height="32"></u-image>
  7. <text>请按照回收要求合理预约服务</text>
  8. </view>
  9. <view class="detail-xqtext">查看详情</view>
  10. </view> -->
  11. <view class="form-data">
  12. <u-form :model="form" ref="uForm" :label-width="140" :error-type="['toast']">
  13. <u-form-item prop="time" label="预约时间:" required>
  14. <u-select v-model="show" mode="mutil-column-auto" :list="list" @confirm="confirm"></u-select>
  15. <u-input placeholder="请选择预约时间" v-model="time" @click="selectTime" :disabled="true"/>
  16. <u-icon name="arrow-right" slot="right" @click="selectTime"></u-icon>
  17. </u-form-item>
  18. <u-form-item prop="info" label="用户信息:" required>
  19. <u-input placeholder="请选择用户信息" v-model="form.info" @click="selectUserInfo" :disabled="true"/>
  20. <u-icon name="arrow-right" slot="right" @click="selectUserInfo"></u-icon>
  21. </u-form-item>
  22. </u-form>
  23. </view>
  24. <view class="form-data rubbishType">
  25. <view class="rubbishType-title u-required:before">回收分类</view>
  26. <view class="rubbishType-tags">
  27. <view :class="['item-tags', item.check ? 'active' : '']" v-for="item in rubbishTypeListData" :key="item.code" @click="itemRubbishChange(item)">{{item.dispName}}</view>
  28. </view>
  29. </view>
  30. <view class="form-data rubbishType">
  31. <view class="rubbishType-title u-required:before">预估重量</view>
  32. <view class="rubbishType-tags">
  33. <view :class="['item-weightTags', checkWeightType == item.code ? 'active' : '']" v-for="item in rubbishweightList" :key="item.code" @click="itemRubbishWeightChange(item)">{{item.dispName}}</view>
  34. </view>
  35. </view>
  36. <view class="form-data qyImg">
  37. <view> 上传图片 <text style="color: #a6a6a6;">(最多3张,单张10MB以内)</text></view>
  38. <view class="info-main">
  39. <view v-if="photograph.length<3 && !isView" class="camera-btn">
  40. <view @click="goPhotograph" class="photograph-camera">
  41. <u-icon name="camera" color="#bfbfbf" size="60" ></u-icon>
  42. </view>
  43. </view>
  44. <view v-show="photograph.length" v-for="(item,index) in photograph" :key="index" class="photograph-con">
  45. <u-icon v-show="!isView" name="close-circle-fill" color="#fa3534" size="50" class="close-circle-icon" @click="cancelPhotograph(index)"></u-icon>
  46. <u-image width="100%" height="100%" :src="item" @click="previewPictures(item)"></u-image>
  47. </view>
  48. </view>
  49. </view>
  50. </view>
  51. <view style="color:#FF2C5C;text-align: center;margin-bottom: 10upx;" v-if="!hasRider">当前地址/时段无可上门骑手,暂不能下单</view>
  52. <view class="btns">
  53. <u-button @click="submit" :loading="loading" :custom-style="submitBtn" :disabled="!hasRider">提交</u-button>
  54. <!-- <u-button @click="submit" :loading="loading" :custom-style="submitBtn">提交</u-button> -->
  55. </view>
  56. </view>
  57. </template>
  58. <script>
  59. import {searchRider} from '@/api/index.js'
  60. import {saveImgToAliOss} from '@/libs/tools.js'
  61. import { getLookUpDatas,userDetail,yuyueInfoSave } from '@/api/data'
  62. export default {
  63. data() {
  64. return {
  65. title:'',
  66. loading:false, // 提交按钮加载圈
  67. check:'', // 是否选中
  68. checkWeightType:'',
  69. photograph: [], // 图片路径
  70. RubbishType:[], // 回收分类
  71. rubbishweightList:[], // 重量分类
  72. latitude:'', // 当前位置经度
  73. longitude:'' ,// 当前位置维度
  74. day:'', // 今天、明天,后天
  75. timeType:'', // 上午、下午
  76. reserveDateBegin:'', // 预约开始时间
  77. reserveDateEnd:'', // 预约结束时间
  78. time: '', // 其它垃圾
  79. rubbishTypeListData:[],
  80. userDetailInfo:{}, // 用户信息
  81. nowDate:'',
  82. form: {
  83. info: '', // 厨余垃圾
  84. },
  85. rubbishTypeList:[], // 垃圾类型
  86. reserveWeight:'',
  87. isView: false ,// 是否是查看详情
  88. hasRider:true, // 是否有骑手
  89. itemId:'',
  90. submitBtn:{
  91. backgroundColor: '#4F88F7',
  92. color: '#fff',
  93. borderRadius: '12px'
  94. },
  95. show: false,
  96. val:'',
  97. list: [
  98. {
  99. value: 1,
  100. label: '今天',
  101. children: [
  102. {
  103. value: 2,
  104. label: '上午(08-13点)',
  105. },
  106. {
  107. value: 3,
  108. label: '下午(13-18点)',
  109. }
  110. ]
  111. },
  112. {
  113. value: 4,
  114. label: '明天',
  115. children: [
  116. {
  117. value: 5,
  118. label: '上午(08-13点)',
  119. },
  120. {
  121. value: 6,
  122. label: '下午(13-18点)',
  123. }
  124. ]
  125. },
  126. {
  127. value: 7,
  128. label: '后天',
  129. children: [
  130. {
  131. value: 8,
  132. label: '上午(08-13点)',
  133. },
  134. {
  135. value: 9,
  136. label: '下午(13-18点)',
  137. }
  138. ]
  139. },
  140. ],
  141. };
  142. },
  143. onLoad(option) {
  144. console.log(option,option.pageType,'ppppppppp')
  145. // this.pageInfo()
  146. // if(!option.pageType){
  147. // this.pageInfo()
  148. // }
  149. uni.$on('pageType', this.pageType)
  150. // 查看
  151. // if(option && option.id){
  152. // this.isView = true
  153. // this.itemId=option.id
  154. // }else {
  155. // console.log('--------新增')
  156. // this.photograph = []
  157. // this.$refs.uForm.resetFields()
  158. // }
  159. wx.getLocation({
  160. type: 'wgs84',
  161. success:(res=> {
  162. if(res.latitude && res.longitude){
  163. this.latitude = res.latitude
  164. this.longitude = res.longitude
  165. }
  166. console.log(res,'位置信息',this.latitude,this.longitude)
  167. })
  168. })
  169. setTimeout(()=>{
  170. this.getRiderStatus()
  171. },300)
  172. },
  173. onShow() {
  174. this.pageInfo()
  175. },
  176. onUnload() {
  177. },
  178. watch:{
  179. },
  180. methods: {
  181. // 初始化页面
  182. pageInfo(){
  183. this.time=''
  184. this.userDetailInfo={}
  185. this.photograph=[]
  186. this.rubbishTypeList=[]
  187. this.rubbishTypeListData=[]
  188. this.latitude='' // 当前位置经度
  189. this.longitude='' // 当前位置维度
  190. this.rubbishType()
  191. this.getDetailData()
  192. this.rubbishWeightType()
  193. },
  194. pageType(e){
  195. this.val += e.data
  196. if(this.val!='userInfo'){
  197. this.pageInfo()
  198. }
  199. console.log(this.val,'----------',e)
  200. },
  201. // 获取垃圾分类
  202. rubbishType () {
  203. let _this = this
  204. getLookUpDatas({
  205. type: 'RESERVE_RUBBISH_TYPE'
  206. }).then(result => {
  207. if (result && result.status + '' === '200') {
  208. result.data.forEach(item=>{
  209. item.check=false
  210. })
  211. this.$nextTick(()=>{
  212. _this.rubbishTypeListData= result.data || []
  213. })
  214. }
  215. })
  216. },
  217. rubbishWeightType () {
  218. let _this = this
  219. getLookUpDatas({
  220. type: 'RUBBISH_WEIGHT_TEMPLATE'
  221. }).then(result => {
  222. if (result && result.status + '' === '200') {
  223. _this.rubbishweightList= result.data || []
  224. }
  225. })
  226. },
  227. // 查询附近有无骑手可接单
  228. getRiderStatus(){
  229. searchRider({lng:this.longitude,lat:this.latitude}).then(res=>{
  230. if(res.status==200){
  231. this.hasRider=res.data
  232. }
  233. })
  234. },
  235. // 选择时间
  236. selectTime(){
  237. wx.hideKeyboard()
  238. this.show=true
  239. },
  240. confirm(e) {
  241. const date=new Date
  242. const year=date.getFullYear()
  243. const month = date.getMonth() + 1
  244. const day = date.getDate()
  245. if(e){
  246. this.time=e[0].label + e[1].label
  247. this.day=e[0].label
  248. this.timeType=e[1].label.substr(0, e[1].label.indexOf("(")) // 上午、下午
  249. if(e[0].label=='今天'){
  250. if(this.timeType=='上午'){
  251. this.reserveDateBegin=this.nowDate = year + "-" +( month<10? '0'+month:month ) + "-" + (day<10? '0'+day:day)+' 08:00:00';
  252. this.reserveDateEnd=this.nowDate = year + "-" +( month<10? '0'+month:month ) + "-" + (day<10? '0'+day:day)+' 12:59:59';
  253. }else{
  254. this.reserveDateBegin=this.nowDate = year + "-" +( month<10? '0'+month:month ) + "-" + (day<10? '0'+day:day)+' 13:00:00';
  255. this.reserveDateEnd=this.nowDate = year + "-" +( month<10? '0'+month:month ) + "-" + (day<10? '0'+day:day)+' 18:00:00';
  256. }
  257. }
  258. if(e[0].label=='明天'){
  259. if(this.timeType=='上午'){
  260. this.reserveDateBegin=this.nowDate = year + "-" +( month<10? '0'+month:month ) + "-" + (day<10? '0'+(day+1):day+1)+' 08:00:00';
  261. this.reserveDateEnd=this.nowDate = year + "-" +( month<10? '0'+month:month ) + "-" + (day<10? '0'+(day+1):day+1)+' 12:59:59';
  262. }else{
  263. this.reserveDateBegin=this.nowDate = year + "-" +( month<10? '0'+month:month ) + "-" + (day<10? '0'+(day+1):day+1)+' 13:00:00';
  264. this.reserveDateEnd=this.nowDate = year + "-" +( month<10? '0'+month:month ) + "-" + (day<10? '0'+(day+1):day+1)+' 18:00:00';
  265. }
  266. }
  267. if(e[0].label=='后天'){
  268. if(this.timeType=='上午'){
  269. this.reserveDateBegin=this.nowDate = year + "-" +( month<10? '0'+month:month ) + "-" + (day<10? '0'+(day+2):day+2)+' 08:00:00';
  270. this.reserveDateEnd=this.nowDate = year + "-" +( month<10? '0'+month:month ) + "-" + (day<10? '0'+(day+2):day+2)+' 12:59:59';
  271. }else{
  272. this.reserveDateBegin=this.nowDate = year + "-" +( month<10? '0'+month:month ) + "-" + (day<10? '0'+(day+2):day+2)+' 13:00:00';
  273. this.reserveDateEnd=this.nowDate = year + "-" +( month<10? '0'+month:month ) + "-" + (day<10? '0'+(day+2):day+2)+' 18:00:00';
  274. }
  275. }
  276. }
  277. },
  278. // 选择用户信息
  279. selectUserInfo(){
  280. uni.navigateTo({
  281. url: '/pages/index/userInfo'
  282. })
  283. },
  284. // 选择垃圾分类
  285. itemRubbishChange(item){
  286. item.check=!item.check
  287. console.log(item,item.code,'--------------',this.check)
  288. },
  289. itemRubbishWeightChange(item){
  290. this.checkWeightType=item.code
  291. console.log(item,item.code,'--------------',this.check,this.checkWeightType)
  292. },
  293. // 获取详情数据
  294. getDetailData(){
  295. userDetail().then(res=>{
  296. if(res.status==200){
  297. this.form.info=res.data.contactName
  298. this.userId=res.data.id
  299. delete res.data.id
  300. this.userDetailInfo=res.data
  301. console.log(res)
  302. }
  303. })
  304. },
  305. // 拍照或从相册选图片
  306. goPhotograph() {
  307. uni.chooseImage({
  308. count: 1, //默认9
  309. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  310. sourceType: ['album','camera'], //从相册选择
  311. success: (res) =>{
  312. console.log(res,'rrrrrrrrrrr')
  313. console.log(JSON.stringify(res.tempFilePaths));
  314. console.log(this.photograph.length,'this.photograph')
  315. if(res.tempFiles[0].size>10485760){
  316. uni.showToast({
  317. title: '图片过大无法上传!',
  318. icon: 'none'
  319. })
  320. return
  321. }
  322. uni.showLoading({
  323. title:'正在保存图片...',
  324. mask: true
  325. })
  326. saveImgToAliOss(res.tempFilePaths[0],(ret)=>{
  327. this.photograph.push(ret.data)
  328. uni.hideLoading()
  329. })
  330. }
  331. });
  332. },
  333. // 预览图片
  334. previewPictures(item) {
  335. const photograph = [item];
  336. uni.previewImage({
  337. urls: photograph,
  338. });
  339. },
  340. // 删除图片
  341. cancelPhotograph(index) {
  342. setTimeout(() => {
  343. this.photograph.splice(index,1)
  344. }, 500);
  345. },
  346. // 提交
  347. submit(){
  348. this.rubbishTypeList=[]
  349. console.log('-------------提交')
  350. this.$refs.uForm.validate(valid => {
  351. const params= Object.assign(this.userDetailInfo, this.form,{userId:this.userId})
  352. console.log('-------------校验')
  353. if (valid) {
  354. if(this.time ==''){
  355. uni.showToast({
  356. title: '请选择预约时间',
  357. icon: 'none'
  358. })
  359. return false
  360. }
  361. console.log('-------------时间校验')
  362. if(this.form.info ==''){
  363. uni.showToast({
  364. title: '请选择用户信息',
  365. icon: 'none'
  366. })
  367. return false
  368. }
  369. console.log('-------------用户校验')
  370. if(this.checkWeightType ==''){
  371. uni.showToast({
  372. title: '请选择预估重量',
  373. icon: 'none'
  374. })
  375. return false
  376. }
  377. console.log('-------------重量校验')
  378. if(this.rubbishTypeListData){
  379. this.rubbishTypeListData.map(item=>{
  380. if(item.check==true){
  381. this.rubbishTypeList.push(item.code)
  382. }
  383. })
  384. console.log(this.rubbishTypeListData,this.rubbishTypeList,'--------选中垃圾分类')
  385. params.rubbishTypeList=this.rubbishTypeList
  386. }
  387. console.log(params,'----------params垃圾类型')
  388. if(this.rubbishTypeList ==[]){
  389. uni.showToast({
  390. title: '请选择回收分类',
  391. icon: 'none'
  392. })
  393. return false
  394. }
  395. console.log(params,'----------params垃圾类型')
  396. if(this.time){
  397. params.reserveDateBegin=this.reserveDateBegin
  398. params.reserveDateEnd=this.reserveDateEnd
  399. }
  400. if(this.checkWeightType){
  401. params.reserveWeight=this.checkWeightType
  402. }
  403. if(this.photograph){
  404. params.imageList=this.photograph
  405. }
  406. console.log(params,'------------参数')
  407. yuyueInfoSave(params).then(res=>{
  408. if(res.status==200){
  409. uni.showToast({
  410. title: res.message,
  411. icon: 'none'
  412. })
  413. setTimeout(()=>{
  414. uni.navigateTo({
  415. url: '/pages/index/yuyueResult'
  416. })
  417. },500)
  418. }
  419. })
  420. } else {
  421. console.log('验证失败');
  422. }
  423. });
  424. },
  425. },
  426. // 必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
  427. onReady() {
  428. this.$refs.uForm.setRules(this.rules);
  429. }
  430. }
  431. </script>
  432. <style lang="scss">
  433. .content{
  434. width: 100%;
  435. height: 100vh;
  436. padding: 0;
  437. background: #F5F5F5;
  438. display: flex;
  439. flex-direction: column;
  440. .content-form{
  441. flex: 1;
  442. overflow-y: scroll;
  443. .content-detail{
  444. padding:20upx 30upx;
  445. background: rgba(255, 209, 0, 0.4);
  446. opacity: 1;
  447. display: flex;
  448. justify-content: space-between;
  449. .detail-text{
  450. display: flex;
  451. align-items: center;
  452. text{
  453. display: inline-block;
  454. margin-left: 15upx;
  455. }
  456. }
  457. .detail-xqtext{
  458. font-size: 30upx;
  459. font-family: PingFang SC;
  460. font-weight: 500;
  461. color: #FF9528;
  462. }
  463. }
  464. }
  465. .receiveAddress{
  466. width: 100%;
  467. line-height: 1.5em;
  468. box-sizing: border-box;
  469. font-style: normal;
  470. }
  471. .form-data{
  472. padding:0 30upx 0 50upx;
  473. margin-bottom: 20upx;
  474. background-color: #fff;
  475. }
  476. .rubbishType{
  477. padding:30upx 30upx 30upx 50upx;
  478. .rubbishType-title{
  479. margin-bottom: 20upx;
  480. }
  481. .rubbishType-tags{
  482. display: flex;
  483. justify-content: space-between;
  484. .item-tags.active{
  485. padding: 10upx;
  486. background-color:rgba(79, 136, 247, 0.2);
  487. border-radius: 100px;
  488. }
  489. .item-weightTags.active{
  490. padding: 10upx;
  491. background-color:rgba(79, 136, 247, 0.2);
  492. border-radius: 100px;
  493. }
  494. .check{
  495. background: #F5F5F5;
  496. }
  497. }
  498. }
  499. .qyImg{
  500. padding: 40upx ;
  501. }
  502. .info-main {
  503. margin-top: 14upx;
  504. border-radius: 12upx;
  505. background-color: #fff;
  506. display: flex;
  507. .location-icon {
  508. padding-left: 10upx;
  509. vertical-align: sub;
  510. }
  511. .photograph-camera {
  512. border: 2upx dashed #bfbfbf;
  513. border-radius: 12upx;
  514. width: 140upx;
  515. height: 140upx;
  516. display: flex;
  517. align-items: center;
  518. justify-content: center;
  519. }
  520. .camera-btn{
  521. display: flex;
  522. flex-direction: column;
  523. align-items: center;
  524. color: #999999;
  525. font-size: 24upx;
  526. }
  527. .photograph-con {
  528. margin: 0 20upx;
  529. width: 140upx;
  530. height: 140upx;
  531. text-align: center;
  532. position: relative;
  533. .photograph-icon {
  534. display: inline-block;
  535. padding-top: 48upx;
  536. }
  537. .close-circle-icon {
  538. background-color: #fff;
  539. border-radius: 50%;
  540. position: absolute;
  541. right: -23upx;
  542. top: -23upx;
  543. z-index: 9;
  544. }
  545. }
  546. }
  547. .btns{
  548. padding: 30upx 30upx 50upx;
  549. background-color: #fff;
  550. }
  551. }
  552. </style>