pay.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. <template>
  2. <view class="pay">
  3. <!-- <view class="shop-info" v-if="!isVisual">
  4. <view class="shop-name">
  5. {{info.shopName}}
  6. </view>
  7. <view class="address">
  8. {{info.address}}
  9. </view>
  10. </view> -->
  11. <view class="pay-info">
  12. <view class="goods-info">
  13. <image class="goods-img" :src="info.goodsPath" mode=""></image>
  14. <view class="info">
  15. <view class="goods-name">
  16. {{ info.goodsName }}
  17. </view>
  18. <view class="num">
  19. {{ info.goodsDescribe }}
  20. </view>
  21. <view class="price">
  22. ¥{{ info.realPrice }}
  23. <!-- ¥{{payInfo.originalPrice}} -->
  24. </view>
  25. </view>
  26. </view>
  27. <view class="coupon">
  28. <view class="label"> 优惠券 </view>
  29. <view class="choose-coupon" :class="[payInfo.offset ? '' : 'none']" @click="choose">
  30. <!-- {{payInfo.goodsCouponName}}-¥{{payInfo.offset}} -->
  31. {{ payInfo.offset ? "-¥" + payInfo.offset : "暂无可用" }}
  32. <image class="icon" src="../static/jiantou-icon.png" mode=""></image>
  33. </view>
  34. </view>
  35. <!-- <view class="explain">
  36. <view class="label">
  37. 优惠说明
  38. </view>
  39. <view class="right">
  40. 已优惠: <view class="red">¥{{payInfo.offset}} </view> 合计: <view class="red fs28">¥{{payInfo.price}}
  41. </view>
  42. </view>
  43. </view> -->
  44. </view>
  45. <view class="input-box">
  46. <view class="label"> 备注 </view>
  47. <view class="choose-coupon" @click="chooseRemark">
  48. {{ info.extend.remark ? info.extend.remark : "请输入您的需求" }}
  49. <image class="icon" src="../static/jiantou-icon.png" mode=""></image>
  50. </view>
  51. </view>
  52. <view class="input-box" v-if="isVisual">
  53. <view class="label"> 充值账号 </view>
  54. <view class="value">
  55. {{ form.account }}
  56. </view>
  57. </view>
  58. <view class="input-box-address" @click="toMap()">
  59. <view class="label"> 到店自取地址 </view>
  60. <view class="value">
  61. <!-- {{ info.address }} -->
  62. 印象贵大文创店
  63. </view>
  64. <view class="label"> 贵州大学西校区西一区体育场楼下</view>
  65. </view>
  66. <view class="btn-box">
  67. <view class="total-price">
  68. <view class="label"> 合计: </view>
  69. <view class="price"> ¥ {{ payInfo.price }} </view>
  70. </view>
  71. <button class="btn" type="default" :loading="loading" @click="creat">
  72. 提交订单
  73. </button>
  74. </view>
  75. </view>
  76. </template>
  77. <script>
  78. import { calculate } from "@/api/order.js";
  79. import { creat } from "@/api/goods.js";
  80. import { creatPayOrder, queryPayOrder, payDetails } from "@/api/payment.js";
  81. import guid from "@/utils/guid.js";
  82. export default {
  83. data() {
  84. return {
  85. isVisual: false, //是否是虚拟商品
  86. loading: false,
  87. info: {},
  88. realPay: {
  89. goodsCouponName: "", //优惠券名
  90. couponGoodsLogId: "", //优惠券id
  91. goodsId: "", //商品id
  92. price: "", //支付价格
  93. offset: "", //实际抵扣值
  94. discount: "", //优惠券值
  95. condition: "", //优惠条件
  96. originalPrice: "", //原价
  97. },
  98. form: {
  99. account: "",
  100. },
  101. rules: {
  102. account: {
  103. type: "string",
  104. required: true,
  105. message: "请输入充值账号",
  106. trigger: ["blur", "change"],
  107. },
  108. },
  109. query: {
  110. // msgType: "wx.unifiedOrder",
  111. msgType: "wx.miniPreOrder",
  112. orderDesc: "测试",
  113. orderNo: "",
  114. subOpenId: "",
  115. userId: "",
  116. },
  117. // 支付信息
  118. payData: {},
  119. };
  120. },
  121. computed: {
  122. // 正式支付时的信息
  123. payInfo() {
  124. return {
  125. goodsCouponName: this.realPay.goodsCouponName || "", //优惠券名
  126. couponGoodsLogId: this.info.couponId, //优惠券id
  127. goodsId: this.realPay.goodsId || this.info.goodsId, //商品id
  128. price: this.realPay.price, //支付价格
  129. offset: this.realPay.offset, //实际抵扣值
  130. discount: this.realPay.discount || 0, //优惠券值
  131. condition: this.realPay.condition || "", //优惠条件
  132. originalPrice: this.realPay.originalPrice, //原价
  133. };
  134. },
  135. },
  136. methods: {
  137. calculate(goodsId, shopId) {
  138. return new Promise((resolve, reject) => {
  139. // uni.request({
  140. // url:'http://192.168.110.226:9002/goodsInfo/calculate',
  141. // method:'post',
  142. // data:{
  143. // "goodsId": goodsId,
  144. // // "shopId": shopId,
  145. // "userId": JSON.parse(uni.getStorageSync('userInfo')).userId
  146. // },
  147. // success() {
  148. // }
  149. // })
  150. calculate({
  151. // couponId: this.info.couponId,
  152. goodsId: goodsId,
  153. shopId: shopId,
  154. userId: JSON.parse(uni.getStorageSync("userInfo")).userId,
  155. }).then((res) => {
  156. if (res.state == "Success") {
  157. this.realPay = res.content;
  158. }
  159. });
  160. });
  161. },
  162. choose() {
  163. let that = this;
  164. uni.navigateTo({
  165. url: "./coupon?couponId=" + this.realPay.couponGoodsLogId,
  166. success: function (res) {
  167. // 通过eventChannel向被打开页面传送数据
  168. res.eventChannel.emit("pay", that.info);
  169. },
  170. });
  171. },
  172. chooseRemark() {
  173. let that = this;
  174. uni.navigateTo({
  175. url: "./remark",
  176. success: function (res) {
  177. // 通过eventChannel向被打开页面传送数据
  178. res.eventChannel.emit("remark", that.info);
  179. },
  180. });
  181. },
  182. toMap() {
  183. uni.openLocation({
  184. latitude: 26.4401,
  185. longitude: 106.664,
  186. name: "印象贵大文创店",
  187. address: "贵州大学西校区西一区体育场楼下",
  188. });
  189. },
  190. setRebackValue(value) {
  191. // console.log('value', value);
  192. this.info.extend.remark = value;
  193. this.$forceUpdate();
  194. },
  195. //创建订单
  196. creat() {
  197. if (this.loading) return;
  198. this.loading = true;
  199. uni.showLoading({
  200. title: "订单创建中",
  201. });
  202. let that = this;
  203. if (!this.payData.timeStamp) {
  204. // 处理扩展字段 暂时只有研学商品和视频会员 视频会员是字符串的JSON 研学是字符串
  205. let extend = {};
  206. if (!this.info.extend) {
  207. this.info.extend = JSON.stringify({ channel: "GZU" });
  208. }else{
  209. this.info.extend.channel = "GZU";
  210. }
  211. console.log("this.info.extend", this.info.extend);
  212. try {
  213. if(typeof this.info.extend == 'string'){
  214. extend = this.info.extend;
  215. }else{
  216. extend = JSON.stringify(this.info.extend);
  217. }
  218. } catch (e) {
  219. console.log("e", e);
  220. extend = this.info.reservationTime || "";
  221. }
  222. creat({
  223. discountId:
  224. this.payInfo.couponGoodsLogId || this.payInfo.couponGoodsLogId == -1
  225. ? [this.payInfo.couponGoodsLogId]
  226. : [],
  227. extend,
  228. channel:"GuiDa",
  229. goodsList: this.info.goodsId ? [this.info.goodsId] : [],
  230. idempotent: guid(),
  231. shopId: this.info.shopId,
  232. }).then((res) => {
  233. this.loading = false;
  234. if (res.state == "Success") {
  235. if (!this.payInfo.price) {
  236. //价格为0
  237. uni.hideLoading();
  238. uni.reLaunch({
  239. url: "/my/order/index",
  240. });
  241. } else {
  242. // 创建订单完成。
  243. this.query.orderNo = res.content.orderNo;
  244. this.query.subOpenId = JSON.parse(
  245. uni.getStorageSync("userInfo")
  246. ).openId;
  247. this.query.orderDesc = this.info.goodsName;
  248. creatPayOrder({
  249. ...this.query,
  250. subAppId: "wxbc64403830bb13c5",
  251. }).then((data) => {
  252. that.payData = JSON.parse(data.content.miniPayRequest);
  253. if (data.content.miniPayRequest == null)
  254. return uni.hideLoading();
  255. uni.redirectTo({
  256. url: "/my/order/detail?id=" + res.content.orderNo,
  257. success() {
  258. that.loading = false;
  259. uni.hideLoading();
  260. },
  261. });
  262. // uni.requestPayment({
  263. // "provider": "wxpay",
  264. // "orderInfo": that.payData,
  265. // "appid": "wxbc64403830bb13c5", // 微信开放平台 - 应用 - AppId,注意和微信小程序、公众号 AppId 可能不一致
  266. // "paySign": that.payData.paySign,
  267. // "nonceStr": that.payData.nonceStr, // 随机字符串
  268. // "package": that.payData.package, // 固定值
  269. // // "prepayid": that.payData.package, // 统一下单订单号
  270. // "timeStamp": that.payData.timeStamp, // 时间戳(单位:秒)
  271. // "signType": that.payData.signType, //签名算法
  272. // success(msg) {
  273. // console.log('msg', msg, res);
  274. // queryPayOrder(that.query.orderNo).then(res1 => {
  275. // if (res1.state == 'Success') {
  276. // uni.hideLoading()
  277. // uni.reLaunch({
  278. // url: '/my/order/index'
  279. // })
  280. // }
  281. // })
  282. // },
  283. // fail(e) {
  284. // console.log('err', e);
  285. // that.loading = false
  286. // uni.hideLoading()
  287. // uni.showToast({
  288. // title: '取消支付',
  289. // icon: 'fail'
  290. // })
  291. // // 取消支付后,获取支付信息以备再次支付
  292. // payDetails(that.query.orderNo).then(r => {
  293. // if (r.state == 'Success') {
  294. // that.payData = JSON.parse(r.content.miniPayRequest)
  295. // }
  296. // })
  297. // }
  298. // })
  299. });
  300. // 跳转到支付页面
  301. // /oreder/detail
  302. // uni.redirectTo({
  303. // url: "/my/order/detail?id=" + res.content.orderNo,
  304. // success() {
  305. // that.loading = false;
  306. // uni.hideLoading();
  307. // },
  308. // });
  309. }
  310. }
  311. });
  312. } else {
  313. // 取消支付后再次支付
  314. uni.requestPayment({
  315. provider: "wxpay",
  316. orderInfo: that.payData,
  317. appid: that.payData.appId, // 微信开放平台 - 应用 - AppId,注意和微信小程序、公众号 AppId 可能不一致
  318. paySign: that.payData.paySign,
  319. nonceStr: that.payData.nonceStr, // 随机字符串
  320. package: that.payData.package, // 固定值
  321. // "prepayid": that.payData.package, // 统一下单订单号
  322. timeStamp: that.payData.timeStamp, // 时间戳(单位:秒)
  323. signType: that.payData.signType, //签名算法
  324. success(msg) {
  325. console.log("msg", msg);
  326. queryPayOrder(that.query.orderNo).then((res1) => {
  327. if (res1.state == "Success") {
  328. uni.hideLoading();
  329. uni.reLaunch({
  330. url: "/my/order/index",
  331. });
  332. }
  333. });
  334. },
  335. fail(e) {
  336. that.loading = false;
  337. uni.hideLoading();
  338. uni.showToast({
  339. title: "取消支付",
  340. icon: "fail",
  341. });
  342. // 取消支付后,获取支付信息以备再次支付
  343. payDetails(that.query.orderNo).then((r) => {
  344. if (r.state == "Success") {
  345. that.payData = JSON.parse(r.content.miniPayRequest);
  346. }
  347. });
  348. console.log("err", e);
  349. },
  350. });
  351. }
  352. },
  353. },
  354. onReady() { },
  355. onLoad() {
  356. let userInfo = JSON.parse(uni.getStorageSync("userInfo"));
  357. this.query.userId = userInfo.userId;
  358. let that = this;
  359. const eventChannel = this.getOpenerEventChannel();
  360. eventChannel.on("pay", function (data) {
  361. that.info = data;
  362. try {
  363. // 初始化备注
  364. that.info.extend = {
  365. remark:''
  366. };
  367. let extend = JSON.parse(that.info.extend);
  368. if (extend.account) {
  369. that.isVisual = true;
  370. that.form.account = extend.account;
  371. }
  372. } catch (e) {
  373. //TODO handle the exception
  374. }
  375. console.log("data", data,that.info);
  376. that.calculate(that.info.goodsId, that.info.shopId);
  377. });
  378. },
  379. };
  380. </script>
  381. <style lang="scss">
  382. .pay {
  383. background: #f9f9f9;
  384. min-height: 100vh;
  385. padding-top: 20rpx;
  386. .shop-info {
  387. margin: 0 30rpx 20rpx;
  388. width: 690rpx;
  389. padding: 24rpx;
  390. box-sizing: border-box;
  391. background: #ffffff;
  392. border-radius: 16rpx 16rpx 16rpx 16rpx;
  393. .shop-name {
  394. color: #181818;
  395. font-size: 32rpx;
  396. }
  397. .address {
  398. color: #999999;
  399. font-size: 24rpx;
  400. margin-top: 12rpx;
  401. }
  402. }
  403. .pay-info {
  404. margin: 0 30rpx;
  405. background: #ffffff;
  406. border-radius: 16rpx 16rpx 16rpx 16rpx;
  407. padding: 28rpx 24rpx;
  408. .goods-info {
  409. display: flex;
  410. margin-bottom: 30rpx;
  411. .goods-img {
  412. width: 164rpx;
  413. height: 164rpx;
  414. border-radius: 16rpx;
  415. }
  416. .info {
  417. margin-left: 28rpx;
  418. flex: 1;
  419. .goods-name {
  420. font-weight: bold;
  421. color: #181818;
  422. font-size: 32rpx;
  423. width: 100%;
  424. word-break: break-all;
  425. text-overflow: ellipsis;
  426. overflow: hidden;
  427. display: -webkit-box;
  428. -webkit-box-orient: vertical;
  429. -webkit-line-clamp: 2;
  430. /* 这里是超出几行省略 */
  431. }
  432. .num {
  433. color: #999999;
  434. font-size: 24rpx;
  435. margin-top: 16rpx;
  436. }
  437. .price {
  438. font-weight: bold;
  439. color: #181818;
  440. font-size: 32rpx;
  441. margin-top: 26rpx;
  442. }
  443. }
  444. }
  445. .coupon {
  446. display: flex;
  447. align-items: center;
  448. justify-content: space-between;
  449. // border-bottom: 2rpx dashed #f3f3f3;
  450. padding: 28rpx 0;
  451. .label {
  452. color: #222222;
  453. font-size: 28rpx;
  454. }
  455. .choose-coupon.none {
  456. color: #aaaaaa;
  457. }
  458. .choose-coupon {
  459. color: #ff4848;
  460. font-size: 28rpx;
  461. display: flex;
  462. align-items: center;
  463. .icon {
  464. width: 28rpx;
  465. height: 28rpx;
  466. display: block;
  467. margin-left: 10rpx;
  468. }
  469. }
  470. }
  471. .explain {
  472. display: flex;
  473. align-items: center;
  474. justify-content: space-between;
  475. padding-top: 28rpx;
  476. .label {
  477. color: #aaaaaa;
  478. font-size: 28rpx;
  479. }
  480. .right {
  481. display: flex;
  482. align-items: center;
  483. font-size: 24rpx;
  484. .red {
  485. font-weight: 500;
  486. color: #ff4848;
  487. margin: 0 10rpx;
  488. }
  489. .fs28 {
  490. font-size: 28rpx !important;
  491. }
  492. }
  493. }
  494. }
  495. .input-box {
  496. margin: 20rpx 30rpx;
  497. padding: 28rpx 24rpx;
  498. background: #ffffff;
  499. border-radius: 16rpx 16rpx 16rpx 16rpx;
  500. display: flex;
  501. align-items: center;
  502. justify-content: space-between;
  503. .label {
  504. color: #222;
  505. font-size: 28rpx;
  506. }
  507. .value {
  508. font-size: 28rpx;
  509. color: #aaaaaa;
  510. }
  511. }
  512. .input-box-address {
  513. margin: 20rpx 30rpx;
  514. padding: 28rpx 24rpx;
  515. background: #ffffff;
  516. border-radius: 16rpx 16rpx 16rpx 16rpx;
  517. // display: flex;
  518. // align-items: center;
  519. // justify-content: space-between;
  520. .value {
  521. color: #222;
  522. font-size: 28rpx;
  523. }
  524. .label {
  525. font-size: 28rpx;
  526. margin: 10rpx 0;
  527. color: #aaaaaa;
  528. }
  529. }
  530. .btn-box {
  531. position: fixed;
  532. bottom: 0%;
  533. left: 0%;
  534. width: 100%;
  535. height: 98rpx;
  536. display: flex;
  537. align-items: center;
  538. justify-content: space-between;
  539. box-sizing: border-box;
  540. padding: 0 30rpx;
  541. border-top: 1rpx solid #eeeeee;
  542. .total-price {
  543. display: flex;
  544. align-items: center;
  545. .label {
  546. color: #181818;
  547. font-size: 28rpx;
  548. }
  549. .price {
  550. font-size: 36rpx;
  551. font-weight: 800;
  552. color: #ff4848;
  553. margin-left: 10rpx;
  554. }
  555. }
  556. .btn {
  557. width: 280rpx;
  558. height: 80rpx;
  559. line-height: 80rpx;
  560. text-align: center;
  561. background: $uni-color-primary;
  562. box-shadow: inset 0rpx 6rpx 12rpx 2rpx rgba(255, 255, 255, 0.16);
  563. border-radius: 46rpx 46rpx 46rpx 46rpx;
  564. font-weight: 800;
  565. color: #ffffff;
  566. font-size: 28rpx;
  567. margin: 0;
  568. }
  569. }
  570. }
  571. .label {
  572. color: #222222;
  573. font-size: 28rpx;
  574. }
  575. .choose-coupon {
  576. color: #aaaaaa;
  577. font-size: 28rpx;
  578. display: flex;
  579. align-items: center;
  580. .icon {
  581. width: 28rpx;
  582. height: 28rpx;
  583. display: block;
  584. margin-left: 10rpx;
  585. }
  586. }
  587. </style>