index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. <template>
  2. <view>
  3. <view v-if="imStaff&&!isLogin" class="auth">
  4. <image src="/static/login-logo.png" mode=""></image>
  5. 提示:工作人员登录后才能显示会员管理信息<br/>
  6. 请点击
  7. <button v-if="!isAuth" type='primary' class="allow" open-type="getUserInfo" @getuserinfo="getUserInfo">授权</button>
  8. <button v-if="isAuth" type="primary" class="allow" open-type="getPhoneNumber" style="font-size: 12px;" @getphonenumber="getPhoneNumber">绑定手机</button>
  9. </view>
  10. <view v-if="imMember&&(!isLogin)" class="auth">
  11. <image src="/static/login-logo.png" mode=""></image>
  12. 提示:会员登录后才能使用会员功能<br/>
  13. 请点击
  14. <button v-if="!isAuth" type='primary' class="allow" open-type="getUserInfo" @getuserinfo="getUserInfo">授权</button>
  15. <button v-if="isAuth" type="primary" class="allow" open-type="getPhoneNumber" style="font-size: 12px;" @getphonenumber="getPhoneNumber">绑定手机</button>
  16. </view>
  17. <uni-popup ref="popup" type="center">
  18. <view class="uni-tip">
  19. <view class="uni-tip-title">登录失败</view>
  20. <view class="uni-tip-content">您授权的手机号与后台信息不匹配,请联系客服人员{{kf_number}}</view>
  21. <button class="uni-tip-button" @click="closePopup">确定</button>
  22. </view>
  23. </uni-popup>
  24. </view>
  25. </template>
  26. <script>
  27. var md5 = require("../../common/md5.js");
  28. import uniPopup from '@/components/uni-popup/uni-popup.vue';
  29. export default {
  30. components: {
  31. uniPopup,
  32. },
  33. data(){
  34. return {
  35. iv:'',
  36. encryptedData:'',
  37. session_key:getApp().globalData.session_key,
  38. open_id: getApp().globalData.open_id,
  39. imStaff:getApp().globalData.imStaff,
  40. imMember:getApp().globalData.imMember,
  41. isAuth:getApp().globalData.isAuth,
  42. isBind:getApp().globalData.isBind,
  43. isLogin:getApp().globalData.isLogin,
  44. kf_number:getApp().globalData.kf_number,
  45. user_type:'',
  46. }
  47. },
  48. onLoad() {
  49. // console.log("是否授权"+getApp().globalData.isAuth);
  50. // console.log("是否绑定"+getApp().globalData.isBind);
  51. // console.log("是否登录"+getApp().globalData.isLogin);
  52. // console.log("是否工作人员"+getApp().globalData.imStaff);
  53. // console.log("是否客户"+getApp().globalData.imMember);
  54. },
  55. watch:{
  56. user_type(){
  57. console.log("监听到用户类型了!");
  58. // this.judgeStaff(getApp().globalData.user_type);
  59. },
  60. },
  61. methods:{
  62. loginRequest(){
  63. uni.login({
  64. success: (res) => {
  65. uni.request({
  66. url: getApp().globalData.shareUrl, //需要设置为全局
  67. method: 'POST',
  68. header: {
  69. 'content-type': 'application/x-www-form-urlencoded',
  70. },
  71. data: {
  72. method: 'login',
  73. timestamp: getApp().globalData.globalTimestamp,
  74. code: res.code,
  75. sign: md5('login' + getApp().globalData.globalTimestamp)
  76. },
  77. success: res => {
  78. // 通过openid发起会员登录
  79. console.log(res);
  80. if(res.data.msg.status===1){
  81. getApp().globalData.isAuth=true;//用户已授权 手机号未绑定
  82. }else if(res.data.msg.status===2){
  83. getApp().globalData.isAuth=true;
  84. getApp().globalData.isBind=true;//用户手机号已绑定 进入调用用户信息流程来判断用户类型
  85. this.getSelInfo();
  86. };
  87. getApp().globalData.open_id = res.data.msg.openId;
  88. getApp().globalData.session_key = res.data.msg.session_key;
  89. console.log('会员&工作人员尝试登录');
  90. },
  91. });
  92. },
  93. });
  94. },
  95. getSelInfo(){
  96. let that = this;
  97. uni.request({
  98. url: getApp().globalData.shareUrl,
  99. method: 'POST',
  100. header: {
  101. 'content-type': 'application/x-www-form-urlencoded'
  102. },
  103. data: {
  104. sign: md5('get_member_info' + getApp().globalData.globalTimestamp),
  105. method: 'get_member_info',
  106. timestamp: getApp().globalData.globalTimestamp,
  107. openId: getApp().globalData.open_id,
  108. },
  109. success:(res)=>{
  110. if(res.data.code===200){
  111. getApp().globalData.user_id=res.data.msg.id;
  112. getApp().globalData.user_type=res.data.msg.type;
  113. getApp().globalData.member_count=res.data.msg.member_count;
  114. getApp().globalData.user_adminid=res.data.msg.adminid;
  115. getApp().globalData.user_headimg=res.data.msg.headimg;
  116. getApp().globalData.user_name=res.data.msg.name;
  117. getApp().globalData.user_nickname=res.data.msg.nickname;
  118. getApp().globalData.user_sex=res.data.msg.sex;
  119. getApp().globalData.user_status=res.data.msg.status;
  120. getApp().globalData.user_birthday=res.data.msg.birthday;
  121. getApp().globalData.user_idnum=res.data.msg.idnum;
  122. getApp().globalData.user_phone=res.data.msg.phone;
  123. getApp().globalData.user_email=res.data.msg.email;
  124. getApp().globalData.user_home_address=res.data.msg.home_address;
  125. getApp().globalData.user_send_address=res.data.msg.send_address;
  126. getApp().globalData.user_pcode=res.data.msg.pcode;
  127. getApp().globalData.user_number=res.data.msg.number;
  128. getApp().globalData.user_firsttime=res.data.msg.firsttime;
  129. getApp().globalData.user_addtime=res.data.msg.addtime;
  130. getApp().globalData.user_balance=res.data.msg.balance;
  131. getApp().globalData.user_deadline=res.data.msg.deadline;
  132. getApp().globalData.user_doctor=res.data.msg.doctor;
  133. getApp().globalData.user_doctor_name=res.data.msg.doctor_name;
  134. getApp().globalData.user_online_doctor=res.data.msg.online_doctor;
  135. getApp().globalData.user_online_doctor_name=res.data.msg.online_doctor_name;
  136. getApp().globalData.user_kf=res.data.msg.kf;
  137. getApp().globalData.user_kf_name=res.data.msg.kf_name;
  138. getApp().globalData.member_count=res.data.msg.member_count;
  139. getApp().globalData.user_health_doc=res.data.msg.health_doc;
  140. getApp().globalData.roomId = res.data.msg.type === '0' ? res.data.msg.rooms[0] :res.data.msg.rooms;
  141. if(getApp().globalData.user_deadline*1000<new Date().getTime()){
  142. getApp().globalData.deadline=true;
  143. }
  144. console.log("读取用户个人信息成功");
  145. that.judgeStaff(getApp().globalData.user_type);
  146. }
  147. },
  148. fail:()=>{
  149. console.log("读取用户个人信息失败");
  150. },
  151. });
  152. },
  153. judgeStaff(type){
  154. if(type==0){
  155. if(!getApp().globalData.imMember){
  156. this.$refs.popup.open();
  157. getApp().globalData.isSignOut=true;
  158. getApp().globalData.isAuth=false;
  159. getApp().globalData.isBind=false;
  160. getApp().globalData.isLogin=false;
  161. this.signout();
  162. }else{
  163. getApp().globalData.isLogin=true;
  164. console.log("该用户登录成功");
  165. if(getApp().globalData.user_deadline*1000<new Date().getTime()){
  166. getApp().globalData.deadline=true;
  167. }
  168. this.refuseBtn();
  169. //登陆成功再获取一次用户信息,登录状态不同获取的信息不一致
  170. }
  171. }else{
  172. if(!getApp().globalData.imStaff){
  173. this.$refs.popup.open();
  174. getApp().globalData.isSignOut=true;
  175. getApp().globalData.isAuth=false;
  176. getApp().globalData.isBind=false;
  177. getApp().globalData.isLogin=false;
  178. this.signout();
  179. }else{
  180. getApp().globalData.isLogin=true;
  181. console.log("该医生&客服登录成功");
  182. this.goChatlist();
  183. // this.getSelInfo();
  184. }
  185. }
  186. },
  187. getUserInfo(e) {
  188. if (e.detail.errMsg == "getUserInfo:ok") {
  189. console.log(e);
  190. getApp().globalData.isAuth = true;
  191. getApp().globalData.user_headimg = e.detail.userInfo.avatarUrl;
  192. getApp().globalData.user_name = e.detail.userInfo.nickName;
  193. this.iv = e.detail.iv;
  194. this.encryptedData = e.detail.encryptedData;
  195. this.isAuth=true;
  196. console.log("用户信息授权成功");
  197. } else {
  198. console.log("用户信息授权失败");
  199. this.isAuth = false;
  200. getApp().globalData.isAuth = false;
  201. }
  202. },
  203. getPhoneNumber(e){
  204. console.log(e);
  205. let that = this;
  206. if (e.detail.errMsg == 'getPhoneNumber:ok') { //允许授权执行跳转
  207. that.phoneRequest(e.detail.iv, e.detail.encryptedData, getApp().globalData.session_key);
  208. } else { //
  209. that.isNeedPhone = false;
  210. }
  211. },
  212. phoneRequest(myIv,myEncryptedData,sKey){
  213. let that = this;
  214. uni.request({
  215. url:getApp().globalData.shareUrl, //需要设置为全局
  216. method: 'POST',
  217. header: {
  218. 'content-type': 'application/x-www-form-urlencoded'
  219. },
  220. data: {
  221. method: 'auth',
  222. timestamp: getApp().globalData.globalTimestamp,
  223. sign: md5('auth' + getApp().globalData.globalTimestamp),
  224. iv:myIv,
  225. encryptedData:myEncryptedData,
  226. session_key:sKey,
  227. openId: that.open_id,
  228. },
  229. success: res => {
  230. console.log(res.data.code);
  231. if(res.data.code===200){
  232. console.log("手机号绑定成功!");
  233. getApp().globalData.isBind=true;
  234. that.uploadHeadimg();
  235. }else{
  236. this.$refs.popup.open();
  237. getApp().globalData.isSignOut=true;
  238. getApp().globalData.isAuth=false;
  239. getApp().globalData.isBind=false;
  240. getApp().globalData.isLogin=false;
  241. this.isBind = false;
  242. }
  243. }
  244. });
  245. },
  246. uploadHeadimg(){
  247. let that = this;
  248. uni.request({
  249. url: getApp().globalData.shareUrl,
  250. method: 'POST',
  251. header: {
  252. 'content-type': 'application/x-www-form-urlencoded'
  253. },
  254. data: {
  255. sign: md5('update_member_info' + getApp().globalData.globalTimestamp),
  256. method: 'update_member_info',
  257. timestamp: getApp().globalData.globalTimestamp,
  258. openId:getApp().globalData.open_id,
  259. key:'headimg',
  260. value:getApp().globalData.user_headimg,
  261. },
  262. success:(res)=>{
  263. if(res.data.code===200){
  264. getApp().globalData.user_headimg=res.data.msg.headimg;
  265. that.getSelInfo()
  266. console.log("将微信头像作为用户头像");
  267. }
  268. },
  269. fail:()=>{
  270. console.log("微信头像作为用户头像更新失败");
  271. },
  272. });
  273. },
  274. refuseBtn(){
  275. uni.navigateBack({
  276. delta: 1
  277. });
  278. },
  279. goChatlist(){
  280. uni.reLaunch({
  281. url: '../index/chatList/index',
  282. success: res => {},
  283. fail: () => {},
  284. complete: () => {}
  285. });
  286. return true;
  287. },
  288. signout(){
  289. getApp().globalData.isAuth=false;
  290. getApp().globalData.isBind=false;
  291. getApp().globalData.isLogin=false;
  292. uni.request({
  293. url: getApp().globalData.shareUrl,
  294. method: 'POST',
  295. header: {
  296. 'content-type': 'application/x-www-form-urlencoded'
  297. },
  298. data: {
  299. sign: md5('update_member_info' + getApp().globalData.globalTimestamp),
  300. method: 'update_member_info',
  301. timestamp: getApp().globalData.globalTimestamp,
  302. uid:getApp().globalData.user_id,
  303. openId:getApp().globalData.open_id,
  304. key:'login_status',
  305. value:0,
  306. },
  307. success:(res)=>{
  308. if(res.data.code===200){
  309. getApp().globalData.login_status=res.data.msg.login_status;
  310. getApp().globalData.user_headimg=res.data.msg.headimg;
  311. getApp().globalData.user_name=res.data.msg.name;
  312. getApp().globalData.user_birthday=res.data.msg.birthday;
  313. getApp().globalData.user_idnum=res.data.msg.idnum;
  314. getApp().globalData.user_phone=res.data.msg.phone;
  315. getApp().globalData.user_email=res.data.msg.email;
  316. getApp().globalData.user_home_address=res.data.msg.home_address;
  317. getApp().globalData.user_send_address=res.data.msg.send_address;
  318. getApp().globalData.user_pcode=res.data.msg.pcode;
  319. getApp().globalData.user_number=res.data.msg.number;
  320. getApp().globalData.user_firsttime=res.data.msg.firsttime;
  321. getApp().globalData.user_balance=res.data.msg.balance;
  322. getApp().globalData.user_deadline=res.data.msg.deadline;
  323. getApp().globalData.user_doctor_name=res.data.msg.doctor_name;
  324. getApp().globalData.user_online_doctor_name=res.data.msg.online_doctor_name;
  325. getApp().globalData.kf_name=res.data.msg.kf_name;
  326. console.log("退出登录成功!");
  327. }
  328. },
  329. fail:()=>{
  330. console.log("999");
  331. },
  332. });
  333. },
  334. closePopup(){
  335. getApp().globalData.isSignOut=true;
  336. getApp().globalData.isAuth=true;
  337. getApp().globalData.isBind=false;
  338. getApp().globalData.isLogin=false;
  339. this.$refs.popup.close();
  340. uni.reLaunch({
  341. url: '../index/chooseId/index',
  342. success: res => {},
  343. fail: () => {},
  344. complete: () => {}
  345. });
  346. },
  347. }
  348. }
  349. </script>
  350. <style>
  351. .auth{
  352. margin-top: 0;
  353. text-align: center;
  354. display: flex;
  355. flex-direction: column;
  356. justify-content: center;
  357. align-items: center;
  358. padding: 100upx;
  359. vertical-align: middle;
  360. }
  361. .auth image{
  362. width: 200upx;
  363. height: 200upx;
  364. }
  365. .auth view {
  366. display: flex;
  367. width: 490upx;
  368. justify-content: space-between;
  369. }
  370. .auth-title {
  371. font-size: 32upx;
  372. }
  373. .auth-content {
  374. font-size: 26upx;
  375. color: #a7aaa9;
  376. }
  377. .allow {
  378. background-color: #27BCEF;
  379. margin: 20rpx 0 200rpx;
  380. text-align: center;
  381. vertical-align: middle;
  382. touch-action: manipulation;
  383. cursor: pointer;
  384. background-image: none;
  385. white-space: nowrap;
  386. user-select: none;
  387. font-size: 14px;
  388. border: 0 !important;
  389. position: relative;
  390. text-decoration: none;
  391. height: 44px;
  392. width: 250rpx;
  393. line-height: 44px;
  394. box-shadow: inset 0 0 0 1px #27BCEF;
  395. background: #fff !important;
  396. color: #27BCEF !important;
  397. display: inline-block;
  398. border-radius: 10rpx;
  399. }
  400. .refuse {
  401. background-color: #19be6b;
  402. margin: 20rpx 20rpx 200rpx 20rpx;
  403. text-align: center;
  404. vertical-align: middle;
  405. touch-action: manipulation;
  406. cursor: pointer;
  407. background-image: none;
  408. white-space: nowrap;
  409. user-select: none;
  410. font-size: 14px;
  411. border: 0 !important;
  412. position: relative;
  413. text-decoration: none;
  414. height: 44px;
  415. width: 250rpx;
  416. line-height: 44px;
  417. box-shadow: inset 0 0 0 1px #8a8a8a;
  418. background: #fff !important;
  419. color: #8a8a8a !important;
  420. display: inline-block;
  421. border-radius: 10rpx;
  422. }
  423. .margin-top-3{
  424. margin-top: 10%;
  425. }
  426. .uni-tip {
  427. padding: 30rpx;
  428. width: 600rpx;
  429. height: 340rpx;
  430. background: #fff;
  431. box-sizing: border-box;
  432. border:2rpx solid #fff;
  433. border-radius: 10rpx;
  434. }
  435. .uni-tip-title {
  436. text-align: center;
  437. height: 40rpx;
  438. /* font-weight: bold; */
  439. font-size: 30rpx;
  440. background: #fff;
  441. /* color: #333; */
  442. }
  443. .uni-tip-content {
  444. text-align: center;
  445. background: #fff;
  446. padding: 15px;
  447. font-size: 28rpx;
  448. height: 70rpx;
  449. line-height: 1.8;
  450. /* color: #666; */
  451. }
  452. .uni-tip-button {
  453. width: 200rpx;
  454. height: 60rpx;
  455. line-height: 60rpx;
  456. margin-top: 30rpx;
  457. /* display: flex; */
  458. text-align: center;
  459. background: #fff;
  460. font-size: 28rpx;
  461. color: #c02924;
  462. border: solid 1rpx #c02924;
  463. border-radius: 30rpx;
  464. }
  465. </style>