index.ts 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792
  1. import { api_schoolAreaDetail, api_schoolAreaList, api_sysAreaQueryAllProvince, api_userBeneficiarySave, api_userBeneficiaryUpdate } from "../../api/new";
  2. import { GRADE_ENUM } from "../../utils/util";
  3. const classList: any = [];
  4. for (let i = 1; i <= 40; i++) {
  5. classList.push({ text: i + '班', value: i });
  6. }
  7. /** 获取年级 */
  8. const getGradeList = (gradeYear?: string, instrumentCode?: string) => {
  9. let tempList: any = [];
  10. const five = [
  11. { text: '一年级', value: 1, instrumentCode },
  12. { text: '二年级', value: 2, instrumentCode },
  13. { text: '三年级', value: 3, instrumentCode },
  14. { text: '四年级', value: 4, instrumentCode },
  15. { text: '五年级', value: 5, instrumentCode }
  16. ];
  17. const one = [{ text: '六年级', value: 6, instrumentCode }];
  18. const three = [
  19. { text: '七年级', value: 7, instrumentCode },
  20. { text: '八年级', value: 8, instrumentCode },
  21. { text: '九年级', value: 9, instrumentCode }
  22. ];
  23. if (gradeYear === 'FIVE_YEAR_SYSTEM') {
  24. tempList.push(...[...five]);
  25. } else if (gradeYear === 'SIX_YEAR_SYSTEM') {
  26. tempList.push(...[...five, ...one]);
  27. } else if (gradeYear === 'THREE_YEAR_SYSTEM') {
  28. tempList.push(...[...three]);
  29. } else if (gradeYear === 'FORE_YEAR_SYSTEM') {
  30. tempList.push(...[...one, ...three]);
  31. } else {
  32. tempList.push(...[...five, ...one, ...three]);
  33. }
  34. return tempList;
  35. };
  36. // pages/buyerInformation/index.ts
  37. Page({
  38. /**
  39. * 页面的初始数据
  40. */
  41. data: {
  42. cacheArea: [] as { cityCode: string, shiftCityCode: string }[], // 临时存储的对应关系
  43. phone: '',
  44. name: '',
  45. gender: '',
  46. schoolAreaId: '',
  47. schoolAreaName: '',
  48. currentClassTxt: '', // 班级
  49. currentClass: null,
  50. currentGradeTxt: '', // 年级
  51. currentGradeNum: null,
  52. cityCode: null,
  53. cityName: "",
  54. provinceCode: null,
  55. provinceName: "",
  56. regionCode: null,
  57. regionName: "",
  58. userBeneficiaryId: '', // 选中用户的编号
  59. userBeneficiaryInfo: {
  60. name: '',
  61. phoneNumber: '',
  62. schoolInfo: ''
  63. },
  64. showArea: false,
  65. showAreaAfterLeave: false,
  66. areaList: [] as any,
  67. showSchool: false,
  68. showSchoolAfterLeave: false, // 离开后
  69. /** 学校列表 */
  70. schoolAreaList: [] as any,
  71. schoolAreaIndex: 0,
  72. /** 临时切换时选择的学校编号 */
  73. tempChangeSchoolAreaId: '',
  74. schoolLoading: false,
  75. /** 搜索学校 */
  76. searchName: '',
  77. /** 学校类型 */
  78. schoolInstrumentSetType: '',
  79. /** 年级 */
  80. gradeGradeList: [] as any,
  81. gradeGradeIndex: 0,
  82. showGradeClass: false,
  83. showGradeClassAfterLeave: false, // 离开后
  84. /** 班级 */
  85. classList: [] as any,
  86. classIndex: 0,
  87. showClass: false,
  88. showClassAfterLeave: false, // 离开后
  89. buyerLoading: false,
  90. currentIndex: 0,
  91. timer: null as any
  92. },
  93. /**
  94. * 生命周期函数--监听页面加载
  95. */
  96. onLoad(options: any) {
  97. if (options.userBeneficiaryId) {
  98. this.setData({
  99. userBeneficiaryId: options.userBeneficiaryId
  100. })
  101. }
  102. // 从缓存里面获取用户信息
  103. this.getUserDetail()
  104. this.getAreas()
  105. this.getSchools()
  106. },
  107. onBack() {
  108. // 如果有购买人编号,返回时则不缓存数据
  109. if (!this.data.userBeneficiaryId) {
  110. this.onSetCatch(this.data)
  111. }
  112. wx.navigateBack()
  113. },
  114. /**
  115. * 生命周期函数--监听页面初次渲染完成
  116. */
  117. onReady() {
  118. },
  119. /**
  120. * 生命周期函数--监听页面显示
  121. */
  122. onShow() {
  123. },
  124. async getUserDetail() {
  125. try {
  126. // const { data } = await api_userBeneficiaryDetail({
  127. // id: this.data.userBeneficiaryId
  128. // })
  129. // console.log(data, 'data')
  130. const information = wx.getStorageSync('buyerInfomation')
  131. const users = information ? JSON.parse(information) : null
  132. if (users) {
  133. this.setData({
  134. phone: users.phone,
  135. name: users.name,
  136. gender: users.gender,
  137. schoolAreaId: users.schoolAreaId,
  138. schoolAreaName: users.schoolAreaName,
  139. currentGradeTxt: users.currentGradeTxt,
  140. currentClass: users.currentClass,
  141. currentClassTxt: users.currentClassTxt,
  142. currentGradeNum: users.currentGradeNum,
  143. cityCode: users.cityCode,
  144. cityName: users.cityName,
  145. provinceCode: users.provinceCode,
  146. provinceName: users.provinceName,
  147. regionCode: users.regionCode,
  148. regionName: users.regionName,
  149. schoolAreaIndex: users.schoolAreaIndex,
  150. gradeGradeIndex: users.gradeGradeIndex,
  151. classIndex: users.classIndex
  152. }, () => {
  153. this.getSchoolAreaDetail()
  154. })
  155. }
  156. } catch {
  157. //
  158. }
  159. },
  160. /** 获取省市区 */
  161. async getAreas() {
  162. try {
  163. const { data } = await api_sysAreaQueryAllProvince({})
  164. this.setData({
  165. areaList: this.formateArea(data.data)
  166. })
  167. } catch {
  168. //
  169. }
  170. },
  171. formateArea(area: any[]) {
  172. const province_list: { [_: string]: string } = {};
  173. const city_list: { [_: string]: string } = {};
  174. const county_list: { [_: string]: string } = {};
  175. area.forEach((item: any) => {
  176. province_list[item.code] = item.name;
  177. });
  178. area.forEach((item: any) => {
  179. item.areas && item.areas.forEach((city: any, index: number) => {
  180. let code = city.code + ""
  181. // 某些数据不标准 这里需要转换一下
  182. if (code[4] !== "0" || code[5] !== "0") {
  183. // 现在把区域的数据改为市的
  184. const newCode = code.substring(0, 2) + (index < 10 ? `a${index}` : index < 20 ? `b${index - 10}` : index < 30 ? `c${index - 20}` : `d${index - 30}`) + "00";
  185. this.data.cacheArea.push({
  186. cityCode: code,
  187. shiftCityCode: newCode
  188. })
  189. code = newCode
  190. }
  191. city_list[code] = city.name;
  192. });
  193. });
  194. area.forEach((item: any) => {
  195. item.areas && item.areas.forEach((city: any) => {
  196. city.areas && city.areas.forEach((county: any) => {
  197. county_list[county.code] = county.name;
  198. });
  199. });
  200. });
  201. return {
  202. province_list,
  203. city_list,
  204. county_list
  205. };
  206. },
  207. // 转换
  208. formateCityCode(reverse?: boolean) {
  209. if (!this.data.regionCode && this.data.cityCode) {
  210. const cityCodeObj = this.data.cacheArea.find((item: any) => {
  211. return item[reverse ? "cityCode" : "shiftCityCode"] == this.data.cityCode
  212. })
  213. return cityCodeObj ? cityCodeObj[reverse ? "shiftCityCode" : "cityCode"] : ""
  214. }
  215. return this.data.cityCode
  216. },
  217. /** 获取学校列表 */
  218. async getSchools(name?: string) {
  219. this.setData({
  220. schoolLoading: true
  221. })
  222. try {
  223. // 判断是否有地区信息
  224. if (!this.data.provinceCode || !this.data.cityCode) {
  225. return
  226. }
  227. const citycode = this.formateCityCode()
  228. const { data } = await api_schoolAreaList({
  229. name,
  230. testFlag: true,
  231. provinceCode: this.data.provinceCode,
  232. cityCode: citycode,
  233. regionCode: this.data.regionCode
  234. })
  235. const result = data.data || []
  236. const tempList: any[] = []
  237. result.forEach((item: any) => {
  238. tempList.push({
  239. text: item.name,
  240. value: item.id
  241. })
  242. })
  243. let tempSchoolId = ''
  244. let areaIndex = 0
  245. if (tempList.length > 0) {
  246. const childIndex = tempList.findIndex((item: any) => this.data.schoolAreaId === item.value)
  247. console.log(childIndex, 'childIndex')
  248. if (childIndex !== -1) {
  249. const first = tempList[childIndex]
  250. tempSchoolId = first.value || ''
  251. areaIndex = childIndex
  252. } else {
  253. const first = tempList[0]
  254. tempSchoolId = first.value || ''
  255. areaIndex = 0
  256. }
  257. }
  258. this.setData({
  259. schoolAreaIndex: areaIndex,
  260. schoolAreaList: tempList,
  261. tempChangeSchoolAreaId: tempSchoolId
  262. }, () => {
  263. const schoolArea = this.selectComponent('#schoolArea')
  264. schoolArea?.setIndexes([areaIndex])
  265. })
  266. } catch {
  267. //
  268. }
  269. this.setData({
  270. schoolLoading: false
  271. })
  272. },
  273. /** 获取学校详情 */
  274. async getSchoolAreaDetail() {
  275. if (!this.data.schoolAreaId) return
  276. const { data } = await api_schoolAreaDetail({ id: this.data.schoolAreaId })
  277. const result = data.data || {}
  278. let tempGradeGradeList: any = []
  279. let tempClassList: any = []
  280. let schoolInstrumentSetType = ''
  281. if (result.school) {
  282. const schoolInfo = result.school || {};
  283. const schoolInstrumentList = schoolInfo.schoolInstrumentList || [];
  284. // forms.schoolInstrumentSetType = schoolInfo.instrumentSetType;
  285. if (schoolInfo.instrumentSetType === 'SCHOOL') {
  286. tempGradeGradeList = getGradeList(schoolInfo.gradeYear)
  287. tempClassList = classList
  288. schoolInstrumentSetType = schoolInfo.instrumentSetType
  289. } else if (schoolInfo.instrumentSetType === 'GRADE') {
  290. const gradeList: any = []
  291. schoolInstrumentList.forEach((item: any) => {
  292. gradeList.push({
  293. text: GRADE_ENUM[item.gradeNum],
  294. value: item.gradeNum,
  295. instrumentId: item.instrumentId
  296. })
  297. });
  298. gradeList.sort((a: any, b: any) => a.value - b.value);
  299. tempGradeGradeList = gradeList
  300. tempClassList = classList
  301. schoolInstrumentSetType = schoolInfo.instrumentSetType
  302. } else if (schoolInfo.instrumentSetType === 'CLASS') {
  303. // // 班级
  304. const tempGradeList: any[] = [];
  305. schoolInstrumentList.forEach((item: any) => {
  306. if (!tempGradeList.includes(item.gradeNum)) {
  307. tempGradeList.push(item.gradeNum);
  308. }
  309. });
  310. const lastGradeList: any[] = [];
  311. tempGradeList.forEach((temp: any) => {
  312. const list = {
  313. text: GRADE_ENUM[temp],
  314. value: temp,
  315. instrumentId: '',
  316. instrumentCode: '',
  317. instrumentName: '',
  318. classList: [] as any
  319. };
  320. schoolInstrumentList.forEach((item: any) => {
  321. if (temp === item.gradeNum) {
  322. list.instrumentId = item.instrumentId;
  323. list.instrumentCode = item.instrumentCode;
  324. list.instrumentName = item.instrumentName;
  325. list.classList.push({
  326. text: item.classNum + '班',
  327. value: item.classNum,
  328. instrumentCode: item.instrumentCode
  329. });
  330. }
  331. });
  332. // 排序班级
  333. list.classList.sort((a: any, b: any) => a.value - b.value);
  334. lastGradeList.push(list);
  335. });
  336. lastGradeList.sort((a: any, b: any) => a.value - b.value);
  337. tempGradeGradeList = lastGradeList
  338. tempClassList = lastGradeList[this.data.gradeGradeIndex]?.classList || []
  339. schoolInstrumentSetType = schoolInfo.instrumentSetType
  340. } else {
  341. tempGradeGradeList = getGradeList()
  342. tempClassList = classList
  343. schoolInstrumentSetType = ''
  344. }
  345. } else {
  346. tempGradeGradeList = getGradeList()
  347. tempClassList = classList
  348. schoolInstrumentSetType = ''
  349. }
  350. // 格式化年级班级 - 如果后台改了学校配置,本地保存了缓存,判断年级、班级是否存在
  351. const gradeIndex = this.data.gradeGradeIndex
  352. const classIndex = this.data.classIndex
  353. if ((tempGradeGradeList.length || 0) - 1 < gradeIndex) {
  354. tempClassList = tempGradeGradeList[0]?.classList || []
  355. this.setData({
  356. gradeGradeList: tempGradeGradeList,
  357. classList: tempClassList,
  358. schoolInstrumentSetType: schoolInstrumentSetType,
  359. gradeGradeIndex: 0,
  360. classIndex: 0,
  361. // currentClass: null,
  362. // currentClassTxt: '',
  363. // currentGradeNum: null,
  364. // currentGradeTxt: ''
  365. })
  366. } else if ((tempClassList.length || 0) - 1 < classIndex) {
  367. this.setData({
  368. gradeGradeList: tempGradeGradeList,
  369. classList: tempClassList,
  370. schoolInstrumentSetType: schoolInstrumentSetType,
  371. classIndex: 0,
  372. // currentClass: null,
  373. // currentClassTxt: '',
  374. })
  375. } else {
  376. this.setData({
  377. gradeGradeList: tempGradeGradeList,
  378. classList: tempClassList,
  379. schoolInstrumentSetType: schoolInstrumentSetType
  380. })
  381. }
  382. },
  383. /** 选择男女 */
  384. onCheckGender(e: any) {
  385. const { dataset } = e.target
  386. this.setData({
  387. gender: dataset.gender
  388. })
  389. },
  390. /** 显示选择地区 */
  391. onShowAreaList() {
  392. this.setData({
  393. showArea: true
  394. })
  395. },
  396. /** 关闭选择地区 */
  397. onCloseAreaList() {
  398. this.setData({
  399. showArea: false
  400. })
  401. },
  402. /** 选择地区关闭后 */
  403. onAreaAfterLeave() {
  404. this.setData({
  405. showAreaAfterLeave: true
  406. })
  407. },
  408. /** 选择地区打开前 */
  409. onAreaBeforeEnter() {
  410. this.setData({
  411. showAreaAfterLeave: false
  412. })
  413. },
  414. /** 确定选择地区 */
  415. submitArea(e: any) {
  416. const selectedOptions: any = e.detail.values
  417. this.setData({
  418. provinceCode: selectedOptions[0].code,
  419. cityCode: selectedOptions[1].code,
  420. regionCode: selectedOptions[2]?.code || null,
  421. provinceName: selectedOptions[0].name || '',
  422. cityName: selectedOptions[1].name || '',
  423. regionName: selectedOptions[2]?.name || '',
  424. showArea: false,
  425. searchName: '',
  426. schoolAreaId: '',
  427. schoolAreaName: '',
  428. schoolAreaIndex: 0,
  429. currentGradeNum: null,
  430. currentGradeTxt: '',
  431. gradeGradeIndex: 0,
  432. currentClass: null,
  433. currentClassTxt: '',
  434. classIndex: 0
  435. }, () => {
  436. this.getSchools()
  437. })
  438. },
  439. /** 关闭选择学校 */
  440. onCloseSchool() {
  441. this.setData({
  442. showSchool: false
  443. })
  444. },
  445. /** 选择学校关闭后 */
  446. onSchoolAfterLeave() {
  447. this.setData({
  448. showSchoolAfterLeave: true
  449. })
  450. },
  451. /** 选择学校打开前 */
  452. onSchoolBeforeEnter() {
  453. this.setData({
  454. showSchoolAfterLeave: false
  455. })
  456. },
  457. /** 选择学校 */
  458. onSelectSchool() {
  459. if (!this.data.provinceName) {
  460. wx.showToast({
  461. title: '请选择地区',
  462. icon: 'none'
  463. })
  464. return
  465. }
  466. this.setData({
  467. showSchool: true
  468. })
  469. },
  470. /** 确定选择学校 */
  471. onSubmitSchool() {
  472. if (this.data.tempChangeSchoolAreaId === this.data.schoolAreaId) {
  473. this.setData({
  474. showSchool: false
  475. })
  476. return
  477. }
  478. const detail = this.data.schoolAreaList.find((item: any) => item.value === this.data.tempChangeSchoolAreaId)
  479. const detailIndex = this.data.schoolAreaList.findIndex((item: any) => item.value === this.data.tempChangeSchoolAreaId)
  480. // console.log(detail, detailIndex, this.data.tempChangeSchoolAreaId)
  481. if (detailIndex === -1) return
  482. this.setData({
  483. schoolAreaName: detail.text,
  484. schoolAreaId: detail.value,
  485. schoolAreaIndex: detailIndex,
  486. showSchool: false,
  487. currentGradeNum: null,
  488. currentGradeTxt: '',
  489. gradeGradeIndex: 0,
  490. currentClass: null,
  491. currentClassTxt: '',
  492. classIndex: 0
  493. }, () => {
  494. this.getSchoolAreaDetail()
  495. })
  496. },
  497. onChangeSchool(e: any) {
  498. const { value } = e.detail.value
  499. this.setData({
  500. tempChangeSchoolAreaId: value
  501. })
  502. },
  503. onSearch() {
  504. this.getSchools(this.data.searchName);
  505. },
  506. onSearchChange(e: any) {
  507. const that = this
  508. that.setData({
  509. searchName: e.detail
  510. }, () => {
  511. // 防抖
  512. clearTimeout(that.data.timer); // 清除之前的定时器
  513. that.data.timer = setTimeout(() => {
  514. that.getSchools(that.data.searchName);
  515. // 这里写业务逻辑
  516. }, 500); // 1秒后执行
  517. })
  518. },
  519. /** 选择年级班级 */
  520. onSelectGradeClass() {
  521. if (!this.data.schoolAreaId) {
  522. wx.showToast({
  523. title: '请选择学校',
  524. icon: 'none'
  525. })
  526. return
  527. }
  528. this.setData({
  529. showGradeClass: true
  530. })
  531. },
  532. /** 年级班级 */
  533. onCloseGradeClass() {
  534. this.setData({
  535. showGradeClass: false
  536. })
  537. },
  538. onGradeClassBeforeEnter() {
  539. this.setData({
  540. showGradeClassAfterLeave: false
  541. })
  542. },
  543. onGradeClassAfterLeave() {
  544. this.setData({
  545. showGradeClassAfterLeave: true
  546. })
  547. },
  548. /** 确认选择年级班级 */
  549. onSubmitGradeClass(e: any) {
  550. const selectedOptions: any = e.detail.value
  551. const selectedIndexs: any = e.detail.index
  552. if (this.data.schoolInstrumentSetType === "CLASS") {
  553. const gradeDetail = this.data.gradeGradeList;
  554. const classList = gradeDetail?.find((item: any) => item.value === selectedOptions.value)
  555. console.log(classList, "classList")
  556. if (classList) {
  557. this.setData({
  558. classIndex: 0,
  559. classList: classList.classList
  560. })
  561. }
  562. }
  563. this.setData({
  564. currentGradeTxt: selectedOptions.text,
  565. currentGradeNum: selectedOptions.value,
  566. gradeGradeIndex: selectedIndexs,
  567. showGradeClass: false,
  568. currentClass: null,
  569. currentClassTxt: ''
  570. })
  571. },
  572. /** 选择班级 */
  573. onSelectClass() {
  574. if (!this.data.currentGradeNum) {
  575. wx.showToast({
  576. title: '请选择所在年级',
  577. icon: 'none'
  578. })
  579. return
  580. }
  581. this.setData({
  582. showClass: true
  583. })
  584. },
  585. /** 班级 */
  586. onCloseClass() {
  587. this.setData({
  588. showClass: false
  589. })
  590. },
  591. onClassBeforeEnter() {
  592. this.setData({
  593. showClassAfterLeave: false
  594. })
  595. },
  596. onClassAfterLeave() {
  597. this.setData({
  598. showClassAfterLeave: true
  599. })
  600. },
  601. /** 确认选择班级 */
  602. onSubmitClass(e: any) {
  603. const selectedOptions: any = e.detail.value
  604. const selectedIndexs: any = e.detail.index
  605. this.setData({
  606. currentClassTxt: selectedOptions.text,
  607. currentClass: selectedOptions.value,
  608. classIndex: selectedIndexs,
  609. showClass: false
  610. })
  611. },
  612. messageName(value: string) {
  613. const nameReg = /^[\u4E00-\u9FA5]+$/
  614. if (!value) {
  615. return '请填写享用者姓名';
  616. } else if (!nameReg.test(value)) {
  617. return '享用者姓名必须为中文';
  618. } else if (value.length < 2 || value.length > 14) {
  619. return '享用者姓名必须为2~14个字';
  620. } else {
  621. return ''
  622. }
  623. },
  624. /** 最终提交 */
  625. async onSubmit() {
  626. try {
  627. const params = this.data
  628. if (!params.provinceCode || !params.cityCode) {
  629. wx.showToast({
  630. title: '请选择学校地区',
  631. icon: "none"
  632. })
  633. return
  634. }
  635. if (!params.schoolAreaId) {
  636. wx.showToast({
  637. title: '请选择所在学校',
  638. icon: "none"
  639. })
  640. return
  641. }
  642. if (!params.phone || !/^1[3456789]\d{9}$/.test(params.phone)) {
  643. wx.showToast({
  644. title: '请填写正确的电话号码',
  645. icon: "none"
  646. })
  647. return
  648. }
  649. if (this.messageName(params.name)) {
  650. wx.showToast({
  651. title: this.messageName(params.name),
  652. icon: "none"
  653. })
  654. return
  655. }
  656. if (!params.gender) {
  657. wx.showToast({
  658. title: '请选择性别',
  659. icon: 'none'
  660. })
  661. return
  662. }
  663. if (!params.currentGradeNum) {
  664. wx.showToast({
  665. title: '请选择所在年级',
  666. icon: "none"
  667. })
  668. return
  669. }
  670. if (!params.currentClass) {
  671. wx.showToast({
  672. title: '请选择所在班级',
  673. icon: "none"
  674. })
  675. return
  676. }
  677. const objs = {
  678. phone: params.phone,
  679. name: params.name,
  680. gender: params.gender,
  681. currentGradeNum: params.currentGradeNum,
  682. currentClass: params.currentClass,
  683. schoolAreaId: params.schoolAreaId,
  684. defaultStatus: false
  685. }
  686. // const userBeneficiary = {
  687. // name: params.name,
  688. // phoneNumber: params.phone,
  689. // schoolInfo: (params.provinceName || '') + (params.cityName || '') + (params.regionName || '') + params.schoolAreaName + params.currentGradeTxt + params.currentClassTxt
  690. // }
  691. this.setData({
  692. buyerLoading: true
  693. })
  694. const pages = getCurrentPages();
  695. const prevPage = pages[pages.length - 2]; // 获取上一个页面实例
  696. if (params.userBeneficiaryId) {
  697. const { data } = await api_userBeneficiaryUpdate({
  698. id: params.userBeneficiaryId,
  699. ...objs
  700. })
  701. wx.showToast({
  702. title: '保存成功',
  703. icon: 'none'
  704. })
  705. prevPage?.setData({ backParams: { userBeneficiaryId: data.data.id, name: params.name, phone: params.phone, schoolInfo: (params.provinceName || '') + (params.cityName || '') + (params.regionName || '') + params.schoolAreaName + params.currentGradeTxt + params.currentClassTxt } });
  706. } else {
  707. const { data } = await api_userBeneficiarySave({
  708. ...objs
  709. })
  710. wx.showToast({
  711. title: '保存成功',
  712. icon: 'none'
  713. })
  714. prevPage?.setData({ backParams: { userBeneficiaryId: data.data.id, name: params.name, phone: params.phone, schoolInfo: (params.provinceName || '') + (params.cityName || '') + (params.regionName || '') + params.schoolAreaName + params.currentGradeTxt + params.currentClassTxt } });
  715. }
  716. this.onSetCatch(params)
  717. setTimeout(() => {
  718. wx.navigateBack()
  719. this.setData({
  720. buyerLoading: false
  721. })
  722. }, 1000);
  723. } catch {
  724. //
  725. this.setData({
  726. buyerLoading: false
  727. })
  728. }
  729. },
  730. /** 设置缓存 */
  731. onSetCatch(params: any) {
  732. wx.setStorageSync('buyerInfomation', JSON.stringify({
  733. phone: params.phone,
  734. name: params.name,
  735. gender: params.gender,
  736. schoolAreaId: params.schoolAreaId,
  737. schoolAreaName: params.schoolAreaName,
  738. currentGradeTxt: params.currentGradeTxt,
  739. currentClass: params.currentClass,
  740. currentClassTxt: params.currentClassTxt,
  741. currentGradeNum: params.currentGradeNum,
  742. cityCode: params.cityCode,
  743. cityName: params.cityName,
  744. provinceCode: params.provinceCode,
  745. provinceName: params.provinceName,
  746. regionCode: params.regionCode,
  747. regionName: params.regionName,
  748. schoolAreaIndex: params.schoolAreaIndex,
  749. gradeGradeIndex: params.gradeGradeIndex,
  750. classIndex: params.classIndex
  751. }))
  752. }
  753. })