index.ts 22 KB

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