index.ts 22 KB

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