confirm_pay.vue 7.6 KB

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