confirmorder.vue 5.9 KB

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