confirm_pay.vue 6.9 KB

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