index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <template>
  2. <view>
  3. <u-navbar :is-back="false" title=" " :border-bottom="false">
  4. <view class="u-flex u-row-right" style="width: 100%;">
  5. <view class="camera u-flex u-row-center">
  6. <u-icon name="camera-fill" color="#000000" size="48"></u-icon>
  7. </view>
  8. </view>
  9. </u-navbar>
  10. <view class="u-flex user-box u-p-l-30 u-p-r-20 u-p-b-30">
  11. <view class="u-m-r-10" @click="login($store.state.vuex_hasLogin)">
  12. <u-avatar :src="userInfo.imgUrl||pic" size="140"></u-avatar>
  13. </view>
  14. <view class="u-flex-1" @click="login($store.state.vuex_hasLogin)">
  15. <view class="u-font-18 u-p-b-20">{{ userInfo.nickname || '请登录' }}</view>
  16. <view class="u-font-14 u-tips-color">手机号:{{ userInfo.tel || '暂无' }}</view>
  17. </view>
  18. <view class="u-m-l-10 u-p-10">
  19. <u-icon name="scan" color="#969799" size="28"></u-icon>
  20. </view>
  21. <view class="u-m-l-10 u-p-10">
  22. <u-icon name="arrow-right" color="#969799" size="28"></u-icon>
  23. </view>
  24. </view>
  25. <view class="u-m-t-20">
  26. <u-cell-group>
  27. <u-cell-item icon="rmb-circle" title="支付" @click="submitOrder()"></u-cell-item>
  28. <u-cell-item icon="rmb-circle" title="退款" @click="refund('20210311150306120323584')"></u-cell-item>
  29. </u-cell-group>
  30. </view>
  31. <view class="u-m-t-20">
  32. <u-cell-group>
  33. <u-cell-item icon="star" title="收藏"></u-cell-item>
  34. <u-cell-item icon="photo" title="相册"></u-cell-item>
  35. <u-cell-item icon="coupon" title="卡券"></u-cell-item>
  36. <u-cell-item icon="heart" title="关注"></u-cell-item>
  37. </u-cell-group>
  38. </view>
  39. <view class="u-m-t-20">
  40. <u-cell-group>
  41. <!-- <u-cell-item icon="setting" title="设置"></u-cell-item> -->
  42. <u-cell-item icon="setting" :title="vuex_user.tel?'更换手机号':'绑定手机号'" @click="openPage('/pages/template/bindPhoneNumber/bindPhoneNumber')"></u-cell-item>
  43. <u-cell-item icon="lock-opened-fill" title="退出" v-if="vuex_hasLogin" @click="logout"></u-cell-item>
  44. </u-cell-group>
  45. </view>
  46. <u-toast ref="uToast" />
  47. </view>
  48. </template>
  49. <script>
  50. export default {
  51. data() {
  52. return {
  53. pic:'https://uviewui.com/common/logo.png',
  54. show:true,
  55. userInfo:[],
  56. requested:true,
  57. }
  58. },
  59. onLoad() {
  60. if(this.$store.state.vuex_hasLogin){
  61. this.userInfo = this.$store.state.vuex_user;
  62. }else{
  63. this.userInfo = [];
  64. }
  65. },
  66. methods: {
  67. openPage(path) {
  68. console.log('path',path);
  69. this.$u.route({
  70. url: path
  71. })
  72. },
  73. showToast() {
  74. this.$refs.uToast.show({
  75. title: this.message || "请设置提示语",
  76. type: this.messageType||"success",
  77. icon:false,
  78. // url: '/pages/user/index'
  79. })
  80. },
  81. //登录判断
  82. login(status){
  83. if(!status){
  84. console.log('config',this.config);
  85. window.location.replace(this.config.loginUrl)
  86. }
  87. },
  88. //提交校验
  89. submitOrder:function(){
  90. if(!this.vuex_hasLogin){
  91. this.message = "请先登录"
  92. this.showToast();
  93. return;
  94. }
  95. if(this.requested){
  96. this.requested = false;
  97. uni.showLoading({
  98. title: '订单生成中。'
  99. });
  100. // if(this.cartList.length == 0){
  101. // this.$api.msg("请先选择产品!")
  102. // return;
  103. // }else{
  104. // let userInfo = uni.getStorageSync("userInfo");
  105. // console.log( uni.getStorageSync("linkType") );
  106. let params = {
  107. // customerId:userInfo.guid,
  108. // list:this.cartList,
  109. // linkType: uni.getStorageSync("linkType") || '',
  110. // activityId:uni.getStorageSync("togetherId") || ''
  111. }
  112. this.syncData(params);
  113. // }
  114. }else{
  115. // this.showToast();
  116. setTimeout(()=>{
  117. uni.showLoading({
  118. title: '订单生成中。'
  119. });
  120. },2000);
  121. return
  122. };
  123. },
  124. //订单提交,拿到订单id
  125. syncData(data){
  126. this.$u.api.createOrder(data)
  127. .then(res=>{
  128. this.requested = true;
  129. console.log('res',res);
  130. if(res.retHead.errCode == 0){
  131. // this.pullWeichatPay(res.retBody)
  132. this.pullWeichatPay(res.retBody.orderId)
  133. }else{
  134. this.message = res.retHead.errMsg;
  135. this.showToast();
  136. }
  137. uni.hideLoading()
  138. }).catch(err=>{console.log('createOrder err',err)})
  139. },
  140. //拉起微信支付
  141. async pullWeichatPay(id){
  142. let params = {
  143. orderId:id,
  144. openid:this.$store.state.vuex_user.openId,
  145. tradeType:"test"
  146. }
  147. this.$pay.wxPay(params).then(res =>{
  148. if(res.code == 0){
  149. uni.reLaunch({
  150. url: '/pages/buySuccess/buySuccess?orderId=' + params.orderId
  151. })
  152. }else if(res.code == 1){
  153. uni.redirectTo({
  154. url: '/pages/userCenter/myOrder/myOrder'
  155. })
  156. }else if(res.code == 2){
  157. this.message = "支付失败,请检查!"
  158. this.showToast();
  159. setTimeout(()=>{
  160. uni.redirectTo({
  161. url: '/pages/userCenter/myOrder/myOrder'
  162. });
  163. },1000)
  164. }
  165. })
  166. },
  167. //退出
  168. logout(){
  169. this.$u.vuex('vuex_hasLogin', false);
  170. this.$router.go(0);
  171. },
  172. //退款
  173. refund(orderId){
  174. this.$u.api.refund({orderId:orderId,refundDesc:'测试'})
  175. .then(res =>{
  176. console.log('refund res',res)
  177. }).catch(err=>{
  178. this.message = err.retHead.errMsg;
  179. this.showToast();
  180. console.log('refund err',err)
  181. })
  182. }
  183. }
  184. }
  185. </script>
  186. <style lang="scss">
  187. page{
  188. background-color: #ededed;
  189. }
  190. .camera{
  191. width: 54px;
  192. height: 44px;
  193. &:active{
  194. background-color: #ededed;
  195. }
  196. }
  197. .user-box{
  198. background-color: #fff;
  199. }
  200. </style>