lex-xin 5 months ago
parent
commit
5f219b7dc6

+ 1 - 1
miniprogram/components/navigation-bar/navigation-bar.ts

@@ -68,7 +68,7 @@ Component({
         ios: !isAndroid,
         innerPaddingRight: `padding-right: ${wxWindowInfo.windowWidth - rect.left}px;`,
         leftWidth: `width: ${wxWindowInfo.windowWidth - rect.left }px;`,
-        safeAreaTop: isDevtools || isAndroid ? `height: calc(var(--height) + ${wxWindowInfo.safeArea.top}px); padding-top: ${wxWindowInfo.safeArea.top}px;` : ``
+        safeAreaTop: isDevtools || isAndroid ? `height: calc(var(--height) + ${wxWindowInfo.safeArea.top || 26}px); padding-top: ${wxWindowInfo.safeArea.top || 26}px;` : ``
       })
     },
   },

+ 46 - 9
miniprogram/pages/index/index.ts

@@ -93,6 +93,7 @@ Page({
     showService: false,
     isFromPreviewImage: false,
     showBuyer: false, // 收益人
+    cacheArea: [] as { cityCode: string, shiftCityCode: string }[], // 临时存储的对应关系
 
     phone: '',
     name: '',
@@ -127,6 +128,7 @@ Page({
       schoolInfo: ''
     },
     showArea: false,
+    showAreaAfterLeave: false,
     areaList: [] as any,
     showSchool: false,
     showSchoolAfterLeave: false, // 离开后
@@ -591,8 +593,19 @@ Page({
       province_list[item.code] = item.name;
     });
     area.forEach((item: any) => {
-      item.areas && item.areas.forEach((city: any) => {
-        city_list[city.code] = city.name;
+      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) => {
@@ -608,6 +621,16 @@ Page({
       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({
@@ -615,14 +638,15 @@ Page({
     })
     try {
       // 判断是否有地区信息
-      if (!this.data.provinceCode || !this.data.cityCode || !this.data.regionCode) {
+      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: this.data.cityCode,
+        cityCode: citycode,
         regionCode: this.data.regionCode
       })
       const result = data.data || []
@@ -764,6 +788,7 @@ Page({
     const classIndex = this.data.classIndex
     console.log(tempGradeGradeList, tempClassList)
     if ((tempGradeGradeList.length || 0) - 1 < gradeIndex) {
+      
       this.setData({
         gradeGradeList: tempGradeGradeList,
         classList: tempClassList,
@@ -811,16 +836,28 @@ Page({
       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,
-      provinceName: selectedOptions[0].name,
-      cityName: selectedOptions[1].name,
-      regionName: selectedOptions[2].name,
+      regionCode: selectedOptions[2]?.code,
+      provinceName: selectedOptions[0].name || '',
+      cityName: selectedOptions[1].name || '',
+      regionName: selectedOptions[2]?.name || '',
       showArea: false,
 
       searchName: '',
@@ -1043,7 +1080,7 @@ Page({
         return
       }
 
-      if (!params.provinceCode || !params.cityCode || !params.regionCode) {
+      if (!params.provinceCode || !params.cityCode) {
         wx.showToast({
           title: '请选择学校地区',
           icon: "none"

+ 4 - 4
miniprogram/pages/index/index.wxml

@@ -174,11 +174,11 @@
             <view class="pop-address-title">享用者信息</view>
             <view class="section">
               <view class="section-content">
-                <van-field label="姓名" model:value="{{ name }}" placeholder="请填写享用者姓名" />
+                <van-field label="姓名" model:value="{{ name }}" maxlength="15" placeholder="请填写享用者姓名" />
                 <van-field label="电话号码" model:value="{{ phone }}" maxlength="11" type="number" placeholder="请填写电话号码" />
                 <van-field label="性别" placeholder="请选择性别" value="{{ gender ? (gender === '1' ? '男' : '女') : '' }}" is-link readonly bind:tap="onCheckedGender"></van-field>
 
-                <van-field label="学校地区" value="{{ provinceName ? provinceName + '/' + cityName + '/' + regionName : '' }}" bind:tap="onShowAreaList" placeholder="请选择学校地区" is-link readonly />
+                <van-field label="学校地区" value="{{ provinceName ? provinceName + '/' + cityName +  (regionName ? ('/' + regionName) : '') : '' }}" bind:tap="onShowAreaList" placeholder="请选择学校地区" is-link readonly />
 
                 <van-field model:value="{{ schoolAreaName }}" label="所在学校" placeholder="请选择所在学校" is-link readonly bind:tap="onSelectSchool" />
                 <van-field value="{{ currentGradeTxt }}" label="所在年级" placeholder="请选择所在年级" is-link readonly bind:tap="onSelectGradeClass" />
@@ -198,8 +198,8 @@
         <van-action-sheet z-index="103" show="{{ showGender }}" actions="{{ genderList }}" description="选择性别" cancel-text="取消" bind:close="onCloseGender" bind:cancel="onCloseGender" bind:select="onSelectGender" />
 
         <!-- 地区 -->
-        <van-popup round="{{true}}" lock-scroll="{{true}}" z-index="{{103}}" show="{{showArea}}" position="bottom" safe-area-inset-bottom="{{false}}" bind:close="onCloseAreaList">
-          <van-area id='area1' areaList="{{areaList}}" visible-item-count="8" item-height="46" value="{{ regionCode }}" bind:cancel="onCloseAreaList" bind:confirm="submitArea" />
+        <van-popup round="{{true}}" lock-scroll="{{true}}" z-index="{{103}}" show="{{showArea}}" position="bottom" safe-area-inset-bottom="{{false}}" bind:close="onCloseAreaList" bind:after-leave="onAreaAfterLeave" bind:before-enter="onAreaBeforeEnter">
+          <van-area wx:if="{{ !showAreaAfterLeave }}" id='area1' areaList="{{areaList}}" visible-item-count="8" item-height="46" value="{{ regionCode || cityCode }}" bind:cancel="onCloseAreaList" bind:confirm="submitArea" />
         </van-popup>
 
         <!-- 学校 -->