yuyue.vue 15 KB

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