yuyue.vue 15 KB

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