user.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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. console.info("req",that.data.phone+","+that.data.avatarRell+","+that.data.openid);
  135. wx.request({
  136. url: app.coreUrl+'updateOwnerUrl',
  137. data:{
  138. tel:that.data.phone,
  139. url:that.data.avatarRell,
  140. weixinid:that.data.openid
  141. },
  142. method: "post",
  143. success:function(e){
  144. console.warn('updateOwnerUrl',e);
  145. if(e.data=='微信头像更新失败,查询不到当前客户'||e.data=='参数有误'){
  146. that.setData({
  147. isPone:false,
  148. phone:'绑定失败,查无业主'
  149. })
  150. }
  151. else{ //绑定成功
  152. var arr=e.data.split(',');
  153. console.info("arr",arr);
  154. that.setData({
  155. isPone:false,
  156. isLogin:false,
  157. ownerType:'',
  158. hcode:arr[0],
  159. hname:arr[1],
  160. ownerid:arr[2],
  161. ownername:arr[3]
  162. });
  163. var value=wx.getStorageSync('ownerdatas');
  164. console.warn('value',value);
  165. if(value!=null&&value.length>0){
  166. let value1=value+','+that.data.phone+','+e.data;
  167. console.warn('ownerdatas',value1);
  168. wx.setStorageSync('ownerdatas', value1); //手机号存储入key为ownerdatas的缓存中
  169. }
  170. }
  171. }
  172. })
  173. }
  174. }
  175. })
  176. },
  177. })
  178. },
  179. jiaoFeiJiLuURL:function(){
  180. // 跳转缴费记录
  181. if(this.data.phone!=''){
  182. wx.navigateTo({
  183. url: `../jfjl/jfjl?openid=${this.data.openid}&ownerid=${this.data.ownerid}`,
  184. })
  185. }
  186. else{
  187. wx.showModal({
  188. title: '提示',
  189. content: '请先点击登录',
  190. showCancel:false,
  191. success (res) {
  192. if (res.confirm) {
  193. }
  194. }
  195. })
  196. }
  197. },
  198. woYaoBaoXiu:function(){
  199. // 跳转我要报修
  200. if(this.data.phone!=''){
  201. wx.navigateTo({
  202. 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}`,
  203. })
  204. }
  205. else{
  206. wx.showModal({
  207. title: '提示',
  208. content: '请先点击登录',
  209. showCancel:false,
  210. success (res) {
  211. if (res.confirm) {
  212. }
  213. }
  214. })
  215. }
  216. },
  217. woYaoTousu:function(){
  218. // 跳转我要投诉
  219. if(this.data.phone!=''){
  220. wx.navigateTo({
  221. 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}`,
  222. })
  223. }
  224. else{
  225. wx.showModal({
  226. title: '提示',
  227. content: '请先点击登录',
  228. showCancel:false,
  229. success (res) {
  230. if (res.confirm) {
  231. }
  232. }
  233. })
  234. }
  235. },
  236. woYaoJiaoFei:function(){
  237. // 跳转我要缴费
  238. if(this.data.phone!=''){
  239. wx.navigateTo({
  240. url: `../wyjf/wyjf?openid=${this.data.openid}&phone=${this.data.phone}`,
  241. })
  242. }
  243. else{
  244. wx.showModal({
  245. title: '提示',
  246. content: '请先点击登录',
  247. showCancel:false,
  248. success (res) {
  249. if (res.confirm) {
  250. }
  251. }
  252. })
  253. }
  254. },
  255. baoXiuJiLuURL:function(){
  256. // 跳转报修记录
  257. if(this.data.phone!=''){
  258. console.info('ownerid',this.data.ownerid);
  259. wx.navigateTo({
  260. url: `../bxjl/bxjl?ownerid=${this.data.ownerid}`,
  261. })
  262. }
  263. else{
  264. wx.showModal({
  265. title: '提示',
  266. content: '请先点击登录',
  267. showCancel:false,
  268. success (res) {
  269. if (res.confirm) {
  270. }
  271. }
  272. })
  273. }
  274. },
  275. tousuJiLuURL:function(){
  276. // 跳转投诉记录
  277. if(this.data.phone!=''){
  278. wx.navigateTo({
  279. url: `../tsjl/tsjl?ownerid=${this.data.ownerid}`,
  280. })
  281. }
  282. else{
  283. wx.showModal({
  284. title: '提示',
  285. content: '请先点击登录',
  286. showCancel:false,
  287. success (res) {
  288. if (res.confirm) {
  289. }
  290. }
  291. })
  292. }
  293. },
  294. fanChanXinXiURL:function(){
  295. //跳转房产信息
  296. if(this.data.phone!=''){
  297. wx.navigateTo({
  298. url: `../fcxx/fcxx?openid=${this.data.openid}&phone=${this.data.phone}`,
  299. })
  300. }
  301. else{
  302. wx.showModal({
  303. title: '提示',
  304. content: '请先点击登录',
  305. showCancel:false,
  306. success (res) {
  307. if (res.confirm) {
  308. }
  309. }
  310. })
  311. }
  312. }
  313. })