yuyue.vue 15 KB

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