index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <!-- 登陆页面 会员/商家 -->
  2. <template>
  3. <view class="main_width">
  4. <view style="text-align: center;overflow: hidden;">
  5. <view class="title">快来优</view>
  6. <view style="color: #7b7b83;margin-top: 20upx;">开启全民赚钱时代</view>
  7. <image style="width: 520upx;height: 520upx;" :src="serverUrlImg"></image>
  8. <button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" class="main_btn_m get_phone">
  9. <image style="width: 35upx;height: 30upx;margin-right: 15upx;" src="../../static/wechat.png"></image>
  10. {{sys_role==1? '商户登录':'会员登录'}}
  11. </button>
  12. </view>
  13. <view class="read">
  14. <checkbox-group @change="checkboxChange">
  15. <checkbox color="#48ccae" value="1" />
  16. </checkbox-group>
  17. <view style="margin-left: 10upx;">
  18. <view style="margin-left: 14upx;">登录代表您已仔细阅读并同意</view>
  19. <view style="display: flex;">
  20. <navigator url="./web?index=6" style="color: rgb(0, 199, 178);">《用户协议》
  21. </navigator>与
  22. <navigator url="./web?index=7" style="color: rgb(0, 199, 178);">《隐私政策》
  23. </navigator>
  24. </view>
  25. </view>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. import commonData from '../../commonData.js'
  31. import commonFun from '../../commonFun.js'
  32. export default {
  33. data() {
  34. return {
  35. serverUrlImg: this.serverUrl + 'login.png',
  36. is_agree: [], //是否同意用户协议
  37. sys_role: commonData.sys_role, //用户角色
  38. baseUserId: '', //登录获取baseUserId
  39. need_back: 0, //是否需要返回到上页
  40. }
  41. },
  42. onLoad(e) {
  43. if (e.need_back) {
  44. this.need_back = e.need_back
  45. }
  46. this.get_openid()
  47. },
  48. methods: {
  49. // 获取openid
  50. get_openid() {
  51. let that = this
  52. let url = '&WsAjaxBiz=' + (commonData.sys_role == 0 ? 'Worker' : 'Trader') +
  53. '&WsAjaxAction=fetchMinaOpenid'
  54. // 微信获取code
  55. uni.login({
  56. success: res => {
  57. commonFun.requestUrl(url, {
  58. minaCode: res.code
  59. }, res => {
  60. if (res.status) {
  61. that.baseUserId = res.data.Result.baseUser.id
  62. }
  63. })
  64. },
  65. fail: res => {
  66. uni.hideLoading()
  67. console.log('获取小程序code失败', res)
  68. }
  69. })
  70. },
  71. // 获取手机号码
  72. getPhoneNumber(e) {
  73. let that = this
  74. console.log(e.detail)
  75. if (e.detail.errMsg.indexOf('fail') !== -1) {
  76. uni.showModal({
  77. content: '获取手机号码失败',
  78. showCancel: false,
  79. success: function(res) {}
  80. });
  81. return
  82. }
  83. if (this.is_agree.length == 0) {
  84. uni.showModal({
  85. content: '请勾选隐私政策',
  86. showCancel: false,
  87. success: function(res) {}
  88. });
  89. return
  90. }
  91. uni.showLoading({
  92. title: '加载中...',
  93. mask: true
  94. })
  95. const params = {
  96. baseUserId: this.baseUserId,
  97. ...e.detail,
  98. }
  99. let url = '&WsAjaxBiz=' + (commonData.sys_role == 0 ? 'Worker' : 'Trader') +
  100. '&WsAjaxAction=fetchMinaPhone'
  101. commonFun.requestUrl(
  102. url,
  103. params, res => {
  104. if (res.status) {
  105. console.log('登录成功返回')
  106. console.log(res.data)
  107. uni.hideLoading()
  108. let result = res.data.Result
  109. uni.setStorageSync('baseUser', result
  110. .baseUser)
  111. uni.setStorageSync('bizWorker', result
  112. .bizWorker)
  113. uni.setStorageSync('bizTrader', result
  114. .bizTrader)
  115. uni.setStorageSync('FOREND_TOKEN', result
  116. .forendToken)
  117. uni.setStorageSync('PHONE', result.baseUser
  118. .mobile)
  119. // 取消游客模式
  120. uni.setStorageSync('IS_TOURIST', '0')
  121. uni.showModal({
  122. content: '登录成功',
  123. showCancel: false,
  124. success: function(res) {
  125. uni.showLoading({
  126. title: '加载中...',
  127. mask: false
  128. })
  129. uni.getUserProfile({
  130. desc: "获取昵称和头像",
  131. success: (res) => {
  132. let params = {
  133. biz_catalog: 1,
  134. nickname: res.userInfo.nickName,
  135. profile_photo: res.userInfo.avatarUrl,
  136. }
  137. let user_info = commonData.sys_role == 0 ? uni
  138. .getStorageSync('bizWorker') : uni
  139. .getStorageSync('bizTrader')
  140. user_info.nickname = res.userInfo.nickName
  141. user_info.profile_photo = res.userInfo
  142. .avatarUrl
  143. commonFun.init_go_easy(user_info, commonData
  144. .sys_role == 0 ? 'user_' : 'mer_')
  145. commonFun.requestUrl(
  146. '&WsAjaxBiz=Worker&WsAjaxAction=registerInfo',
  147. params, res => {
  148. if (that.need_back == 1) {
  149. uni.navigateBack({
  150. delta: 1,
  151. })
  152. } else {
  153. uni.reLaunch({
  154. url: commonData
  155. .sys_role == 0 ?
  156. '../index/index' :
  157. '../merchant/index'
  158. });
  159. }
  160. uni.hideLoading()
  161. })
  162. },
  163. fail: (err) => {
  164. uni.hideLoading()
  165. uni.showToast({
  166. icon: "none",
  167. title: '获取昵称和头像失败'
  168. })
  169. let user_info = commonData.sys_role == 0 ? uni
  170. .getStorageSync('bizWorker') : uni
  171. .getStorageSync('bizTrader')
  172. commonFun.init_go_easy(user_info, commonData
  173. .sys_role == 0 ? 'user_' : 'mer_')
  174. uni.reLaunch({
  175. url: '../personal/index'
  176. });
  177. }
  178. })
  179. }
  180. });
  181. }
  182. })
  183. },
  184. // 选中同意协议
  185. checkboxChange(e) {
  186. this.is_agree = e.detail.value
  187. },
  188. }
  189. }
  190. </script>
  191. <style>
  192. .get_phone {
  193. margin-top: 30upx;
  194. display: flex;
  195. align-items: center;
  196. justify-content: center;
  197. }
  198. .title {
  199. color: #40d0ae;
  200. font-size: 60upx;
  201. margin-top: 60upx;
  202. }
  203. .read {
  204. color: #8E97AE;
  205. margin-top: 100upx;
  206. font-size: 28upx;
  207. display: flex;
  208. flex-direction: row;
  209. justify-content: center;
  210. align-items: center;
  211. }
  212. </style>