yuyue.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  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.userDetailInfo=res.data
  291. console.log(res)
  292. }
  293. })
  294. },
  295. // 拍照或从相册选图片
  296. goPhotograph() {
  297. uni.chooseImage({
  298. count: 1, //默认9
  299. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  300. sourceType: ['album','camera'], //从相册选择
  301. success: (res) =>{
  302. console.log(res,'rrrrrrrrrrr')
  303. console.log(JSON.stringify(res.tempFilePaths));
  304. console.log(this.photograph.length,'this.photograph')
  305. if(res.tempFiles[0].size>10485760){
  306. uni.showToast({
  307. title: '图片过大无法上传!',
  308. icon: 'none'
  309. })
  310. return
  311. }
  312. uni.showLoading({
  313. title:'正在保存图片...',
  314. mask: true
  315. })
  316. saveImgToAliOss(res.tempFilePaths[0],(ret)=>{
  317. this.photograph.push(ret.data)
  318. uni.hideLoading()
  319. })
  320. }
  321. });
  322. },
  323. // 预览图片
  324. previewPictures(item) {
  325. const photograph = [item];
  326. uni.previewImage({
  327. urls: photograph,
  328. });
  329. },
  330. // 删除图片
  331. cancelPhotograph(index) {
  332. setTimeout(() => {
  333. this.photograph.splice(index,1)
  334. }, 500);
  335. },
  336. // 提交
  337. submit(){
  338. this.$refs.uForm.validate(valid => {
  339. if (valid) {
  340. if(this.time ==''){
  341. uni.showToast({
  342. title: '请选择预约时间',
  343. icon: 'none'
  344. })
  345. return false
  346. }
  347. if(this.form.info ==''){
  348. uni.showToast({
  349. title: '请选择用户信息',
  350. icon: 'none'
  351. })
  352. return false
  353. }
  354. if(this.checkWeightType ==''){
  355. uni.showToast({
  356. title: '请选择预估重量',
  357. icon: 'none'
  358. })
  359. return false
  360. }
  361. if(this.rubbishTypeList ==[]){
  362. uni.showToast({
  363. title: '请选择回收分类',
  364. icon: 'none'
  365. })
  366. return false
  367. }
  368. const params= Object.assign(this.userDetailInfo, this.form)
  369. if(this.time){
  370. params.reserveDateBegin=this.reserveDateBegin
  371. params.reserveDateEnd=this.reserveDateEnd
  372. }
  373. if(this.reserveWeight){
  374. params.reserveWeight=this.checkWeightType
  375. }
  376. if(this.photograph){
  377. params.imageList=this.photograph
  378. }
  379. if(this.rubbishTypeListData){
  380. this.rubbishTypeListData.map(item=>{
  381. if(item.check==true){
  382. this.rubbishTypeList.push(item.code)
  383. }
  384. })
  385. params.rubbishTypeList=this.rubbishTypeList
  386. }
  387. yuyueInfoSave(params).then(res=>{
  388. if(res.status==200){
  389. uni.showToast({
  390. title: res.message,
  391. icon: 'none'
  392. })
  393. setTimeout(()=>{
  394. uni.navigateTo({
  395. url: '/pages/index/yuyueResult'
  396. })
  397. },500)
  398. }
  399. })
  400. } else {
  401. console.log('验证失败');
  402. }
  403. });
  404. },
  405. },
  406. // 必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
  407. onReady() {
  408. this.$refs.uForm.setRules(this.rules);
  409. }
  410. }
  411. </script>
  412. <style lang="scss">
  413. .content{
  414. width: 100%;
  415. height: 100vh;
  416. padding: 0;
  417. background: #F5F5F5;
  418. display: flex;
  419. flex-direction: column;
  420. .content-form{
  421. flex: 1;
  422. overflow-y: scroll;
  423. .content-detail{
  424. padding:20upx 30upx;
  425. background: rgba(255, 209, 0, 0.4);
  426. opacity: 1;
  427. display: flex;
  428. justify-content: space-between;
  429. .detail-text{
  430. display: flex;
  431. align-items: center;
  432. text{
  433. display: inline-block;
  434. margin-left: 15upx;
  435. }
  436. }
  437. .detail-xqtext{
  438. font-size: 30upx;
  439. font-family: PingFang SC;
  440. font-weight: 500;
  441. color: #FF9528;
  442. }
  443. }
  444. }
  445. .receiveAddress{
  446. width: 100%;
  447. line-height: 1.5em;
  448. box-sizing: border-box;
  449. font-style: normal;
  450. }
  451. .form-data{
  452. padding:0 30upx 0 50upx;
  453. margin-bottom: 20upx;
  454. background-color: #fff;
  455. }
  456. .rubbishType{
  457. padding:30upx 30upx 30upx 50upx;
  458. .rubbishType-title{
  459. margin-bottom: 20upx;
  460. }
  461. .rubbishType-tags{
  462. display: flex;
  463. justify-content: space-between;
  464. .item-tags.active{
  465. padding: 10upx;
  466. background-color:rgba(79, 136, 247, 0.2);
  467. border-radius: 100px;
  468. }
  469. .item-weightTags.active{
  470. padding: 10upx;
  471. background-color:rgba(79, 136, 247, 0.2);
  472. border-radius: 100px;
  473. }
  474. .check{
  475. background: #F5F5F5;
  476. }
  477. }
  478. }
  479. .qyImg{
  480. padding: 40upx ;
  481. }
  482. .info-main {
  483. margin-top: 14upx;
  484. border-radius: 12upx;
  485. background-color: #fff;
  486. display: flex;
  487. .location-icon {
  488. padding-left: 10upx;
  489. vertical-align: sub;
  490. }
  491. .photograph-camera {
  492. border: 2upx dashed #bfbfbf;
  493. border-radius: 12upx;
  494. width: 140upx;
  495. height: 140upx;
  496. display: flex;
  497. align-items: center;
  498. justify-content: center;
  499. }
  500. .camera-btn{
  501. display: flex;
  502. flex-direction: column;
  503. align-items: center;
  504. color: #999999;
  505. font-size: 24upx;
  506. }
  507. .photograph-con {
  508. margin: 0 20upx;
  509. width: 140upx;
  510. height: 140upx;
  511. text-align: center;
  512. position: relative;
  513. .photograph-icon {
  514. display: inline-block;
  515. padding-top: 48upx;
  516. }
  517. .close-circle-icon {
  518. background-color: #fff;
  519. border-radius: 50%;
  520. position: absolute;
  521. right: -23upx;
  522. top: -23upx;
  523. z-index: 9;
  524. }
  525. }
  526. }
  527. .btns{
  528. padding: 30upx 30upx 50upx;
  529. background-color: #fff;
  530. }
  531. }
  532. </style>