register.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <template>
  2. <view>
  3. <image class="top-img" src="https://jzmall.lifejingzhi.com/file/jzmall/weixin/register-bg.jpg" mode="widthFix"></image>
  4. <view class="form-wrapper">
  5. <view class="form-item">
  6. <view class="item-left">城市选择</view>
  7. <view class="item-right city-select" @tap="showPickerFun">
  8. <text class="city">{{ cityValue }}</text>
  9. <view class="arrow-down"></view>
  10. </view>
  11. </view>
  12. <view class="form-item">
  13. <view class="item-left">姓 名</view>
  14. <view class="item-right">
  15. <input class="weui-input name-input" maxlength="10" placeholder="请输入姓名" :value="username" @input="nameInput" />
  16. </view>
  17. </view>
  18. <view class="form-item">
  19. <view class="item-left">手 机</view>
  20. <view class="item-right">{{ phone }}</view>
  21. </view>
  22. <!-- <view class="form-item">
  23. <view class="item-left">邀 请 码</view>
  24. <view class="item-right">{{bCode}}</view>
  25. </view> -->
  26. </view>
  27. <view class="register-btn" ontap="confirmRegister">确认注册</view>
  28. <van-popup :show="showPicker" position="bottom">
  29. <van-picker show-toolbar :columns="columns" @cancel="onCancel" @confirm="onConfirm" />
  30. </van-popup>
  31. </view>
  32. </template>
  33. <script>
  34. const util = require('../../../../utils/util.js');
  35. const api = require('../../../../config/api.js');
  36. const app = getApp();
  37. export default {
  38. data() {
  39. return {
  40. phone: '',
  41. bCode: '',
  42. showPicker: false,
  43. cityId: '',
  44. cityValue: '请选择城市',
  45. cityList: [],
  46. columns: [],
  47. username: '',
  48. userInfo: {}
  49. };
  50. }
  51. /**
  52. * 生命周期函数--监听页面加载
  53. */,
  54. onLoad: function (options) {
  55. this.getAllCity();
  56. this.setData({
  57. phone: app.globalData.recommend.phone,
  58. bCode: app.globalData.recommend.bCode
  59. });
  60. },
  61. /**
  62. * 生命周期函数--监听页面初次渲染完成
  63. */
  64. onReady: function () {},
  65. /**
  66. * 生命周期函数--监听页面显示
  67. */
  68. onShow: function () {},
  69. /**
  70. * 生命周期函数--监听页面隐藏
  71. */
  72. onHide: function () {},
  73. /**
  74. * 生命周期函数--监听页面卸载
  75. */
  76. onUnload: function () {},
  77. /**
  78. * 页面相关事件处理函数--监听用户下拉动作
  79. */
  80. onPullDownRefresh: function () {},
  81. /**
  82. * 页面上拉触底事件的处理函数
  83. */
  84. onReachBottom: function () {},
  85. /**
  86. * 用户点击右上角分享
  87. */
  88. onShareAppMessage: function () {},
  89. methods: {
  90. onCancel: function () {
  91. this.setData({
  92. showPicker: false
  93. });
  94. },
  95. onConfirm: function (event) {
  96. this.setData({
  97. cityId: this.cityList[event.detail.index].id,
  98. cityValue: event.detail.value,
  99. showPicker: false
  100. });
  101. },
  102. showPickerFun() {
  103. this.setData({
  104. showPicker: true
  105. });
  106. },
  107. nameInput(e) {
  108. this.setData({
  109. username: e.detail.value
  110. });
  111. },
  112. getAllCity() {
  113. util.request(api.GetAllCity, {}, 'get').then((res) => {
  114. if (res.errno === 0) {
  115. let list = res.data;
  116. let columns = list.map((item) => {
  117. return item.cityName;
  118. });
  119. this.setData({
  120. cityList: list,
  121. columns: columns
  122. });
  123. } else {
  124. util.showErrorToast(res.errmsg);
  125. }
  126. });
  127. },
  128. confirmRegister() {
  129. let that = this;
  130. if (that.cityValue == '请选择城市') {
  131. util.showErrorToast('请选择城市');
  132. } else if (that.username == '') {
  133. util.showErrorToast('请输入姓名');
  134. } else {
  135. uni.getUserProfile({
  136. desc: '用于完善会员资料',
  137. // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  138. success: (res) => {
  139. console.log(res);
  140. if (res.userInfo == null) {
  141. uni.showToast({
  142. title: '未授权,无法完善信息',
  143. icon: 'success',
  144. duration: 3000
  145. });
  146. return;
  147. } else {
  148. that.setData({
  149. userInfo: res.userInfo
  150. });
  151. that.registerReferrer();
  152. }
  153. },
  154. fail: (res) => {
  155. uni.showToast({
  156. title: '未授权,无法完善信息',
  157. icon: 'success',
  158. duration: 3000
  159. });
  160. }
  161. });
  162. }
  163. },
  164. registerReferrer() {
  165. util.request(
  166. api.RegisterReferrer,
  167. {
  168. applyCode: this.bCode,
  169. avatar: this.userInfo.avatarUrl,
  170. cityId: this.cityId,
  171. customerName: this.username,
  172. gender: this.userInfo.gender,
  173. nickname: this.userInfo.nickName,
  174. openId: app.globalData.recommend.openId,
  175. phone: this.phone,
  176. ruserid: app.globalData.rId,
  177. sessionKey: app.globalData.recommend.sessionKey,
  178. unionId: app.globalData.recommend.unionId
  179. },
  180. 'POST'
  181. ).then((res) => {
  182. if (res.errno == 0) {
  183. //存储用户信息
  184. app.globalData.hasLogin = true;
  185. uni.setStorageSync('userInfo', res.data.userInfo);
  186. uni.setStorageSync('token', res.data.token);
  187. app.globalData.shareImage = res.data.sharImage;
  188. // wx.navigateTo({
  189. // url: '../steward/steward',
  190. // })
  191. uni.showToast({
  192. title: '注册成功',
  193. duration: 2000,
  194. success: function () {
  195. setTimeout(function () {
  196. uni.switchTab({
  197. url: '/pages/index/index'
  198. });
  199. }, 2000);
  200. }
  201. });
  202. } else {
  203. util.showErrorToast(res.errmsg);
  204. }
  205. });
  206. }
  207. }
  208. };
  209. </script>
  210. <style>
  211. .top-img {
  212. width: 100%;
  213. }
  214. .form-wrapper {
  215. padding: 86rpx 66rpx 0;
  216. }
  217. .form-item {
  218. display: flex;
  219. height: 68rpx;
  220. margin: 0 0 32rpx;
  221. }
  222. .item-left {
  223. width: 120rpx;
  224. color: #2a2a2a;
  225. font-size: 30rpx;
  226. text-align: justify;
  227. line-height: 78rpx;
  228. margin-right: 20rpx;
  229. }
  230. .item-right {
  231. border-radius: 10rpx;
  232. border: 2rpx solid #dcdcdc;
  233. flex: 1;
  234. padding: 0 20rpx 0;
  235. text-align: left;
  236. color: #85868a;
  237. font-size: 28rpx;
  238. height: 78rpx;
  239. line-height: 78rpx;
  240. }
  241. .city-select {
  242. display: flex;
  243. justify-content: flex-end;
  244. align-items: center;
  245. }
  246. .city {
  247. color: #85868a;
  248. }
  249. .arrow-down {
  250. width: 0rpx;
  251. height: 0;
  252. border-left: 14rpx solid transparent;
  253. border-right: 14rpx solid transparent;
  254. border-top: 16rpx solid #85868a;
  255. margin-left: 8rpx;
  256. }
  257. .register-btn {
  258. background: url('https://jzmall.lifejingzhi.com/file/jzmall/weixin/btn.png') no-repeat center;
  259. background-size: 100%;
  260. width: 592rpx;
  261. height: 114rpx;
  262. margin: 200rpx auto 80rpx;
  263. color: #fff;
  264. font-size: 36rpx;
  265. line-height: 114rpx;
  266. text-align: center;
  267. font-weight: bold;
  268. }
  269. .name-input {
  270. color: #85868a;
  271. font-size: 28rpx;
  272. text-align: left;
  273. height: 78rpx;
  274. line-height: 78rpx;
  275. }
  276. </style>