index.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. // nova-werun/pages/my/my-profile/index.js
  2. const Parse = getApp().Parse;
  3. const company = getApp().globalData.company;
  4. const uid = Parse.User.current()?.id
  5. const real = require("../../../../utils/real")
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. name: '',
  12. idcard: '',
  13. sex: '',
  14. mobile: '',
  15. fittingCosts: '', //身高
  16. center: '', //部门
  17. showStorePopup: false,
  18. shop: null,
  19. shopList: null,
  20. },
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onLoad: async function (options) {
  25. // await this.getname()
  26. // await this.getdep()
  27. // // this.getDepartment()
  28. // this.getwritedep()
  29. // this.getUptoken()
  30. this.refersh()
  31. },
  32. async refersh() {
  33. this.getUserProfile()
  34. },
  35. /**打开选择位置 */
  36. openStore() {
  37. this.getShop()
  38. this.setData({
  39. showStorePopup: true
  40. })
  41. },
  42. /**关闭位置选择 */
  43. closeStore() {
  44. this.setData({
  45. showStorePopup: false
  46. })
  47. },
  48. /**获取可选位置 */
  49. async getShop() {
  50. let query = new Parse.Query('Department')
  51. query.equalTo('company', company)
  52. query.notEqualTo('isDeleted', true)
  53. query.equalTo('isEnabled', true)
  54. let d = await query.find()
  55. let shopList = d.map(item => item.toJSON())
  56. this.setData({
  57. shopList
  58. })
  59. },
  60. /**选择位置 */
  61. chooseShop(e) {
  62. let {
  63. shopList,
  64. } = this.data
  65. let {
  66. index
  67. } = e.currentTarget.dataset
  68. console.log(shopList[index])
  69. this.setData({
  70. shop: shopList[index],
  71. showStorePopup: false
  72. })
  73. },
  74. /**获取当前用户和身份 */
  75. async getUserProfile() {
  76. let profile
  77. let query = new Parse.Query('Profile')
  78. query.notEqualTo("isDeleted", true)
  79. query.equalTo('user', uid)
  80. query.include('center')
  81. profile = await query.first()
  82. if (!profile?.id) {
  83. let Pro = Parse.Object.extend('Profile')
  84. profile = new Pro()
  85. } else {
  86. this.setData({
  87. name: profile.get('name') || '',
  88. idcard: profile.get('idcard') || '',
  89. sex: profile.get('sex') || '',
  90. mobile: profile.get('mobile') || '',
  91. fittingCosts: profile.get('fittingCosts') || '',
  92. center: profile.get('center') || '',
  93. shop: profile.get('center')?.toJSON()
  94. })
  95. }
  96. this.setData({
  97. profile
  98. })
  99. },
  100. onChangeSex(event) {
  101. this.setData({
  102. sex: event.detail,
  103. });
  104. },
  105. /** 立即预约*/
  106. async enlists(e) {
  107. let {
  108. name,
  109. idcard,
  110. sex,
  111. mobile,
  112. fittingCosts,
  113. center,
  114. } = this.data
  115. console.log(name,
  116. idcard,
  117. sex,
  118. mobile,
  119. fittingCosts, )
  120. if (!name || !idcard || !sex || !fittingCosts || !mobile) {
  121. wx.showToast({
  122. title: '存在未填项',
  123. icon: 'none',
  124. duration: 5000
  125. })
  126. return
  127. }
  128. if (!real.IdentityCodeValid(idcard)) {
  129. wx.showToast({
  130. title: '身份证格式错误',
  131. icon: 'none',
  132. });
  133. return
  134. }
  135. if (!real.isPoneAvailable(mobile)) {
  136. wx.showToast({
  137. title: '手机号有误',
  138. icon: 'none',
  139. });
  140. return
  141. }
  142. let {
  143. shop
  144. } = this.data
  145. if (!shop?.objectId) {
  146. wx.showToast({
  147. title: '请选择位置',
  148. icon: 'none',
  149. duration: 5000
  150. })
  151. return
  152. }
  153. let {
  154. profile,
  155. } = this.data
  156. profile.set('name', name || '')
  157. profile.set('mobile', mobile || '')
  158. profile.set('sex', sex || '')
  159. profile.set('idcard', idcard || '')
  160. profile.set('fittingCosts', parseFloat(fittingCosts || '0') || 0)
  161. profile.set('company', {
  162. className: 'Company',
  163. __type: 'Pointer',
  164. objectId: company
  165. })
  166. profile.set('user', {
  167. className: '_User',
  168. __type: 'Pointer',
  169. objectId: uid
  170. })
  171. profile.set('center', {
  172. className: 'Department',
  173. __type: 'Pointer',
  174. objectId: shop?.objectId
  175. })
  176. // profile.set('isCheck', false)
  177. let proSave = await profile.save()
  178. wx.showToast({
  179. title: '已提交',
  180. icon: 'none'
  181. })
  182. wx.navigateBack({
  183. delta: 1
  184. })
  185. },
  186. /**
  187. * 生命周期函数--监听页面初次渲染完成
  188. */
  189. onReady: function () {
  190. },
  191. /**
  192. * 生命周期函数--监听页面显示
  193. */
  194. onShow: function () {
  195. },
  196. /**
  197. * 生命周期函数--监听页面隐藏
  198. */
  199. onHide: function () {
  200. },
  201. /**
  202. * 生命周期函数--监听页面卸载
  203. */
  204. onUnload: function () {
  205. },
  206. /**
  207. * 页面相关事件处理函数--监听用户下拉动作
  208. */
  209. onPullDownRefresh: function () {
  210. },
  211. /**
  212. * 页面上拉触底事件的处理函数
  213. */
  214. onReachBottom: function () {
  215. },
  216. /**
  217. * 用户点击右上角分享
  218. */
  219. onShareAppMessage: function () {
  220. },
  221. })