yuyue.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  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. console.log(this.list,'--------------时间数组')
  279. // return
  280. this.show=true
  281. },
  282. confirm(e) {
  283. const date=new Date
  284. const year=date.getFullYear()
  285. const month = date.getMonth() + 1
  286. const day = date.getDate()
  287. if(e){
  288. this.time=e[0].label + e[1].label
  289. this.day=e[0].label
  290. this.timeType=e[1].label.substr(0, e[1].label.indexOf("(")) // 上午、下午
  291. if(e[0].label=='今天'){
  292. if(this.timeType=='上午'){
  293. this.reserveDateBegin=this.nowDate = year + "-" +( month<10? '0'+month:month ) + "-" + (day<10? '0'+day:day)+' 08:00:00';
  294. this.reserveDateEnd=this.nowDate = year + "-" +( month<10? '0'+month:month ) + "-" + (day<10? '0'+day:day)+' 12:59:59';
  295. }else{
  296. this.reserveDateBegin=this.nowDate = year + "-" +( month<10? '0'+month:month ) + "-" + (day<10? '0'+day:day)+' 13:00:00';
  297. this.reserveDateEnd=this.nowDate = year + "-" +( month<10? '0'+month:month ) + "-" + (day<10? '0'+day:day)+' 18:00:00';
  298. }
  299. }
  300. if(e[0].label=='明天'){
  301. if(this.timeType=='上午'){
  302. this.reserveDateBegin=this.nowDate = year + "-" +( month<10? '0'+month:month ) + "-" + (day<10? '0'+(day+1):day+1)+' 08:00:00';
  303. this.reserveDateEnd=this.nowDate = year + "-" +( month<10? '0'+month:month ) + "-" + (day<10? '0'+(day+1):day+1)+' 12:59:59';
  304. }else{
  305. this.reserveDateBegin=this.nowDate = year + "-" +( month<10? '0'+month:month ) + "-" + (day<10? '0'+(day+1):day+1)+' 13:00:00';
  306. this.reserveDateEnd=this.nowDate = year + "-" +( month<10? '0'+month:month ) + "-" + (day<10? '0'+(day+1):day+1)+' 18:00:00';
  307. }
  308. }
  309. if(e[0].label=='后天'){
  310. if(this.timeType=='上午'){
  311. this.reserveDateBegin=this.nowDate = year + "-" +( month<10? '0'+month:month ) + "-" + (day<10? '0'+(day+2):day+2)+' 08:00:00';
  312. this.reserveDateEnd=this.nowDate = year + "-" +( month<10? '0'+month:month ) + "-" + (day<10? '0'+(day+2):day+2)+' 12:59:59';
  313. }else{
  314. this.reserveDateBegin=this.nowDate = year + "-" +( month<10? '0'+month:month ) + "-" + (day<10? '0'+(day+2):day+2)+' 13:00:00';
  315. this.reserveDateEnd=this.nowDate = year + "-" +( month<10? '0'+month:month ) + "-" + (day<10? '0'+(day+2):day+2)+' 18:00:00';
  316. }
  317. }
  318. }
  319. },
  320. // 选择用户信息
  321. selectUserInfo(){
  322. uni.navigateTo({
  323. url: '/pages/index/userInfo'
  324. })
  325. },
  326. // 选择垃圾分类
  327. itemRubbishChange(item){
  328. item.check=!item.check
  329. },
  330. itemRubbishWeightChange(item){
  331. this.checkWeightType=item.code
  332. },
  333. // 获取详情数据
  334. getDetailData(){
  335. userDetail().then(res=>{
  336. if(res.status==200){
  337. this.$u.vuex('vuex_userInfoData',res.data)
  338. this.form.info=res.data.contactName
  339. this.userId=res.data.id
  340. this.userLatitude=res.data.lat // 用户位置经度
  341. this.userLongitude=res.data.lng // 用户位置维度
  342. delete res.data.id
  343. this.userDetailInfo=res.data
  344. this.getRiderStatus()
  345. console.log(res)
  346. }
  347. })
  348. },
  349. // 拍照或从相册选图片
  350. goPhotograph() {
  351. uni.chooseImage({
  352. count: 1, //默认9
  353. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  354. sourceType: ['album','camera'], //从相册选择
  355. success: (res) =>{
  356. console.log(res,'rrrrrrrrrrr')
  357. console.log(JSON.stringify(res.tempFilePaths));
  358. console.log(this.photograph.length,'this.photograph')
  359. if(res.tempFiles[0].size>10485760){
  360. uni.showToast({
  361. title: '图片过大无法上传!',
  362. icon: 'none'
  363. })
  364. return
  365. }
  366. uni.showLoading({
  367. title:'正在保存图片...',
  368. mask: true
  369. })
  370. saveImgToAliOss(res.tempFilePaths[0],(ret)=>{
  371. this.photograph.push(ret.data)
  372. uni.hideLoading()
  373. })
  374. }
  375. });
  376. },
  377. // 预览图片
  378. previewPictures(item) {
  379. const photograph = [item];
  380. uni.previewImage({
  381. urls: photograph,
  382. });
  383. },
  384. // 删除图片
  385. cancelPhotograph(index) {
  386. setTimeout(() => {
  387. this.photograph.splice(index,1)
  388. }, 500);
  389. },
  390. // 提交
  391. submit(){
  392. this.rubbishTypeList=[]
  393. this.$refs.uForm.validate(valid => {
  394. const params= Object.assign(this.userDetailInfo, this.form,{userId:this.userId})
  395. if (valid) {
  396. if(this.time ==''){
  397. uni.showToast({
  398. title: '请选择预约时间',
  399. icon: 'none'
  400. })
  401. return false
  402. }
  403. if(this.form.info ==''){
  404. uni.showToast({
  405. title: '请选择用户信息',
  406. icon: 'none'
  407. })
  408. return false
  409. }
  410. if(this.checkWeightType ==''){
  411. uni.showToast({
  412. title: '请选择预估重量',
  413. icon: 'none'
  414. })
  415. return false
  416. }
  417. if(this.rubbishTypeListData){
  418. this.rubbishTypeListData.map(item=>{
  419. if(item.check==true){
  420. this.rubbishTypeList.push(item.code)
  421. }
  422. })
  423. params.rubbishTypeList=this.rubbishTypeList
  424. }
  425. if(this.rubbishTypeList.length ==0){
  426. uni.showToast({
  427. title: '请选择回收分类',
  428. icon: 'none'
  429. })
  430. return false
  431. }
  432. if(this.time){
  433. params.reserveDateBegin=this.reserveDateBegin
  434. params.reserveDateEnd=this.reserveDateEnd
  435. }
  436. if(this.checkWeightType){
  437. params.reserveWeight=this.checkWeightType
  438. }
  439. if(this.photograph){
  440. params.imageList=this.photograph
  441. }
  442. console.log(params,'------------参数')
  443. yuyueInfoSave(params).then(res=>{
  444. if(res.status==200){
  445. uni.showToast({
  446. title: res.message,
  447. icon: 'none'
  448. })
  449. setTimeout(()=>{
  450. uni.navigateTo({
  451. url: '/pages/index/yuyueResult'
  452. })
  453. },500)
  454. }
  455. })
  456. } else {
  457. console.log('验证失败');
  458. }
  459. });
  460. },
  461. },
  462. // 必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
  463. onReady() {
  464. this.$refs.uForm.setRules(this.rules);
  465. }
  466. }
  467. </script>
  468. <style lang="scss">
  469. .content{
  470. width: 100%;
  471. height: 100vh;
  472. padding: 0;
  473. background: #F5F5F5;
  474. display: flex;
  475. flex-direction: column;
  476. .content-form{
  477. flex: 1;
  478. overflow-y: scroll;
  479. .content-detail{
  480. padding:20upx 30upx;
  481. background: rgba(255, 209, 0, 0.4);
  482. opacity: 1;
  483. display: flex;
  484. justify-content: space-between;
  485. .detail-text{
  486. display: flex;
  487. align-items: center;
  488. text{
  489. display: inline-block;
  490. margin-left: 15upx;
  491. }
  492. }
  493. .detail-xqtext{
  494. font-size: 30upx;
  495. font-family: PingFang SC;
  496. font-weight: 500;
  497. color: #FF9528;
  498. }
  499. }
  500. }
  501. .receiveAddress{
  502. width: 100%;
  503. line-height: 1.5em;
  504. box-sizing: border-box;
  505. font-style: normal;
  506. }
  507. .form-data{
  508. padding:0 30upx 0 50upx;
  509. margin-bottom: 20upx;
  510. background-color: #fff;
  511. }
  512. .rubbishType{
  513. padding:30upx 30upx 30upx 50upx;
  514. .rubbishType-title{
  515. margin-bottom: 20upx;
  516. }
  517. .rubbishType-tags{
  518. display: flex;
  519. justify-content: space-between;
  520. .item-tags.active{
  521. padding: 10upx;
  522. background-color:rgba(79, 136, 247, 0.2);
  523. border-radius: 100px;
  524. }
  525. .item-weightTags.active{
  526. padding: 10upx;
  527. background-color:rgba(79, 136, 247, 0.2);
  528. border-radius: 100px;
  529. }
  530. .check{
  531. background: #F5F5F5;
  532. }
  533. }
  534. }
  535. .qyImg{
  536. padding: 40upx ;
  537. }
  538. .info-main {
  539. margin-top: 14upx;
  540. border-radius: 12upx;
  541. background-color: #fff;
  542. display: flex;
  543. .location-icon {
  544. padding-left: 10upx;
  545. vertical-align: sub;
  546. }
  547. .photograph-camera {
  548. border: 2upx dashed #bfbfbf;
  549. border-radius: 12upx;
  550. width: 140upx;
  551. height: 140upx;
  552. display: flex;
  553. align-items: center;
  554. justify-content: center;
  555. }
  556. .camera-btn{
  557. display: flex;
  558. flex-direction: column;
  559. align-items: center;
  560. color: #999999;
  561. font-size: 24upx;
  562. }
  563. .photograph-con {
  564. margin: 0 20upx;
  565. width: 140upx;
  566. height: 140upx;
  567. text-align: center;
  568. position: relative;
  569. .photograph-icon {
  570. display: inline-block;
  571. padding-top: 48upx;
  572. }
  573. .close-circle-icon {
  574. background-color: #fff;
  575. border-radius: 50%;
  576. position: absolute;
  577. right: -23upx;
  578. top: -23upx;
  579. z-index: 9;
  580. }
  581. }
  582. }
  583. .btns{
  584. padding: 30upx 30upx 50upx;
  585. background-color: #fff;
  586. }
  587. }
  588. </style>