confirm_pay.vue 8.7 KB

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