123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428 |
- // nova-werun/pages/my/my-profile/index.js
- const Parse = getApp().Parse;
- const company = getApp().globalData.company;
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- //屏幕高度
- statusBarHeight: 0, // 状态栏高度
- screenHeight: 0, // 屏幕高度
- customHeight: 0, // 自定义导航栏高度(如小程序右上角胶囊按钮)
- bottomNavHeight: 0, // 底部导航栏高度
- contentHeight: 0, // 可用内容高度
- contentpadding: 0, //顶部padding高度
- User1List: [],
- actions: [{
- name: '男',
- },
- {
- name: '女',
- },
- ],
- avatar: null,
- sex: '男',
- nickname: null,
- height: null,
- // 选择部门
- mainActiveIndex: 0,
- activeId: null,
- items: [],
- //显示遮罩层
- show: false,
- selectname: '',
- selectobjectid: '',
- upiobjectid: '',
- // 图片
- fileList: [],
- uptokenURL: '',
- domain: '',
- uploadURL: '',
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- // 计算
- const systemInfo = wx.getSystemInfoSync();
- const statusBarHeight = systemInfo.statusBarHeight || 0;
- const screenHeight = systemInfo.screenHeight || 0;
- const custom = wx.getMenuButtonBoundingClientRect();
- const customHeight = custom.height + 10 + 2 || 0;
- const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
- const contentpadding = (statusBarHeight + customHeight) * 750 / systemInfo.windowWidth;
- const contentHeight = (screenHeight - bottomNavHeight - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
- this.setData({
- statusBarHeight,
- screenHeight,
- customHeight,
- bottomNavHeight,
- contentHeight,
- contentpadding
- });
- this.getname()
- this.getdep()
- this.getDepartment()
- this.getUptoken()
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- },
- //获取身高
- getHeight(e) {
- let height = e.detail.value;
- // 身高范围在 50 到 250 之间的正则表达式,允许浮点数
- let a = /^(?:[5-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|250)(\.\d)?$/;
- if (!height.match(a)) {
- wx.showToast({
- icon: "none",
- title: "请填写正确的身高格式",
- });
- return;
- } else {
- this.setData({
- height: height
- });
- console.log(this.data.height);
- }
- },
- //点击清空
- clearHeight() {
- this.setData({
- height: null
- })
- console.log('清空', this.data.height);
- },
- //获取头像名称
- async getname() {
- const currentUser = Parse.User.current();
- let Userquery = new Parse.Query('_User');
- Userquery.equalTo('company', company);
- Userquery.equalTo('objectId', currentUser.id);
- Userquery.notEqualTo('isDeleted', true)
- let P2 = await Userquery.find();
- let User1List = P2.map(item => item.toJSON());
- this.setData({
- User1List
- })
- this.setData({
- avatar: User1List[0].avatar,
- nickname: User1List[0].nickname,
- sex: User1List[0].sex || '男',
- })
- console.log(this.data.User1List);
- },
- //获取部门
- async getdep() {
- const currentUser = Parse.User.current();
- let Userquery = new Parse.Query('Profile');
- Userquery.equalTo('company', company);
- Userquery.equalTo('user', currentUser.id);
- // Userquery.equalTo('isCheck', true);
- Userquery.notEqualTo('isDeleted', true)
- Userquery.include('center');
- let P2 = await Userquery.find();
- let dep = P2.map(item => item.toJSON());
- if (dep) {
- if (dep[0].isCheck == true) {
- this.setData({
- selectname: dep[0].center.name,
- selectobjectid: dep[0].center.objectId,
- upiobjectid: dep[0].department.objectId
- })
- } else {
- wx.showToast({
- title: '您之前提交信息在审核当中',
- icon: 'none',
- duration: 2000
- })
- }
- }
- console.log('getdep', dep);
- },
- onSelect(event) {
- let {
- name
- } = event.detail
- this.setData({
- sex: name,
- show2: false
- })
- console.log(this.data.sex);
- },
- showSelect() {
- this.setData({
- show2: true
- })
- },
- //修改名字
- changenickname(e) {
- this.setData({
- nickname: e.detail
- })
- console.log(this.data.nickname);
- },
- //上传信息
- async setinfo() {
- if (!this.data.nickname || !this.data.sex || !this.data.selectobjectid || !this.data.avatar) {
- wx.showToast({
- title: '请输入相关内容',
- icon: 'none',
- duration: 2000
- })
- return
- }
- const currentUser = Parse.User.current();
- let Userquery = new Parse.Query('_User');
- Userquery.equalTo('company', company);
- Userquery.equalTo('objectId', currentUser.id);
- Userquery.notEqualTo('isDeleted', true)
- let user = await Userquery.first();
- user.set('sex', this.data.sex)
- user.set('avatar', this.data.avatar)
- user.set('nickname', this.data.nickname)
- try {
- user.save()
- console.log('昵称保存成功');
- } catch {
- console.log('保存失败');
- }
- let Profilerquery = new Parse.Query('Profile');
- Profilerquery.equalTo('company', company);
- Profilerquery.equalTo('user', currentUser.id);
- Profilerquery.notEqualTo('isDeleted', true)
- let Profile = await Profilerquery.first();
- //工会
- let Departmentquery = new Parse.Query('Department');
- Departmentquery.equalTo('company', company);
- Departmentquery.equalTo('objectId', this.data.upiobjectid);
- Departmentquery.notEqualTo('isDeleted', true)
- let Department = await Departmentquery.first();
- //部门
- let unionquery = new Parse.Query('Department');
- unionquery.equalTo('company', company);
- unionquery.equalTo('objectId', this.data.selectobjectid);
- unionquery.notEqualTo('isDeleted', true)
- let union = await unionquery.first();
- if (Profile) {
- Profile.set('department', Department.toPointer())
- Profile.set('center', union.toPointer())
- try {
- Profile.save()
- wx.showToast({
- title: '提交成功',
- icon: 'success',
- duration: 2000
- })
- console.log('部门保存成功');
- } catch {
- console.log('部门保存失败');
- }
- } else {
- const currentUser = Parse.User.current();
- let Userquery = new Parse.Query('_User');
- Userquery.equalTo('company', company);
- Userquery.equalTo('objectId', currentUser.id);
- Userquery.notEqualTo('isDeleted', true)
- let P2 = await Userquery.first();
- let companyPointer = Parse.Object.extend('Company').createWithoutData(company);
- console.log(companyPointer);
- let Profile = new Parse.Object('Profile');
- Profile.set('company', companyPointer);
- Profile.set('isCheck', false);
- Profile.set('user', P2.toPointer());
- Profile.set('department', Department.toPointer());
- Profile.set('center', union.toPointer());
- try {
- Profile.save()
- console.log('部门保存成功');
- } catch {
- console.log('部门保存失败');
- }
- }
- },
- // 获取部门信息
- async getDepartment() {
- const currentUser = Parse.User.current();
- let Userquery = new Parse.Query('Department');
- Userquery.equalTo('company', company); // 假设 company 是你要查询的公司对象
- Userquery.equalTo('isEnabled', true);
- Userquery.notEqualTo('isDeleted', true);
- Userquery.include('parent');
- let P2 = await Userquery.find();
- let Departmentlist = P2.map(item => item.toJSON());
- // 创建一个以工会为键的对象,以便于匹配
- const unionsMap = {};
- console.log(Departmentlist);
- // 遍历部门列表,构建工会映射
- Departmentlist.forEach(department => {
- //有工会的部门
- if (department.parent && department.parent.objectId) {
- const unionId = department.parent.objectId; //工会id
- // 如果工会还没有在映射中,创建一个新的工会对象
- if (!unionsMap[unionId]) {
- unionsMap[unionId] = {
- text: department.parent.name, // 工会名称
- objectId: department.parent.objectId,
- children: [] // 初始化子部门数组
- };
- }
- // 将部门添加到对应的工会子项中
- unionsMap[unionId].children.push({
- text: department.name, // 部门名称
- id: department.objectId, // 部门 ID
- upid: department.parent.objectId
- });
- } else {
- if (!unionsMap[department.objectId]) {
- unionsMap[department.objectId] = {
- text: department.name, // 工会名称
- objectId: department.objectId,
- children: [] // 初始化子部门数组
- };
- }
- }
- });
- // 将映射转换为数组
- const result = Object.values(unionsMap);
- console.log(result);
- this.setData({
- items: result
- })
- },
- //点击工会
- onClickNav({
- detail = {}
- }) {
- this.setData({
- mainActiveIndex: detail.index || 0,
- });
- console.log(detail);
- },
- //点击部门
- onClickItem({
- detail = {}
- }) {
- const activeId = this.data.activeId === detail.id ? null : detail.id;
- this.setData({
- activeId,
- selectname: detail.text,
- selectobjectid: detail.id,
- upiobjectid: detail.upid
- });
- this.onClickHide()
- console.log(detail);
- },
- //显示遮罩层
- onClickShow() {
- this.setData({
- show: true
- });
- },
- //关闭遮罩层
- onClickHide() {
- this.setData({
- show: false
- });
- },
- //返回上一页
- goback() {
- wx.navigateBack({
- delta: 1 // 返回上一页
- });
- },
- //删除头像
- deleteavater() {
- this.setData({
- avatar: ''
- })
- },
- async getUptoken() {
- let res = await Parse.Cloud.run('qiniu_uptoken', {
- company: company
- })
- this.setData({
- uptokenURL: res.uptoken,
- domain: res.domain,
- uploadURL: res.zoneUrl
- })
- console.log(this.data.uptokenURL, this.data.domain, this.data.uploadURL);
- },
- //本地上传头像
- picture(event) {
- console.log('event', event);
- let FileList = event.detail
- let url = []
- for (let i = 0; i < FileList.length; i++) {
- url.push(FileList[i].url)
- }
- this.setData({
- fileList: url
- })
- this.setData({
- avatar:this.data.fileList[0]
- })
- console.log('图片', this.data.fileList);
- },
- })
|