user.js 8.5 KB

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