加油站付款小程序,打印小票
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

268 lines
5.7 KiB

9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
  1. <template>
  2. <view class="payment">
  3. <uni-nav-bar dark :fixed="true" background-color="#00aaff" :border="false" status-bar title="加油" />
  4. <view class="container">
  5. <uni-section title="油号" type="line" titleFontSize="34rpx"></uni-section>
  6. <view class="select-oil">
  7. <view class="oil-item">
  8. <view class="oil active-oil">
  9. <!-- <view class="unit"></view> -->
  10. <view class="number">#95</view>
  11. </view>
  12. </view>
  13. </view>
  14. <uni-section title="输入金额" type="line" titleFontSize="34rpx"></uni-section>
  15. <view class="money-input">
  16. <image src="/static/payment/money.png" mode="widthFix"></image>
  17. <input v-model="form.money" @focus="focus" placeholder="请输入加油金额" type="number" />
  18. </view>
  19. <view v-if="form.money" class="tip">
  20. 折后共计{{
  21. (form.money *
  22. (configList.preferential ?
  23. configList.preferential.keyCentent
  24. : 1)).toFixed(2)
  25. }}
  26. </view>
  27. <view class="select-money">
  28. <view v-for="(item, index) in rechargeList" class="money-item" :key="index">
  29. <view @click="selectMoney(item.price,index)" :class="{ 'active-money' : currentIndex == index }"
  30. class="money">
  31. <view class="unit"></view>
  32. <view class="number">{{ item.price }}</view>
  33. </view>
  34. </view>
  35. </view>
  36. <view class="sumit" @click="submit">提交订单</view>
  37. </view>
  38. <PrivacyAgreementPoup ref="showPrivacy"></PrivacyAgreementPoup>
  39. <uni-fab ref="fab" :content="content" :horizontal="horizontal" :vertical="vertical" :direction="direction"
  40. @trigger="clickMenu" />
  41. </view>
  42. </template>
  43. <script setup>
  44. import PrivacyAgreementPoup from "@/components/PrivacyAgreementPoup/PrivacyAgreementPoup.vue";
  45. import { mapState } from 'vuex'
  46. export default {
  47. name: 'Payment',
  48. components: {
  49. PrivacyAgreementPoup
  50. },
  51. computed : {
  52. ...mapState(['configList']),
  53. },
  54. data() {
  55. return {
  56. form: {
  57. money: ''
  58. },
  59. resolvePrivacyAuthorization: {},
  60. currentIndex: 0,
  61. content: [{
  62. iconPath: '/static/payment/wedding-celebration.png',
  63. text: '婚庆服务',
  64. active: false,
  65. path: '/pages/weddingCelebration/weddingCelebration'
  66. }],
  67. horizontal: 'right',
  68. vertical: 'bottom',
  69. direction: 'vertical',
  70. rechargeList : []
  71. }
  72. },
  73. onShow() {
  74. if (wx.onNeedPrivacyAuthorization) {
  75. console.log('onNeedPrivacyAuthorization');
  76. wx.onNeedPrivacyAuthorization(resolve => {
  77. console.log('onNeedPrivacyAuthorization');
  78. this.resolvePrivacyAuthorization = resolve
  79. this.$refs.showPrivacy.init(resolve)
  80. })
  81. }
  82. // wx.getPrivacySetting({
  83. // success: res => {
  84. // console.log(res)
  85. // if (res.needAuthorization) {
  86. // // 需要弹出隐私协议
  87. // this.$refs.showPrivacy.init()
  88. // }
  89. // },
  90. // fail: () => {}
  91. // })
  92. this.getRechargePage()
  93. },
  94. methods: {
  95. // 用户选择加油金额
  96. selectMoney(money, item) {
  97. this.form.money = money
  98. this.currentIndex = item
  99. },
  100. //输入框获得焦点
  101. focus() {
  102. },
  103. //用户点击了悬浮按钮
  104. clickMenu({
  105. item
  106. }) {
  107. uni.navigateTo({
  108. url: item.path
  109. })
  110. },
  111. submit() {
  112. if (!uni.getStorageSync('token')) {
  113. return uni.navigateTo({
  114. url: '/pages/login/login'
  115. })
  116. }
  117. this.$api('createOrderPay', this.form, res => {
  118. this.form.money = ''
  119. if(res.code == 200){
  120. uni.requestPayment({
  121. provider: 'wxpay', // 服务提提供商
  122. timeStamp: res.result.timeStamp, // 时间戳
  123. nonceStr: res.result.nonceStr, // 随机字符串
  124. package: res.result.packageValue,
  125. signType: res.result.signType, // 签名算法
  126. paySign: res.result.paySign, // 签名
  127. success: function (res) {
  128. console.log('支付成功',res);
  129. uni.switchTab({
  130. url: '/pages/center/center'
  131. })
  132. },
  133. fail: function (err) {
  134. console.log('支付失败',err);
  135. uni.showToast({
  136. icon:'none',
  137. title:"支付失败"
  138. })
  139. }
  140. });
  141. // uni.showToast({
  142. // icon : 'none',
  143. // title: '支付成功'
  144. // });
  145. }
  146. })
  147. },
  148. //获取充值套餐
  149. getRechargePage(){
  150. this.$api('getRechargePage', res => {
  151. this.rechargeList = res.result.records
  152. })
  153. }
  154. }
  155. }
  156. </script>
  157. <style scoped>
  158. .payment {
  159. height: 100vh;
  160. background: #F1F5F8;
  161. width: 750rpx;
  162. margin: 0 auto;
  163. }
  164. .container {
  165. width: 96%;
  166. margin: 0rpx auto;
  167. border-radius: 20rpx;
  168. box-sizing: border-box;
  169. padding: 20rpx;
  170. overflow: hidden;
  171. background: white;
  172. margin-top: 20rpx;
  173. }
  174. .money-input {
  175. display: flex;
  176. align-items: center;
  177. background: #F6F7FB;
  178. padding: 30rpx 10rpx;
  179. border-radius: 20rpx;
  180. }
  181. .tip {
  182. color: #00aaff;
  183. margin-top: 10rpx;
  184. }
  185. .money-input image {
  186. width: 45rpx;
  187. }
  188. .money-input input {
  189. font-size: 36rpx;
  190. }
  191. .select-oil,
  192. .select-money {
  193. display: flex;
  194. justify-content: space-between;
  195. flex-wrap: wrap;
  196. margin: 30rpx 0rpx;
  197. }
  198. .select-oil {
  199. margin: 0;
  200. }
  201. .select-oil .oil-item,
  202. .select-money .money-item {
  203. width: 32.33%;
  204. background: #F1F5F8;
  205. border-radius: 20rpx;
  206. margin-bottom: 20rpx;
  207. overflow: hidden;
  208. }
  209. .select-oil .oil,
  210. .select-money .money {
  211. display: flex;
  212. align-items: center;
  213. justify-content: center;
  214. padding: 30rpx 0rpx;
  215. box-sizing: border-box;
  216. color: #5D5C61;
  217. }
  218. .select-oil .active-oil,
  219. .select-money .active-money {
  220. background: #00aaff;
  221. color: white;
  222. }
  223. .select-money .unit {
  224. font-size: 26rpx;
  225. }
  226. .select-money .number {
  227. font-size: 34rpx;
  228. }
  229. .sumit {
  230. background: #33a5fc;
  231. color: white;
  232. font-size: 36rpx;
  233. display: flex;
  234. align-items: center;
  235. justify-content: center;
  236. height: 80rpx;
  237. border-radius: 20rpx;
  238. }
  239. </style>