index.vue 5.4 KB

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