1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195 |
- // index.ts
- import { api_shopInstruments, api_shopProduct } from "../../api/login";
- import { api_schoolAreaDetail, api_schoolAreaList, api_sysAreaQueryAllProvince, api_userBeneficiarySave, api_userBeneficiaryUpdate } from "../../api/new";
- import { debounce, formatPrice, GRADE_ENUM } from '../../utils/util'
- const classList: any = [];
- for (let i = 1; i <= 40; i++) {
- classList.push({ text: i + '班', value: i });
- }
- /** 获取年级 */
- const getGradeList = (gradeYear?: string, instrumentCode?: string) => {
- let tempList: any = [];
- const five = [
- { text: '一年级', value: 1, instrumentCode },
- { text: '二年级', value: 2, instrumentCode },
- { text: '三年级', value: 3, instrumentCode },
- { text: '四年级', value: 4, instrumentCode },
- { text: '五年级', value: 5, instrumentCode }
- ];
- const one = [{ text: '六年级', value: 6, instrumentCode }];
- const three = [
- { text: '七年级', value: 7, instrumentCode },
- { text: '八年级', value: 8, instrumentCode },
- { text: '九年级', value: 9, instrumentCode }
- ];
- if (gradeYear === 'FIVE_YEAR_SYSTEM') {
- tempList.push(...[...five]);
- } else if (gradeYear === 'SIX_YEAR_SYSTEM') {
- tempList.push(...[...five, ...one]);
- } else if (gradeYear === 'THREE_YEAR_SYSTEM') {
- tempList.push(...[...three]);
- } else if (gradeYear === 'FORE_YEAR_SYSTEM') {
- tempList.push(...[...one, ...three]);
- } else {
- tempList.push(...[...five, ...one, ...three]);
- }
- return tempList;
- };
- // 获取应用实例
- const app = getApp<IAppOption>()
- // pages/orders/orders.ts
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- firstImgList: [
- 'https://oss.dayaedu.com/ktyq/1739181226082.png',
- 'https://oss.dayaedu.com/ktyq/1739181253580.png',
- 'https://oss.dayaedu.com/ktyq/1739181268714.png',
- 'https://oss.dayaedu.com/ktyq/1739181284457.png',
- 'https://oss.dayaedu.com/ktyq/1739181316779.png',
- 'https://oss.dayaedu.com/ktyq/1739181329436.png'
- ],
- firstCurrent: 0,
- imgList: [
- 'https://oss.dayaedu.com/ktyq/1739429062237.png',
- 'https://oss.dayaedu.com/ktyq/1732610940095.png',
- 'https://oss.dayaedu.com/ktyq/1732610952376.png',
- 'https://oss.dayaedu.com/ktyq/1732610965625.png',
- // 'https://oss.dayaedu.com/ktyq/1731664269098.png',
- ],
- goodsImgList: [
- 'https://oss.dayaedu.com/ktyq/1739182504757.png',
- 'https://oss.dayaedu.com/ktyq/1739182521080.png',
- 'https://oss.dayaedu.com/ktyq/1739182535430.png',
- 'https://oss.dayaedu.com/ktyq/1739182557976.png',
- 'https://oss.dayaedu.com/ktyq/1739182545221.png'
- ],
- current: 0,
- autoplay: false,
- interval: 5000,
- duration: 500,
- popupShow: false,
- instrumentList: [] as any,
- list: [] as any,
- isOverSaled: false, // 是否所有商品都没有库存
- smallGoods: {}, // 最小金额商品
- selected: {} as any,
- selectInstrumentId: '', // 选中的乐器
- selectedInstrument: {} as any,
- formatSelectGood: {
- typeName: '',
- showSalePrice: '', // 显示的现价
- originalPrice: 0, // 原价
- salePrice: 0, // 现价
- discountPrice: '' // 已省
- } as any, // 格式化所有选中的数据
- showService: false,
- isFromPreviewImage: false,
- showBuyer: false, // 收益人
- cacheArea: [] as { cityCode: string, shiftCityCode: string }[], // 临时存储的对应关系
- phone: '',
- name: '',
- gender: '',
- schoolAreaId: '',
- schoolAreaName: '',
- currentClassTxt: '', // 班级
- currentClass: null,
- currentGradeTxt: '', // 年级
- currentGradeNum: null,
- cityCode: null,
- cityName: "",
- provinceCode: null,
- provinceName: "",
- regionCode: null,
- regionName: "",
- showGender: false,
- genderList: [{
- name: '男',
- value: '1',
- className: 'one-gender cancel-gender'
- }, {
- name: '女',
- value: '0',
- className: 'two-gender cancel-gender'
- }],
- userBeneficiaryId: '', // 选中用户的编号
- userBeneficiaryInfo: {
- name: '',
- phoneNumber: '',
- schoolInfo: ''
- },
- showArea: false,
- showAreaAfterLeave: false,
- areaList: [] as any,
- showSchool: false,
- showSchoolAfterLeave: false, // 离开后
- /** 学校列表 */
- schoolAreaList: [] as any,
- schoolAreaIndex: 0,
- /** 临时切换时选择的学校编号 */
- tempChangeSchoolAreaId: '',
- schoolLoading: false,
- /** 搜索学校 */
- searchName: '',
- /** 学校类型 */
- schoolInstrumentSetType: '',
- /** 年级 */
- gradeGradeList: [] as any,
- gradeGradeIndex: 0,
- showGradeClass: false,
- showGradeClassAfterLeave: false, // 离开后
- /** 班级 */
- classList: [] as any,
- classIndex: 0,
- showClass: false,
- showClassAfterLeave: false, // 离开后
- buyerLoading: false,
- currentIndex: 0,
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad() {
- // this.onInit()
- },
- /**
- * 获取基础信息
- */
- async onInit() {
- try {
- const result = await api_shopInstruments({ appId: app.globalData.appId })
- const instrumentList = result.data.data || []
- instrumentList?.forEach((item: any) => {
- item.showSalePrice = formatPrice(item.salePrice || 0, 'ALL')
- })
- const { data } = await api_shopProduct({ appId: app.globalData.appId });
- const list = data.data || []
- let selected: any = {}
- let isOverSaled = true // 是否销售完
- // 最少金额商品
- let smallGoods: any = {}
- list.forEach((item: any) => {
- item.originalPrice = formatPrice(item.originalPrice, "ALL");
- item.showSalePrice = formatPrice(item.salePrice, "ALL");
- item.typeName = this.formatPeriod(item.num, item.period);
- item.discountPrice = formatPrice(
- item.originalPrice - item.salePrice,
- "ALL"
- );
- const prices: any = formatPrice(item.salePrice)
- item.integerPart = prices.integerPart
- item.decimalPart = prices.decimalPart
- if (item.stockNum > 0) {
- isOverSaled = false
- if (!selected.id) {
- selected = item
- }
- }
- // 获取最小金额
- if (smallGoods?.salePrice) {
- smallGoods = smallGoods.salePrice <= item.salePrice ? smallGoods : item
- } else {
- smallGoods = item
- }
- });
- if (isOverSaled) {
- // 没有可购买商品则默认选中第一个商品
- selected = list[0]
- }
- this.setData({
- list,
- instrumentList, // 乐器列表
- isOverSaled,
- selected,
- smallGoods,
- selectInstrumentId: '',
- selectedInstrument: {},
- userBeneficiaryId: '',
- userBeneficiaryInfo: {
- name: '',
- phoneNumber: '',
- schoolInfo: ''
- }
- }, () => {
- this.onFormatGoods()
- })
- } catch (e) {
- console.log(e, 'e')
- }
- },
- // 格式化类型
- formatPeriod(num: number, type: string) {
- const template: any = {
- DAY: "天卡",
- MONTH: "月卡",
- YEAR: "年卡"
- }
- if (type === "YEAR" && num >= 99) {
- return '永久卡'
- }
- return num + (template[type] || '')
- },
- /** 切换swiper */
- onSwiperChange(e: any) {
- console.log(e, 'e')
- return false
- },
- // 选择
- onSelectGoods(e: any) {
- const { dataset } = e.currentTarget
- const item = this.data.list.find((item: any) => item.id === dataset.id)
- // 判断是否有库存
- if (item.stockNum <= 0) {
- return
- }
- this.setData({
- selected: item || {}
- }, () => {
- this.onFormatGoods()
- })
- },
- /** 选中乐器 */
- onSelectInstrument(e: any) {
- const { dataset } = e.currentTarget;
- if (dataset.id === this.data.selectInstrumentId) {
- this.setData({
- selectInstrumentId: '',
- selectedInstrument: {}
- }, () => {
- this.onFormatGoods()
- })
- } else {
- const item = this.data.instrumentList.find((item: any) => item.id === dataset.id);
- this.setData({
- selectInstrumentId: dataset.id,
- selectedInstrument: item || {}
- }, () => {
- this.onFormatGoods()
- })
- }
- },
- onFirstChange(e: any) {
- const detail = e.detail;
- if (detail.source === 'touch' || detail.source == 'autoplay') {
- this.setData({
- firstCurrent: detail.current
- })
- }
- },
- // 事件处理函数
- changeSwiper(e: any) {
- const detail = e.detail;
- if (detail.source === 'touch' || detail.source == 'autoplay') {
- this.setData({
- current: detail.current
- })
- }
- },
- /** 格式化选中的商品 */
- onFormatGoods() {
- const selected = this.data.selected;
- const selectedInstrument = this.data.selectedInstrument
- const params = {
- typeName: '',
- showSalePrice: '' as any, // 显示的现价
- originalPrice: 0, // 原价
- salePrice: 0, // 现价
- discountPrice: '' as any, // 已省
- integerPart: '',
- decimalPart: '',
- }
- // 选中期限
- if (selected.id) {
- params.typeName = selected.typeName
- params.showSalePrice = selected.showSalePrice
- params.originalPrice = selected.originalPrice
- params.salePrice = selected.salePrice
- params.discountPrice = selected.discountPrice
- const prices: any = formatPrice(params.salePrice);
- params.integerPart = prices.integerPart
- params.decimalPart = prices.decimalPart
- }
- // 选中乐器
- if (selectedInstrument.id) {
- params.typeName = selected.typeName ? selected.typeName + '+' + selectedInstrument.name : selectedInstrument.name
- params.originalPrice = Number(selected.originalPrice) + Number(selectedInstrument.originalPrice)
- params.salePrice = Number(selected.salePrice) + Number(selectedInstrument.salePrice)
- params.showSalePrice = formatPrice(params.salePrice, "ALL");
- params.discountPrice = formatPrice(
- params.originalPrice - params.salePrice,
- "ALL"
- );
- const prices: any = formatPrice(params.salePrice);
- params.integerPart = prices.integerPart
- params.decimalPart = prices.decimalPart
- }
- this.setData({
- formatSelectGood: params
- })
- },
- isLogin() {
- // 判断是否登录
- if (!app.globalData.isLogin) {
- wx.navigateTo({
- url: '../login/login',
- })
- return false
- }
- return true
- },
- /** 我的订单 */
- onOrder() {
- // 判断是否登录
- if (!this.isLogin()) {
- return
- }
- wx.navigateTo({
- url: '../orders/orders',
- })
- },
- /** 客服 */
- onService() {
- this.setData({
- showService: true
- })
- },
- changePop(event: { detail: any }) {
- this.setData({
- showService: event.detail
- })
- },
- onBuyShop() {
- // 判断是否登录
- if (!this.isLogin()) {
- return
- }
- this.setData({
- popupShow: true
- })
- },
- onClose() {
- this.setData({
- popupShow: false,
- currentIndex: 1,
- userBeneficiaryId: '',
- userBeneficiaryInfo: {
- name: '',
- phoneNumber: '',
- schoolInfo: ''
- }
- })
- },
- onSubmit() {
- // 判断是否登录
- const that = this
- if (!this.data.userBeneficiaryId) {
- wx.showToast({
- title: '请填写享用者的个人信息',
- icon: 'none'
- })
- return
- }
- debounce(function () {
- if (!that.isLogin()) {
- return
- }
- const params = [] as any
- const selected = that.data.selected
- if (selected.id) {
- params.push({
- pic: selected.pic,
- name: selected.name,
- period: selected.period,
- num: selected.num,
- originalPrice: selected.originalPrice,
- salePrice: selected.salePrice,
- shopId: selected.shopId,
- id: selected.id,
- goodsType: 'ACTIVATION_CODE', // INSTRUMENTS
- })
- }
- const selectedInstrument = that.data.selectedInstrument
- if (selectedInstrument.id) {
- params.push({
- pic: selectedInstrument.pic,
- name: selectedInstrument.name,
- period: selectedInstrument?.period,
- num: selectedInstrument?.num || 0,
- originalPrice: selectedInstrument.originalPrice,
- salePrice: selectedInstrument.salePrice,
- shopId: selectedInstrument.shopId,
- id: selectedInstrument.id,
- goodsType: 'INSTRUMENTS', // INSTRUMENTS
- })
- }
- let info = JSON.stringify({
- ...params
- });
- info = encodeURIComponent(info);
- console.log(params, "params")
- wx.navigateTo({
- url: `../orders/order-detail?orderInfo=${info}&userBeneficiaryId=${that.data.userBeneficiaryId}`,
- success: () => {
- that.setData({
- popupShow: false,
- currentIndex: 1,
- })
- }
- })
- }, 500)()
- },
- onPreivewBannerImg(e: { currentTarget: { dataset: any } }) {
- wx.previewImage({
- current: e.currentTarget.dataset.src,
- urls: this.data.imgList,
- success: () => {
- this.setData({
- isFromPreviewImage: true
- })
- }
- })
- },
- onPreivewGoodsImg(e: { currentTarget: { dataset: any } }) {
- wx.previewImage({
- current: e.currentTarget.dataset.src,
- urls: this.data.goodsImgList,
- success: () => {
- this.setData({
- isFromPreviewImage: true
- })
- }
- })
- },
- onPreivewGoods(e: { currentTarget: { dataset: any } }) {
- wx.previewImage({
- current: e.currentTarget.dataset.src,
- urls: [e.currentTarget.dataset.src],
- success: () => {
- this.setData({
- isFromPreviewImage: true
- })
- }
- })
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- if (!this.data.isFromPreviewImage) {
- this.onInit()
- } else {
- this.setData({
- isFromPreviewImage: false
- })
- }
- },
- onShareAppMessage() {
- return {
- title: '器乐数字AI工具',
- path: '/pages/index/index',
- imageUrl: 'https://oss.dayaedu.com/ktyq/1733312164991.png'
- }
- },
- onShareTimeline() {
- return {
- title: '器乐数字AI工具',
- path: '/pages/index/index',
- imageUrl: 'https://oss.dayaedu.com/ktyq/1733312164991.png'
- }
- },
- onSelectBuyer() {
- // 从缓存里面获取用户信息
- this.getUserDetail()
- if (this.data.areaList.length <= 0) {
- this.getAreas()
- }
- this.getSchools()
- this.setData({
- showBuyer: true
- })
- },
- onCloseBuyer() {
- this.setData({
- showBuyer: false
- }, () => {
- if (!this.data.userBeneficiaryId) {
- this.onSetCatch(this.data)
- }
- })
- },
- async getUserDetail() {
- try {
- // const { data } = await api_userBeneficiaryDetail({
- // id: this.data.userBeneficiaryId
- // })
- // console.log(data, 'data')
- const information = wx.getStorageSync('buyerInfomation')
- const users = information ? JSON.parse(information) : null
- if (users) {
- this.setData({
- phone: users.phone,
- name: users.name,
- gender: users.gender,
- schoolAreaId: users.schoolAreaId,
- schoolAreaName: users.schoolAreaName,
- currentGradeTxt: users.currentGradeTxt,
- currentClass: users.currentClass,
- currentClassTxt: users.currentClassTxt,
- currentGradeNum: users.currentGradeNum,
- cityCode: users.cityCode,
- cityName: users.cityName,
- provinceCode: users.provinceCode,
- provinceName: users.provinceName,
- regionCode: users.regionCode,
- regionName: users.regionName,
- schoolAreaIndex: users.schoolAreaIndex,
- gradeGradeIndex: users.gradeGradeIndex,
- classIndex: users.classIndex
- }, () => {
- this.getSchoolAreaDetail()
- })
- }
- } catch {
- //
- }
- },
- /** 获取省市区 */
- async getAreas() {
- try {
- const { data } = await api_sysAreaQueryAllProvince({})
- this.setData({
- areaList: this.formateArea(data.data)
- })
- } catch {
- //
- }
- },
- formateArea(area: any[]) {
- const province_list: { [_: string]: string } = {};
- const city_list: { [_: string]: string } = {};
- const county_list: { [_: string]: string } = {};
- area.forEach((item: any) => {
- province_list[item.code] = item.name;
- });
- area.forEach((item: any) => {
- item.areas && item.areas.forEach((city: any, index: number) => {
- let code = city.code + ""
- // 某些数据不标准 这里需要转换一下
- if (code[4] !== "0" || code[5] !== "0") {
- // 现在把区域的数据改为市的
- const newCode = code.substring(0, 2) + (index < 10 ? `a${index}` : index < 20 ? `b${index - 10}` : index < 30 ? `c${index - 20}` : `d${index - 30}`) + "00";
- this.data.cacheArea.push({
- cityCode: code,
- shiftCityCode: newCode
- })
- code = newCode
- }
- city_list[code] = city.name;
- });
- });
- area.forEach((item: any) => {
- item.areas && item.areas.forEach((city: any) => {
- city.areas && city.areas.forEach((county: any) => {
- county_list[county.code] = county.name;
- });
- });
- });
- return {
- province_list,
- city_list,
- county_list
- };
- },
- // 转换
- formateCityCode(reverse?: boolean) {
- if (!this.data.regionCode && this.data.cityCode) {
- const cityCodeObj = this.data.cacheArea.find((item: any) => {
- return item[reverse ? "cityCode" : "shiftCityCode"] == this.data.cityCode
- })
- return cityCodeObj ? cityCodeObj[reverse ? "shiftCityCode" : "cityCode"] : ""
- }
- return this.data.cityCode
- },
- /** 获取学校列表 */
- async getSchools(name?: string) {
- this.setData({
- schoolLoading: true
- })
- try {
- // 判断是否有地区信息
- if (!this.data.provinceCode || !this.data.cityCode) {
- return
- }
- const citycode = this.formateCityCode()
- const { data } = await api_schoolAreaList({
- name,
- testFlag: true,
- provinceCode: this.data.provinceCode,
- cityCode: citycode,
- regionCode: this.data.regionCode
- })
- const result = data.data || []
- const tempList: any[] = []
- result.forEach((item: any) => {
- tempList.push({
- text: item.name,
- value: item.id
- })
- })
- let tempSchoolId = ''
- if (tempList.length > 0) {
- const first = tempList[0]
- tempSchoolId = first.value || ''
- }
- this.setData({
- schoolAreaList: tempList,
- tempChangeSchoolAreaId: tempSchoolId
- })
- } catch {
- //
- }
- this.setData({
- schoolLoading: false
- })
- },
- onCheckedGender() {
- this.setData({
- showGender: true
- })
- },
- onCloseGender() {
- this.setData({
- showGender: false,
- })
- },
- onSelectGender(e: any) {
- const genderList = this.data.genderList
- const gender = e.detail.value
- genderList.forEach((item: any, index: number) => {
- if (item.value === gender) {
- item.className = index === 0 ? 'one-gender select-gender' : 'two-gender select-gender'
- } else {
- item.className = index === 0 ? 'one-gender cancel-gender' : 'two-gender cancel-gender'
- }
- })
- console.log(e, genderList, gender, '1212')
- this.setData({
- gender,
- genderList
- })
- },
- /** 获取学校详情 */
- async getSchoolAreaDetail() {
- if (!this.data.schoolAreaId) return
- const { data } = await api_schoolAreaDetail({ id: this.data.schoolAreaId })
- const result = data.data || {}
- let tempGradeGradeList: any = []
- let tempClassList: any = []
- let schoolInstrumentSetType = ''
- if (result.school) {
- const schoolInfo = result.school || {};
- const schoolInstrumentList = schoolInfo.schoolInstrumentList || [];
- // forms.schoolInstrumentSetType = schoolInfo.instrumentSetType;
- if (schoolInfo.instrumentSetType === 'SCHOOL') {
- tempGradeGradeList = getGradeList(schoolInfo.gradeYear)
- tempClassList = classList
- schoolInstrumentSetType = schoolInfo.instrumentSetType
- } else if (schoolInfo.instrumentSetType === 'GRADE') {
- const gradeList: any = []
- schoolInstrumentList.forEach((item: any) => {
- gradeList.push({
- text: GRADE_ENUM[item.gradeNum],
- value: item.gradeNum,
- instrumentId: item.instrumentId
- })
- });
- gradeList.sort((a: any, b: any) => a.value - b.value);
- tempGradeGradeList = gradeList
- tempClassList = classList
- schoolInstrumentSetType = schoolInfo.instrumentSetType
- } else if (schoolInfo.instrumentSetType === 'CLASS') {
- // // 班级
- const tempGradeList: any[] = [];
- schoolInstrumentList.forEach((item: any) => {
- if (!tempGradeList.includes(item.gradeNum)) {
- tempGradeList.push(item.gradeNum);
- }
- });
- const lastGradeList: any[] = [];
- tempGradeList.forEach((temp: any) => {
- const list = {
- text: GRADE_ENUM[temp],
- value: temp,
- instrumentId: '',
- instrumentCode: '',
- instrumentName: '',
- classList: [] as any
- };
- schoolInstrumentList.forEach((item: any) => {
- if (temp === item.gradeNum) {
- list.instrumentId = item.instrumentId;
- list.instrumentCode = item.instrumentCode;
- list.instrumentName = item.instrumentName;
- list.classList.push({
- text: item.classNum + '班',
- value: item.classNum,
- instrumentCode: item.instrumentCode
- });
- }
- });
- // 排序班级
- list.classList.sort((a: any, b: any) => a.value - b.value);
- lastGradeList.push(list);
- });
- lastGradeList.sort((a: any, b: any) => a.value - b.value);
- tempGradeGradeList = lastGradeList
- tempClassList = lastGradeList[this.data.gradeGradeIndex]?.classList || []
- schoolInstrumentSetType = schoolInfo.instrumentSetType
- } else {
- tempGradeGradeList = getGradeList()
- tempClassList = classList
- schoolInstrumentSetType = ''
- }
- } else {
- tempGradeGradeList = getGradeList()
- tempClassList = classList
- schoolInstrumentSetType = ''
- }
- // 格式化年级班级 - 如果后台改了学校配置,本地保存了缓存,判断年级、班级是否存在
- const gradeIndex = this.data.gradeGradeIndex
- const classIndex = this.data.classIndex
- if ((tempGradeGradeList.length || 0) - 1 < gradeIndex) {
- tempClassList = tempGradeGradeList[0]?.classList || []
- this.setData({
- gradeGradeList: tempGradeGradeList,
- classList: tempClassList,
- schoolInstrumentSetType: schoolInstrumentSetType,
- gradeGradeIndex: 0,
- classIndex: 0,
- // currentClass: null,
- // currentClassTxt: '',
- // currentGradeNum: null,
- // currentGradeTxt: ''
- })
- } else if ((tempClassList.length || 0) - 1 < classIndex) {
- this.setData({
- gradeGradeList: tempGradeGradeList,
- classList: tempClassList,
- schoolInstrumentSetType: schoolInstrumentSetType,
- classIndex: 0,
- // currentClass: null,
- // currentClassTxt: '',
- })
- } else {
- this.setData({
- gradeGradeList: tempGradeGradeList,
- classList: tempClassList,
- schoolInstrumentSetType: schoolInstrumentSetType
- })
- }
- },
- /** 选择男女 */
- onCheckGender(e: any) {
- const { dataset } = e.target
- this.setData({
- gender: dataset.gender
- })
- },
- /** 显示选择地区 */
- onShowAreaList() {
- this.setData({
- showArea: true
- })
- },
- /** 关闭选择地区 */
- onCloseAreaList() {
- this.setData({
- showArea: false
- })
- },
- /** 选择地区关闭后 */
- onAreaAfterLeave() {
- this.setData({
- showAreaAfterLeave: true
- })
- },
- /** 选择地区打开前 */
- onAreaBeforeEnter() {
- this.setData({
- showAreaAfterLeave: false
- })
- },
- /** 确定选择地区 */
- submitArea(e: any) {
- const selectedOptions: any = e.detail.values
- this.setData({
- provinceCode: selectedOptions[0].code,
- cityCode: selectedOptions[1].code,
- regionCode: selectedOptions[2]?.code || null,
- provinceName: selectedOptions[0].name || '',
- cityName: selectedOptions[1].name || '',
- regionName: selectedOptions[2]?.name || '',
- showArea: false,
- searchName: '',
- schoolAreaId: '',
- schoolAreaName: '',
- schoolAreaIndex: 0,
- currentGradeNum: null,
- currentGradeTxt: '',
- gradeGradeIndex: 0,
- currentClass: null,
- currentClassTxt: '',
- classIndex: 0
- }, () => {
- this.getSchools()
- })
- },
- /** 关闭选择学校 */
- onCloseSchool() {
- this.setData({
- showSchool: false
- })
- },
- /** 选择学校关闭后 */
- onSchoolAfterLeave() {
- this.setData({
- showSchoolAfterLeave: true
- })
- },
- /** 选择学校打开前 */
- onSchoolBeforeEnter() {
- this.setData({
- showSchoolAfterLeave: false
- })
- },
- /** 选择学校 */
- onSelectSchool() {
- if (!this.data.provinceName) {
- wx.showToast({
- title: '请选择地区',
- icon: 'none'
- })
- return
- }
- this.setData({
- showSchool: true
- })
- },
- /** 确定选择学校 */
- onSubmitSchool() {
- const detail = this.data.schoolAreaList.find((item: any) => item.value === this.data.tempChangeSchoolAreaId)
- const detailIndex = this.data.schoolAreaList.findIndex((item: any) => item.value === this.data.tempChangeSchoolAreaId)
- // console.log(detail, detailIndex, this.data.tempChangeSchoolAreaId)
- if (detailIndex === -1) return
- this.setData({
- schoolAreaName: detail.text,
- schoolAreaId: detail.value,
- schoolAreaIndex: detailIndex,
- showSchool: false,
- currentGradeNum: null,
- currentGradeTxt: '',
- gradeGradeIndex: 0,
- currentClass: null,
- currentClassTxt: '',
- classIndex: 0
- }, () => {
- this.getSchoolAreaDetail()
- })
- },
- onChangeSchool(e: any) {
- const { value } = e.detail.value
- this.setData({
- tempChangeSchoolAreaId: value
- })
- },
- onSearch() {
- this.setData({
- schoolAreaIndex: 0
- }, () => {
- this.getSchools(this.data.searchName);
- })
- },
- onSearchChange(e: any) {
- this.setData({
- searchName: e.detail
- })
- },
- /** 选择年级班级 */
- onSelectGradeClass() {
- if (!this.data.schoolAreaId) {
- wx.showToast({
- title: '请选择学校',
- icon: 'none'
- })
- return
- }
- this.setData({
- showGradeClass: true
- })
- },
- /** 年级班级 */
- onCloseGradeClass() {
- this.setData({
- showGradeClass: false
- })
- },
- onGradeClassBeforeEnter() {
- this.setData({
- showGradeClassAfterLeave: false
- })
- },
- onGradeClassAfterLeave() {
- this.setData({
- showGradeClassAfterLeave: true
- })
- },
- /** 确认选择年级班级 */
- onSubmitGradeClass(e: any) {
- const selectedOptions: any = e.detail.value
- const selectedIndexs: any = e.detail.index
- if (this.data.schoolInstrumentSetType === "CLASS") {
- const gradeDetail = this.data.gradeGradeList;
- const classList = gradeDetail?.find((item: any) => item.value === selectedOptions.value)
- console.log(classList, "classList")
- if (classList) {
- this.setData({
- classIndex: 0,
- classList: classList.classList
- })
- }
- }
- this.setData({
- currentGradeTxt: selectedOptions.text,
- currentGradeNum: selectedOptions.value,
- gradeGradeIndex: selectedIndexs,
- showGradeClass: false,
- currentClass: null,
- currentClassTxt: ''
- })
- },
- /** 选择班级 */
- onSelectClass() {
- if (!this.data.schoolAreaId) {
- wx.showToast({
- title: '请选择所在年级',
- icon: 'none'
- })
- return
- }
- this.setData({
- showClass: true
- })
- },
- /** 班级 */
- onCloseClass() {
- this.setData({
- showClass: false
- })
- },
- onClassBeforeEnter() {
- this.setData({
- showClassAfterLeave: false
- })
- },
- onClassAfterLeave() {
- this.setData({
- showClassAfterLeave: true
- })
- },
- /** 确认选择班级 */
- onSubmitClass(e: any) {
- const selectedOptions: any = e.detail.value
- const selectedIndexs: any = e.detail.index
- this.setData({
- currentClassTxt: selectedOptions.text,
- currentClass: selectedOptions.value,
- classIndex: selectedIndexs,
- showClass: false
- })
- },
- messageName(value: string) {
- const nameReg = /^[\u4E00-\u9FA5]+$/
- if (!value) {
- return '请填写享用者姓名';
- } else if (!nameReg.test(value)) {
- return '享用者姓名必须为中文';
- } else if (value.length < 2 || value.length > 14) {
- return '享用者姓名必须为2~14个字';
- } else {
- return ''
- }
- },
- /** 最终提交 */
- async onSubmitBuyer() {
- try {
- const params = this.data
- if (this.messageName(params.name)) {
- wx.showToast({
- title: this.messageName(params.name),
- icon: "none"
- })
- return
- }
- if (!params.phone || !/^1[3456789]\d{9}$/.test(params.phone)) {
- wx.showToast({
- title: '请填写正确的电话号码',
- icon: "none"
- })
- return
- }
- if (!params.gender) {
- wx.showToast({
- title: '请选择性别',
- icon: 'none'
- })
- return
- }
- if (!params.provinceCode || !params.cityCode) {
- wx.showToast({
- title: '请选择学校地区',
- icon: "none"
- })
- return
- }
- if (!params.schoolAreaId) {
- wx.showToast({
- title: '请选择所在学校',
- icon: "none"
- })
- return
- }
- if (!params.currentGradeNum) {
- wx.showToast({
- title: '请选择所在年级',
- icon: "none"
- })
- return
- }
- if (!params.currentClass) {
- wx.showToast({
- title: '请选择所在班级',
- icon: "none"
- })
- return
- }
- const objs = {
- phone: params.phone,
- name: params.name,
- gender: params.gender,
- currentGradeNum: params.currentGradeNum,
- currentClass: params.currentClass,
- schoolAreaId: params.schoolAreaId,
- defaultStatus: false
- }
- const userBeneficiary = {
- name: params.name,
- phoneNumber: params.phone,
- schoolInfo: (params.provinceName || '') + (params.cityName || '') + (params.regionName || '') + params.schoolAreaName + params.currentGradeTxt + params.currentClassTxt
- }
- let userBeneficiaryId = ''
- this.setData({
- buyerLoading: true
- })
- if (params.userBeneficiaryId) {
- const { data } = await api_userBeneficiaryUpdate({
- id: params.userBeneficiaryId,
- ...objs
- })
- wx.showToast({
- title: '保存成功',
- icon: 'none'
- })
- userBeneficiaryId = data.data.id
- } else {
- const { data } = await api_userBeneficiarySave({
- ...objs
- })
- wx.showToast({
- title: '保存成功',
- icon: 'none'
- })
- userBeneficiaryId = data.data.id
- }
- this.setData({
- userBeneficiaryId,
- userBeneficiaryInfo: userBeneficiary
- })
- this.onSetCatch(params)
- this.onCloseBuyer()
- } catch {
- //
- }
- this.setData({
- buyerLoading: false
- })
- },
- /** 设置缓存 */
- onSetCatch(params: any) {
- wx.setStorageSync('buyerInfomation', JSON.stringify({
- phone: params.phone,
- name: params.name,
- gender: params.gender,
- schoolAreaId: params.schoolAreaId,
- schoolAreaName: params.schoolAreaName,
- currentGradeTxt: params.currentGradeTxt,
- currentClass: params.currentClass,
- currentClassTxt: params.currentClassTxt,
- currentGradeNum: params.currentGradeNum,
- cityCode: params.cityCode,
- cityName: params.cityName,
- provinceCode: params.provinceCode,
- provinceName: params.provinceName,
- regionCode: params.regionCode,
- regionName: params.regionName,
- schoolAreaIndex: params.schoolAreaIndex,
- gradeGradeIndex: params.gradeGradeIndex,
- classIndex: params.classIndex
- }))
- }
- })
|