加油站付款小程序,打印小票
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.

282 lines
6.0 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year 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="digit" />
  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: -1,
  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. let money = (this.form.money *
  118. (this.configList.preferential ?
  119. this.configList.preferential.keyCentent
  120. : 1)).toFixed(2)
  121. // if(!money){
  122. // uni.showToast({
  123. // icon: 'none',
  124. // title: ''
  125. // })
  126. // }
  127. this.$api('createOrderPay', {
  128. money
  129. }, res => {
  130. this.form.money = ''
  131. if(res.code == 200){
  132. uni.requestPayment({
  133. provider: 'wxpay', // 服务提提供商
  134. timeStamp: res.result.timeStamp, // 时间戳
  135. nonceStr: res.result.nonceStr, // 随机字符串
  136. package: res.result.packageValue,
  137. signType: res.result.signType, // 签名算法
  138. paySign: res.result.paySign, // 签名
  139. success: function (res) {
  140. console.log('支付成功',res);
  141. uni.switchTab({
  142. url: '/pages/center/center'
  143. })
  144. },
  145. fail: function (err) {
  146. console.log('支付失败',err);
  147. uni.showToast({
  148. icon:'none',
  149. title:"支付失败"
  150. })
  151. }
  152. });
  153. // uni.showToast({
  154. // icon : 'none',
  155. // title: '支付成功'
  156. // });
  157. }
  158. }, "订单创建中...")
  159. },
  160. //获取充值套餐
  161. getRechargePage(){
  162. this.$api('getRechargePage', res => {
  163. this.rechargeList = res.result.records
  164. })
  165. }
  166. }
  167. }
  168. </script>
  169. <style scoped>
  170. .payment {
  171. height: 100vh;
  172. background: #F1F5F8;
  173. width: 750rpx;
  174. margin: 0 auto;
  175. }
  176. .container {
  177. width: 96%;
  178. margin: 0rpx auto;
  179. border-radius: 20rpx;
  180. box-sizing: border-box;
  181. padding: 20rpx;
  182. overflow: hidden;
  183. background: white;
  184. margin-top: 20rpx;
  185. }
  186. .money-input {
  187. display: flex;
  188. align-items: center;
  189. background: #F6F7FB;
  190. padding: 30rpx 10rpx;
  191. border-radius: 20rpx;
  192. }
  193. .tip {
  194. color: #00aaff;
  195. margin-top: 10rpx;
  196. }
  197. .money-input image {
  198. width: 45rpx;
  199. }
  200. .money-input input {
  201. font-size: 36rpx;
  202. }
  203. .select-oil,
  204. .select-money {
  205. display: flex;
  206. justify-content: space-between;
  207. flex-wrap: wrap;
  208. margin: 30rpx 0rpx;
  209. }
  210. .select-oil {
  211. margin: 0;
  212. }
  213. .select-oil .oil-item,
  214. .select-money .money-item {
  215. width: 32.33%;
  216. background: #F1F5F8;
  217. border-radius: 20rpx;
  218. margin-bottom: 20rpx;
  219. overflow: hidden;
  220. }
  221. .select-oil .oil,
  222. .select-money .money {
  223. display: flex;
  224. align-items: center;
  225. justify-content: center;
  226. padding: 30rpx 0rpx;
  227. box-sizing: border-box;
  228. color: #5D5C61;
  229. }
  230. .select-oil .active-oil,
  231. .select-money .active-money {
  232. background: #00aaff;
  233. color: white;
  234. }
  235. .select-money .unit {
  236. font-size: 26rpx;
  237. }
  238. .select-money .number {
  239. font-size: 34rpx;
  240. }
  241. .sumit {
  242. background: #33a5fc;
  243. color: white;
  244. font-size: 36rpx;
  245. display: flex;
  246. align-items: center;
  247. justify-content: center;
  248. height: 80rpx;
  249. border-radius: 20rpx;
  250. }
  251. </style>