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.

product-detail.vue 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <template>
  2. <navBar title="产品详情"></navBar>
  3. <navBgCar></navBgCar>
  4. <view class="content-wrap">
  5. <view class="ul-item">
  6. <image style="width: 100%; height: 170rpx; background-color: #eeeeee"
  7. :src="`${$imgUrl}applyCard/product-bg.png`"></image>
  8. <view class="item-value">
  9. <image class="icon-tip" :src="`${$imgUrl}applyCard/wechat.png`"></image>
  10. <view class="content">
  11. <view class="title"> 微信车主服务 </view>
  12. <view style="margin-top: 15rpx" class="tip"> 先通行后付费! </view>
  13. </view>
  14. </view>
  15. </view>
  16. <view class="value-wrapper">
  17. <view class="flex">
  18. <view class="title"> 产品金额 </view>
  19. <view class="value">
  20. {{ "¥" + state.clientFee }}
  21. </view>
  22. </view>
  23. <view class="flex">
  24. <view class="title"> 加购权益 </view>
  25. <view class="value"> ¥0.00 </view>
  26. </view>
  27. <view class="flex">
  28. <view class="title"> 运费 </view>
  29. <view class="value"> ¥0.00 </view>
  30. </view>
  31. <view class="flex">
  32. <view class="title"> 优惠券 </view>
  33. <view class="value"> 暂无优惠券 </view>
  34. </view>
  35. <view class="flex">
  36. <view class="title"> 积分兑换 </view>
  37. <view class="value"> 暂无积分 </view>
  38. </view>
  39. <view class="flex">
  40. <view class="title"> 实付款 </view>
  41. <view class="money">
  42. {{ "¥" + state.clientFee }}
  43. </view>
  44. </view>
  45. </view>
  46. <view class="action">
  47. <button type="default" class="button" @click="savaHandle()">
  48. {{ "确认办理:¥" + state.clientFee }}
  49. </button>
  50. </view>
  51. </view>
  52. </template>
  53. <script setup lang="ts">
  54. import {
  55. onLoad,
  56. onShow
  57. } from "@dcloudio/uni-app";
  58. import {
  59. reactive
  60. } from "vue";
  61. import {
  62. etcQueryProduct
  63. } from "@/utils/network/api.js";
  64. import {
  65. request
  66. } from "@/utils/network/request.js";
  67. import {
  68. stringToJson
  69. } from "@/utils/network/encryption";
  70. import {
  71. fileURL
  72. } from "@/datas/fileURL.js";
  73. import navBgCar from "./components/nav-bg-car5";
  74. import navBar from "../components/nav-bar/nav-bar2.vue";
  75. import {
  76. getItem,
  77. StorageKeys
  78. } from "@/utils/storage.ts";
  79. import {
  80. checkOrderStatus,
  81. orderPay,
  82. wechatAppID,
  83. wechatPayConfigId,
  84. wechatSecret,
  85. } from "@/utils/network/api";
  86. import {
  87. confirm,
  88. msg
  89. } from "@/utils/utils";
  90. const imgURL = `${fileURL}image/`;
  91. const savaHandle = () => {
  92. wxPayment();
  93. };
  94. //获取微信小程序openid
  95. const getOpenID = () => {
  96. uni.login({
  97. provider: "weixin",
  98. success: function(e) {
  99. wx.request({
  100. url: `https://api.weixin.qq.com/sns/jscode2session?appid=${wechatAppID}&secret=${wechatSecret}&js_code=${e.code}&grant_type=authorization_code`,
  101. success: (res: any) => {
  102. state.openid = res.data.openid;
  103. // console.log(state.openid);
  104. },
  105. });
  106. },
  107. });
  108. };
  109. //掉起微信支付
  110. const wxPayment = () => {
  111. // #ifdef MP-WEIXIN
  112. const options = {
  113. type: 2,
  114. data: {
  115. openid: state.openid,
  116. productId: state.id,
  117. orderId: state.orderId,
  118. payConfigId: wechatPayConfigId,
  119. },
  120. method: "POST",
  121. showLoading: true,
  122. };
  123. request(orderPay, options).then((res) => {
  124. const data = stringToJson(res.bizContent);
  125. uni.requestPayment({
  126. provider: "wxpay",
  127. orderInfo: "",
  128. timeStamp: data.timestamp,
  129. nonceStr: data.noncestr,
  130. package: data.wxPackage ?? "",
  131. signType: data.signType,
  132. paySign: data.sign,
  133. success: function(e) {
  134. console.log("支付成功", e);
  135. checkOrder();
  136. },
  137. fail: function(err) {
  138. checkOrder();
  139. confirm(err, () => {}, "支付失败", false);
  140. },
  141. });
  142. });
  143. // #endif
  144. };
  145. //支付成功改变订单状态
  146. const checkOrder = () => {
  147. const options = {
  148. type: 2,
  149. data: {
  150. orderId: state.orderId,
  151. payConfigId: wechatPayConfigId,
  152. },
  153. method: "POST",
  154. showLoading: true,
  155. };
  156. request(checkOrderStatus, options).then((res) => {
  157. msg("支付成功!");
  158. var pages = getCurrentPages().length;
  159. uni.$emit("refreshOrder");
  160. uni.switchTab({
  161. url: "/pages/order/order"
  162. })
  163. });
  164. };
  165. onLoad((option: any) => {
  166. state.orderId = option.orderId;
  167. state.clientFee = option.clientFee / 100;
  168. state.id = option.id;
  169. getOpenID();
  170. });
  171. const state = reactive({
  172. openid: "",
  173. orderId: "",
  174. clientFee: undefined,
  175. id: "",
  176. });
  177. </script>
  178. <style lang="scss" scoped>
  179. .action {
  180. margin-top: 40rpx;
  181. padding-left: 20rpx;
  182. padding-right: 20rpx;
  183. padding-bottom: 30rpx;
  184. .button {
  185. height: 80rpx;
  186. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  187. border-radius: 40rpx;
  188. font-size: 32rpx;
  189. font-weight: 400;
  190. color: #ffffff;
  191. line-height: 80rpx;
  192. }
  193. }
  194. .value-wrapper {
  195. margin-top: 40rpx;
  196. padding: 0rpx 30rpx;
  197. .flex {
  198. padding: 20rpx 0rpx;
  199. display: flex;
  200. justify-content: space-between;
  201. align-items: center;
  202. .title {
  203. font-size: 28rpx;
  204. font-family: Microsoft YaHei;
  205. font-weight: 400;
  206. color: #777777;
  207. line-height: 28rpx;
  208. }
  209. .value {
  210. font-size: 28rpx;
  211. font-family: Microsoft YaHei;
  212. font-weight: 400;
  213. color: #333333;
  214. line-height: 28rpx;
  215. }
  216. .money {
  217. font-size: 36rpx;
  218. font-family: Microsoft YaHei;
  219. font-weight: 400;
  220. color: #00b38b;
  221. line-height: 36rpx;
  222. }
  223. }
  224. }
  225. .content-wrap {
  226. position: relative;
  227. margin-top: -50rpx;
  228. padding: 0rpx 30rpx;
  229. .ul-item {
  230. padding: 5px 20rpx;
  231. display: flex;
  232. align-items: center;
  233. .item-value {
  234. padding: 20rpx;
  235. position: absolute;
  236. display: flex;
  237. align-items: center;
  238. justify-content: space-around;
  239. .content {
  240. .title {
  241. font-size: 32rpx;
  242. font-family: Microsoft YaHei;
  243. font-weight: 400;
  244. color: #ffffff;
  245. }
  246. .tip {
  247. font-size: 24rpx;
  248. font-family: Microsoft YaHei;
  249. font-weight: 400;
  250. color: #ffffff;
  251. }
  252. }
  253. }
  254. .icon-tip {
  255. width: 100rpx;
  256. height: 100rpx;
  257. }
  258. .content {
  259. margin-left: 40rpx;
  260. }
  261. }
  262. }
  263. </style>