123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- // nova-werun/pages/my/my-profile/index.js
- const Parse = getApp().Parse;
- const company = getApp().globalData.company;
- const uid = Parse.User.current()?.id
- const real = require("../../../../utils/real")
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- name: '',
- idcard: '',
- sex: '',
- mobile: '',
- fittingCosts: '', //身高
- center: '', //部门
- showStorePopup: false,
- shop: null,
- shopList: null,
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: async function (options) {
- // await this.getname()
- // await this.getdep()
- // // this.getDepartment()
- // this.getwritedep()
- // this.getUptoken()
- this.refersh()
- },
- async refersh() {
- this.getUserProfile()
- },
- /**打开选择位置 */
- openStore() {
- this.getShop()
- this.setData({
- showStorePopup: true
- })
- },
- /**关闭位置选择 */
- closeStore() {
- this.setData({
- showStorePopup: false
- })
- },
- /**获取可选位置 */
- async getShop() {
- let query = new Parse.Query('Department')
- query.equalTo('company', company)
- query.notEqualTo('isDeleted', true)
- query.equalTo('isEnabled', true)
- let d = await query.find()
- let shopList = d.map(item => item.toJSON())
- this.setData({
- shopList
- })
- },
- /**选择位置 */
- chooseShop(e) {
- let {
- shopList,
- } = this.data
- let {
- index
- } = e.currentTarget.dataset
- console.log(shopList[index])
- this.setData({
- shop: shopList[index],
- showStorePopup: false
- })
- },
- /**获取当前用户和身份 */
- async getUserProfile() {
- let profile
- let query = new Parse.Query('Profile')
- query.notEqualTo("isDeleted", true)
- query.equalTo('user', uid)
- query.include('center')
- profile = await query.first()
- if (!profile?.id) {
- let Pro = Parse.Object.extend('Profile')
- profile = new Pro()
- } else {
- this.setData({
- name: profile.get('name') || '',
- idcard: profile.get('idcard') || '',
- sex: profile.get('sex') || '',
- mobile: profile.get('mobile') || '',
- fittingCosts: profile.get('fittingCosts') || '',
- center: profile.get('center') || '',
- shop: profile.get('center')?.toJSON()
- })
- }
- this.setData({
- profile
- })
- },
- onChangeSex(event) {
- this.setData({
- sex: event.detail,
- });
- },
- /** 立即预约*/
- async enlists(e) {
- let {
- name,
- idcard,
- sex,
- mobile,
- fittingCosts,
- center,
- } = this.data
- console.log(name,
- idcard,
- sex,
- mobile,
- fittingCosts, )
- if (!name || !idcard || !sex || !fittingCosts || !mobile) {
- wx.showToast({
- title: '存在未填项',
- icon: 'none',
- duration: 5000
- })
- return
- }
- if (!real.IdentityCodeValid(idcard)) {
- wx.showToast({
- title: '身份证格式错误',
- icon: 'none',
- });
- return
- }
- if (!real.isPoneAvailable(mobile)) {
- wx.showToast({
- title: '手机号有误',
- icon: 'none',
- });
- return
- }
- let {
- shop
- } = this.data
- if (!shop?.objectId) {
- wx.showToast({
- title: '请选择位置',
- icon: 'none',
- duration: 5000
- })
- return
- }
- let {
- profile,
- } = this.data
- profile.set('name', name || '')
- profile.set('mobile', mobile || '')
- profile.set('sex', sex || '')
- profile.set('idcard', idcard || '')
- profile.set('fittingCosts', parseFloat(fittingCosts || '0') || 0)
- profile.set('company', {
- className: 'Company',
- __type: 'Pointer',
- objectId: company
- })
- profile.set('user', {
- className: '_User',
- __type: 'Pointer',
- objectId: uid
- })
- profile.set('center', {
- className: 'Department',
- __type: 'Pointer',
- objectId: shop?.objectId
- })
- // profile.set('isCheck', false)
- let proSave = await profile.save()
- wx.showToast({
- title: '已提交',
- icon: 'none'
- })
- wx.navigateBack({
- delta: 1
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- },
- })
|