yuyue.vue 15 KB

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