user.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. const Parser = require('../xml/xmldom/dom-parser');
  2. //获取应用实例
  3. var app = getApp();
  4. Page({
  5. data: {
  6. ownerType:'',
  7. ownerid:'', //业主id
  8. ownername:'', //业主名
  9. hname:'', //房名
  10. hcode:'', //房号
  11. phone:'', //微信手机号
  12. openid:'',
  13. session_key:'',
  14. nickName:'', //微信昵称
  15. avatarRell:'../../img/timg.jpg', //微信头像
  16. isPone:false , //是否需要显示获取手机号权限
  17. isLogin:false, //是否需要重新登录
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad: function (options) {
  23. wx.showToast({
  24. title: '加载中',
  25. icon: 'loading',
  26. duration: 2000,
  27. sessionPhone:'',
  28. })
  29. },
  30. /**
  31. * 生命周期函数--监听页面显示
  32. */
  33. onShow: function (options) {
  34. var that = this;
  35. wx.getSetting({
  36. success (res) {
  37. console.log('获取用户的当前设置',res)
  38. }
  39. })
  40. try {
  41. wx.getStorage({
  42. key: 'ownerdatas',
  43. success:function(res){
  44. console.warn('获取缓存数据',res.data);
  45. if(res.data!=null&&res.data.length>0){
  46. var sum = res.data.split(',');
  47. if(sum.length!=8){ //若数组没有8个,则表明缓存数据不足,删除缓存,重新获取
  48. wx.removeStorageSync('ownerdatas');
  49. that.setData({isLogin:true});
  50. }
  51. else{ //若足够,则重新给data赋值
  52. that.setData({
  53. avatarRell:sum[0],
  54. openid:sum[1],
  55. nickName:sum[2],
  56. phone:sum[3],
  57. hcode:sum[4],
  58. hname:sum[5],
  59. ownerid:sum[6],
  60. ownername:sum[7],
  61. isLogin:false
  62. })
  63. }
  64. }
  65. },
  66. fail:function(res){
  67. console.warn('获取缓存失败',res);
  68. that.setData({isLogin:true});
  69. }
  70. })
  71. if(that.data.phone!=undefined&&that.data.phone!=null&&that.data.phone!=''){
  72. that.setData({isPone:false});
  73. return;
  74. }
  75. //微信登录
  76. wx.login({
  77. complete: (res) => {
  78. console.warn('login',res);
  79. wx.request({
  80. // 获取微信openid
  81. url: app.coreUrl+`GetOpenid?code=${res.code}`,
  82. method:"get",
  83. success:function(resopenid){
  84. console.warn('coreUrl',app.coreUrl);
  85. console.warn('resopenid',resopenid);
  86. var ownerData = resopenid.data.split(',');
  87. that.setData({
  88. openid:ownerData[0],
  89. session_key:ownerData[1]
  90. })
  91. }
  92. })
  93. },
  94. })
  95.   } catch(error) {
  96. console.error('try失败',error);
  97.   }
  98. },
  99. sp:function(){
  100. },
  101. getUserInfo(e){
  102. console.warn('getUserInfo',e);
  103. var that = this;
  104. that.setData({
  105. avatarRell:e.detail.userInfo.avatarUrl,
  106. nickName:e.detail.userInfo.nickName,
  107. isPone:true
  108. })
  109. //获取的用户信息存入缓存
  110. wx.setStorageSync(
  111. 'ownerdatas',e.detail.userInfo.avatarUrl+','+that.data.openid+','+that.data.nickName
  112. )
  113. },
  114. // 获取手机号
  115. getPhoneNumber (e) {
  116. var that = this;
  117. wx.login({
  118. complete: (res) => {
  119. wx.request({
  120. url: app.coreUrl+'PostPhoneNumber',
  121. data: {
  122. encryptedData: e.detail.encryptedData,
  123. iv: e.detail.iv,
  124. code:res.code
  125. },
  126. method: "post",
  127. success: function (resphone) {
  128. console.log('getPhoneNumber',resphone);
  129. that.setData({
  130. phone:resphone.data.phoneNumber
  131. });
  132. if(resphone.data.phoneNumber!=undefined&&resphone.data.phoneNumber!=''&&resphone.data.phoneNumber!=null){
  133. wx.request({
  134. url: app.coreUrl+'updateOwnerUrl',
  135. data:{
  136. tel:that.data.phone,
  137. url:that.data.avatarRell,
  138. weixinid:that.data.openid
  139. },
  140. method: "post",
  141. success:function(e){
  142. console.warn('updateOwnerUrl',e.data);
  143. if(e.data=='微信头像更新失败,查询不到当前客户'||e.data=='参数有误'){
  144. that.setData({
  145. isPone:false,
  146. phone:'绑定失败,查无业主'
  147. })
  148. }
  149. else{ //绑定成功
  150. var arr=e.data.split(',');
  151. that.setData({
  152. isPone:false,
  153. isLogin:false,
  154. ownerType:'',
  155. hcode:arr[0],
  156. hname:arr[1],
  157. ownerid:arr[2],
  158. ownername:arr[3]
  159. });
  160. var value=wx.getStorageSync('ownerdatas');
  161. console.warn('value',value);
  162. if(value!=null&&value.length>0){
  163. let value1=value+','+that.data.phone+','+e.data;
  164. console.warn('ownerdatas',value1);
  165. wx.setStorageSync('ownerdatas', value1); //手机号存储入key为ownerdatas的缓存中
  166. }
  167. }
  168. }
  169. })
  170. }
  171. }
  172. })
  173. },
  174. })
  175. },
  176. jiaoFeiJiLuURL:function(){
  177. // 跳转缴费记录
  178. if(this.data.phone!=''){
  179. wx.navigateTo({
  180. url: `../jfjl/jfjl?openid=${this.data.openid}&ownerid=${this.data.ownerid}`,
  181. })
  182. }
  183. else{
  184. wx.showModal({
  185. title: '提示',
  186. content: '请先点击登录',
  187. showCancel:false,
  188. success (res) {
  189. if (res.confirm) {
  190. }
  191. }
  192. })
  193. }
  194. },
  195. woYaoBaoXiu:function(){
  196. // 跳转我要报修
  197. if(this.data.phone!=''){
  198. wx.navigateTo({
  199. url: `../baoxiu/baoxiu?openid=${this.data.openid}&phone=${this.data.phone}&hname=${this.data.hname}&hcode=${this.data.hcode}&ownerid=${this.data.ownerid}&ownername=${this.data.ownername}`,
  200. })
  201. }
  202. else{
  203. wx.showModal({
  204. title: '提示',
  205. content: '请先点击登录',
  206. showCancel:false,
  207. success (res) {
  208. if (res.confirm) {
  209. }
  210. }
  211. })
  212. }
  213. },
  214. woYaoJiaoFei:function(){
  215. // 跳转我要缴费
  216. if(this.data.phone!=''){
  217. wx.navigateTo({
  218. url: `../wyjf/wyjf?openid=${this.data.openid}&phone=${this.data.phone}`,
  219. })
  220. }
  221. else{
  222. wx.showModal({
  223. title: '提示',
  224. content: '请先点击登录',
  225. showCancel:false,
  226. success (res) {
  227. if (res.confirm) {
  228. }
  229. }
  230. })
  231. }
  232. },
  233. baoXiuJiLuURL:function(){
  234. // 跳转报修记录
  235. if(this.data.phone!=''){
  236. wx.navigateTo({
  237. url: `../bxjl/bxjl?ownerid=${this.data.ownerid}`,
  238. })
  239. }
  240. else{
  241. wx.showModal({
  242. title: '提示',
  243. content: '请先点击登录',
  244. showCancel:false,
  245. success (res) {
  246. if (res.confirm) {
  247. }
  248. }
  249. })
  250. }
  251. },
  252. fanChanXinXiURL:function(){
  253. //跳转房产信息
  254. if(this.data.phone!=''){
  255. wx.navigateTo({
  256. url: `../fcxx/fcxx?openid=${this.data.openid}&phone=${this.data.phone}`,
  257. })
  258. }
  259. else{
  260. wx.showModal({
  261. title: '提示',
  262. content: '请先点击登录',
  263. showCancel:false,
  264. success (res) {
  265. if (res.confirm) {
  266. }
  267. }
  268. })
  269. }
  270. }
  271. })