index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. const app = getApp();
  2. const api = app.api;
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. isChinesePeople: true,
  9. statusOptions: [
  10. {id: '0', value: '藏家 Collector'},
  11. {id: '1', value: '艺术行业 Art Professional'},
  12. {id: '2', value: '院校师生 Academic'},
  13. {id: '3', value: '媒体 Media'},
  14. {id: '4', value: '合作方 Partner'},
  15. {id: '5', value: '其他 Other '}
  16. ],
  17. idTypeOptions: [
  18. {id: '0', value: '身份证 ID Card'},
  19. {id: '1', value: '护照 Passport'},
  20. {id: '2', value: '回乡证 Home Return Certificate'},
  21. {id: '3', value: '台胞证 MTP'}
  22. ],
  23. countryOptions: [
  24. {id: '0', value: '中国 China'},
  25. {id: '1', value: '外籍 Foreigners'}
  26. ],
  27. genderOptions: [
  28. {id: '0', value: '男 Male'},
  29. {id: '1', value: '女 Female'},
  30. {id: '2', value: '其他 Other'}
  31. ],
  32. isSign: false, // 已核验
  33. navigatePageCode: '', // 请求来源页编号
  34. dataForm: {
  35. id: '',
  36. status: '0',
  37. statusOther: '',
  38. realName: '',
  39. idType: '0',
  40. idNumber: '',
  41. country: '0',
  42. liveCity: ['北京市', '北京市', '东城区'],
  43. liveCityNotChina: '',
  44. gender: '0',
  45. emailAddress: '',
  46. company: '',
  47. position: ''
  48. }
  49. },
  50. /**
  51. * 选择身份
  52. * @param {*} event
  53. */
  54. changeStatusOptions: function (event) {
  55. const self = this;
  56. const value = parseInt(event.detail.value);
  57. self.setData({
  58. ['dataForm.status']: value
  59. });
  60. if (self.data.dataForm.statusOther === 5 && value !== 5) {
  61. self.setData({
  62. ['dataForm.statusOther']: ''
  63. });
  64. }
  65. },
  66. /**
  67. * 选择证件类型
  68. * @param {*} event
  69. */
  70. changeIdTypeOptions: function (event) {
  71. const self = this;
  72. self.setData({
  73. ['dataForm.idType']: event.detail.value
  74. });
  75. },
  76. /**
  77. * 选择国家
  78. * @param {*} event
  79. */
  80. changeCountryOptions: function (event) {
  81. const self = this;
  82. const value = parseInt(event.detail.value);
  83. const isChinesePeople = value === 1 ? false : true;
  84. // 外籍切换至中国
  85. if (self.data.dataForm.country === 1 && value === 0) {
  86. self.setData({
  87. ['dataForm.liveCity']: ['北京市', '北京市', '东城区'],
  88. ['dataForm.liveCityNotChina']: ''
  89. });
  90. }
  91. // 中国切换至外籍
  92. if (self.data.dataForm.country === 0 && value === 1) {
  93. self.setData({
  94. ['dataForm.liveCity']: [],
  95. ['dataForm.liveCityNotChina']: ''
  96. });
  97. }
  98. self.setData({
  99. ['dataForm.country']: value,
  100. ['isChinesePeople']: isChinesePeople
  101. });
  102. },
  103. /**
  104. * 选择居住城市
  105. * @param {*} event
  106. */
  107. changeLiveCityOptions: function (event) {
  108. const self = this;
  109. self.setData({
  110. ['dataForm.liveCity']: event.detail.value
  111. });
  112. },
  113. /**
  114. * 选择性别
  115. * @param {*} event
  116. */
  117. changeGenderOptions: function (event) {
  118. const self = this;
  119. self.setData({
  120. ['dataForm.gender']: event.detail.value
  121. });
  122. },
  123. /**
  124. * 输入框值变化
  125. * @param {*} event
  126. */
  127. changeInput: function (event) {
  128. const self = this;
  129. const inputType = event.currentTarget.dataset.inputtype;
  130. const value = event.detail.value;
  131. // 身份
  132. if (inputType === 'status') {
  133. self.setData({
  134. ['dataForm.statusOther']: value
  135. });
  136. }
  137. // 真实姓名
  138. if (inputType === 'realName') {
  139. self.setData({
  140. ['dataForm.realName']: value
  141. });
  142. }
  143. // 证件号
  144. if (inputType === 'idNumber') {
  145. self.setData({
  146. ['dataForm.idNumber']: value
  147. });
  148. }
  149. // 居住城市
  150. if (inputType === 'liveCity') {
  151. self.setData({
  152. ['dataForm.liveCityNotChina']: value
  153. });
  154. }
  155. // 邮箱
  156. if (inputType === 'emailAddress') {
  157. self.setData({
  158. ['dataForm.emailAddress']: value
  159. });
  160. }
  161. // 公司
  162. if (inputType === 'company') {
  163. self.setData({
  164. ['dataForm.company']: value
  165. });
  166. }
  167. // 职位
  168. if (inputType === 'position') {
  169. self.setData({
  170. ['dataForm.position']: value
  171. });
  172. }
  173. },
  174. /**
  175. * 提交表单
  176. */
  177. submitDataForm: function () {
  178. const self = this;
  179. if (self.valiator()) {
  180. const dataForm = {
  181. id: self.data.dataForm.id,
  182. roles: self.data.dataForm.status,
  183. roleOther: self.data.dataForm.statusOther,
  184. name: self.data.dataForm.realName,
  185. types: self.data.dataForm.idType,
  186. nums: self.data.dataForm.idNumber,
  187. country: self.data.dataForm.country,
  188. states: self.data.dataForm.liveCityNotChina,
  189. province: parseInt(self.data.dataForm.country) === 0 ? self.data.dataForm.liveCity[0] : '',
  190. city: parseInt(self.data.dataForm.country) === 0 ? self.data.dataForm.liveCity[1] : '',
  191. district: parseInt(self.data.dataForm.country) === 0 ? self.data.dataForm.liveCity[2] : '',
  192. gender: self.data.dataForm.gender,
  193. mail: self.data.dataForm.emailAddress,
  194. company: self.data.dataForm.company,
  195. position: self.data.dataForm.position
  196. }
  197. app.post(dataForm.id === '' ? api.InvitationSave : api.InvitationUpdate, dataForm).then(response => {
  198. if (response.success) {
  199. // 登记
  200. if (dataForm.id === '') {
  201. wx.showToast({
  202. title: '登记成功',
  203. mask: true,
  204. complete: function () {
  205. setTimeout(() => {
  206. wx.redirectTo({
  207. url: '../navigation/index',
  208. })
  209. }, 1500)
  210. }
  211. })
  212. }
  213. // 修改
  214. if (dataForm.id !== '') {
  215. wx.showToast({
  216. title: '修改成功',
  217. mask: true,
  218. complete: function () {
  219. setTimeout(() => {
  220. wx.navigateBack({
  221. delta: 0,
  222. })
  223. }, 1500)
  224. }
  225. })
  226. }
  227. }
  228. }).catch(() => {
  229. wx.showToast({
  230. title: '系统繁忙,请稍后再试',
  231. icon: 'none',
  232. complete: function () {
  233. setTimeout(self.getData, 1500)
  234. }
  235. })
  236. })
  237. }
  238. },
  239. /**
  240. * 查询已登记信息
  241. */
  242. getData() {
  243. const self = this;
  244. app.post(api.InvitationGet, {}).then(response => {
  245. if (response.success) {
  246. self.setData({
  247. ['dataForm.id']: response.data.id,
  248. ['dataForm.status']: response.data.roles,
  249. ['dataForm.statusOther']: response.data.roleOther,
  250. ['dataForm.realName']: response.data.name,
  251. ['dataForm.idType']: response.data.types,
  252. ['dataForm.idNumber']: response.data.nums,
  253. ['dataForm.country']: response.data.country,
  254. ['dataForm.liveCity']: response.data.country === 0 ? [response.data.province, response.data.city, response.data.district] : [],
  255. ['dataForm.liveCityNotChina']: response.data.country === 1 ? response.data.states : '',
  256. ['dataForm.gender']: response.data.gender + '',
  257. ['dataForm.emailAddress']: response.data.mail,
  258. ['dataForm.company']: response.data.company,
  259. ['dataForm.position']: response.data.position
  260. })
  261. // 已核验校验
  262. if (response.data.signTime !== null && response.data.signTime !== '') {
  263. self.setData({
  264. isSign: true
  265. })
  266. }
  267. }
  268. }).catch(() => {
  269. // 若请求来自中转页,且没有查询到登记信息,则关闭此页面
  270. const navigatePageCode = self.data.navigatePageCode
  271. if (navigatePageCode === 'navigation') {
  272. wx.showModal({
  273. content: '没有查询到您的登记信息',
  274. cancelText: '返回',
  275. confirmText: '去登记',
  276. success: function (response) {
  277. if (response.confirm) {
  278. wx.redirectTo({
  279. url: '../index/index',
  280. })
  281. } else {
  282. wx.navigateBack({
  283. delta: 0,
  284. })
  285. }
  286. }
  287. })
  288. }
  289. })
  290. },
  291. /**
  292. * 生命周期函数--监听页面加载
  293. */
  294. onLoad: function (options) {
  295. const self = this
  296. /**
  297. * 请求来源
  298. * protocol 不处理
  299. * navigation 如果没有查询到登记信息则关闭此页面
  300. */
  301. const navigatePageCode = options.pageCode
  302. self.setData({
  303. navigatePageCode: navigatePageCode
  304. })
  305. // 查询已登记信息
  306. self.getData()
  307. // 修改页面标题
  308. wx.setNavigationBarTitle({
  309. title: '个人信息',
  310. })
  311. },
  312. /**
  313. * 表单校验
  314. */
  315. valiator: function () {
  316. const self = this;
  317. if (self.data.dataForm.status === '') {
  318. wx.showToast({
  319. title: '请选择身份/Status',
  320. icon: 'none',
  321. mask: true
  322. });
  323. return false;
  324. } else {
  325. if (parseInt(self.data.dataForm.status) === 5 && self.data.dataForm.statusOther === '') {
  326. wx.showToast({
  327. title: '请填写身份/Status',
  328. icon: 'none',
  329. mask: true
  330. });
  331. return false;
  332. }
  333. }
  334. if (self.data.dataForm.realName === '') {
  335. wx.showToast({
  336. title: '请填写真实姓名/Real Name',
  337. icon: 'none',
  338. mask: true
  339. });
  340. return false;
  341. }
  342. if (self.data.dataForm.idType === '') {
  343. wx.showToast({
  344. title: '请选择证件类型/ID Type',
  345. icon: 'none',
  346. mask: true
  347. });
  348. return false;
  349. }
  350. if (self.data.dataForm.idNumber === '') {
  351. wx.showToast({
  352. title: '请填写证件号/ID Number',
  353. icon: 'none',
  354. mask: true
  355. });
  356. return false;
  357. }
  358. if (self.data.dataForm.country === '') {
  359. wx.showToast({
  360. title: '请选择国家/Country',
  361. icon: 'none',
  362. mask: true
  363. });
  364. return false;
  365. } else {
  366. if (parseInt(self.data.dataForm.country) === 0 && self.data.dataForm.liveCity.length === 0) {
  367. wx.showToast({
  368. title: '请选择居住城市/Live City',
  369. icon: 'none',
  370. mask: true
  371. });
  372. return false;
  373. }
  374. if (parseInt(self.data.dataForm.country) === 1 && self.data.dataForm.liveCityNotChina === '') {
  375. wx.showToast({
  376. title: '请填写居住城市/Live City',
  377. icon: 'none',
  378. mask: true
  379. });
  380. return false;
  381. }
  382. }
  383. if (self.data.dataForm.gender === '') {
  384. wx.showToast({
  385. title: '请选择性别/Gender',
  386. icon: 'none',
  387. mask: true
  388. });
  389. return false;
  390. }
  391. if(self.data.dataForm.emailAddress === '') {
  392. // wx.showToast({
  393. // title: '请填写邮箱/Email Address',
  394. // icon: 'none',
  395. // mask: true
  396. // });
  397. // return false;
  398. } else {
  399. const regex = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
  400. if(!regex.test(self.data.dataForm.emailAddress)) {
  401. wx.showToast({
  402. title: '邮箱/Email Address不合法,请重新填写',
  403. icon: 'none'
  404. });
  405. return false;
  406. }
  407. }
  408. if (self.data.dataForm.company === '') {
  409. wx.showToast({
  410. title: '请填写公司/Company',
  411. icon: 'none',
  412. mask: true
  413. });
  414. return false;
  415. }
  416. if (self.data.dataForm.position === '') {
  417. wx.showToast({
  418. title: '请填写职位/Position',
  419. icon: 'none',
  420. mask: true
  421. });
  422. return false;
  423. }
  424. return true;
  425. }
  426. })