confirm_pay.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. <template>
  2. <view>
  3. <nav-bar title="订单支付"></nav-bar>
  4. <view>
  5. <view style="padding: 8rpx">
  6. <view class="box2">
  7. <view class="title2">支付信息</view>
  8. <u-line color="#D6D6DB" />
  9. <view
  10. style="padding: 10rpx 30rpx"
  11. v-for="(item, index) in shoppingCartList"
  12. :key="index"
  13. >
  14. <view class="list_title">
  15. <view class="txt_left">商品名称</view>
  16. <view class="txt_right">{{ item.goodsName }}</view>
  17. </view>
  18. <view class="list_item">
  19. <view class="txt_left">应付金额</view>
  20. <view class="txt_right_price">¥ {{ item.standPrice }}</view>
  21. </view>
  22. </view>
  23. <view style="padding: 10rpx 30rpx">
  24. <u-line color="#D6D6DB" />
  25. <view class="list_item">
  26. <view class="txt_left">应付总金额</view>
  27. <view class="txt_right_price">¥ {{ totalPrice }}</view>
  28. </view>
  29. </view>
  30. </view>
  31. <view class="box3">
  32. <view class="title2">支付方式</view>
  33. <u-line color="#D6D6DB" />
  34. <view style="padding: 20rpx 30rpx">
  35. <u-radio-group v-model="value" @change="radioGroupChange">
  36. <view class="list_item">
  37. <view class="txt_left_pay"
  38. ><image src="/static/wepay.png" class="pay_icon"></image
  39. >微信支付</view
  40. >
  41. <view
  42. ><u-radio @change="radioChange" name="wepay"></u-radio
  43. ></view>
  44. </view>
  45. <view class="list_item" v-if="false">
  46. <view class="txt_left_pay"
  47. ><image src="/static/unipay.png" class="pay_icon"></image
  48. >云闪付</view
  49. >
  50. <view
  51. ><u-radio @change="radioChange" name="unipay"></u-radio
  52. ></view>
  53. </view>
  54. </u-radio-group>
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. <button class="bottomBtn" @click="pay()" :disabled="btnNo">确认支付</button>
  60. <u-modal
  61. v-model="showModal"
  62. :confirm-text="confirmText"
  63. cancel-text="知道了"
  64. cancel-color="#666666"
  65. confirm-color="rgba(0, 122, 255, 1);"
  66. :show-confirm-button="showConfirmButton"
  67. :show-cancel-button="true"
  68. :content="modalMsg"
  69. @cancel="modalCancel()"
  70. @confirm="modalConfirm()"
  71. ref="uModal"
  72. ></u-modal>
  73. </view>
  74. </template>
  75. <script>
  76. import { mapGetters } from "vuex";
  77. export default {
  78. components: {},
  79. data() {
  80. return {
  81. showModal: false,
  82. modalMsg: "",
  83. list: [
  84. {
  85. name: "网课",
  86. },
  87. {
  88. name: "题库通",
  89. },
  90. ],
  91. array: [
  92. "全部",
  93. "建设工程施工管理",
  94. "机电全科",
  95. "机电工程管理与实",
  96. "机电全科",
  97. "全科",
  98. ],
  99. current: 0,
  100. menuIndex: 0,
  101. value: "wepay",
  102. btnNo: false,
  103. isBK: "",
  104. fromCart: "",
  105. hasPaying: false,
  106. showConfirmButton: false,
  107. totalPrice: 0,
  108. confirmText: "",
  109. };
  110. },
  111. onPullDownRefresh() {},
  112. onLoad(option) {
  113. let self = this;
  114. this.fromCart = option.fromCart;
  115. console.log(self.shoppingCartList, 6);
  116. let list = self.shoppingCartList;
  117. this.isBK = option.isBK;
  118. for (let i = 0; i < list.length; i++) {
  119. this.totalPrice += Number(list[i].standPrice);
  120. }
  121. console.log(this.isBK == "1");
  122. },
  123. onShow() {},
  124. methods: {
  125. postOrder() {
  126. let self = this;
  127. let list = self.shoppingCartList;
  128. for (let i = 0; i < list.length; i++) {
  129. let item = list[i];
  130. if (item.goodsType == 1) {
  131. if (item.templateType == "class") {
  132. delete item.gradObj.goodsList;
  133. let goodsInputData = {
  134. type: "class",
  135. gradeId: item.gradObj.gradeId,
  136. gradeJson: JSON.stringify(item.gradObj),
  137. };
  138. item.goodsInputData = goodsInputData;
  139. }
  140. if (item.templateType == "apply") {
  141. let goodsInputData = {
  142. type: "apply",
  143. applyAreasJson: JSON.stringify(item.applyAreas),
  144. examDateJson: JSON.stringify(item.examDate),
  145. };
  146. item.goodsInputData = goodsInputData;
  147. }
  148. }
  149. }
  150. let data = { goodsList: list };
  151. this.$api.placeSmallOrder(data).then((res) => {
  152. console.log(res, "res");
  153. if (res.data.code == 200) {
  154. uni.setStorageSync("updateCart", 1); //提醒刷新购物车
  155. if (this.totalPrice == 0) {
  156. //免费商品
  157. uni.redirectTo({
  158. url: `/pages2/order/confirm_success?sn=${res.data.orderSn}&isBk=${self.isBK}`,
  159. });
  160. } else {
  161. let data = res.data.data;
  162. uni.showLoading({
  163. title: "支付中",
  164. mask: true,
  165. });
  166. uni.requestPayment({
  167. provider: data.provider,
  168. nonceStr: data.nonceStr,
  169. package: data.package,
  170. signType: data.signType,
  171. paySign: data.sign,
  172. timeStamp: String(data.timeStamp),
  173. success: function (res) {
  174. uni.hideLoading();
  175. self.btnNo = false;
  176. uni.redirectTo({
  177. url: `/pages2/order/confirm_success?sn=${data.orderSn}&isBk=${self.isBK}`,
  178. });
  179. console.log("success:" + JSON.stringify(res));
  180. },
  181. fail: function (err) {
  182. uni.hideLoading();
  183. self.btnNo = false;
  184. console.log("fail:" + JSON.stringify(err));
  185. },
  186. });
  187. }
  188. } else if (res.data.code == 510) {
  189. //有未支付订单
  190. self.hasPaying = true;
  191. self.btnNo = false;
  192. this.modalMsg = res.data.msg;
  193. this.showConfirmButton = true;
  194. this.confirmText = "跳转到【我的订单】\n查看未支付订单";
  195. this.showModal = true;
  196. } else if (res.data.code == 511) {
  197. //511 重复购买
  198. self.hasPaying = false;
  199. self.btnNo = false;
  200. this.modalMsg = res.data.msg;
  201. this.showConfirmButton = true;
  202. this.showModal = true;
  203. if (this.fromCart) {
  204. console.log(this.fromCart);
  205. this.confirmText = "返回购物车";
  206. } else {
  207. let type = "";
  208. if (this.shoppingCartList.length == 1) {
  209. type = this.shoppingCartList[0].goodsType;
  210. } else {
  211. type = this.shoppingCartList[0].goodsType;
  212. if (
  213. this.shoppingCartList.find((item) => item.goodsType != type)
  214. ) {
  215. type = 3;
  216. }
  217. }
  218. this.confirmText =
  219. type == 1 || type == 6
  220. ? "继续选课"
  221. : type == 2
  222. ? "继续选题"
  223. : type == 3
  224. ? "继续选购"
  225. : "";
  226. }
  227. } else {
  228. self.hasPaying = false;
  229. self.btnNo = false;
  230. this.showConfirmButton = false;
  231. this.modalMsg = res.data.msg;
  232. this.showModal = true;
  233. }
  234. });
  235. },
  236. modalCancel() {
  237. this.showModal = false;
  238. },
  239. modalConfirm() {
  240. if (this.hasPaying) {
  241. uni.navigateTo({
  242. url: "/pages2/order/index?current=0",
  243. });
  244. } else {
  245. if (this.fromCart) {
  246. uni.switchTab({
  247. url: "/pages/shopping/shoppingCart",
  248. });
  249. } else {
  250. uni.switchTab({
  251. url: "/pages/course/index",
  252. });
  253. }
  254. }
  255. },
  256. getOpenid(code) {
  257. let self = this;
  258. this.$api.wxOpenid({ code: code }).then((res) => {
  259. if (res.data.code == 200) {
  260. self.postOrder();
  261. }
  262. });
  263. },
  264. pay() {
  265. let self = this;
  266. this.btnNo = true;
  267. uni.login({
  268. provider: "weixin",
  269. success: function (loginRes) {
  270. console.log(loginRes, 69);
  271. self.getOpenid(loginRes.code);
  272. },
  273. });
  274. //
  275. },
  276. radioChange(e) {
  277. // console.log(e);
  278. },
  279. // 选中任一radio时,由radio-group触发
  280. radioGroupChange(e) {
  281. // console.log(e);
  282. },
  283. cMenu(index) {
  284. this.menuIndex = index;
  285. },
  286. change(index) {
  287. this.current = index;
  288. },
  289. },
  290. onReachBottom() {},
  291. computed: { ...mapGetters(["userInfo", "shoppingCartList"]) },
  292. };
  293. </script>
  294. <style >
  295. ::-webkit-scrollbar {
  296. width: 0;
  297. height: 0;
  298. color: transparent;
  299. }
  300. page {
  301. background-color: #eaeef1;
  302. }
  303. </style>
  304. <style scoped>
  305. .txt_left_pay {
  306. display: flex;
  307. align-items: center;
  308. height: 64rpx;
  309. font-size: 24rpx;
  310. color: #666666;
  311. }
  312. .pay_icon {
  313. width: 64rpx;
  314. height: 64rpx;
  315. margin-right: 10rpx;
  316. }
  317. .box3 {
  318. width: 100%;
  319. background: #ffffff;
  320. border-radius: 16rpx;
  321. margin-top: 16rpx;
  322. }
  323. .tip {
  324. font-size: 24rpx;
  325. color: #999999;
  326. height: 40rpx;
  327. line-height: 40rpx;
  328. }
  329. .txt_right_sn {
  330. font-size: 30rpx;
  331. font-weight: bold;
  332. color: #666666;
  333. }
  334. .txt_right_price {
  335. font-size: 30rpx;
  336. font-weight: bold;
  337. color: #ff2d55;
  338. }
  339. .txt_left {
  340. font-size: 24rpx;
  341. color: #666666;
  342. }
  343. .txt_right {
  344. text-align: right;
  345. color: #333333;
  346. font-weight: bold;
  347. width: 75%;
  348. }
  349. .list_title {
  350. display: flex;
  351. justify-content: space-between;
  352. }
  353. .list_item {
  354. display: flex;
  355. justify-content: space-between;
  356. height: 80rpx;
  357. align-items: center;
  358. }
  359. .title2 {
  360. font-size: 30rpx;
  361. font-weight: bold;
  362. color: #333333;
  363. height: 80rpx;
  364. line-height: 80rpx;
  365. margin-left: 30rpx;
  366. }
  367. .box2 {
  368. width: 100%;
  369. background: #ffffff;
  370. border-radius: 16rpx;
  371. }
  372. .box1_t2 {
  373. font-size: 24rpx;
  374. color: #999999;
  375. text-align: center;
  376. }
  377. .box1_t1 {
  378. font-size: 30rpx;
  379. font-weight: bold;
  380. color: #333333;
  381. height: 70rpx;
  382. display: flex;
  383. align-items: center;
  384. justify-content: center;
  385. }
  386. .box1 {
  387. width: 100%;
  388. height: 120rpx;
  389. background: #ffffff;
  390. border-radius: 16rpx;
  391. }
  392. .bottomBtn {
  393. position: fixed;
  394. bottom: 0;
  395. width: 100%;
  396. height: 98rpx;
  397. background: linear-gradient(0deg, #015eea, #00c0fa);
  398. color: #ffffff;
  399. text-align: center;
  400. line-height: 98rpx;
  401. font-weight: bold;
  402. font-size: 30rpx;
  403. border-radius: 0;
  404. }
  405. </style>