Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

2 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. <template>
  2. <view class="wrapper">
  3. <!-- 背景颜色充满屏 -->
  4. <view class="bg-color"></view>
  5. <navBar title="收银"></navBar>
  6. <view class="money">
  7. <text class="money-title">需支付金额(元)</text>
  8. <text class="money-value"
  9. >¥{{ state.orderData.amount / 100 ?? "0.00" }}</text
  10. >
  11. </view>
  12. <view class="bankcard">
  13. <view class="method-item border-line">
  14. <view class="method-name">
  15. <image class="name-img" :src="`${$imgUrl}order/bank.png`"></image>
  16. <text class="name-text">{{ state.bankInfo.name }}</text>
  17. </view>
  18. <image
  19. class="name-img-selected"
  20. :src="`${$imgUrl}order/selected.png`"
  21. v-if="state.methodSelected == state.bankInfo.id"
  22. ></image>
  23. <view
  24. class="select-circle"
  25. @click="methodHandle(state.bankInfo.id)"
  26. v-else
  27. ></view>
  28. </view>
  29. <view class="method-item other-method" @click="showList">
  30. <view class="method-name">
  31. <text class="name-text text-space">其他银行卡</text>
  32. </view>
  33. <image class="img-arrow" :src="`${$imgUrl}user/icon-arrow.png`"></image>
  34. </view>
  35. </view>
  36. <view class="pay-method">
  37. <view class="method-item border-line" @click="methodHandle('wx')">
  38. <view class="method-name">
  39. <image class="name-img" :src="`${$imgUrl}order/wx.png`"></image>
  40. <text class="name-text">微信支付</text>
  41. </view>
  42. <image
  43. class="name-img-selected"
  44. :src="`${$imgUrl}order/selected.png`"
  45. v-if="state.methodSelected == 'wx'"
  46. ></image>
  47. <view class="select-circle" v-else></view>
  48. </view>
  49. <view class="method-item border-line" @click="methodHandle('ysf')">
  50. <view class="method-name">
  51. <image class="name-img" :src="`${$imgUrl}order/ysf.png`"></image>
  52. <text class="name-text">云闪付</text>
  53. </view>
  54. <image
  55. class="name-img-selected"
  56. :src="`${$imgUrl}order/selected.png`"
  57. v-if="state.methodSelected == 'ysf'"
  58. ></image>
  59. <view class="select-circle" v-else></view>
  60. </view>
  61. <view class="method-item" @click="methodHandle('wxhy')">
  62. <view class="method-name">
  63. <image class="name-img" :src="`${$imgUrl}order/wx1.png`"></image>
  64. <text class="name-text">微信好友支付</text>
  65. </view>
  66. <image
  67. class="name-img-selected"
  68. :src="`${$imgUrl}order/selected.png`"
  69. v-if="state.methodSelected == 'wxhy'"
  70. ></image>
  71. <view class="select-circle" v-else></view>
  72. </view>
  73. </view>
  74. <view class="btn" @click="toPayOrder">支付</view>
  75. <!-- 银行list弹窗 -->
  76. <u-popup
  77. v-model="state.listInfo.show"
  78. mode="bottom"
  79. :mask-close-able="false"
  80. >
  81. <view class="list-header">请选择</view>
  82. <scroll-view scroll-y="true" style="height: 530rpx; background: #f4f4f4">
  83. <view class="list-box">
  84. <view
  85. v-for="item in state.listInfo.list"
  86. :key="item.id"
  87. class="p-list-item"
  88. @click="listSelected(item)"
  89. >
  90. {{ item.name }}
  91. </view>
  92. </view>
  93. </scroll-view>
  94. </u-popup>
  95. </view>
  96. </template>
  97. <script setup lang="ts">
  98. import navBar from "@/components/nav-bar/nav-bar.vue";
  99. import { reactive } from "vue";
  100. import { request } from "@/utils/network/request.js";
  101. import {
  102. checkOrderStatus,
  103. orderPay,
  104. wechatAppID,
  105. wechatPayConfigId,
  106. wechatSecret,
  107. } from "@/utils/network/api";
  108. import { stringToJson } from "@/utils/network/encryption";
  109. import { onLoad } from "@dcloudio/uni-app";
  110. import { confirm, msg } from "@/utils/utils";
  111. const state = reactive({
  112. methodSelected: "wx",
  113. bankInfo: { id: 1, name: "招商银行储蓄卡(0843)" },
  114. listInfo: {
  115. show: false,
  116. list: [
  117. { name: "工商银行", id: 2 },
  118. { name: "建设银行", id: 3 },
  119. ],
  120. },
  121. orderData: {} as any, //订单数据
  122. openid: "",
  123. });
  124. const methodHandle = (val) => {
  125. state.methodSelected = val;
  126. console.log(state.methodSelected);
  127. };
  128. // 展开其他银行卡
  129. const showList = () => {
  130. state.listInfo.show = true;
  131. };
  132. //其他银行卡选择
  133. const listSelected = (item) => {
  134. state.listInfo.show = false;
  135. };
  136. //订单支付
  137. const toPayOrder = () => {
  138. if (state.methodSelected == "wx") {
  139. //微信支付
  140. wxPayment();
  141. } else {
  142. msg("目前只支持微信支付!");
  143. }
  144. };
  145. //掉起微信支付
  146. const wxPayment = () => {
  147. // #ifdef MP-WEIXIN
  148. if (!state.openid) {
  149. getOpenID();
  150. msg("请求失败,请稍后重试!");
  151. return;
  152. }
  153. const options = {
  154. type: 2,
  155. data: {
  156. openid: state.openid,
  157. productId: state.orderData.productId, //产品id
  158. orderId: state.orderData.orderId,
  159. payConfigId: wechatPayConfigId,
  160. },
  161. method: "POST",
  162. showLoading: true,
  163. };
  164. request(orderPay, options).then((res) => {
  165. const data = stringToJson(res.bizContent);
  166. uni.requestPayment({
  167. provider: "wxpay",
  168. orderInfo: "",
  169. timeStamp: data.timestamp,
  170. nonceStr: data.noncestr,
  171. package: data.wxPackage ?? "",
  172. signType: data.signType,
  173. paySign: data.sign,
  174. success: function (e) {
  175. console.log("支付成功", e);
  176. checkOrder();
  177. },
  178. fail: function (err) {
  179. confirm(err, () => {}, "支付失败", false);
  180. },
  181. });
  182. });
  183. // #endif
  184. };
  185. //获取微信小程序openid
  186. const getOpenID = () => {
  187. uni.login({
  188. provider: "weixin",
  189. success: function (e) {
  190. wx.request({
  191. url: `https://api.weixin.qq.com/sns/jscode2session?appid=${wechatAppID}&secret=${wechatSecret}&js_code=${e.code}&grant_type=authorization_code`,
  192. success: (res: any) => {
  193. state.openid = res.data.openid;
  194. },
  195. });
  196. },
  197. });
  198. };
  199. //支付成功改变订单状态
  200. const checkOrder = () => {
  201. const options = {
  202. type: 2,
  203. data: {
  204. orderId: state.orderData.orderId,
  205. payConfigId: wechatPayConfigId,
  206. },
  207. method: "POST",
  208. showLoading: true,
  209. };
  210. request(checkOrderStatus, options).then((res) => {
  211. payOrderSuccess();
  212. });
  213. };
  214. const payOrderSuccess = () => {
  215. confirm(
  216. "您申办的ETC订单支付成功,请等待业务员审核信息,确认无误后发货!",
  217. () => {
  218. uni.$emit("refreshOrder");
  219. uni.navigateBack();
  220. },
  221. "支付成功",
  222. false
  223. );
  224. };
  225. onLoad((options) => {
  226. //需要参数参数json形式:{orderId, productId,amount}
  227. state.orderData = JSON.parse(options.data);
  228. console.log(state.orderData);
  229. getOpenID();
  230. });
  231. </script>
  232. <style lang="scss" scoped>
  233. .bg-color {
  234. position: fixed;
  235. top: 0;
  236. left: 0;
  237. right: 0;
  238. bottom: 0;
  239. background: #f3f3f3;
  240. z-index: -1;
  241. }
  242. .wrapper {
  243. padding-bottom: 20rpx;
  244. }
  245. .money {
  246. background: #ffffff;
  247. display: flex;
  248. flex-direction: column;
  249. height: 266rpx;
  250. justify-content: center;
  251. align-items: center;
  252. .money-title {
  253. color: #717171;
  254. font-size: 29rpx;
  255. }
  256. .money-value {
  257. font-size: 40rpx;
  258. color: #2a2a2a;
  259. font-weight: 500;
  260. margin-top: 32rpx;
  261. }
  262. }
  263. .bankcard,
  264. .pay-method {
  265. background: #ffffff;
  266. margin-top: 20rpx;
  267. padding: 0 30rpx;
  268. }
  269. .method-item {
  270. display: flex;
  271. justify-content: space-between;
  272. align-items: center;
  273. padding: 20rpx 0;
  274. .text-space {
  275. margin-left: 69rpx;
  276. }
  277. .img-arrow {
  278. width: 14rpx;
  279. height: 25rpx;
  280. margin-right: 12rpx;
  281. }
  282. .method-name {
  283. .name-img {
  284. width: 50rpx;
  285. height: 50rpx;
  286. vertical-align: middle;
  287. }
  288. .name-text {
  289. color: #333333;
  290. font-size: 28rpx;
  291. margin-left: 19rpx;
  292. line-height: 30rpx;
  293. }
  294. }
  295. .select-circle {
  296. width: 37rpx;
  297. height: 37rpx;
  298. background: #ffffff;
  299. border: 2px solid #999999;
  300. border-radius: 50%;
  301. }
  302. .name-img-selected {
  303. width: 37rpx;
  304. height: 37rpx;
  305. }
  306. .text-icon {
  307. font-size: 25rpx;
  308. }
  309. }
  310. .border-line {
  311. border-bottom: 1rpx solid #dcdcdc;
  312. }
  313. .btn {
  314. margin: 233rpx 40rpx 40rpx 40rpx;
  315. height: 80rpx;
  316. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  317. border-radius: 40rpx;
  318. font-size: 32rpx;
  319. font-weight: 400;
  320. color: #fff;
  321. text-align: center;
  322. line-height: 80rpx;
  323. }
  324. .list-header {
  325. height: 81rpx;
  326. background: #ffffff;
  327. border: 1px solid #dcdcdc;
  328. line-height: 81rpx;
  329. text-align: center;
  330. color: #333333;
  331. font-size: 36rpx;
  332. }
  333. .p-list-item {
  334. padding: 30rpx 46rpx;
  335. border-bottom: 1px solid #dcdcdc;
  336. font-size: 28rpx;
  337. color: #333333;
  338. }
  339. .list-box {
  340. padding: 0 30rpx;
  341. }
  342. </style>