12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154 |
- // 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: {
- goodsImgList: [
- 'https://oss.dayaedu.com/ktyq/1739523537634.png',
- 'https://oss.dayaedu.com/ktyq/1739523564827.png',
- 'https://oss.dayaedu.com/ktyq/1739523574402.png',
- 'https://oss.dayaedu.com/ktyq/1739523583463.png'
- ],
- current: 0,
- 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()
- })
- }
- },
- /** 格式化选中的商品 */
- 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)()
- },
- 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() {
- if(this.data.tempChangeSchoolAreaId === this.data.schoolAreaId) {
- this.setData({
- showSchool: false
- })
- return
- }
- 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
- }))
- }
- })
|