confirm_pay.vue 8.0 KB

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