pay.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  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" style="word-break: keep-all; margin-right: 20rpx;" > 备注 </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.shopInfo.shopName }}
  62. <!-- 印象贵大文创店 -->
  63. </view>
  64. <view class="label">{{ info.shopInfo.address }}</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: +this.info.shopInfo.mapLat,
  185. longitude: +this.info.shopInfo.mapLon,
  186. name: this.info.shopInfo.shopName,
  187. address: this.info.shopInfo.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. console.log(data)
  362. that.info = data;
  363. try {
  364. // 初始化备注
  365. that.info.extend = {
  366. remark:''
  367. };
  368. let extend = JSON.parse(that.info.extend);
  369. if (extend.account) {
  370. that.isVisual = true;
  371. that.form.account = extend.account;
  372. }
  373. } catch (e) {
  374. //TODO handle the exception
  375. }
  376. console.log("data", data,that.info);
  377. that.calculate(that.info.goodsId, that.info.shopId);
  378. });
  379. },
  380. };
  381. </script>
  382. <style lang="scss">
  383. .pay {
  384. background: #f9f9f9;
  385. min-height: 100vh;
  386. padding-top: 20rpx;
  387. .shop-info {
  388. margin: 0 30rpx 20rpx;
  389. width: 690rpx;
  390. padding: 24rpx;
  391. box-sizing: border-box;
  392. background: #ffffff;
  393. border-radius: 16rpx 16rpx 16rpx 16rpx;
  394. .shop-name {
  395. color: #181818;
  396. font-size: 32rpx;
  397. }
  398. .address {
  399. color: #999999;
  400. font-size: 24rpx;
  401. margin-top: 12rpx;
  402. }
  403. }
  404. .pay-info {
  405. margin: 0 30rpx;
  406. background: #ffffff;
  407. border-radius: 16rpx 16rpx 16rpx 16rpx;
  408. padding: 28rpx 24rpx;
  409. .goods-info {
  410. display: flex;
  411. margin-bottom: 30rpx;
  412. .goods-img {
  413. width: 164rpx;
  414. height: 164rpx;
  415. border-radius: 16rpx;
  416. }
  417. .info {
  418. margin-left: 28rpx;
  419. flex: 1;
  420. .goods-name {
  421. font-weight: bold;
  422. color: #181818;
  423. font-size: 32rpx;
  424. width: 100%;
  425. word-break: break-all;
  426. text-overflow: ellipsis;
  427. overflow: hidden;
  428. display: -webkit-box;
  429. -webkit-box-orient: vertical;
  430. -webkit-line-clamp: 2;
  431. /* 这里是超出几行省略 */
  432. }
  433. .num {
  434. color: #999999;
  435. font-size: 24rpx;
  436. margin-top: 16rpx;
  437. }
  438. .price {
  439. font-weight: bold;
  440. color: #181818;
  441. font-size: 32rpx;
  442. margin-top: 26rpx;
  443. }
  444. }
  445. }
  446. .coupon {
  447. display: flex;
  448. align-items: center;
  449. justify-content: space-between;
  450. // border-bottom: 2rpx dashed #f3f3f3;
  451. padding: 28rpx 0;
  452. .label {
  453. color: #222222;
  454. font-size: 28rpx;
  455. }
  456. .choose-coupon.none {
  457. color: #aaaaaa;
  458. }
  459. .choose-coupon {
  460. color: #ff4848;
  461. font-size: 28rpx;
  462. display: flex;
  463. align-items: center;
  464. word-break: break-word;
  465. .icon {
  466. width: 28rpx;
  467. height: 28rpx;
  468. display: block;
  469. margin-left: 10rpx;
  470. }
  471. }
  472. }
  473. .explain {
  474. display: flex;
  475. align-items: center;
  476. justify-content: space-between;
  477. padding-top: 28rpx;
  478. .label {
  479. color: #aaaaaa;
  480. font-size: 28rpx;
  481. }
  482. .right {
  483. display: flex;
  484. align-items: center;
  485. font-size: 24rpx;
  486. .red {
  487. font-weight: 500;
  488. color: #ff4848;
  489. margin: 0 10rpx;
  490. }
  491. .fs28 {
  492. font-size: 28rpx !important;
  493. }
  494. }
  495. }
  496. }
  497. .input-box {
  498. margin: 20rpx 30rpx;
  499. padding: 28rpx 24rpx;
  500. background: #ffffff;
  501. border-radius: 16rpx 16rpx 16rpx 16rpx;
  502. display: flex;
  503. align-items: center;
  504. justify-content: space-between;
  505. .label {
  506. color: #222;
  507. font-size: 28rpx;
  508. }
  509. .value {
  510. font-size: 28rpx;
  511. color: #aaaaaa;
  512. }
  513. }
  514. .input-box-address {
  515. margin: 20rpx 30rpx;
  516. padding: 28rpx 24rpx;
  517. background: #ffffff;
  518. border-radius: 16rpx 16rpx 16rpx 16rpx;
  519. // display: flex;
  520. // align-items: center;
  521. // justify-content: space-between;
  522. .value {
  523. color: #222;
  524. font-size: 28rpx;
  525. }
  526. .label {
  527. font-size: 28rpx;
  528. margin: 10rpx 0;
  529. color: #aaaaaa;
  530. }
  531. }
  532. .btn-box {
  533. position: fixed;
  534. bottom: 0%;
  535. left: 0%;
  536. width: 100%;
  537. height: 98rpx;
  538. display: flex;
  539. align-items: center;
  540. justify-content: space-between;
  541. box-sizing: border-box;
  542. padding: 0 30rpx;
  543. border-top: 1rpx solid #eeeeee;
  544. .total-price {
  545. display: flex;
  546. align-items: center;
  547. .label {
  548. color: #181818;
  549. font-size: 28rpx;
  550. }
  551. .price {
  552. font-size: 36rpx;
  553. font-weight: 800;
  554. color: #ff4848;
  555. margin-left: 10rpx;
  556. }
  557. }
  558. .btn {
  559. width: 280rpx;
  560. height: 80rpx;
  561. line-height: 80rpx;
  562. text-align: center;
  563. background: $uni-color-primary;
  564. box-shadow: inset 0rpx 6rpx 12rpx 2rpx rgba(255, 255, 255, 0.16);
  565. border-radius: 46rpx 46rpx 46rpx 46rpx;
  566. font-weight: 800;
  567. color: #ffffff;
  568. font-size: 28rpx;
  569. margin: 0;
  570. }
  571. }
  572. }
  573. .label {
  574. color: #222222;
  575. font-size: 28rpx;
  576. }
  577. .choose-coupon {
  578. color: #aaaaaa;
  579. font-size: 28rpx;
  580. display: flex;
  581. align-items: center;
  582. word-break: break-word;
  583. .icon {
  584. width: 28rpx;
  585. height: 28rpx;
  586. display: block;
  587. margin-left: 10rpx;
  588. }
  589. }
  590. </style>