yuyue.vue 17 KB

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