yuyue.vue 15 KB

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