index.js 19 KB

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