confirm_pay.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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="confirmText" 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. confirmText:''
  77. };
  78. },
  79. onPullDownRefresh(){
  80. },
  81. onLoad(option) {
  82. let self = this
  83. this.fromCart = option.fromCart;
  84. console.log(self.shoppingCartList,6)
  85. let list = self.shoppingCartList
  86. this.isBK = option.isBK
  87. for(let i=0;i<list.length;i++){
  88. this.totalPrice+=Number(list[i].standPrice)
  89. }
  90. console.log(this.isBK == '1')
  91. },
  92. onShow() {
  93. },
  94. methods: {
  95. postOrder(){
  96. let self = this
  97. let list = self.shoppingCartList
  98. for(let i=0;i<list.length;i++){
  99. let item = list[i];
  100. if(item.goodsType==1){
  101. if(item.templateType=='class'){
  102. delete item.gradObj.goodsList
  103. let goodsInputData = {
  104. type:'class',
  105. gradeId:item.gradObj.gradeId,
  106. gradeJson:JSON.stringify(item.gradObj)
  107. }
  108. item.goodsInputData = goodsInputData
  109. }
  110. if(item.templateType=='apply'){
  111. let goodsInputData = {
  112. type:'apply',
  113. applyAreasJson:JSON.stringify(item.applyAreas),
  114. examDateJson:JSON.stringify(item.examDate)
  115. }
  116. item.goodsInputData = goodsInputData
  117. }
  118. }
  119. }
  120. let data = {goodsList:list}
  121. this.$api.placeSmallOrder(data).then(res => {
  122. console.log(res,'res')
  123. if(res.data.code==200){
  124. uni.setStorageSync('updateCart',1) //提醒刷新购物车
  125. let data = res.data.data
  126. uni.showLoading({
  127. title:'支付中',
  128. mask:true,
  129. })
  130. uni.requestPayment({
  131. provider: data.provider,
  132. nonceStr: data.nonceStr,
  133. package: data.package,
  134. signType: data.signType,
  135. paySign: data.sign,
  136. timeStamp: String(data.timeStamp),
  137. success: function (res) {
  138. uni.hideLoading()
  139. self.btnNo = false
  140. uni.redirectTo({
  141. url: `/pages2/order/confirm_success?sn=${data.orderSn}&isBk=${self.isBK}`
  142. });
  143. console.log('success:' + JSON.stringify(res));
  144. },
  145. fail: function (err) {
  146. uni.hideLoading()
  147. self.btnNo = false
  148. console.log('fail:' + JSON.stringify(err));
  149. }
  150. });
  151. }else if(res.data.code == 510){ //有未支付订单
  152. self.hasPaying = true;
  153. self.btnNo = false
  154. this.modalMsg = res.data.msg;
  155. this.showConfirmButton = true;
  156. this.confirmText = "跳转到【我的订单】\n查看未支付订单";
  157. this.showModal = true;
  158. } else if(res.data.code == 511) { //511 重复购买
  159. self.hasPaying = false;
  160. self.btnNo = false
  161. this.modalMsg = res.data.msg;
  162. this.showConfirmButton = true;
  163. this.showModal = true;
  164. if(this.fromCart) {
  165. console.log(this.fromCart)
  166. this.confirmText = "返回购物车";
  167. } else {
  168. this.confirmText = "继续选课";
  169. }
  170. } else {
  171. self.hasPaying = false;
  172. self.btnNo = false
  173. this.showConfirmButton = false;
  174. this.modalMsg = res.data.msg;
  175. this.showModal = true;
  176. }
  177. });
  178. },
  179. modalCancel() {
  180. this.showModal = false;
  181. },
  182. modalConfirm() {
  183. if(this.hasPaying) {
  184. uni.navigateTo({
  185. url:'/pages2/order/index?current=0'
  186. })
  187. } else {
  188. if(this.fromCart) {
  189. uni.switchTab({
  190. url:'/pages/shopping/shoppingCart'
  191. })
  192. } else {
  193. uni.switchTab({
  194. url:'/pages/course/index'
  195. })
  196. }
  197. }
  198. },
  199. getOpenid(code){
  200. let self = this
  201. this.$api.wxOpenid({code:code}).then(res => {
  202. if(res.data.code==200){
  203. self.postOrder()
  204. }
  205. });
  206. },
  207. pay(){
  208. let self = this
  209. this.btnNo = true
  210. uni.login({
  211. provider: 'weixin',
  212. success: function(loginRes) {
  213. console.log(loginRes,69)
  214. self.getOpenid(loginRes.code)
  215. }
  216. });
  217. //
  218. },
  219. radioChange(e) {
  220. // console.log(e);
  221. },
  222. // 选中任一radio时,由radio-group触发
  223. radioGroupChange(e) {
  224. // console.log(e);
  225. },
  226. cMenu(index){
  227. this.menuIndex = index;
  228. },
  229. change(index){
  230. this.current = index;
  231. }
  232. },
  233. onReachBottom() {},
  234. computed: { ...mapGetters(['userInfo','shoppingCartList']) }
  235. };
  236. </script>
  237. <style >
  238. ::-webkit-scrollbar{
  239. width: 0;
  240. height: 0;
  241. color: transparent
  242. }
  243. page{
  244. background-color: #EAEEF1;
  245. }
  246. </style>
  247. <style scoped>
  248. .txt_left_pay{
  249. display: flex;
  250. align-items: center;
  251. height: 64rpx;
  252. font-size: 24rpx;
  253. color: #666666;
  254. }
  255. .pay_icon{
  256. width: 64rpx;
  257. height: 64rpx;
  258. margin-right: 10rpx;
  259. }
  260. .box3{
  261. width: 100%;
  262. background: #FFFFFF;
  263. border-radius: 16rpx;
  264. margin-top: 16rpx;
  265. }
  266. .tip{
  267. font-size: 24rpx;
  268. color: #999999;
  269. height: 40rpx;
  270. line-height: 40rpx;
  271. }
  272. .txt_right_sn{
  273. font-size: 30rpx;
  274. font-weight: bold;
  275. color: #666666;
  276. }
  277. .txt_right_price{
  278. font-size: 30rpx;
  279. font-weight: bold;
  280. color: #FF2D55;
  281. }
  282. .txt_left{
  283. font-size: 24rpx;
  284. color: #666666;
  285. }
  286. .txt_right{
  287. text-align: right;
  288. color: #333333;
  289. font-weight: bold;
  290. width: 75%;
  291. }
  292. .list_title {
  293. display: flex;
  294. justify-content: space-between;
  295. }
  296. .list_item{
  297. display: flex;
  298. justify-content: space-between;
  299. height: 80rpx;
  300. align-items: center;
  301. }
  302. .title2{
  303. font-size: 30rpx;
  304. font-weight: bold;
  305. color: #333333;
  306. height: 80rpx;
  307. line-height: 80rpx;
  308. margin-left: 30rpx;
  309. }
  310. .box2{
  311. width: 100%;
  312. background: #FFFFFF;
  313. border-radius: 16rpx;
  314. }
  315. .box1_t2{
  316. font-size: 24rpx;
  317. color: #999999;
  318. text-align: center;
  319. }
  320. .box1_t1{
  321. font-size: 30rpx;
  322. font-weight: bold;
  323. color: #333333;
  324. height: 70rpx;
  325. display: flex;
  326. align-items: center;
  327. justify-content: center;
  328. }
  329. .box1{
  330. width: 100%;
  331. height: 120rpx;
  332. background: #FFFFFF;
  333. border-radius: 16rpx;
  334. }
  335. .bottomBtn{
  336. position: fixed;
  337. bottom: 0;
  338. width: 100%;
  339. height: 98rpx;
  340. background: linear-gradient(0deg, #015EEA, #00C0FA);
  341. color: #FFFFFF;
  342. text-align: center;
  343. line-height: 98rpx;
  344. font-weight: bold;
  345. font-size: 30rpx;
  346. border-radius: 0;
  347. }
  348. </style>