confirm_pay.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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. self.btnNo = false
  118. if(res.data.code==200){
  119. uni.setStorageSync('updateCart',1) //提醒刷新购物车
  120. let data = res.data.data
  121. uni.requestPayment({
  122. provider: data.provider,
  123. nonceStr: data.nonceStr,
  124. package: data.package,
  125. signType: data.signType,
  126. paySign: data.sign,
  127. timeStamp: String(data.timeStamp),
  128. success: function (res) {
  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. console.log('fail:' + JSON.stringify(err));
  136. }
  137. });
  138. }else{
  139. this.modalMsg = res.data.msg;
  140. this.showModal = true;
  141. }
  142. });
  143. },
  144. modalCancel() {
  145. this.showModal = false;
  146. },
  147. modalConfirm() {
  148. uni.switchTab({
  149. url:'/pages/shopping/shoppingCart'
  150. })
  151. },
  152. getOpenid(code){
  153. let self = this
  154. this.$api.wxOpenid({code:code}).then(res => {
  155. if(res.data.code==200){
  156. self.postOrder()
  157. }
  158. });
  159. },
  160. pay(){
  161. let self = this
  162. this.btnNo = true
  163. uni.login({
  164. provider: 'weixin',
  165. success: function(loginRes) {
  166. console.log(loginRes,69)
  167. self.getOpenid(loginRes.code)
  168. }
  169. });
  170. //
  171. },
  172. radioChange(e) {
  173. // console.log(e);
  174. },
  175. // 选中任一radio时,由radio-group触发
  176. radioGroupChange(e) {
  177. // console.log(e);
  178. },
  179. cMenu(index){
  180. this.menuIndex = index;
  181. },
  182. change(index){
  183. this.current = index;
  184. }
  185. },
  186. onReachBottom() {},
  187. computed: { ...mapGetters(['userInfo','shoppingCartList']) }
  188. };
  189. </script>
  190. <style >
  191. ::-webkit-scrollbar{
  192. width: 0;
  193. height: 0;
  194. color: transparent
  195. }
  196. page{
  197. background-color: #EAEEF1;
  198. }
  199. </style>
  200. <style scoped>
  201. .txt_left_pay{
  202. display: flex;
  203. align-items: center;
  204. height: 64rpx;
  205. font-size: 24rpx;
  206. color: #666666;
  207. }
  208. .pay_icon{
  209. width: 64rpx;
  210. height: 64rpx;
  211. margin-right: 10rpx;
  212. }
  213. .box3{
  214. width: 100%;
  215. background: #FFFFFF;
  216. border-radius: 16rpx;
  217. margin-top: 16rpx;
  218. }
  219. .tip{
  220. font-size: 24rpx;
  221. color: #999999;
  222. height: 40rpx;
  223. line-height: 40rpx;
  224. }
  225. .txt_right_sn{
  226. font-size: 30rpx;
  227. font-weight: bold;
  228. color: #666666;
  229. }
  230. .txt_right_price{
  231. font-size: 30rpx;
  232. font-weight: bold;
  233. color: #FF2D55;
  234. }
  235. .txt_left{
  236. font-size: 24rpx;
  237. color: #666666;
  238. }
  239. .txt_right{
  240. text-align: right;
  241. color: #333333;
  242. font-weight: bold;
  243. width: 75%;
  244. }
  245. .list_title {
  246. display: flex;
  247. justify-content: space-between;
  248. }
  249. .list_item{
  250. display: flex;
  251. justify-content: space-between;
  252. height: 80rpx;
  253. align-items: center;
  254. }
  255. .title2{
  256. font-size: 30rpx;
  257. font-weight: bold;
  258. color: #333333;
  259. height: 80rpx;
  260. line-height: 80rpx;
  261. margin-left: 30rpx;
  262. }
  263. .box2{
  264. width: 100%;
  265. background: #FFFFFF;
  266. border-radius: 16rpx;
  267. }
  268. .box1_t2{
  269. font-size: 24rpx;
  270. color: #999999;
  271. text-align: center;
  272. }
  273. .box1_t1{
  274. font-size: 30rpx;
  275. font-weight: bold;
  276. color: #333333;
  277. height: 70rpx;
  278. display: flex;
  279. align-items: center;
  280. justify-content: center;
  281. }
  282. .box1{
  283. width: 100%;
  284. height: 120rpx;
  285. background: #FFFFFF;
  286. border-radius: 16rpx;
  287. }
  288. .bottomBtn{
  289. position: fixed;
  290. bottom: 0;
  291. width: 100%;
  292. height: 98rpx;
  293. background: linear-gradient(0deg, #015EEA, #00C0FA);
  294. color: #FFFFFF;
  295. text-align: center;
  296. line-height: 98rpx;
  297. font-weight: bold;
  298. font-size: 30rpx;
  299. border-radius: 0;
  300. }
  301. </style>