refuelDetail.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  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. "epId": this.epId,
  388. "itemName":this.num,
  389. "gunNo": this.gun,
  390. "itemId": this.itemId,
  391. "litre": this.payInfo.litre,
  392. "openExtra": "",
  393. "originalAmount": this.payInfo.totalPrice,
  394. "outNewUserFlag": "",
  395. "paymentAmount": this.payInfo.realPrice,
  396. "promotionInfo": [
  397. {
  398. "allowanceId": "string",
  399. "allowanceType": 0
  400. }
  401. ],
  402. "serviceFee": this.payInfo.serviceFee,
  403. "storeId":this.storeId,
  404. "storePrice": this.price.storePrice,
  405. "vipPrice": this.price.vipPrice
  406. }
  407. queryNewOrder(query).then(res=>{
  408. this.loading = false
  409. if(res.state == 'Success'){
  410. uni.navigateToMiniProgram({
  411. appId:"wx0d252f6ed9755862", // 滴滴加油小程序appId
  412. path: `packageA/pages/open-energy-pay/index?orderId=${res.content.xjOrderId}&tradeId=${res.content.tradeId}`, // 滴滴加油收银台页面地址,需要拼接orderId和tradeId
  413. envVersion: 'release' // 固定release
  414. })
  415. }
  416. })
  417. }
  418. },
  419. onPageScroll(e) {
  420. if (e.scrollTop >= 50) {
  421. this.background = true
  422. } else {
  423. this.background = false
  424. }
  425. },
  426. onReady() {
  427. this.map = uni.createMapContext("map", this);
  428. },
  429. onShow() {
  430. if(!this.btnDisabled){
  431. uni.reLaunch({
  432. url:'/my/order/index'
  433. })
  434. }
  435. },
  436. onLoad(options) {
  437. this.epId = options.epId
  438. // '5154031457384536897'
  439. this.storeId = options.id
  440. this.queryStoreDetail(options.id)
  441. }
  442. }
  443. </script>
  444. <style lang="scss" >
  445. .refuelDetail{
  446. .banner{
  447. width: 100%;
  448. height: 382rpx;
  449. }
  450. .content{
  451. margin-top: -20rpx;
  452. min-height: 500rpx;
  453. border-radius: 16rpx 16rpx 0 0;
  454. position: relative;
  455. z-index: 2;
  456. background: #fff;
  457. padding: 28rpx 24rpx;
  458. .title{
  459. font-weight: 600;
  460. font-size: 32rpx;
  461. color: #222222;
  462. }
  463. .time{
  464. font-weight: 300;
  465. font-size: 24rpx;
  466. color: #AAAAAA;
  467. padding: 20rpx 0;
  468. border-bottom: 1rpx solid #F0F0F0;
  469. }
  470. .distance{
  471. font-weight: 300;
  472. font-size: 24rpx;
  473. color: #AAAAAA;
  474. padding: 20rpx 0;
  475. }
  476. .address-box{
  477. display: flex;
  478. align-items: center;
  479. justify-content: space-between;
  480. width: 702rpx;
  481. height: 140rpx;
  482. background-image: url('@/static/white-map.png');
  483. background-repeat: repeat;
  484. background-size: 100% 140rpx;
  485. box-sizing: border-box;
  486. padding: 36rpx 24rpx;
  487. .address{
  488. font-weight: 600;
  489. font-size: 24rpx;
  490. color: #222222;
  491. line-height: 40rpx;
  492. overflow: hidden;
  493. padding-right: 20rpx;
  494. text-overflow: ellipsis;
  495. /* 弹性伸缩盒子模型显示 */
  496. display: -webkit-box;
  497. /* 限制在一个块元素显示的文本的行数 */
  498. -webkit-line-clamp: 2;
  499. /* 设置或检索伸缩盒对象的子元素的排列方式 */
  500. -webkit-box-orient: vertical;
  501. }
  502. .btn-box{
  503. display: flex;
  504. .btn+.btn{
  505. margin-left: 16rpx;
  506. }
  507. .btn{
  508. width: 120rpx;
  509. height: 52rpx;
  510. line-height: 52rpx;
  511. text-align: center;
  512. background: #E2ECFF;
  513. border-radius: 26rpx 26rpx 26rpx 26rpx;
  514. font-weight: 300;
  515. font-size: 28rpx;
  516. color: #3879F9;
  517. }
  518. }
  519. }
  520. .price-box{
  521. display: flex;
  522. align-items: center;
  523. justify-content: space-between;
  524. padding: 20rpx 0;
  525. .price{
  526. font-weight: 600;
  527. font-size: 28rpx;
  528. color: #222222;
  529. }
  530. .right-box{
  531. display: flex;
  532. align-items: center;
  533. .old-price{
  534. font-weight: 300;
  535. font-size: 24rpx;
  536. color: #AAAAAA;
  537. margin-left: 20rpx;
  538. }
  539. }
  540. }
  541. .choose-box{
  542. display: flex;
  543. justify-content: space-between;
  544. .item{
  545. width: 340rpx;
  546. height: 80rpx;
  547. line-height: 80rpx;
  548. text-align: center;
  549. background: #F0F0F0;
  550. border-radius: 8rpx;
  551. font-weight: 600;
  552. font-size: 28rpx;
  553. color: #222222;
  554. position: relative;
  555. .icon{
  556. width: 32rpx;
  557. height: 32rpx;
  558. position: absolute;
  559. top: 50%;
  560. right: 24rpx;
  561. transform: translateY(-50%);
  562. }
  563. }
  564. .item.active{
  565. background: #FFF6F5;
  566. color: #FF4D3A;
  567. }
  568. }
  569. .price-input{
  570. width: 702rpx;
  571. height: 120rpx;
  572. line-height: 120rpx;
  573. border-radius: 8rpx 8rpx 8rpx 8rpx;
  574. border: 2rpx solid #AAAAAA;
  575. font-weight: bold;
  576. font-size: 32rpx;
  577. color: #222;
  578. padding: 28rpx;
  579. box-sizing: border-box;
  580. margin-top: 20rpx;
  581. }
  582. .order-box{
  583. .item{
  584. display: flex;
  585. align-items: center;
  586. justify-content: space-between;
  587. padding: 24rpx 0;
  588. border-bottom: 1rpx solid #F0F0F0;
  589. .label{
  590. font-weight: 300;
  591. font-size: 28rpx;
  592. color: #222222;
  593. }
  594. .value-box{
  595. display: flex;
  596. align-items: center;
  597. .num{
  598. font-weight: 300;
  599. font-size: 28rpx;
  600. color: #AAAAAA;
  601. }
  602. }
  603. .value{
  604. font-weight: 300;
  605. font-size: 28rpx;
  606. color: #222222;
  607. margin-left: 20rpx;
  608. }
  609. .gray{
  610. color: #AAAAAA!important;
  611. }
  612. }
  613. }
  614. }
  615. .buy-box {
  616. position: fixed;
  617. bottom: 0%;
  618. left: 0%;
  619. width: 100%;
  620. display: flex;
  621. align-items: center;
  622. justify-content: space-between;
  623. box-sizing: border-box;
  624. padding: 10rpx 30rpx env(safe-area-inset-bottom);
  625. border-top: 1rpx solid #EEEEEE;
  626. .total-price {
  627. display: flex;
  628. align-items: center;
  629. .label {
  630. color: #181818;
  631. font-size: 28rpx;
  632. }
  633. .price {
  634. font-size: 36rpx;
  635. font-weight: 800;
  636. color: #222222;
  637. margin-left: 10rpx;
  638. }
  639. }
  640. .btn {
  641. width: 280rpx;
  642. height: 80rpx;
  643. line-height: 80rpx;
  644. text-align: center;
  645. background: $uni-color-primary;
  646. box-shadow: inset 0rpx 6rpx 12rpx 2rpx rgba(255, 255, 255, 0.16);
  647. border-radius: 46rpx 46rpx 46rpx 46rpx;
  648. font-weight: 800;
  649. color: #FFFFFF;
  650. font-size: 28rpx;
  651. margin: 0;
  652. }
  653. .btn.disabled{
  654. filter: grayscale(1);
  655. }
  656. }
  657. .map{
  658. position: absolute;
  659. top: -9999rpx;
  660. left: -9999rpx;
  661. }
  662. .u-popup__content{
  663. padding: 28rpx 24rpx;
  664. background: #F9F9F9 !important;
  665. .popup-title{
  666. font-weight: 600;
  667. font-size: 32rpx;
  668. color: #222222;
  669. }
  670. .item-box{
  671. width: 100%;
  672. background: #FFFFFF;
  673. border-radius: 16rpx 16rpx 16rpx 16rpx;
  674. margin-top: 20rpx;
  675. padding: 24rpx;
  676. box-sizing: border-box;
  677. .sub-title{
  678. font-weight: 600;
  679. font-size: 28rpx;
  680. color: #222222;
  681. margin-bottom: 20rpx;
  682. display: flex;
  683. align-items: flex-end;
  684. .notice{
  685. font-weight: 300;
  686. font-size: 24rpx;
  687. color: #AAAAAA;
  688. margin-left: 20rpx;
  689. }
  690. }
  691. .box{
  692. display: flex;
  693. flex-wrap: wrap;
  694. max-height: 600rpx;
  695. overflow: auto;
  696. .item{
  697. width: 148rpx;
  698. height: 52rpx;
  699. line-height: 52rpx;
  700. text-align: center;
  701. background: #F0F0F0;
  702. border-radius: 8rpx 8rpx 8rpx 8rpx;
  703. font-weight: 400;
  704. font-size: 28rpx;
  705. color: #222222;
  706. margin-bottom: 20rpx;
  707. margin-right: 20rpx;
  708. }
  709. .item.active{
  710. background: #FFF6F5;
  711. color: #EE4320;
  712. }
  713. .item.m0{
  714. margin-right: 0!important;
  715. }
  716. }
  717. }
  718. }
  719. }
  720. </style>