confirmorder.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <template>
  2. <view class="pages">
  3. <view class="content-wrap">
  4. <view class="select-bar" @click="getAddrs">
  5. <svg class="icon select-bar-icon" aria-hidden="true">
  6. <use xlink:href="#icondizhi1"></use>
  7. </svg>
  8. <!-- <view class="select-bar-text">请选择收货信息</view> -->
  9. <view class="select-bar-text">
  10. <picker mode="selector" @change="bindPickerChange" :value="index" :range="addrsList" :range-key="'detailAddress'">
  11. <view class="uni-input">{{theAddr}}</view>
  12. </picker>
  13. </view>
  14. <view class="select-bar-arrow"></view>
  15. </view>
  16. <view class="bill-info">
  17. <view class="bill-product">
  18. <view class="bill-product-imgwrap">
  19. <image :src="billData.productImg" class="bill-product-img" mode="aspectFill"></image>
  20. </view>
  21. <view class="bill-product-info">
  22. <view class="bill-product-name">{{billData.productName}}</view>
  23. <view class="bill-product-price-wrap">
  24. <view class="left">
  25. ¥
  26. <text class="bill-product-price">{{billData.productPrice}}</text>
  27. <text class="bill-product-unit" v-if="billData.productUnit">/{{billData.productUnit}}</text>
  28. </view>
  29. <view class="bill-product-number">
  30. X {{billData.bayNum}}
  31. </view>
  32. </view>
  33. </view>
  34. </view>
  35. <!-- bill-product end -->
  36. <view class="form-item">
  37. <view class="form-item-til">商品总额</view>
  38. <view class="form-item-con amount">
  39. ¥ {{ billData.productPrice*billData.bayNum }}
  40. </view>
  41. </view>
  42. <view class="form-item">
  43. <view class="form-item-til">配送方式</view>
  44. <view class="form-item-con">
  45. 普通快递
  46. </view>
  47. </view>
  48. <view class="form-item">
  49. <view class="form-item-til">运费</view>
  50. <view class="form-item-con">
  51. ¥ 0
  52. </view>
  53. </view>
  54. </view>
  55. <!-- bill-info end -->
  56. <view class="bottom-btn-wrap">
  57. <view class="bottom-btn" @click="submit">确认购买</view>
  58. </view>
  59. </view>
  60. <!-- content-wrap end -->
  61. </view>
  62. </template>
  63. <script>
  64. import {bus} from "../../utils/bus.js";
  65. export default {
  66. data() {
  67. return {
  68. token:'',
  69. params:{},
  70. billData:null,
  71. addrsList:[],
  72. index:0,
  73. theAddr:'请选择收货地址',
  74. memberReceiveAddressId:'',
  75. }
  76. },
  77. onShow() {
  78. },
  79. onLoad() {
  80. let self = this;
  81. if(Object.keys(bus.data).length>0){
  82. this.billData = bus.data;
  83. // console.log('bus.data',bus.data);
  84. };
  85. uni.getStorage({
  86. key:'token',
  87. success: function (res) {
  88. self.token = res.data;
  89. // console.log(self.token);
  90. }
  91. });
  92. this.getAddrs();
  93. },
  94. methods: {
  95. submit(){
  96. let param = {productId:this.billData.productId,bayNum:this.billData.bayNum,memberReceiveAddressId:this.memberReceiveAddressId};
  97. this.$api.http.post(this.config.apiBaseurl + '/order/insert',param,{
  98. header: {
  99. Accept:'application/json',
  100. Authorization: 'Bearer '+ this.token, //注意Bearer后面有一空格
  101. },
  102. }).then(res => {
  103. // console.log('res',res);
  104. if(res.data.code == 200 ){
  105. this.pay(res.data.data.order.id,res.data.data.order.payType)
  106. }else{
  107. uni.showToast({
  108. icon:"none",
  109. title:res.data.message,
  110. duration: 2000
  111. });
  112. }
  113. }).catch(err =>{
  114. console.log('err',err)
  115. });
  116. // console.log('param',param);
  117. },
  118. async pay(orderId,payType){
  119. let userInfo = uni.getStorageSync("userInfo");
  120. let params = {
  121. orderId:orderId,
  122. payType:payType,
  123. openid:userInfo.wxUsers.openid,
  124. "tradeType":"test"
  125. }
  126. this.$pay.wxPay(params).then(res =>{
  127. console.log('payres',res);
  128. if(res.code == 0){
  129. uni.reLaunch({
  130. url: '/pages/usercenter/myorder/myorder'
  131. })
  132. }else if(res.code == 1){
  133. uni.navigateTo({
  134. url: '/pages/usercenter/myorder/myorder'
  135. })
  136. }else if(res.code == 2){
  137. this.$api.msg("支付失败,请检查!")
  138. setTimeout(()=>{
  139. uni.navigateTo({
  140. url: '/pages/usercenter/myorder/myorder',
  141. fail:function(err){
  142. console.log(err)
  143. }
  144. });
  145. },1000)
  146. }else{
  147. uni.showToast({
  148. icon:"none",
  149. title:res.data.message,
  150. duration: 2000
  151. });
  152. }
  153. });
  154. // let param = {orderId:orderId,payType:payType};
  155. // this.$api.http.post(this.config.apiBaseurl + '/order/paySuccess',param,{
  156. // header: {
  157. // Accept:'application/json',
  158. // Authorization: 'Bearer '+ this.token, //注意Bearer后面有一空格
  159. // },
  160. // }).then(res => {
  161. // console.log('res',res);
  162. // if(res.data.code == 200 ){
  163. // }
  164. // }).catch(err =>{
  165. // console.log('err',err)
  166. // });
  167. },
  168. getAddrs(){
  169. // console.log('this.token',this.token);
  170. let thetoken = 'Bearer ' + this.token;
  171. this.$api.http.get(this.config.apiBaseurl + '/member/address/list',{header: {Authorization:thetoken}}).then(res => {
  172. // console.log('getAddrList', res.data.data);
  173. this.addrsList = res.data.data;
  174. if(res.data.data.length>0){
  175. this.memberReceiveAddressId = res.data.data[0].id;
  176. this.theAddr = res.data.data[0].detailAddress;
  177. // console.log('this.memberReceiveAddressId',this.memberReceiveAddressId);
  178. }else{
  179. this.theAddr = '您还没有设置收货地址,请到个人中心页面设置!';
  180. }
  181. }).catch(err => {
  182. // console.log('err', err)
  183. })
  184. },
  185. bindPickerChange(e){
  186. console.log(this.addrsList[e.target.value]);
  187. this.memberReceiveAddressId = this.addrsList[e.target.value].id;
  188. this.theAddr = this.addrsList[e.target.value].detailAddress;
  189. // console.log('this.memberReceiveAddressId',this.memberReceiveAddressId);
  190. }
  191. }
  192. }
  193. </script>
  194. <style scoped>
  195. @import url("./confirmorder.css");
  196. </style>