confirm_pay.vue 8.1 KB

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