index.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. // nova-werun/pages/my/my-profile/index.js
  2. const Parse = getApp().Parse;
  3. const company = getApp().globalData.company;
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. //屏幕高度
  10. statusBarHeight: 0, // 状态栏高度
  11. screenHeight: 0, // 屏幕高度
  12. customHeight: 0, // 自定义导航栏高度(如小程序右上角胶囊按钮)
  13. bottomNavHeight: 0, // 底部导航栏高度
  14. contentHeight: 0, // 可用内容高度
  15. contentpadding: 0, //顶部padding高度
  16. User1List: [],
  17. actions: [{
  18. name: '男',
  19. },
  20. {
  21. name: '女',
  22. },
  23. ],
  24. avatar: null,
  25. sex: '男',
  26. nickname: null,
  27. height: null,
  28. // 选择部门
  29. // mainActiveIndex: 0,
  30. // activeId: null,
  31. // items: [],
  32. Departmentlist:[],
  33. departs:['1','2','3'],
  34. //显示遮罩层
  35. show: false,
  36. selectname: '', //部门名字
  37. departname: '', //工会名字
  38. selectobjectid: '',
  39. upiobjectid: '',
  40. // 图片
  41. fileList: [],
  42. uptokenURL: '',
  43. domain: '',
  44. uploadURL: '',
  45. title: '',
  46. //
  47. name: '',
  48. phone: '',
  49. },
  50. /**
  51. * 生命周期函数--监听页面加载
  52. */
  53. onLoad: function (options) {
  54. // 计算
  55. const systemInfo = wx.getSystemInfoSync();
  56. const statusBarHeight = systemInfo.statusBarHeight || 0;
  57. const screenHeight = systemInfo.screenHeight || 0;
  58. const custom = wx.getMenuButtonBoundingClientRect();
  59. const customHeight = custom.height + 10 + 2 || 0;
  60. const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
  61. const contentpadding = (statusBarHeight + customHeight) * 750 / systemInfo.windowWidth;
  62. const contentHeight = (screenHeight - bottomNavHeight - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
  63. this.setData({
  64. statusBarHeight,
  65. screenHeight,
  66. customHeight,
  67. bottomNavHeight,
  68. contentHeight,
  69. contentpadding
  70. });
  71. this.setData({
  72. title: options.type
  73. })
  74. this.getname()
  75. this.getdep()
  76. // this.getDepartment()
  77. this.getwritedep()
  78. this.getUptoken()
  79. },
  80. /**
  81. * 生命周期函数--监听页面初次渲染完成
  82. */
  83. onReady: function () {
  84. },
  85. /**
  86. * 生命周期函数--监听页面显示
  87. */
  88. onShow: function () {
  89. },
  90. /**
  91. * 生命周期函数--监听页面隐藏
  92. */
  93. onHide: function () {
  94. },
  95. /**
  96. * 生命周期函数--监听页面卸载
  97. */
  98. onUnload: function () {
  99. },
  100. /**
  101. * 页面相关事件处理函数--监听用户下拉动作
  102. */
  103. onPullDownRefresh: function () {
  104. },
  105. /**
  106. * 页面上拉触底事件的处理函数
  107. */
  108. onReachBottom: function () {
  109. },
  110. /**
  111. * 用户点击右上角分享
  112. */
  113. onShareAppMessage: function () {
  114. },
  115. //获取身高
  116. getHeight(e) {
  117. let height = e.detail.value;
  118. // 身高范围在 50 到 250 之间的正则表达式,允许浮点数
  119. let a = /^(?:[5-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|250)(\.\d)?$/;
  120. if (!height.match(a)) {
  121. wx.showToast({
  122. icon: "none",
  123. title: "请填写正确的身高格式",
  124. });
  125. return;
  126. } else {
  127. this.setData({
  128. height: height
  129. });
  130. console.log(this.data.height);
  131. }
  132. },
  133. //点击清空
  134. clearHeight() {
  135. this.setData({
  136. height: null
  137. })
  138. console.log('清空', this.data.height);
  139. },
  140. //获取头像名称
  141. async getname() {
  142. const currentUser = Parse.User.current();
  143. let Userquery = new Parse.Query('_User');
  144. Userquery.equalTo('company', company);
  145. Userquery.equalTo('objectId', currentUser.id);
  146. Userquery.notEqualTo('isDeleted', true)
  147. let P2 = await Userquery.find();
  148. let User1List = P2.map(item => item.toJSON());
  149. this.setData({
  150. User1List
  151. })
  152. this.setData({
  153. avatar: User1List[0].avatar || 'https://file-cloud.fmode.cn/qpFbRRSZrO/20241120/95uip6030022742.png?imageView2/1/w/200/h/200',
  154. nickname: User1List[0].nickname || '微信用户',
  155. sex: User1List[0].sex || '男',
  156. })
  157. if (User1List[0].diyform) {
  158. this.setData({
  159. height: User1List[0].diyform.height
  160. })
  161. }
  162. console.log(this.data.User1List);
  163. },
  164. //获取填写部门信息
  165. async getwritedep() {
  166. let Userquery = new Parse.Query('Department');
  167. Userquery.equalTo('company', company);
  168. Userquery.equalTo('isEnabled', true);
  169. // Userquery.equalTo('type', 'center');
  170. Userquery.notEqualTo('isDeleted', true);
  171. // Userquery.include('parent');
  172. let P2 = await Userquery.find();
  173. let Departmentlist = P2.map(item => item.toJSON());
  174. let departs=[]
  175. Departmentlist.forEach((item)=>{
  176. departs.push(item.name)
  177. })
  178. this.setData({
  179. departs,
  180. Departmentlist,
  181. })
  182. console.log('departs',this.data.Departmentlist);
  183. },
  184. //获取部门
  185. async getdep() {
  186. const currentUser = Parse.User.current();
  187. let Userquery = new Parse.Query('Profile');
  188. Userquery.equalTo('company', company);
  189. Userquery.equalTo('user', currentUser.id);
  190. // Userquery.equalTo('isCheck', true);
  191. Userquery.notEqualTo('isDeleted', true)
  192. Userquery.include('center');
  193. Userquery.include('department');
  194. let P2 = await Userquery.find();
  195. let dep = P2.map(item => item.toJSON());
  196. if (dep) {
  197. if (dep[0].isCheck == true) {
  198. this.setData({
  199. name: dep[0].name,
  200. phone: dep[0].mobile,
  201. // departname: dep[0].department.name,//工会
  202. selectname: dep[0].center.name,//部门
  203. selectobjectid: dep[0].center.objectId,//部门
  204. // upiobjectid: dep[0].department.objectId//工会
  205. })
  206. } else {
  207. this.setData({
  208. name: dep[0].name,
  209. phone: dep[0].mobile,
  210. // departname: dep[0].department.name,
  211. selectname: dep[0].center.name,
  212. selectobjectid: dep[0].center.objectId,
  213. // upiobjectid: dep[0].department.objectId
  214. })
  215. wx.showToast({
  216. title: '您之前提交信息在审核当中',
  217. icon: 'none',
  218. duration: 2000
  219. })
  220. }
  221. }
  222. console.log('getdep', dep);
  223. },
  224. onSelect(event) {
  225. let {
  226. name
  227. } = event.detail
  228. this.setData({
  229. sex: name,
  230. show2: false
  231. })
  232. console.log(this.data.sex);
  233. },
  234. showSelect() {
  235. this.setData({
  236. show2: true
  237. })
  238. },
  239. //修改昵称
  240. changenickname(e) {
  241. this.setData({
  242. nickname: e.detail
  243. })
  244. console.log(this.data.nickname);
  245. },
  246. //上传信息
  247. async setinfo() {
  248. if (this.data.title == '资料认证') {
  249. if (!this.data.name || !this.data.sex || !this.data.selectobjectid || !this.data.height || !this.data.phone) {
  250. wx.showToast({
  251. title: '请输入相关内容',
  252. icon: 'none',
  253. duration: 2000
  254. })
  255. return
  256. }
  257. const currentUser = Parse.User.current();
  258. let Userquery = new Parse.Query('_User');
  259. Userquery.equalTo('company', company);
  260. Userquery.equalTo('objectId', currentUser.id);
  261. Userquery.notEqualTo('isDeleted', true)
  262. let user = await Userquery.first();
  263. user.set('sex', this.data.sex)
  264. // user.set('avatar', this.data.avatar)
  265. let diyform = {
  266. height: this.data.height
  267. }
  268. user.set('diyform', diyform)
  269. // user.set('nickname', this.data.nickname)
  270. try {
  271. user.save()
  272. console.log('昵称保存成功');
  273. } catch {
  274. console.log('保存失败');
  275. }
  276. let Profilerquery = new Parse.Query('Profile');
  277. Profilerquery.equalTo('company', company);
  278. Profilerquery.equalTo('user', currentUser.id);
  279. Profilerquery.notEqualTo('isDeleted', true)
  280. let Profile = await Profilerquery.first();
  281. //工会
  282. // let Departmentquery = new Parse.Query('Department');
  283. // Departmentquery.equalTo('company', company);
  284. // Departmentquery.equalTo('objectId', this.data.upiobjectid);
  285. // Departmentquery.notEqualTo('isDeleted', true)
  286. // let Department = await Departmentquery.first();
  287. //部门
  288. let unionquery = new Parse.Query('Department');
  289. unionquery.equalTo('company', company);
  290. unionquery.equalTo('objectId', this.data.selectobjectid);
  291. unionquery.notEqualTo('isDeleted', true)
  292. let union = await unionquery.first();
  293. if (Profile) {
  294. // Profile.set('department', Department.toPointer())
  295. Profile.set('center', union.toPointer())
  296. Profile.set('name', this.data.name)
  297. Profile.set('mobile', this.data.phone)
  298. try {
  299. Profile.save()
  300. wx.showToast({
  301. title: '提交成功',
  302. icon: 'success',
  303. duration: 2000
  304. })
  305. setTimeout(() => {
  306. this.goback()
  307. }, 2000);
  308. console.log('部门保存成功');
  309. } catch {
  310. console.log('部门保存失败');
  311. }
  312. } else {
  313. const currentUser = Parse.User.current();
  314. let Userquery = new Parse.Query('_User');
  315. Userquery.equalTo('company', company);
  316. Userquery.equalTo('objectId', currentUser.id);
  317. Userquery.notEqualTo('isDeleted', true)
  318. let P2 = await Userquery.first();
  319. let companyPointer = Parse.Object.extend('Company').createWithoutData(company);
  320. console.log(companyPointer);
  321. let Profile = new Parse.Object('Profile');
  322. Profile.set('company', companyPointer);
  323. Profile.set('isCheck', false);
  324. Profile.set('user', P2.toPointer());
  325. // Profile.set('department', Department.toPointer());
  326. Profile.set('center', union.toPointer());
  327. Profile.set('name', this.data.name)
  328. Profile.set('mobile', this.data.phone)
  329. try {
  330. Profile.save()
  331. wx.showToast({
  332. title: '提交成功',
  333. icon: 'success',
  334. duration: 2000
  335. })
  336. setTimeout(() => {
  337. this.goback()
  338. }, 2000);
  339. console.log('部门保存成功');
  340. } catch {
  341. console.log('部门保存失败');
  342. }
  343. }
  344. }
  345. if (this.data.title == '完善资料') {
  346. if (!this.data.avatar || !this.data.nickname) {
  347. wx.showToast({
  348. title: '请输入相关内容',
  349. icon: 'none',
  350. duration: 2000
  351. })
  352. return
  353. }
  354. const currentUser = Parse.User.current();
  355. let Userquery = new Parse.Query('_User');
  356. Userquery.equalTo('company', company);
  357. Userquery.equalTo('objectId', currentUser.id);
  358. Userquery.notEqualTo('isDeleted', true)
  359. let user = await Userquery.first();
  360. user.set('avatar', this.data.avatar)
  361. user.set('nickname', this.data.nickname)
  362. try {
  363. user.save()
  364. wx.showToast({
  365. title: '提交成功',
  366. icon: 'success',
  367. duration: 2000
  368. })
  369. setTimeout(() => {
  370. this.goback()
  371. }, 2000);
  372. } catch {
  373. console.log('保存失败');
  374. }
  375. }
  376. },
  377. // 获取部门信息
  378. // async getDepartment() {
  379. // const currentUser = Parse.User.current();
  380. // let Userquery = new Parse.Query('Department');
  381. // Userquery.equalTo('company', company); // 假设 company 是你要查询的公司对象
  382. // Userquery.equalTo('isEnabled', true);
  383. // Userquery.notEqualTo('isDeleted', true);
  384. // Userquery.include('parent');
  385. // let P2 = await Userquery.find();
  386. // let Departmentlist = P2.map(item => item.toJSON());
  387. // // 创建一个以工会为键的对象,以便于匹配
  388. // const unionsMap = {};
  389. // console.log(Departmentlist);
  390. // // 遍历部门列表,构建工会映射
  391. // Departmentlist.forEach(department => {
  392. // //有工会的部门
  393. // if (department.parent && department.parent.objectId) {
  394. // const unionId = department.parent.objectId; //工会id
  395. // // 如果工会还没有在映射中,创建一个新的工会对象
  396. // if (!unionsMap[unionId]) {
  397. // unionsMap[unionId] = {
  398. // text: department.parent.name, // 工会名称
  399. // objectId: department.parent.objectId,
  400. // children: [] // 初始化子部门数组
  401. // };
  402. // }
  403. // // 将部门添加到对应的工会子项中
  404. // unionsMap[unionId].children.push({
  405. // text: department.name, // 部门名称
  406. // id: department.objectId, // 部门 ID
  407. // upid: department.parent.objectId
  408. // });
  409. // } else {
  410. // if (!unionsMap[department.objectId]) {
  411. // unionsMap[department.objectId] = {
  412. // text: department.name, // 工会名称
  413. // objectId: department.objectId,
  414. // children: [] // 初始化子部门数组
  415. // };
  416. // }
  417. // }
  418. // });
  419. // // 将映射转换为数组
  420. // const result = Object.values(unionsMap);
  421. // console.log(result);
  422. // this.setData({
  423. // items: result
  424. // })
  425. // console.log(this.data.items);
  426. // },
  427. //点击工会
  428. // onClickNav({
  429. // detail = {}
  430. // }) {
  431. // this.setData({
  432. // mainActiveIndex: detail.index || 0,
  433. // });
  434. // console.log(detail);
  435. // },
  436. //点击部门
  437. onClickItem(
  438. {
  439. detail = {}
  440. }
  441. ) {
  442. // const activeId = this.data.activeId === detail.id ? null : detail.id;
  443. // this.data.items.forEach((item) => {
  444. // if (item.objectId == detail.upid) {
  445. // this.setData({
  446. // departname: item.text
  447. // })
  448. // }
  449. // })
  450. const id = this.data.Departmentlist[detail.index].objectId
  451. this.setData({
  452. // activeId,
  453. selectname: detail.value,
  454. selectobjectid:id
  455. // selectobjectid: detail.id,
  456. // upiobjectid: detail.upid
  457. });
  458. this.onClickHide()
  459. console.log(this.data.selectobjectid);
  460. },
  461. //显示遮罩层
  462. onClickShow() {
  463. this.setData({
  464. show: true
  465. });
  466. },
  467. //关闭遮罩层
  468. onClickHide() {
  469. this.setData({
  470. show: false
  471. });
  472. },
  473. //返回上一页
  474. async goback() {
  475. let pages = getCurrentPages(); //页面对象
  476. let prevpage = pages[pages.length - 2]; //上一个页面对象
  477. console.log(prevpage);
  478. await prevpage.updateCom3()
  479. wx.navigateBack({
  480. delta: 1 // 返回上一页
  481. });
  482. },
  483. //删除头像
  484. deleteavater() {
  485. this.setData({
  486. avatar: ''
  487. })
  488. },
  489. async getUptoken() {
  490. let res = await Parse.Cloud.run('qiniu_uptoken', {
  491. company: company
  492. })
  493. this.setData({
  494. uptokenURL: res.uptoken,
  495. domain: res.domain,
  496. uploadURL: res.zoneUrl
  497. })
  498. console.log(this.data.uptokenURL, this.data.domain, this.data.uploadURL);
  499. },
  500. //本地上传头像
  501. picture(event) {
  502. console.log('event', event);
  503. let FileList = event.detail
  504. let url = []
  505. for (let i = 0; i < FileList.length; i++) {
  506. url.push(FileList[i].url)
  507. }
  508. this.setData({
  509. fileList: url
  510. })
  511. this.setData({
  512. avatar: this.data.fileList[0]
  513. })
  514. console.log('图片', this.data.fileList);
  515. },
  516. //修改姓名
  517. changename(e) {
  518. this.setData({
  519. name: e.detail
  520. })
  521. console.log(this.data.name);
  522. },
  523. //修改电话
  524. changephone(e) {
  525. const mobileNumber = e.detail.value; // 假设手机号是通过 e.detail.value 传递的
  526. console.log(mobileNumber);
  527. // 正则表达式:匹配中国大陆手机号
  528. const mobilePattern = /^1[3-9]\d{9}$/;
  529. // 验证手机号格式
  530. if (mobilePattern.test(mobileNumber)) {
  531. this.setData({
  532. phone: mobileNumber
  533. })
  534. console.log("手机号格式正确");
  535. // 这里可以执行其他操作,比如保存手机号或进行下一步操作
  536. } else {
  537. wx.showToast({
  538. title: '手机号格式不正确',
  539. icon: 'none',
  540. })
  541. console.log("手机号格式不正确");
  542. // 这里可以提示用户手机号格式不正确
  543. }
  544. console.log(this.data.phone);
  545. }
  546. })