refuelDetail.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  1. <template>
  2. <view class="refuelDetail">
  3. <zs-header :background="background"></zs-header>
  4. <image class="banner" :src="info.logo" mode=""></image>
  5. <view class="content">
  6. <view class="title">
  7. {{info.storeName}}
  8. </view>
  9. <view class="time">
  10. 营业时间 周一至周日 {{info.openTimeHourStart}}:00 - {{info.openTimeHourEnd}}:00
  11. </view>
  12. <view class="distance">
  13. 距离您{{(distance/1000).toFixed(2)}}公里
  14. </view>
  15. <view class="address-box">
  16. <view class="address">
  17. {{info.address}}
  18. </view>
  19. <view class="btn-box">
  20. <view class="btn" @click="handleNavigation">
  21. 导航
  22. </view>
  23. <view class="btn" @click="handleCall">
  24. 电话
  25. </view>
  26. </view>
  27. </view>
  28. <view class="price-box">
  29. <view class="price">
  30. 优惠加油 ¥{{price.vipPrice?(price.vipPrice/100).toFixed(2):'--'}}/L
  31. </view>
  32. <view class="right-box">
  33. <view class="old-price">
  34. 油站价¥{{price.cityPrice?(price.storePrice/100).toFixed(2):'--'}}/L
  35. </view>
  36. <view class="old-price">
  37. 国标价¥{{price.cityPrice?(price.cityPrice/100).toFixed(2):'--'}}/L
  38. </view>
  39. </view>
  40. </view>
  41. <view class="choose-box">
  42. <view class="item" :class="[num?'active':'']" @click="hanleChoose">
  43. {{num||"请选择油号"}}
  44. <image class="icon" src="../static/shop-desc.png" mode=""></image>
  45. </view>
  46. <view class="item" :class="[gun?'active':'']" @click="hanleChoose">
  47. {{gun ? (gun + '号枪'):"请选择油枪"}}
  48. <image class="icon" src="../static/shop-desc.png" mode=""></image>
  49. </view>
  50. </view>
  51. <input class="price-input" type="digit" v-model="amount" placeholder-style="color:#AAAAAA;font-weight: 500;" placeholder="请输入加油金额,优惠价格计算" />
  52. <view class="order-box">
  53. <view class="item">
  54. <view class="label">
  55. 订单金额
  56. </view>
  57. <view class="value-box">
  58. <view class="num">
  59. 约{{(payInfo.litre/1000).toFixed(2)}}升
  60. </view>
  61. <view class="value">
  62. {{'¥'+ (payInfo.totalPrice/100).toFixed(2) }}
  63. </view>
  64. </view>
  65. </view>
  66. <view class="item">
  67. <view class="label">
  68. 服务费
  69. </view>
  70. <view class="value" :class="[!payInfo.totalPrice?'gray':'']">
  71. {{payInfo.totalPrice?'¥'+(payInfo.serviceFee/100).toFixed(2) : '输入金额后查看服务费'}}
  72. </view>
  73. </view>
  74. <view class="item">
  75. <view class="label">
  76. 优惠券减免金额
  77. </view>
  78. <view class="value" :class="[!payInfo.totalPrice?'gray':'']">
  79. {{payInfo.totalPrice?'¥'+(payInfo.promotionAmount/100).toFixed(2) : '输入金额后查看优惠金额'}}
  80. </view>
  81. </view>
  82. <view class="item">
  83. <view class="label">
  84. 优惠券
  85. </view>
  86. <view class="value gray">
  87. {{payInfo.totalPrice?'暂无可用' : '输入金额后查看优惠券'}}
  88. </view>
  89. </view>
  90. </view>
  91. </view>
  92. <view class="buy-box">
  93. <view class="total-price">
  94. <view class="label">
  95. 合计:
  96. </view>
  97. <view class="price">
  98. ¥ {{(payInfo.realPrice/100).toFixed(2)}}
  99. </view>
  100. </view>
  101. <button class="btn" :class="[btnDisabled?'disabled':'']" type="default" :loading="loading" :disabled="btnDisabled" @click="handlePay">立即支付</button>
  102. </view>
  103. <u-popup :show="show" round="16rpx" mode="bottom" @close="close">
  104. <view class="popup-title">
  105. 选择油号/油枪
  106. </view>
  107. <view class="item-box">
  108. <view class="sub-title">
  109. 选择油号
  110. </view>
  111. <view class="box">
  112. <view class="item" :class="[numIndex === index ?'active':'']" v-for="(item,index) in info.itemInfoList" :key="item.itemId" @click="handleTab(item,'',index)">
  113. {{item.itemName}}
  114. </view>
  115. </view>
  116. </view>
  117. <view class="item-box">
  118. <view class="sub-title">
  119. 选择油枪
  120. <view class="notice">
  121. 请与加油员确认油枪号
  122. </view>
  123. </view>
  124. <view class="box">
  125. <view class="item" :class="[gun == item ?'active':'',(index+1)%4 == 0?'m0':'']" v-for="(item,index) in gunList" :key="item" @click="handleTab(item,'gun')">
  126. {{item}}号
  127. </view>
  128. </view>
  129. </view>
  130. </u-popup>
  131. <map class="map" id="map"></map>
  132. </view>
  133. </template>
  134. <script>
  135. import { queryStoreDetail,queryCalPrice,queryNewOrder } from '@/api/refuel.js';
  136. import {debounce} from '@/utils/tool.js'
  137. // 腾讯地图
  138. var QQMapWX = require('@/libs/qqmap-wx-jssdk.min.js');
  139. var qqmapsdk = new QQMapWX({key:'KX5BZ-B64RC-RO62W-AMWAZ-VVTC3-YAFXF'});
  140. export default {
  141. data() {
  142. return {
  143. type:1,
  144. background:false,
  145. map:null,
  146. show:false,
  147. loading:false,
  148. info:null,
  149. distance:0,
  150. itemId:'',//油号id
  151. num:'',//油号
  152. numIndex:undefined,//选择油号的index
  153. gun:'',//油枪
  154. price:{//选择的油号价格
  155. cityPrice:0,
  156. vipPrice:0,
  157. storePrice:0
  158. },
  159. storeId:'',
  160. amount:'',//输入金额
  161. payInfo:{//计算出来的金额
  162. discountPrice: 0,
  163. itemName: "",
  164. litre: 0,
  165. priceDetailVo: {deductionDetail: null, gunCoupon: null},
  166. promotionAmount: 0,
  167. realPrice: 0,
  168. serviceFee: 0,
  169. storeId: "",
  170. totalPrice: 0,
  171. },
  172. epId:'',//店铺id
  173. }
  174. },
  175. watch: {
  176. amount:debounce(function(val){
  177. if(!val){
  178. this.payInfo = {//计算出来的金额
  179. discountPrice: 0,
  180. itemName: "",
  181. litre: 0,
  182. priceDetailVo: {deductionDetail: null, gunCoupon: null},
  183. promotionAmount: 0,
  184. realPrice: 0,
  185. serviceFee: 0,
  186. storeId: "",
  187. totalPrice: 0,
  188. }
  189. }
  190. this.queryCalPrice()
  191. // else if(!this.num||!this.gun){
  192. // uni.showToast({
  193. // title:'请选择油号/油枪',
  194. // icon:'none'
  195. // })
  196. // }else if(val<10){
  197. // uni.showToast({
  198. // title:'加油金额不能小于10',
  199. // icon:'none'
  200. // })
  201. // }
  202. })
  203. },
  204. computed: {
  205. btnDisabled(){
  206. if(!this.payInfo.realPrice || !this.num || !this.gun || this.loading || this.amount<10){
  207. return true
  208. }else{
  209. return false
  210. }
  211. },
  212. gunList() {
  213. if(this.numIndex == undefined){
  214. return []
  215. }else{
  216. return this.info.itemInfoList[this.numIndex].gunNoList
  217. }
  218. },
  219. query(){
  220. return {
  221. amount:this.amount*100,
  222. itemName :this.num,
  223. storeId:this.storeId,
  224. }
  225. },
  226. notice(){
  227. if(this.amount&&this.amount<10){
  228. return uni.showToast({
  229. title:'加油金额不能小于10',
  230. icon:'none'
  231. })
  232. }else if(!this.num||!this.gun){
  233. return uni.showToast({
  234. title:'请选择油号/油枪',
  235. icon:'none'
  236. })
  237. }else if(!this.amount){
  238. return uni.showToast({
  239. title:'请输入加油金额',
  240. icon:'none'
  241. })
  242. }
  243. else if(this.amount>999){
  244. this.amount = 999
  245. return uni.showToast({
  246. title:'加油最大金额999',
  247. icon:'none'
  248. })
  249. }
  250. }
  251. },
  252. methods: {
  253. handleTab(item,type,index){
  254. if(type == 'gun'){
  255. this.gun = item
  256. this.show = false
  257. }else{
  258. this.gun = ''
  259. this.numIndex = index
  260. this.itemId = item.itemId
  261. this.num = item.itemName
  262. this.price.cityPrice = item.cityPrice
  263. this.price.vipPrice = item.vipPrice
  264. this.price.storePrice = item.storePrice
  265. }
  266. this.queryCalPrice()
  267. },
  268. handleNavigation() {
  269. uni.openLocation({
  270. latitude: this.info.lat,
  271. longitude: this.info.lon,
  272. name:this.info.storeName,
  273. address:this.info.address,
  274. success: function () {
  275. console.log('success');
  276. }
  277. });
  278. // this.map.openMapApp({
  279. // longitude:this.info.lon,
  280. // latitude:this.info.lat,
  281. // destination:this.info.storeName,
  282. // success(res){
  283. // console.log(res);
  284. // }
  285. // })
  286. },
  287. handleCall() {
  288. if(this.info.tel){
  289. uni.makePhoneCall({
  290. phoneNumber: this.info.tel //仅为示例
  291. });
  292. }else{
  293. uni.showToast({
  294. title:'商家没有预留电话',
  295. icon:'none'
  296. })
  297. }
  298. },
  299. hanleChoose(){
  300. this.show = true
  301. },
  302. close(){
  303. this.show = false
  304. },
  305. // 加油站详情
  306. queryStoreDetail(storeId){
  307. queryStoreDetail(storeId).then(res=>{
  308. this.info = res.content
  309. this.getDistance()
  310. this.info.itemInfoList.map((item,index)=>{
  311. if(item.itemName == '92#'){
  312. this.numIndex = index
  313. this.itemId = item.itemId
  314. this.num = item.itemName
  315. this.price.cityPrice = item.cityPrice
  316. this.price.vipPrice = item.vipPrice
  317. this.price.storePrice = item.storePrice
  318. }
  319. })
  320. })
  321. },
  322. queryCalPrice(){
  323. if(this.num&&this.gun&&this.amount>=10){
  324. uni.showLoading({
  325. title:'计算中'
  326. })
  327. queryCalPrice(this.query).then(res=>{
  328. uni.hideLoading()
  329. if(res.state == 'Success'){
  330. this.payInfo = res.content
  331. }
  332. })
  333. }
  334. },
  335. getDistance(){
  336. let location = JSON.parse(uni.getStorageSync('location'))
  337. qqmapsdk.calculateDistance({from:{latitude:location.latitude,longitude:location.longitude},to:[{latitude:this.info.location[1],longitude:this.info.location[0]}],success:(res)=>{
  338. console.log(res);
  339. this.distance = res.result.elements[0].distance
  340. }})
  341. },
  342. getRad(d) {
  343. return d * Math.PI / 180.0;
  344. },
  345. /*参数:两地的经纬度数值*/
  346. getFlatternDistance(lat1, lng1, lat2, lng2) {
  347. var radLat1 = this.getRad(lat1);
  348. var radLat2 = this.getRad(lat2);
  349. var a = radLat1 - radLat2;
  350. var b = this.getRad(lng1) - this.getRad(lng2);
  351. var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
  352. Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
  353. s = s * 6378137.0;//地球半径 单位米;
  354. s = Math.round(s * 10000) / 10000; //输出为米
  355. s = s.toFixed(0)
  356. return s
  357. },
  358. handlePay(){
  359. let that = this
  360. let location = JSON.parse(uni.getStorageSync('location'))
  361. console.log('不能超过(米):',this.amount*1000,'距离加油站(米):',this.getFlatternDistance(location.latitude,location.longitude,this.info.lat,this.info.lon))
  362. if(this.getFlatternDistance(location.latitude,location.longitude,this.info.lat,this.info.lon)>1000){
  363. return uni.showModal({
  364. title:'提示',
  365. content:'您当前距离加油站较远,请到达加油站后与加油员确定信息',
  366. confirmText:'刷新位置',
  367. success: function (res) {
  368. if (res.confirm) {
  369. uni.showLoading({
  370. title:'刷新中'
  371. })
  372. uni.getLocation({
  373. type: 'gcj02',
  374. success: (res) => {
  375. // 存储经纬度
  376. uni.setStorageSync('location',JSON.stringify({latitude:res.latitude,longitude:res.longitude}))
  377. uni.hideLoading()
  378. that.getDistance()
  379. }
  380. })
  381. }
  382. }
  383. })
  384. }
  385. this.loading = true
  386. let query = {
  387. "channel":'ZhongShu',
  388. "epId": this.epId,
  389. "itemName":this.num,
  390. "gunNo": this.gun,
  391. "itemId": this.itemId,
  392. "litre": this.payInfo.litre,
  393. "openExtra": "",
  394. "originalAmount": this.payInfo.totalPrice,
  395. "outNewUserFlag": "",
  396. "paymentAmount": this.payInfo.realPrice,
  397. "promotionInfo": [
  398. {
  399. "allowanceId": "string",
  400. "allowanceType": 0
  401. }
  402. ],
  403. "serviceFee": this.payInfo.serviceFee,
  404. "storeId":this.storeId,
  405. "storePrice": this.price.storePrice,
  406. "vipPrice": this.price.vipPrice
  407. }
  408. queryNewOrder(query).then(res=>{
  409. this.loading = false
  410. if(res.state == 'Success'){
  411. uni.navigateToMiniProgram({
  412. appId:"wx0d252f6ed9755862", // 滴滴加油小程序appId
  413. path: `packageA/pages/open-energy-pay/index?orderId=${res.content.xjOrderId}&tradeId=${res.content.tradeId}`, // 滴滴加油收银台页面地址,需要拼接orderId和tradeId
  414. envVersion: 'release' // 固定release
  415. })
  416. }
  417. })
  418. }
  419. },
  420. onPageScroll(e) {
  421. if (e.scrollTop >= 50) {
  422. this.background = true
  423. } else {
  424. this.background = false
  425. }
  426. },
  427. onReady() {
  428. this.map = uni.createMapContext("map", this);
  429. },
  430. onShow() {
  431. if(!this.btnDisabled){
  432. uni.reLaunch({
  433. url:'/my/order/index'
  434. })
  435. }
  436. },
  437. onLoad(options) {
  438. this.epId = options.epId
  439. // '5154031457384536897'
  440. this.storeId = options.id
  441. this.queryStoreDetail(options.id)
  442. }
  443. }
  444. </script>
  445. <style lang="scss" >
  446. .refuelDetail{
  447. .banner{
  448. width: 100%;
  449. height: 382rpx;
  450. }
  451. .content{
  452. margin-top: -20rpx;
  453. min-height: 500rpx;
  454. border-radius: 16rpx 16rpx 0 0;
  455. position: relative;
  456. z-index: 2;
  457. background: #fff;
  458. padding: 28rpx 24rpx;
  459. .title{
  460. font-weight: 600;
  461. font-size: 32rpx;
  462. color: #222222;
  463. }
  464. .time{
  465. font-weight: 300;
  466. font-size: 24rpx;
  467. color: #AAAAAA;
  468. padding: 20rpx 0;
  469. border-bottom: 1rpx solid #F0F0F0;
  470. }
  471. .distance{
  472. font-weight: 300;
  473. font-size: 24rpx;
  474. color: #AAAAAA;
  475. padding: 20rpx 0;
  476. }
  477. .address-box{
  478. display: flex;
  479. align-items: center;
  480. justify-content: space-between;
  481. width: 702rpx;
  482. height: 140rpx;
  483. background-image: url('@/static/white-map.png');
  484. background-repeat: repeat;
  485. background-size: 100% 140rpx;
  486. box-sizing: border-box;
  487. padding: 36rpx 24rpx;
  488. .address{
  489. font-weight: 600;
  490. font-size: 24rpx;
  491. color: #222222;
  492. line-height: 40rpx;
  493. overflow: hidden;
  494. padding-right: 20rpx;
  495. text-overflow: ellipsis;
  496. /* 弹性伸缩盒子模型显示 */
  497. display: -webkit-box;
  498. /* 限制在一个块元素显示的文本的行数 */
  499. -webkit-line-clamp: 2;
  500. /* 设置或检索伸缩盒对象的子元素的排列方式 */
  501. -webkit-box-orient: vertical;
  502. }
  503. .btn-box{
  504. display: flex;
  505. .btn+.btn{
  506. margin-left: 16rpx;
  507. }
  508. .btn{
  509. width: 120rpx;
  510. height: 52rpx;
  511. line-height: 52rpx;
  512. text-align: center;
  513. background: #E2ECFF;
  514. border-radius: 26rpx 26rpx 26rpx 26rpx;
  515. font-weight: 300;
  516. font-size: 28rpx;
  517. color: #3879F9;
  518. }
  519. }
  520. }
  521. .price-box{
  522. display: flex;
  523. align-items: center;
  524. justify-content: space-between;
  525. padding: 20rpx 0;
  526. .price{
  527. font-weight: 600;
  528. font-size: 28rpx;
  529. color: #222222;
  530. }
  531. .right-box{
  532. display: flex;
  533. align-items: center;
  534. .old-price{
  535. font-weight: 300;
  536. font-size: 24rpx;
  537. color: #AAAAAA;
  538. margin-left: 20rpx;
  539. }
  540. }
  541. }
  542. .choose-box{
  543. display: flex;
  544. justify-content: space-between;
  545. .item{
  546. width: 340rpx;
  547. height: 80rpx;
  548. line-height: 80rpx;
  549. text-align: center;
  550. background: #F0F0F0;
  551. border-radius: 8rpx;
  552. font-weight: 600;
  553. font-size: 28rpx;
  554. color: #222222;
  555. position: relative;
  556. .icon{
  557. width: 32rpx;
  558. height: 32rpx;
  559. position: absolute;
  560. top: 50%;
  561. right: 24rpx;
  562. transform: translateY(-50%);
  563. }
  564. }
  565. .item.active{
  566. background: #FFF6F5;
  567. color: #FF4D3A;
  568. }
  569. }
  570. .price-input{
  571. width: 702rpx;
  572. height: 120rpx;
  573. line-height: 120rpx;
  574. border-radius: 8rpx 8rpx 8rpx 8rpx;
  575. border: 2rpx solid #AAAAAA;
  576. font-weight: bold;
  577. font-size: 32rpx;
  578. color: #222;
  579. padding: 28rpx;
  580. box-sizing: border-box;
  581. margin-top: 20rpx;
  582. }
  583. .order-box{
  584. .item{
  585. display: flex;
  586. align-items: center;
  587. justify-content: space-between;
  588. padding: 24rpx 0;
  589. border-bottom: 1rpx solid #F0F0F0;
  590. .label{
  591. font-weight: 300;
  592. font-size: 28rpx;
  593. color: #222222;
  594. }
  595. .value-box{
  596. display: flex;
  597. align-items: center;
  598. .num{
  599. font-weight: 300;
  600. font-size: 28rpx;
  601. color: #AAAAAA;
  602. }
  603. }
  604. .value{
  605. font-weight: 300;
  606. font-size: 28rpx;
  607. color: #222222;
  608. margin-left: 20rpx;
  609. }
  610. .gray{
  611. color: #AAAAAA!important;
  612. }
  613. }
  614. }
  615. }
  616. .buy-box {
  617. position: fixed;
  618. bottom: 0%;
  619. left: 0%;
  620. width: 100%;
  621. display: flex;
  622. align-items: center;
  623. justify-content: space-between;
  624. box-sizing: border-box;
  625. padding: 10rpx 30rpx env(safe-area-inset-bottom);
  626. border-top: 1rpx solid #EEEEEE;
  627. .total-price {
  628. display: flex;
  629. align-items: center;
  630. .label {
  631. color: #181818;
  632. font-size: 28rpx;
  633. }
  634. .price {
  635. font-size: 36rpx;
  636. font-weight: 800;
  637. color: #222222;
  638. margin-left: 10rpx;
  639. }
  640. }
  641. .btn {
  642. width: 280rpx;
  643. height: 80rpx;
  644. line-height: 80rpx;
  645. text-align: center;
  646. background: $uni-color-primary;
  647. box-shadow: inset 0rpx 6rpx 12rpx 2rpx rgba(255, 255, 255, 0.16);
  648. border-radius: 46rpx 46rpx 46rpx 46rpx;
  649. font-weight: 800;
  650. color: #FFFFFF;
  651. font-size: 28rpx;
  652. margin: 0;
  653. }
  654. .btn.disabled{
  655. filter: grayscale(1);
  656. }
  657. }
  658. .map{
  659. position: absolute;
  660. top: -9999rpx;
  661. left: -9999rpx;
  662. }
  663. .u-popup__content{
  664. padding: 28rpx 24rpx;
  665. background: #F9F9F9 !important;
  666. .popup-title{
  667. font-weight: 600;
  668. font-size: 32rpx;
  669. color: #222222;
  670. }
  671. .item-box{
  672. width: 100%;
  673. background: #FFFFFF;
  674. border-radius: 16rpx 16rpx 16rpx 16rpx;
  675. margin-top: 20rpx;
  676. padding: 24rpx;
  677. box-sizing: border-box;
  678. .sub-title{
  679. font-weight: 600;
  680. font-size: 28rpx;
  681. color: #222222;
  682. margin-bottom: 20rpx;
  683. display: flex;
  684. align-items: flex-end;
  685. .notice{
  686. font-weight: 300;
  687. font-size: 24rpx;
  688. color: #AAAAAA;
  689. margin-left: 20rpx;
  690. }
  691. }
  692. .box{
  693. display: flex;
  694. flex-wrap: wrap;
  695. max-height: 600rpx;
  696. overflow: auto;
  697. .item{
  698. width: 148rpx;
  699. height: 52rpx;
  700. line-height: 52rpx;
  701. text-align: center;
  702. background: #F0F0F0;
  703. border-radius: 8rpx 8rpx 8rpx 8rpx;
  704. font-weight: 400;
  705. font-size: 28rpx;
  706. color: #222222;
  707. margin-bottom: 20rpx;
  708. margin-right: 20rpx;
  709. }
  710. .item.active{
  711. background: #FFF6F5;
  712. color: #EE4320;
  713. }
  714. .item.m0{
  715. margin-right: 0!important;
  716. }
  717. }
  718. }
  719. }
  720. }
  721. </style>