ソースを参照

区域地址和收货地址调整,参考了vant框架的Area组件

Junling Bu 6 年 前
コミット
faaf94b77a
20 ファイル変更10882 行追加4377 行削除
  1. 1 26
      litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminAddressController.java
  2. 144 70
      litemall-db/src/main/java/org/linlinjava/litemall/db/domain/LitemallAddress.java
  3. 502 188
      litemall-db/src/main/java/org/linlinjava/litemall/db/domain/LitemallAddressExample.java
  4. 0 6
      litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallRegionService.java
  5. 103 71
      litemall-db/src/main/resources/org/linlinjava/litemall/db/dao/LitemallAddressMapper.xml
  6. 3 3
      litemall-db/src/main/resources/org/linlinjava/litemall/db/dao/LitemallPermissionMapper.xml
  7. 1 1
      litemall-vue/src/api/api.js
  8. 3239 3607
      litemall-vue/src/views/user/module-address-edit/area.json
  9. 3 13
      litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/service/WxOrderService.java
  10. 15 76
      litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxAddressController.java
  11. 2 1
      litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxCartController.java
  12. 0 43
      litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxRegionController.java
  13. 2 2
      litemall-wx/pages/ucenter/address/address.wxml
  14. 123 120
      litemall-wx/pages/ucenter/addressAdd/addressAdd.js
  15. 5 5
      litemall-wx/pages/ucenter/addressAdd/addressAdd.wxml
  16. 3296 0
      litemall-wx/utils/area.js
  17. 2 2
      renard-wx/pages/ucenter/address/address.wxml
  18. 141 138
      renard-wx/pages/ucenter/addressAdd/addressAdd.js
  19. 5 5
      renard-wx/pages/ucenter/addressAdd/addressAdd.wxml
  20. 3295 0
      renard-wx/utils/area.js

+ 1 - 26
litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminAddressController.java

@@ -34,26 +34,6 @@ public class AdminAddressController {
     @Autowired
     private LitemallRegionService regionService;
 
-    private Map<String, Object> toVo(LitemallAddress address) {
-        Map<String, Object> addressVo = new HashMap<>();
-        addressVo.put("id", address.getId());
-        addressVo.put("userId", address.getUserId());
-        addressVo.put("name", address.getName());
-        addressVo.put("mobile", address.getMobile());
-        addressVo.put("isDefault", address.getIsDefault());
-        addressVo.put("provinceId", address.getProvinceId());
-        addressVo.put("cityId", address.getCityId());
-        addressVo.put("areaId", address.getAreaId());
-        addressVo.put("address", address.getAddress());
-        String province = regionService.findById(address.getProvinceId()).getName();
-        String city = regionService.findById(address.getCityId()).getName();
-        String area = regionService.findById(address.getAreaId()).getName();
-        addressVo.put("province", province);
-        addressVo.put("city", city);
-        addressVo.put("area", area);
-        return addressVo;
-    }
-
     @RequiresPermissions("admin:address:list")
     @RequiresPermissionsDesc(menu={"用户管理" , "收货地址"}, button="查询")
     @GetMapping("/list")
@@ -66,15 +46,10 @@ public class AdminAddressController {
         List<LitemallAddress> addressList = addressService.querySelective(userId, name, page, limit, sort, order);
         long total = PageInfo.of(addressList).getTotal();
 
-        List<Map<String, Object>> addressVoList = new ArrayList<>(addressList.size());
-        for (LitemallAddress address : addressList) {
-            Map<String, Object> addressVo = toVo(address);
-            addressVoList.add(addressVo);
-        }
 
         Map<String, Object> data = new HashMap<>();
         data.put("total", total);
-        data.put("items", addressVoList);
+        data.put("items", addressList);
 
         return ResponseUtil.ok(data);
     }

+ 144 - 70
litemall-db/src/main/java/org/linlinjava/litemall/db/domain/LitemallAddress.java

@@ -53,47 +53,65 @@ public class LitemallAddress {
     /**
      *
      * This field was generated by MyBatis Generator.
-     * This field corresponds to the database column litemall_address.province_id
+     * This field corresponds to the database column litemall_address.province
      *
      * @mbg.generated
      */
-    private Integer provinceId;
+    private String province;
 
     /**
      *
      * This field was generated by MyBatis Generator.
-     * This field corresponds to the database column litemall_address.city_id
+     * This field corresponds to the database column litemall_address.city
      *
      * @mbg.generated
      */
-    private Integer cityId;
+    private String city;
 
     /**
      *
      * This field was generated by MyBatis Generator.
-     * This field corresponds to the database column litemall_address.area_id
+     * This field corresponds to the database column litemall_address.county
      *
      * @mbg.generated
      */
-    private Integer areaId;
+    private String county;
 
     /**
      *
      * This field was generated by MyBatis Generator.
-     * This field corresponds to the database column litemall_address.address
+     * This field corresponds to the database column litemall_address.address_detail
      *
      * @mbg.generated
      */
-    private String address;
+    private String addressDetail;
 
     /**
      *
      * This field was generated by MyBatis Generator.
-     * This field corresponds to the database column litemall_address.mobile
+     * This field corresponds to the database column litemall_address.area_code
      *
      * @mbg.generated
      */
-    private String mobile;
+    private String areaCode;
+
+    /**
+     *
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column litemall_address.postal_code
+     *
+     * @mbg.generated
+     */
+    private String postalCode;
+
+    /**
+     *
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column litemall_address.tel
+     *
+     * @mbg.generated
+     */
+    private String tel;
 
     /**
      *
@@ -205,122 +223,170 @@ public class LitemallAddress {
 
     /**
      * This method was generated by MyBatis Generator.
-     * This method returns the value of the database column litemall_address.province_id
+     * This method returns the value of the database column litemall_address.province
+     *
+     * @return the value of litemall_address.province
+     *
+     * @mbg.generated
+     */
+    public String getProvince() {
+        return province;
+    }
+
+    /**
+     * This method was generated by MyBatis Generator.
+     * This method sets the value of the database column litemall_address.province
+     *
+     * @param province the value for litemall_address.province
+     *
+     * @mbg.generated
+     */
+    public void setProvince(String province) {
+        this.province = province;
+    }
+
+    /**
+     * This method was generated by MyBatis Generator.
+     * This method returns the value of the database column litemall_address.city
+     *
+     * @return the value of litemall_address.city
+     *
+     * @mbg.generated
+     */
+    public String getCity() {
+        return city;
+    }
+
+    /**
+     * This method was generated by MyBatis Generator.
+     * This method sets the value of the database column litemall_address.city
+     *
+     * @param city the value for litemall_address.city
+     *
+     * @mbg.generated
+     */
+    public void setCity(String city) {
+        this.city = city;
+    }
+
+    /**
+     * This method was generated by MyBatis Generator.
+     * This method returns the value of the database column litemall_address.county
      *
-     * @return the value of litemall_address.province_id
+     * @return the value of litemall_address.county
      *
      * @mbg.generated
      */
-    public Integer getProvinceId() {
-        return provinceId;
+    public String getCounty() {
+        return county;
     }
 
     /**
      * This method was generated by MyBatis Generator.
-     * This method sets the value of the database column litemall_address.province_id
+     * This method sets the value of the database column litemall_address.county
      *
-     * @param provinceId the value for litemall_address.province_id
+     * @param county the value for litemall_address.county
      *
      * @mbg.generated
      */
-    public void setProvinceId(Integer provinceId) {
-        this.provinceId = provinceId;
+    public void setCounty(String county) {
+        this.county = county;
     }
 
     /**
      * This method was generated by MyBatis Generator.
-     * This method returns the value of the database column litemall_address.city_id
+     * This method returns the value of the database column litemall_address.address_detail
      *
-     * @return the value of litemall_address.city_id
+     * @return the value of litemall_address.address_detail
      *
      * @mbg.generated
      */
-    public Integer getCityId() {
-        return cityId;
+    public String getAddressDetail() {
+        return addressDetail;
     }
 
     /**
      * This method was generated by MyBatis Generator.
-     * This method sets the value of the database column litemall_address.city_id
+     * This method sets the value of the database column litemall_address.address_detail
      *
-     * @param cityId the value for litemall_address.city_id
+     * @param addressDetail the value for litemall_address.address_detail
      *
      * @mbg.generated
      */
-    public void setCityId(Integer cityId) {
-        this.cityId = cityId;
+    public void setAddressDetail(String addressDetail) {
+        this.addressDetail = addressDetail;
     }
 
     /**
      * This method was generated by MyBatis Generator.
-     * This method returns the value of the database column litemall_address.area_id
+     * This method returns the value of the database column litemall_address.area_code
      *
-     * @return the value of litemall_address.area_id
+     * @return the value of litemall_address.area_code
      *
      * @mbg.generated
      */
-    public Integer getAreaId() {
-        return areaId;
+    public String getAreaCode() {
+        return areaCode;
     }
 
     /**
      * This method was generated by MyBatis Generator.
-     * This method sets the value of the database column litemall_address.area_id
+     * This method sets the value of the database column litemall_address.area_code
      *
-     * @param areaId the value for litemall_address.area_id
+     * @param areaCode the value for litemall_address.area_code
      *
      * @mbg.generated
      */
-    public void setAreaId(Integer areaId) {
-        this.areaId = areaId;
+    public void setAreaCode(String areaCode) {
+        this.areaCode = areaCode;
     }
 
     /**
      * This method was generated by MyBatis Generator.
-     * This method returns the value of the database column litemall_address.address
+     * This method returns the value of the database column litemall_address.postal_code
      *
-     * @return the value of litemall_address.address
+     * @return the value of litemall_address.postal_code
      *
      * @mbg.generated
      */
-    public String getAddress() {
-        return address;
+    public String getPostalCode() {
+        return postalCode;
     }
 
     /**
      * This method was generated by MyBatis Generator.
-     * This method sets the value of the database column litemall_address.address
+     * This method sets the value of the database column litemall_address.postal_code
      *
-     * @param address the value for litemall_address.address
+     * @param postalCode the value for litemall_address.postal_code
      *
      * @mbg.generated
      */
-    public void setAddress(String address) {
-        this.address = address;
+    public void setPostalCode(String postalCode) {
+        this.postalCode = postalCode;
     }
 
     /**
      * This method was generated by MyBatis Generator.
-     * This method returns the value of the database column litemall_address.mobile
+     * This method returns the value of the database column litemall_address.tel
      *
-     * @return the value of litemall_address.mobile
+     * @return the value of litemall_address.tel
      *
      * @mbg.generated
      */
-    public String getMobile() {
-        return mobile;
+    public String getTel() {
+        return tel;
     }
 
     /**
      * This method was generated by MyBatis Generator.
-     * This method sets the value of the database column litemall_address.mobile
+     * This method sets the value of the database column litemall_address.tel
      *
-     * @param mobile the value for litemall_address.mobile
+     * @param tel the value for litemall_address.tel
      *
      * @mbg.generated
      */
-    public void setMobile(String mobile) {
-        this.mobile = mobile;
+    public void setTel(String tel) {
+        this.tel = tel;
     }
 
     /**
@@ -434,11 +500,13 @@ public class LitemallAddress {
         sb.append(", id=").append(id);
         sb.append(", name=").append(name);
         sb.append(", userId=").append(userId);
-        sb.append(", provinceId=").append(provinceId);
-        sb.append(", cityId=").append(cityId);
-        sb.append(", areaId=").append(areaId);
-        sb.append(", address=").append(address);
-        sb.append(", mobile=").append(mobile);
+        sb.append(", province=").append(province);
+        sb.append(", city=").append(city);
+        sb.append(", county=").append(county);
+        sb.append(", addressDetail=").append(addressDetail);
+        sb.append(", areaCode=").append(areaCode);
+        sb.append(", postalCode=").append(postalCode);
+        sb.append(", tel=").append(tel);
         sb.append(", isDefault=").append(isDefault);
         sb.append(", addTime=").append(addTime);
         sb.append(", updateTime=").append(updateTime);
@@ -468,11 +536,13 @@ public class LitemallAddress {
         return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
             && (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName()))
             && (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId()))
-            && (this.getProvinceId() == null ? other.getProvinceId() == null : this.getProvinceId().equals(other.getProvinceId()))
-            && (this.getCityId() == null ? other.getCityId() == null : this.getCityId().equals(other.getCityId()))
-            && (this.getAreaId() == null ? other.getAreaId() == null : this.getAreaId().equals(other.getAreaId()))
-            && (this.getAddress() == null ? other.getAddress() == null : this.getAddress().equals(other.getAddress()))
-            && (this.getMobile() == null ? other.getMobile() == null : this.getMobile().equals(other.getMobile()))
+            && (this.getProvince() == null ? other.getProvince() == null : this.getProvince().equals(other.getProvince()))
+            && (this.getCity() == null ? other.getCity() == null : this.getCity().equals(other.getCity()))
+            && (this.getCounty() == null ? other.getCounty() == null : this.getCounty().equals(other.getCounty()))
+            && (this.getAddressDetail() == null ? other.getAddressDetail() == null : this.getAddressDetail().equals(other.getAddressDetail()))
+            && (this.getAreaCode() == null ? other.getAreaCode() == null : this.getAreaCode().equals(other.getAreaCode()))
+            && (this.getPostalCode() == null ? other.getPostalCode() == null : this.getPostalCode().equals(other.getPostalCode()))
+            && (this.getTel() == null ? other.getTel() == null : this.getTel().equals(other.getTel()))
             && (this.getIsDefault() == null ? other.getIsDefault() == null : this.getIsDefault().equals(other.getIsDefault()))
             && (this.getAddTime() == null ? other.getAddTime() == null : this.getAddTime().equals(other.getAddTime()))
             && (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime()))
@@ -492,11 +562,13 @@ public class LitemallAddress {
         result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
         result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
         result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode());
-        result = prime * result + ((getProvinceId() == null) ? 0 : getProvinceId().hashCode());
-        result = prime * result + ((getCityId() == null) ? 0 : getCityId().hashCode());
-        result = prime * result + ((getAreaId() == null) ? 0 : getAreaId().hashCode());
-        result = prime * result + ((getAddress() == null) ? 0 : getAddress().hashCode());
-        result = prime * result + ((getMobile() == null) ? 0 : getMobile().hashCode());
+        result = prime * result + ((getProvince() == null) ? 0 : getProvince().hashCode());
+        result = prime * result + ((getCity() == null) ? 0 : getCity().hashCode());
+        result = prime * result + ((getCounty() == null) ? 0 : getCounty().hashCode());
+        result = prime * result + ((getAddressDetail() == null) ? 0 : getAddressDetail().hashCode());
+        result = prime * result + ((getAreaCode() == null) ? 0 : getAreaCode().hashCode());
+        result = prime * result + ((getPostalCode() == null) ? 0 : getPostalCode().hashCode());
+        result = prime * result + ((getTel() == null) ? 0 : getTel().hashCode());
         result = prime * result + ((getIsDefault() == null) ? 0 : getIsDefault().hashCode());
         result = prime * result + ((getAddTime() == null) ? 0 : getAddTime().hashCode());
         result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode());
@@ -526,11 +598,13 @@ public class LitemallAddress {
         id("id", "id", "INTEGER", false),
         name("name", "name", "VARCHAR", true),
         userId("user_id", "userId", "INTEGER", false),
-        provinceId("province_id", "provinceId", "INTEGER", false),
-        cityId("city_id", "cityId", "INTEGER", false),
-        areaId("area_id", "areaId", "INTEGER", false),
-        address("address", "address", "VARCHAR", false),
-        mobile("mobile", "mobile", "VARCHAR", false),
+        province("province", "province", "VARCHAR", false),
+        city("city", "city", "VARCHAR", false),
+        county("county", "county", "VARCHAR", false),
+        addressDetail("address_detail", "addressDetail", "VARCHAR", false),
+        areaCode("area_code", "areaCode", "CHAR", false),
+        postalCode("postal_code", "postalCode", "CHAR", false),
+        tel("tel", "tel", "VARCHAR", false),
         isDefault("is_default", "isDefault", "BIT", false),
         addTime("add_time", "addTime", "TIMESTAMP", false),
         updateTime("update_time", "updateTime", "TIMESTAMP", false),

ファイルの差分が大きいため隠しています
+ 502 - 188
litemall-db/src/main/java/org/linlinjava/litemall/db/domain/LitemallAddressExample.java


+ 0 - 6
litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallRegionService.java

@@ -52,10 +52,4 @@ public class LitemallRegionService {
         return regionMapper.selectByExample(example);
     }
 
-
-    public List<LitemallRegion> queryChildren(Integer id) {
-        LitemallRegionExample example = new LitemallRegionExample();
-        example.or().andPidEqualTo(id);
-        return regionMapper.selectByExample(example);
-    }
 }

+ 103 - 71
litemall-db/src/main/resources/org/linlinjava/litemall/db/dao/LitemallAddressMapper.xml

@@ -9,11 +9,13 @@
     <id column="id" jdbcType="INTEGER" property="id" />
     <result column="name" jdbcType="VARCHAR" property="name" />
     <result column="user_id" jdbcType="INTEGER" property="userId" />
-    <result column="province_id" jdbcType="INTEGER" property="provinceId" />
-    <result column="city_id" jdbcType="INTEGER" property="cityId" />
-    <result column="area_id" jdbcType="INTEGER" property="areaId" />
-    <result column="address" jdbcType="VARCHAR" property="address" />
-    <result column="mobile" jdbcType="VARCHAR" property="mobile" />
+    <result column="province" jdbcType="VARCHAR" property="province" />
+    <result column="city" jdbcType="VARCHAR" property="city" />
+    <result column="county" jdbcType="VARCHAR" property="county" />
+    <result column="address_detail" jdbcType="VARCHAR" property="addressDetail" />
+    <result column="area_code" jdbcType="CHAR" property="areaCode" />
+    <result column="postal_code" jdbcType="CHAR" property="postalCode" />
+    <result column="tel" jdbcType="VARCHAR" property="tel" />
     <result column="is_default" jdbcType="BIT" property="isDefault" />
     <result column="add_time" jdbcType="TIMESTAMP" property="addTime" />
     <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
@@ -90,8 +92,8 @@
       WARNING - @mbg.generated
       This element is automatically generated by MyBatis Generator, do not modify.
     -->
-    id, `name`, user_id, province_id, city_id, area_id, address, mobile, is_default, 
-    add_time, update_time, deleted
+    id, `name`, user_id, province, city, county, address_detail, area_code, postal_code, 
+    tel, is_default, add_time, update_time, deleted
   </sql>
   <select id="selectByExample" parameterType="org.linlinjava.litemall.db.domain.LitemallAddressExample" resultMap="BaseResultMap">
     <!--
@@ -128,8 +130,8 @@
         </foreach>
       </when>
       <otherwise>
-        id, `name`, user_id, province_id, city_id, area_id, address, mobile, is_default, 
-          add_time, update_time, deleted
+        id, `name`, user_id, province, city, county, address_detail, area_code, postal_code, 
+          tel, is_default, add_time, update_time, deleted
       </otherwise>
     </choose>
     from litemall_address
@@ -188,8 +190,8 @@
         </foreach>
       </when>
       <otherwise>
-        id, `name`, user_id, province_id, city_id, area_id, address, mobile, is_default, 
-          add_time, update_time, deleted
+        id, `name`, user_id, province, city, county, address_detail, area_code, postal_code, 
+          tel, is_default, add_time, update_time, deleted
       </otherwise>
     </choose>
     from litemall_address
@@ -221,14 +223,16 @@
     <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">
       SELECT LAST_INSERT_ID()
     </selectKey>
-    insert into litemall_address (`name`, user_id, province_id, 
-      city_id, area_id, address, 
-      mobile, is_default, add_time, 
-      update_time, deleted)
-    values (#{name,jdbcType=VARCHAR}, #{userId,jdbcType=INTEGER}, #{provinceId,jdbcType=INTEGER}, 
-      #{cityId,jdbcType=INTEGER}, #{areaId,jdbcType=INTEGER}, #{address,jdbcType=VARCHAR}, 
-      #{mobile,jdbcType=VARCHAR}, #{isDefault,jdbcType=BIT}, #{addTime,jdbcType=TIMESTAMP}, 
-      #{updateTime,jdbcType=TIMESTAMP}, #{deleted,jdbcType=BIT})
+    insert into litemall_address (`name`, user_id, province, 
+      city, county, address_detail, 
+      area_code, postal_code, tel, 
+      is_default, add_time, update_time, 
+      deleted)
+    values (#{name,jdbcType=VARCHAR}, #{userId,jdbcType=INTEGER}, #{province,jdbcType=VARCHAR}, 
+      #{city,jdbcType=VARCHAR}, #{county,jdbcType=VARCHAR}, #{addressDetail,jdbcType=VARCHAR}, 
+      #{areaCode,jdbcType=CHAR}, #{postalCode,jdbcType=CHAR}, #{tel,jdbcType=VARCHAR}, 
+      #{isDefault,jdbcType=BIT}, #{addTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, 
+      #{deleted,jdbcType=BIT})
   </insert>
   <insert id="insertSelective" parameterType="org.linlinjava.litemall.db.domain.LitemallAddress">
     <!--
@@ -246,20 +250,26 @@
       <if test="userId != null">
         user_id,
       </if>
-      <if test="provinceId != null">
-        province_id,
+      <if test="province != null">
+        province,
       </if>
-      <if test="cityId != null">
-        city_id,
+      <if test="city != null">
+        city,
       </if>
-      <if test="areaId != null">
-        area_id,
+      <if test="county != null">
+        county,
       </if>
-      <if test="address != null">
-        address,
+      <if test="addressDetail != null">
+        address_detail,
       </if>
-      <if test="mobile != null">
-        mobile,
+      <if test="areaCode != null">
+        area_code,
+      </if>
+      <if test="postalCode != null">
+        postal_code,
+      </if>
+      <if test="tel != null">
+        tel,
       </if>
       <if test="isDefault != null">
         is_default,
@@ -281,20 +291,26 @@
       <if test="userId != null">
         #{userId,jdbcType=INTEGER},
       </if>
-      <if test="provinceId != null">
-        #{provinceId,jdbcType=INTEGER},
+      <if test="province != null">
+        #{province,jdbcType=VARCHAR},
+      </if>
+      <if test="city != null">
+        #{city,jdbcType=VARCHAR},
+      </if>
+      <if test="county != null">
+        #{county,jdbcType=VARCHAR},
       </if>
-      <if test="cityId != null">
-        #{cityId,jdbcType=INTEGER},
+      <if test="addressDetail != null">
+        #{addressDetail,jdbcType=VARCHAR},
       </if>
-      <if test="areaId != null">
-        #{areaId,jdbcType=INTEGER},
+      <if test="areaCode != null">
+        #{areaCode,jdbcType=CHAR},
       </if>
-      <if test="address != null">
-        #{address,jdbcType=VARCHAR},
+      <if test="postalCode != null">
+        #{postalCode,jdbcType=CHAR},
       </if>
-      <if test="mobile != null">
-        #{mobile,jdbcType=VARCHAR},
+      <if test="tel != null">
+        #{tel,jdbcType=VARCHAR},
       </if>
       <if test="isDefault != null">
         #{isDefault,jdbcType=BIT},
@@ -336,20 +352,26 @@
       <if test="record.userId != null">
         user_id = #{record.userId,jdbcType=INTEGER},
       </if>
-      <if test="record.provinceId != null">
-        province_id = #{record.provinceId,jdbcType=INTEGER},
+      <if test="record.province != null">
+        province = #{record.province,jdbcType=VARCHAR},
       </if>
-      <if test="record.cityId != null">
-        city_id = #{record.cityId,jdbcType=INTEGER},
+      <if test="record.city != null">
+        city = #{record.city,jdbcType=VARCHAR},
       </if>
-      <if test="record.areaId != null">
-        area_id = #{record.areaId,jdbcType=INTEGER},
+      <if test="record.county != null">
+        county = #{record.county,jdbcType=VARCHAR},
       </if>
-      <if test="record.address != null">
-        address = #{record.address,jdbcType=VARCHAR},
+      <if test="record.addressDetail != null">
+        address_detail = #{record.addressDetail,jdbcType=VARCHAR},
       </if>
-      <if test="record.mobile != null">
-        mobile = #{record.mobile,jdbcType=VARCHAR},
+      <if test="record.areaCode != null">
+        area_code = #{record.areaCode,jdbcType=CHAR},
+      </if>
+      <if test="record.postalCode != null">
+        postal_code = #{record.postalCode,jdbcType=CHAR},
+      </if>
+      <if test="record.tel != null">
+        tel = #{record.tel,jdbcType=VARCHAR},
       </if>
       <if test="record.isDefault != null">
         is_default = #{record.isDefault,jdbcType=BIT},
@@ -377,11 +399,13 @@
     set id = #{record.id,jdbcType=INTEGER},
       `name` = #{record.name,jdbcType=VARCHAR},
       user_id = #{record.userId,jdbcType=INTEGER},
-      province_id = #{record.provinceId,jdbcType=INTEGER},
-      city_id = #{record.cityId,jdbcType=INTEGER},
-      area_id = #{record.areaId,jdbcType=INTEGER},
-      address = #{record.address,jdbcType=VARCHAR},
-      mobile = #{record.mobile,jdbcType=VARCHAR},
+      province = #{record.province,jdbcType=VARCHAR},
+      city = #{record.city,jdbcType=VARCHAR},
+      county = #{record.county,jdbcType=VARCHAR},
+      address_detail = #{record.addressDetail,jdbcType=VARCHAR},
+      area_code = #{record.areaCode,jdbcType=CHAR},
+      postal_code = #{record.postalCode,jdbcType=CHAR},
+      tel = #{record.tel,jdbcType=VARCHAR},
       is_default = #{record.isDefault,jdbcType=BIT},
       add_time = #{record.addTime,jdbcType=TIMESTAMP},
       update_time = #{record.updateTime,jdbcType=TIMESTAMP},
@@ -403,20 +427,26 @@
       <if test="userId != null">
         user_id = #{userId,jdbcType=INTEGER},
       </if>
-      <if test="provinceId != null">
-        province_id = #{provinceId,jdbcType=INTEGER},
+      <if test="province != null">
+        province = #{province,jdbcType=VARCHAR},
+      </if>
+      <if test="city != null">
+        city = #{city,jdbcType=VARCHAR},
+      </if>
+      <if test="county != null">
+        county = #{county,jdbcType=VARCHAR},
       </if>
-      <if test="cityId != null">
-        city_id = #{cityId,jdbcType=INTEGER},
+      <if test="addressDetail != null">
+        address_detail = #{addressDetail,jdbcType=VARCHAR},
       </if>
-      <if test="areaId != null">
-        area_id = #{areaId,jdbcType=INTEGER},
+      <if test="areaCode != null">
+        area_code = #{areaCode,jdbcType=CHAR},
       </if>
-      <if test="address != null">
-        address = #{address,jdbcType=VARCHAR},
+      <if test="postalCode != null">
+        postal_code = #{postalCode,jdbcType=CHAR},
       </if>
-      <if test="mobile != null">
-        mobile = #{mobile,jdbcType=VARCHAR},
+      <if test="tel != null">
+        tel = #{tel,jdbcType=VARCHAR},
       </if>
       <if test="isDefault != null">
         is_default = #{isDefault,jdbcType=BIT},
@@ -441,11 +471,13 @@
     update litemall_address
     set `name` = #{name,jdbcType=VARCHAR},
       user_id = #{userId,jdbcType=INTEGER},
-      province_id = #{provinceId,jdbcType=INTEGER},
-      city_id = #{cityId,jdbcType=INTEGER},
-      area_id = #{areaId,jdbcType=INTEGER},
-      address = #{address,jdbcType=VARCHAR},
-      mobile = #{mobile,jdbcType=VARCHAR},
+      province = #{province,jdbcType=VARCHAR},
+      city = #{city,jdbcType=VARCHAR},
+      county = #{county,jdbcType=VARCHAR},
+      address_detail = #{addressDetail,jdbcType=VARCHAR},
+      area_code = #{areaCode,jdbcType=CHAR},
+      postal_code = #{postalCode,jdbcType=CHAR},
+      tel = #{tel,jdbcType=VARCHAR},
       is_default = #{isDefault,jdbcType=BIT},
       add_time = #{addTime,jdbcType=TIMESTAMP},
       update_time = #{updateTime,jdbcType=TIMESTAMP},
@@ -483,8 +515,8 @@
         </foreach>
       </when>
       <otherwise>
-        id, `name`, user_id, province_id, city_id, area_id, address, mobile, is_default, 
-          add_time, update_time, deleted
+        id, `name`, user_id, province, city, county, address_detail, area_code, postal_code, 
+          tel, is_default, add_time, update_time, deleted
       </otherwise>
     </choose>
     from litemall_address

+ 3 - 3
litemall-db/src/main/resources/org/linlinjava/litemall/db/dao/LitemallPermissionMapper.xml

@@ -115,7 +115,7 @@
       distinct
     </if>
     <choose>
-      <when test="selective != null and selective.length > 0">
+      <when test="selective != null and selective.length &gt; 0">
         <foreach collection="selective" item="column" separator=",">
           ${column.escapedColumnName}
         </foreach>
@@ -174,7 +174,7 @@
     -->
     select
     <choose>
-      <when test="selective != null and selective.length > 0">
+      <when test="selective != null and selective.length &gt; 0">
         <foreach collection="selective" item="column" separator=",">
           ${column.escapedColumnName}
         </foreach>
@@ -380,7 +380,7 @@
     -->
     select
     <choose>
-      <when test="selective != null and selective.length > 0">
+      <when test="selective != null and selective.length &gt; 0">
         <foreach collection="selective" item="column" separator=",">
           ${column.escapedColumnName}
         </foreach>

+ 1 - 1
litemall-vue/src/api/api.js

@@ -327,7 +327,7 @@ export function couponReceive(data) {
 }
 const CouponExchange='wx/coupon/exchange'; //优惠券兑换
 
-const StorageUpload='wx/torage/upload'; //图片上传,
+const StorageUpload='wx/storage/upload'; //图片上传,
 
 const UserIndex='wx/user/index'; //个人页面用户相关信息
 export function userIndex() {

ファイルの差分が大きいため隠しています
+ 3239 - 3607
litemall-vue/src/views/user/module-address-edit/area.json


+ 3 - 13
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/service/WxOrderService.java

@@ -106,17 +106,6 @@ public class WxOrderService {
     @Autowired
     private CouponVerifyService couponVerifyService;
 
-    private String detailedAddress(LitemallAddress litemallAddress) {
-        Integer provinceId = litemallAddress.getProvinceId();
-        Integer cityId = litemallAddress.getCityId();
-        Integer areaId = litemallAddress.getAreaId();
-        String provinceName = regionService.findById(provinceId).getName();
-        String cityName = regionService.findById(cityId).getName();
-        String areaName = regionService.findById(areaId).getName();
-        String fullRegion = provinceName + " " + cityName + " " + areaName;
-        return fullRegion + " " + litemallAddress.getAddress();
-    }
-
     /**
      * 订单列表
      *
@@ -165,6 +154,7 @@ public class WxOrderService {
                 orderGoodsVo.put("goodsName", orderGoods.getGoodsName());
                 orderGoodsVo.put("number", orderGoods.getNumber());
                 orderGoodsVo.put("picUrl", orderGoods.getPicUrl());
+                orderGoodsVo.put("specifications", orderGoods.getSpecifications());
                 orderGoodsVoList.add(orderGoodsVo);
             }
             orderVo.put("goodsList", orderGoodsVoList);
@@ -348,9 +338,9 @@ public class WxOrderService {
         order.setOrderSn(orderService.generateOrderSn(userId));
         order.setOrderStatus(OrderUtil.STATUS_CREATE);
         order.setConsignee(checkedAddress.getName());
-        order.setMobile(checkedAddress.getMobile());
+        order.setMobile(checkedAddress.getTel());
         order.setMessage(message);
-        String detailedAddress = detailedAddress(checkedAddress);
+        String detailedAddress = checkedAddress.getProvince() + checkedAddress.getCity() + checkedAddress.getCounty() + " " + checkedAddress.getAddressDetail();
         order.setAddress(detailedAddress);
         order.setGoodsPrice(checkedGoodsPrice);
         order.setFreightPrice(freightPrice);

+ 15 - 76
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxAddressController.java

@@ -5,7 +5,6 @@ import org.apache.commons.logging.LogFactory;
 import org.linlinjava.litemall.core.util.RegexUtil;
 import org.linlinjava.litemall.core.util.ResponseUtil;
 import org.linlinjava.litemall.db.domain.LitemallAddress;
-import org.linlinjava.litemall.db.domain.LitemallRegion;
 import org.linlinjava.litemall.db.service.LitemallAddressService;
 import org.linlinjava.litemall.db.service.LitemallRegionService;
 import org.linlinjava.litemall.wx.annotation.LoginUser;
@@ -16,11 +15,7 @@ import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
 import javax.validation.constraints.NotNull;
-import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
-import java.util.concurrent.*;
 
 /**
  * 用户收货地址服务
@@ -37,11 +32,6 @@ public class WxAddressController extends GetRegionService {
 	@Autowired
 	private LitemallRegionService regionService;
 
-	private final static ArrayBlockingQueue<Runnable> WORK_QUEUE = new ArrayBlockingQueue<>(6);
-
-	private final static RejectedExecutionHandler HANDLER = new ThreadPoolExecutor.CallerRunsPolicy();
-
-	private static ThreadPoolExecutor executorService = new ThreadPoolExecutor(3, 6, 1000, TimeUnit.MILLISECONDS, WORK_QUEUE, HANDLER);
 
 	/**
 	 * 用户收货地址列表
@@ -55,39 +45,7 @@ public class WxAddressController extends GetRegionService {
 			return ResponseUtil.unlogin();
 		}
 		List<LitemallAddress> addressList = addressService.queryByUid(userId);
-		List<Map<String, Object>> addressVoList = new ArrayList<>(addressList.size());
-		List<LitemallRegion> regionList = getLitemallRegions();
-		for (LitemallAddress address : addressList) {
-			Map<String, Object> addressVo = new HashMap<>();
-			addressVo.put("id", address.getId());
-			addressVo.put("name", address.getName());
-			addressVo.put("mobile", address.getMobile());
-			addressVo.put("isDefault", address.getIsDefault());
-			Callable<String> provinceCallable = () -> regionList.stream().filter(region -> region.getId().equals(address.getProvinceId())).findAny().orElse(null).getName();
-			Callable<String> cityCallable = () -> regionList.stream().filter(region -> region.getId().equals(address.getCityId())).findAny().orElse(null).getName();
-			Callable<String> areaCallable = () -> regionList.stream().filter(region -> region.getId().equals(address.getAreaId())).findAny().orElse(null).getName();
-			FutureTask<String> provinceNameCallableTask = new FutureTask<>(provinceCallable);
-			FutureTask<String> cityNameCallableTask = new FutureTask<>(cityCallable);
-			FutureTask<String> areaNameCallableTask = new FutureTask<>(areaCallable);
-			executorService.submit(provinceNameCallableTask);
-			executorService.submit(cityNameCallableTask);
-			executorService.submit(areaNameCallableTask);
-			String detailedAddress = "";
-			try {
-				String province = provinceNameCallableTask.get();
-				String city = cityNameCallableTask.get();
-				String area = areaNameCallableTask.get();
-				String addr = address.getAddress();
-				detailedAddress = province + city + area + " " + addr;
-			}
-			catch (Exception e) {
-				e.printStackTrace();
-			}
-			addressVo.put("detailedAddress", detailedAddress);
-
-			addressVoList.add(addressVo);
-		}
-		return ResponseUtil.ok(addressVoList);
+		return ResponseUtil.ok(addressList);
 	}
 
 	/**
@@ -107,23 +65,7 @@ public class WxAddressController extends GetRegionService {
 		if (address == null) {
 			return ResponseUtil.badArgumentValue();
 		}
-
-		Map<Object, Object> data = new HashMap<Object, Object>();
-		data.put("id", address.getId());
-		data.put("name", address.getName());
-		data.put("provinceId", address.getProvinceId());
-		data.put("cityId", address.getCityId());
-		data.put("areaId", address.getAreaId());
-		data.put("mobile", address.getMobile());
-		data.put("address", address.getAddress());
-		data.put("isDefault", address.getIsDefault());
-		String pname = regionService.findById(address.getProvinceId()).getName();
-		data.put("provinceName", pname);
-		String cname = regionService.findById(address.getCityId()).getName();
-		data.put("cityName", cname);
-		String dname = regionService.findById(address.getAreaId()).getName();
-		data.put("areaName", dname);
-		return ResponseUtil.ok(data);
+		return ResponseUtil.ok(address);
 	}
 
 	private Object validate(LitemallAddress address) {
@@ -133,7 +75,7 @@ public class WxAddressController extends GetRegionService {
 		}
 
 		// 测试收货手机号码是否正确
-		String mobile = address.getMobile();
+		String mobile = address.getTel();
 		if (StringUtils.isEmpty(mobile)) {
 			return ResponseUtil.badArgument();
 		}
@@ -141,31 +83,28 @@ public class WxAddressController extends GetRegionService {
 			return ResponseUtil.badArgument();
 		}
 
-		Integer pid = address.getProvinceId();
-		if (pid == null) {
+		String province = address.getProvince();
+		if (StringUtils.isEmpty(province)) {
 			return ResponseUtil.badArgument();
 		}
-		if (regionService.findById(pid) == null) {
-			return ResponseUtil.badArgumentValue();
-		}
 
-		Integer cid = address.getCityId();
-		if (cid == null) {
+		String city = address.getCity();
+		if (StringUtils.isEmpty(city)) {
 			return ResponseUtil.badArgument();
 		}
-		if (regionService.findById(cid) == null) {
-			return ResponseUtil.badArgumentValue();
-		}
 
-		Integer aid = address.getAreaId();
-		if (aid == null) {
+		String county = address.getCounty();
+		if (StringUtils.isEmpty(county)) {
 			return ResponseUtil.badArgument();
 		}
-		if (regionService.findById(aid) == null) {
-			return ResponseUtil.badArgumentValue();
+
+
+		String areaCode = address.getAreaCode();
+		if (StringUtils.isEmpty(areaCode)) {
+			return ResponseUtil.badArgument();
 		}
 
-		String detailedAddress = address.getAddress();
+		String detailedAddress = address.getAddressDetail();
 		if (StringUtils.isEmpty(detailedAddress)) {
 			return ResponseUtil.badArgument();
 		}

+ 2 - 1
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxCartController.java

@@ -491,10 +491,11 @@ public class WxCartController {
 
         Map<String, Object> data = new HashMap<>();
         data.put("addressId", addressId);
+        data.put("couponId", couponId);
+        data.put("cartId", cartId);
         data.put("grouponRulesId", grouponRulesId);
         data.put("grouponPrice", grouponPrice);
         data.put("checkedAddress", checkedAddress);
-        data.put("couponId", couponId);
         data.put("availableCouponLength", availableCouponLength);
         data.put("goodsTotalPrice", checkedGoodsPrice);
         data.put("freightPrice", freightPrice);

+ 0 - 43
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxRegionController.java

@@ -1,43 +0,0 @@
-package org.linlinjava.litemall.wx.web;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.linlinjava.litemall.core.util.ResponseUtil;
-import org.linlinjava.litemall.db.domain.LitemallRegion;
-import org.linlinjava.litemall.db.service.LitemallRegionService;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-import javax.validation.constraints.NotNull;
-import java.util.List;
-
-/**
- * 区域服务
- */
-@RestController
-@RequestMapping("/wx/region")
-@Validated
-public class WxRegionController {
-    private final Log logger = LogFactory.getLog(WxRegionController.class);
-
-    @Autowired
-    private LitemallRegionService regionService;
-
-    /**
-     * 区域数据
-     * <p>
-     * 根据父区域ID,返回子区域数据。
-     * 如果父区域ID是0,则返回省级区域数据;
-     *
-     * @param pid 父区域ID
-     * @return 区域数据
-     */
-    @GetMapping("list")
-    public Object list(@NotNull Integer pid) {
-        List<LitemallRegion> regionList = regionService.queryByPid(pid);
-        return ResponseUtil.ok(regionList);
-    }
-}

+ 2 - 2
litemall-wx/pages/ucenter/address/address.wxml

@@ -6,8 +6,8 @@
         <view class="default" wx:if="{{item.isDefault}}">默认</view>
       </view>
       <view class="c">
-        <view class="mobile">{{item.mobile}}</view>
-        <view class="address">{{item.detailedAddress}}</view>
+        <view class="mobile">{{item.tel}}</view>
+        <view class="address">{{item.addressDetail}}</view>
       </view>
       <view class="r">
         <image catchtap="deleteAddress" data-address-id="{{item.id}}" class="del" src="/static/images/del-address.png"></image>

+ 123 - 120
litemall-wx/pages/ucenter/addressAdd/addressAdd.js

@@ -1,42 +1,35 @@
 var util = require('../../../utils/util.js');
 var api = require('../../../config/api.js');
 var check = require('../../../utils/check.js');
+var area = require('../../../utils/area.js');
 
 var app = getApp();
 Page({
   data: {
     address: {
       id: 0,
-      provinceId: 0,
-      cityId: 0,
-      areaId: 0,
+      areaCode: 0,
       address: '',
       name: '',
-      mobile: '',
+      tel: '',
       isDefault: 0,
-      provinceName: '',
-      cityName: '',
-      areaName: ''
+      province: '',
+      city: '',
+      county: ''
     },
     addressId: 0,
     openSelectRegion: false,
     selectRegionList: [{
-        id: 0,
-        name: '省份',
-        pid: 1,
-        type: 1
+        code: 0,
+        name: '省份'
       },
       {
-        id: 0,
-        name: '城市',
-        pid: 1,
-        type: 2
+        code: 0,
+        name: '城市'
       },
       {
-        id: 0,
-        name: '区县',
-        pid: 1,
-        type: 3
+        code: 0,
+        name: '区县'
       }
     ],
     regionType: 1,
@@ -45,7 +38,7 @@ Page({
   },
   bindinputMobile(event) {
     let address = this.data.address;
-    address.mobile = event.detail.value;
+    address.tel = event.detail.value;
     this.setData({
       address: address
     });
@@ -59,7 +52,7 @@ Page({
   },
   bindinputAddress(event) {
     let address = this.data.address;
-    address.address = event.detail.value;
+    address.addressDetail = event.detail.value;
     this.setData({
       address: address
     });
@@ -88,7 +81,7 @@ Page({
   setRegionDoneStatus() {
     let that = this;
     let doneStatus = that.data.selectRegionList.every(item => {
-      return item.id != 0;
+      return item.code != 0;
     });
 
     that.setData({
@@ -104,50 +97,54 @@ Page({
 
     //设置区域选择数据
     let address = this.data.address;
-    if (address.provinceId > 0 && address.cityId > 0 && address.areaId > 0) {
+    if (address.areaCode > 0) {
       let selectRegionList = this.data.selectRegionList;
-      selectRegionList[0].id = address.provinceId;
-      selectRegionList[0].name = address.provinceName;
-      selectRegionList[0].pid = 0;
+      selectRegionList[0].code = address.areaCode.slice(0, 2) + '0000';
+      selectRegionList[0].name = address.province;
 
-      selectRegionList[1].id = address.cityId;
-      selectRegionList[1].name = address.cityName;
-      selectRegionList[1].pid = address.provinceId;
+      selectRegionList[1].code = address.areaCode.slice(0, 4) + '00';
+      selectRegionList[1].name = address.city;
 
-      selectRegionList[2].id = address.areaId;
-      selectRegionList[2].name = address.areaName;
-      selectRegionList[2].pid = address.cityId;
+      selectRegionList[2].code = address.areaCode;
+      selectRegionList[2].name = address.county;
+
+      let regionList = area.getList('county', address.areaCode.slice(0, 4));
+      regionList = regionList.map(item => {
+        //标记已选择的
+        if (address.areaCode === item.code) {
+          item.selected = true;
+        } else {
+          item.selected = false;
+        }
+        return item;
+      })
 
       this.setData({
         selectRegionList: selectRegionList,
-        regionType: 3
+        regionType: 3,
+        regionList: regionList
       });
 
-      this.getRegionList(address.cityId);
     } else {
-      this.setData({
-        selectRegionList: [{
-            id: 0,
+      let selectRegionList = [{
+            code: 0,
             name: '省份',
-            pid: 0,
-            type: 1
           },
           {
-            id: 0,
+            code: 0,
             name: '城市',
-            pid: 0,
-            type: 2
           },
           {
-            id: 0,
+            code: 0,
             name: '区县',
-            pid: 0,
-            type: 3
           }
-        ],
-        regionType: 1
-      })
-      this.getRegionList(0);
+        ];
+
+      this.setData({
+        selectRegionList: selectRegionList,
+        regionType: 1,
+        regionList: area.getList('province')
+      });
     }
 
     this.setRegionDoneStatus();
@@ -172,73 +169,104 @@ Page({
     let selectRegionList = that.data.selectRegionList;
 
     //判断是否可点击
-    if (regionTypeIndex + 1 == this.data.regionType || (regionTypeIndex - 1 >= 0 && selectRegionList[regionTypeIndex - 1].id <= 0)) {
+    if (regionTypeIndex + 1 == this.data.regionType || (regionTypeIndex - 1 >= 0 && selectRegionList[regionTypeIndex - 1].code <= 0)) {
       return false;
     }
 
+    let selectRegionItem = selectRegionList[regionTypeIndex];
+    let code = selectRegionItem.code;
+    let regionList;
+    if (regionTypeIndex === 0) {
+      // 点击省级,取省级
+      regionList = area.getList('province');
+    }
+    else if (regionTypeIndex === 1) {
+      // 点击市级,取市级
+      regionList = area.getList('city', code.slice(0, 2)); 
+    }
+    else{
+      // 点击县级,取县级
+      regionList = area.getList('county', code.slice(0, 4)); 
+    }
+
+    regionList = regionList.map(item => {
+      //标记已选择的
+      if (that.data.selectRegionList[regionTypeIndex].code == item.code) {
+        item.selected = true;
+      } else {
+        item.selected = false;
+      }
+      return item;
+    })
+
     this.setData({
+      regionList: regionList,
       regionType: regionTypeIndex + 1
     })
 
-    let selectRegionItem = selectRegionList[regionTypeIndex];
-
-    this.getRegionList(selectRegionItem.pid);
-
     this.setRegionDoneStatus();
-
   },
   selectRegion(event) {
     let that = this;
     let regionIndex = event.target.dataset.regionIndex;
     let regionItem = this.data.regionList[regionIndex];
-    let regionType = regionItem.type;
+    let regionType = this.data.regionType;
     let selectRegionList = this.data.selectRegionList;
     selectRegionList[regionType - 1] = regionItem;
 
-
-    if (regionType != 3) {
+    if (regionType == 3) {
       this.setData({
-        selectRegionList: selectRegionList,
-        regionType: regionType + 1
+        selectRegionList: selectRegionList
       })
-      this.getRegionList(regionItem.id);
-    } else {
+
+      let regionList = that.data.regionList.map(item => {
+        //标记已选择的
+        if (that.data.selectRegionList[that.data.regionType - 1].code == item.code) {
+          item.selected = true;
+        } else {
+          item.selected = false;
+        }
+        return item;
+      })
+
       this.setData({
-        selectRegionList: selectRegionList
+        regionList: regionList
       })
+
+      this.setRegionDoneStatus();
+      return
     }
 
     //重置下级区域为空
     selectRegionList.map((item, index) => {
       if (index > regionType - 1) {
-        item.id = 0;
+        item.code = 0;
         item.name = index == 1 ? '城市' : '区县';
-        item.pid = 0;
       }
       return item;
     });
 
     this.setData({
-      selectRegionList: selectRegionList
+      selectRegionList: selectRegionList,
+      regionType: regionType + 1
     })
+    
+    let code = regionItem.code;
+    let regionList = [];
+    if (regionType === 1) {
+      // 点击省级,取市级
+      regionList= area.getList('city', code.slice(0, 2))
+    }
+    else {
+      // 点击市级,取县级
+      regionList= area.getList('county', code.slice(0, 4))
+    }
 
-
-    that.setData({
-      regionList: that.data.regionList.map(item => {
-
-        //标记已选择的
-        if (that.data.regionType == item.type && that.data.selectRegionList[that.data.regionType - 1].id == item.id) {
-          item.selected = true;
-        } else {
-          item.selected = false;
-        }
-
-        return item;
-      })
-    });
+    this.setData({
+      regionList: regionList
+    })
 
     this.setRegionDoneStatus();
-
   },
   doneSelectRegion() {
     if (this.data.selectRegionDone === false) {
@@ -247,12 +275,10 @@ Page({
 
     let address = this.data.address;
     let selectRegionList = this.data.selectRegionList;
-    address.provinceId = selectRegionList[0].id;
-    address.cityId = selectRegionList[1].id;
-    address.areaId = selectRegionList[2].id;
-    address.provinceName = selectRegionList[0].name;
-    address.cityName = selectRegionList[1].name;
-    address.areaName = selectRegionList[2].name;
+    address.province = selectRegionList[0].name;
+    address.city = selectRegionList[1].name;
+    address.county = selectRegionList[2].name;
+    address.areaCode = selectRegionList[2].code;
 
     this.setData({
       address: address,
@@ -267,29 +293,6 @@ Page({
     });
 
   },
-  getRegionList(regionId) {
-    let that = this;
-    let regionType = that.data.regionType;
-    util.request(api.RegionList, {
-      pid: regionId
-    }).then(function(res) {
-      if (res.errno === 0) {
-        that.setData({
-          regionList: res.data.map(item => {
-
-            //标记已选择的
-            if (regionType == item.type && that.data.selectRegionList[regionType - 1].id == item.id) {
-              item.selected = true;
-            } else {
-              item.selected = false;
-            }
-
-            return item;
-          })
-        });
-      }
-    });
-  },
   cancelAddress() {
     wx.navigateBack();
   },
@@ -303,23 +306,23 @@ Page({
       return false;
     }
 
-    if (address.mobile == '') {
+    if (address.tel == '') {
       util.showErrorToast('请输入手机号码');
       return false;
     }
 
 
-    if (address.areaId == 0) {
+    if (address.areaCode == 0) {
       util.showErrorToast('请输入省市区');
       return false;
     }
 
-    if (address.address == '') {
+    if (address.addressDetail == '') {
       util.showErrorToast('请输入详细地址');
       return false;
     }
 
-    if (!check.isValidPhone(address.mobile)) {
+    if (!check.isValidPhone(address.tel)) {
       util.showErrorToast('手机号不正确');
       return false;
     }
@@ -328,11 +331,12 @@ Page({
     util.request(api.AddressSave, {
       id: address.id,
       name: address.name,
-      mobile: address.mobile,
-      provinceId: address.provinceId,
-      cityId: address.cityId,
-      areaId: address.areaId,
-      address: address.address,
+      tel: address.tel,
+      province: address.province,
+      city: address.city,
+      county: address.county,
+      areaCode: address.areaCode,
+      addressDetail: address.addressDetail,
       isDefault: address.isDefault
     }, 'POST').then(function(res) {
       if (res.errno === 0) {
@@ -359,7 +363,6 @@ Page({
   },
   onShow: function() {
     // 页面显示
-
   },
   onHide: function() {
     // 页面隐藏

+ 5 - 5
litemall-wx/pages/ucenter/addressAdd/addressAdd.wxml

@@ -4,13 +4,13 @@
       <input class="input" bindinput="bindinputName" placeholder="姓名" value="{{address.name}}" auto-focus/>
     </view>
     <view class="form-item">
-      <input class="input" bindinput="bindinputMobile" value="{{address.mobile}}" placeholder="手机号码" />
+      <input class="input" bindinput="bindinputMobile" value="{{address.tel}}" placeholder="手机号码" />
     </view>
     <view class="form-item">
-      <input class="input" value="{{address.provinceName +  address.cityName + address.areaName}}" disabled="true" bindtap="chooseRegion" placeholder="省份、城市、区县" />
+      <input class="input" value="{{address.province + address.city + address.county}}" disabled="true" bindtap="chooseRegion" placeholder="省份、城市、区县" />
     </view>
     <view class="form-item">
-      <input class="input" bindinput="bindinputAddress" value="{{address.address}}" placeholder="详细地址, 如街道、楼盘号等" />
+      <input class="input" bindinput="bindinputAddress" value="{{address.addressDetail}}" placeholder="详细地址, 如街道、楼盘号等" />
     </view>
     <view class="form-default">
       <text bindtap="bindIsDefault" class="default-input {{address.isDefault == 1 ? 'selected' : ''}}">设为默认地址</text>
@@ -25,13 +25,13 @@
   <view class="region-select" wx:if="{{openSelectRegion}}">
     <view class="hd">
       <view class="region-selected">
-        <view class="item {{item.id == 0 ? 'disabled' : ''}} {{(regionType -1) === index ? 'selected' : ''}}" bindtap="selectRegionType" data-region-type-index="{{index}}" wx:for="{{selectRegionList}}" wx:key="id">{{item.name}}</view>
+        <view class="item {{item.code == 0 ? 'disabled' : ''}} {{(regionType -1) === index ? 'selected' : ''}}" bindtap="selectRegionType" data-region-type-index="{{index}}" wx:for="{{selectRegionList}}" wx:key="code">{{item.name}}</view>
       </view>
       <view class="done {{selectRegionDone ? '' : 'disabled'}}" bindtap="doneSelectRegion">确定</view>
     </view>
     <view class="bd">
       <scroll-view scroll-y class="region-list">
-        <view class="item {{item.selected ? 'selected' : ''}}" bindtap="selectRegion" data-region-index="{{index}}" wx:for="{{regionList}}" wx:key="id">{{item.name}}</view>
+        <view class="item {{item.selected ? 'selected' : ''}}" bindtap="selectRegion" data-region-index="{{index}}" wx:for="{{regionList}}" wx:key="code">{{item.name}}</view>
       </scroll-view>
     </view>
   </view>

ファイルの差分が大きいため隠しています
+ 3296 - 0
litemall-wx/utils/area.js


+ 2 - 2
renard-wx/pages/ucenter/address/address.wxml

@@ -6,8 +6,8 @@
         <view class="default" wx:if="{{item.isDefault}}">默认</view>
       </view>
       <view class="c">
-        <view class="mobile">{{item.mobile}}</view>
-        <view class="address">{{item.detailedAddress}}</view>
+        <view class="mobile">{{item.tel}}</view>
+        <view class="address">{{item.addressDetail}}</view>
       </view>
       <view class="r">
         <image catchtap="deleteAddress" data-address-id="{{item.id}}" class="del" src="/static/images/del-address.png"></image>

+ 141 - 138
renard-wx/pages/ucenter/addressAdd/addressAdd.js

@@ -1,43 +1,36 @@
 var util = require('../../../utils/util.js');
 var api = require('../../../config/api.js');
 var check = require('../../../utils/check.js');
+var area = require('../../../utils/area.js');
 
 var app = getApp();
 Page({
   data: {
     address: {
       id: 0,
-      provinceId: 0,
-      cityId: 0,
-      areaId: 0,
+      areaCode: 0,
       address: '',
       name: '',
-      mobile: '',
+      tel: '',
       isDefault: 0,
-      provinceName: '',
-      cityName: '',
-      areaName: ''
+      province: '',
+      city: '',
+      county: ''
     },
     addressId: 0,
     openSelectRegion: false,
     selectRegionList: [{
-        id: 0,
-        name: '省份',
-        pid: 1,
-        type: 1
-      },
-      {
-        id: 0,
-        name: '城市',
-        pid: 1,
-        type: 2
-      },
-      {
-        id: 0,
-        name: '区县',
-        pid: 1,
-        type: 3
-      }
+      code: 0,
+      name: '省份'
+    },
+    {
+      code: 0,
+      name: '城市'
+    },
+    {
+      code: 0,
+      name: '区县'
+    }
     ],
     regionType: 1,
     regionList: [],
@@ -45,7 +38,7 @@ Page({
   },
   bindinputMobile(event) {
     let address = this.data.address;
-    address.mobile = event.detail.value;
+    address.tel = event.detail.value;
     this.setData({
       address: address
     });
@@ -59,7 +52,7 @@ Page({
   },
   bindinputAddress(event) {
     let address = this.data.address;
-    address.address = event.detail.value;
+    address.addressDetail = event.detail.value;
     this.setData({
       address: address
     });
@@ -75,7 +68,7 @@ Page({
     let that = this;
     util.request(api.AddressDetail, {
       id: that.data.addressId
-    }).then(function(res) {
+    }).then(function (res) {
       if (res.errno === 0) {
         if (res.data) {
           that.setData({
@@ -88,7 +81,7 @@ Page({
   setRegionDoneStatus() {
     let that = this;
     let doneStatus = that.data.selectRegionList.every(item => {
-      return item.id != 0;
+      return item.code != 0;
     });
 
     that.setData({
@@ -104,56 +97,60 @@ Page({
 
     //设置区域选择数据
     let address = this.data.address;
-    if (address.provinceId > 0 && address.cityId > 0 && address.areaId > 0) {
+    if (address.areaCode > 0) {
       let selectRegionList = this.data.selectRegionList;
-      selectRegionList[0].id = address.provinceId;
-      selectRegionList[0].name = address.provinceName;
-      selectRegionList[0].pid = 0;
+      selectRegionList[0].code = address.areaCode.slice(0, 2) + '0000';
+      selectRegionList[0].name = address.province;
 
-      selectRegionList[1].id = address.cityId;
-      selectRegionList[1].name = address.cityName;
-      selectRegionList[1].pid = address.provinceId;
+      selectRegionList[1].code = address.areaCode.slice(0, 4) + '00';
+      selectRegionList[1].name = address.city;
 
-      selectRegionList[2].id = address.areaId;
-      selectRegionList[2].name = address.areaName;
-      selectRegionList[2].pid = address.cityId;
+      selectRegionList[2].code = address.areaCode;
+      selectRegionList[2].name = address.county;
+
+      let regionList = area.getList('county', address.areaCode.slice(0, 4));
+      regionList = regionList.map(item => {
+        //标记已选择的
+        if (address.areaCode === item.code) {
+          item.selected = true;
+        } else {
+          item.selected = false;
+        }
+        return item;
+      })
 
       this.setData({
         selectRegionList: selectRegionList,
-        regionType: 3
+        regionType: 3,
+        regionList: regionList
       });
 
-      this.getRegionList(address.cityId);
     } else {
+      let selectRegionList = [{
+        code: 0,
+        name: '省份',
+      },
+      {
+        code: 0,
+        name: '城市',
+      },
+      {
+        code: 0,
+        name: '区县',
+      }
+      ];
+
       this.setData({
-        selectRegionList: [{
-            id: 0,
-            name: '省份',
-            pid: 0,
-            type: 1
-          },
-          {
-            id: 0,
-            name: '城市',
-            pid: 0,
-            type: 2
-          },
-          {
-            id: 0,
-            name: '区县',
-            pid: 0,
-            type: 3
-          }
-        ],
-        regionType: 1
-      })
-      this.getRegionList(0);
+        selectRegionList: selectRegionList,
+        regionType: 1,
+        regionList: area.getList('province')
+      });
     }
 
     this.setRegionDoneStatus();
 
   },
-  onLoad: function(options) {
+  onLoad: function (options) {
     // 页面初始化 options为页面跳转所带来的参数
     console.log(options)
     if (options.id && options.id != 0) {
@@ -163,7 +160,7 @@ Page({
       this.getAddressDetail();
     }
   },
-  onReady: function() {
+  onReady: function () {
 
   },
   selectRegionType(event) {
@@ -172,73 +169,104 @@ Page({
     let selectRegionList = that.data.selectRegionList;
 
     //判断是否可点击
-    if (regionTypeIndex + 1 == this.data.regionType || (regionTypeIndex - 1 >= 0 && selectRegionList[regionTypeIndex - 1].id <= 0)) {
+    if (regionTypeIndex + 1 == this.data.regionType || (regionTypeIndex - 1 >= 0 && selectRegionList[regionTypeIndex - 1].code <= 0)) {
       return false;
     }
 
+    let selectRegionItem = selectRegionList[regionTypeIndex];
+    let code = selectRegionItem.code;
+    let regionList;
+    if (regionTypeIndex === 0) {
+      // 点击省级,取省级
+      regionList = area.getList('province');
+    }
+    else if (regionTypeIndex === 1) {
+      // 点击市级,取市级
+      regionList = area.getList('city', code.slice(0, 2));
+    }
+    else {
+      // 点击县级,取县级
+      regionList = area.getList('county', code.slice(0, 4));
+    }
+
+    regionList = regionList.map(item => {
+      //标记已选择的
+      if (that.data.selectRegionList[regionTypeIndex].code == item.code) {
+        item.selected = true;
+      } else {
+        item.selected = false;
+      }
+      return item;
+    })
+
     this.setData({
+      regionList: regionList,
       regionType: regionTypeIndex + 1
     })
 
-    let selectRegionItem = selectRegionList[regionTypeIndex];
-
-    this.getRegionList(selectRegionItem.pid);
-
     this.setRegionDoneStatus();
-
   },
   selectRegion(event) {
     let that = this;
     let regionIndex = event.target.dataset.regionIndex;
     let regionItem = this.data.regionList[regionIndex];
-    let regionType = regionItem.type;
+    let regionType = this.data.regionType;
     let selectRegionList = this.data.selectRegionList;
     selectRegionList[regionType - 1] = regionItem;
 
-
-    if (regionType != 3) {
+    if (regionType == 3) {
       this.setData({
-        selectRegionList: selectRegionList,
-        regionType: regionType + 1
+        selectRegionList: selectRegionList
       })
-      this.getRegionList(regionItem.id);
-    } else {
+
+      let regionList = that.data.regionList.map(item => {
+        //标记已选择的
+        if (that.data.selectRegionList[that.data.regionType - 1].code == item.code) {
+          item.selected = true;
+        } else {
+          item.selected = false;
+        }
+        return item;
+      })
+
       this.setData({
-        selectRegionList: selectRegionList
+        regionList: regionList
       })
+
+      this.setRegionDoneStatus();
+      return
     }
 
     //重置下级区域为空
     selectRegionList.map((item, index) => {
       if (index > regionType - 1) {
-        item.id = 0;
+        item.code = 0;
         item.name = index == 1 ? '城市' : '区县';
-        item.pid = 0;
       }
       return item;
     });
 
     this.setData({
-      selectRegionList: selectRegionList
+      selectRegionList: selectRegionList,
+      regionType: regionType + 1
     })
 
+    let code = regionItem.code;
+    let regionList = [];
+    if (regionType === 1) {
+      // 点击省级,取市级
+      regionList = area.getList('city', code.slice(0, 2))
+    }
+    else {
+      // 点击市级,取县级
+      regionList = area.getList('county', code.slice(0, 4))
+    }
 
-    that.setData({
-      regionList: that.data.regionList.map(item => {
-
-        //标记已选择的
-        if (that.data.regionType == item.type && that.data.selectRegionList[that.data.regionType - 1].id == item.id) {
-          item.selected = true;
-        } else {
-          item.selected = false;
-        }
-
-        return item;
-      })
-    });
+    this.setData({
+      regionList: regionList
+    })
 
     this.setRegionDoneStatus();
-
   },
   doneSelectRegion() {
     if (this.data.selectRegionDone === false) {
@@ -247,12 +275,10 @@ Page({
 
     let address = this.data.address;
     let selectRegionList = this.data.selectRegionList;
-    address.provinceId = selectRegionList[0].id;
-    address.cityId = selectRegionList[1].id;
-    address.areaId = selectRegionList[2].id;
-    address.provinceName = selectRegionList[0].name;
-    address.cityName = selectRegionList[1].name;
-    address.areaName = selectRegionList[2].name;
+    address.province = selectRegionList[0].name;
+    address.city = selectRegionList[1].name;
+    address.county = selectRegionList[2].name;
+    address.areaCode = selectRegionList[2].code;
 
     this.setData({
       address: address,
@@ -267,29 +293,6 @@ Page({
     });
 
   },
-  getRegionList(regionId) {
-    let that = this;
-    let regionType = that.data.regionType;
-    util.request(api.RegionList, {
-      pid: regionId
-    }).then(function(res) {
-      if (res.errno === 0) {
-        that.setData({
-          regionList: res.data.map(item => {
-
-            //标记已选择的
-            if (regionType == item.type && that.data.selectRegionList[regionType - 1].id == item.id) {
-              item.selected = true;
-            } else {
-              item.selected = false;
-            }
-
-            return item;
-          })
-        });
-      }
-    });
-  },
   cancelAddress() {
     wx.navigateBack();
   },
@@ -303,23 +306,23 @@ Page({
       return false;
     }
 
-    if (address.mobile == '') {
+    if (address.tel == '') {
       util.showErrorToast('请输入手机号码');
       return false;
     }
 
 
-    if (address.areaId == 0) {
+    if (address.areaCode == 0) {
       util.showErrorToast('请输入省市区');
       return false;
     }
 
-    if (address.address == '') {
+    if (address.addressDetail == '') {
       util.showErrorToast('请输入详细地址');
       return false;
     }
 
-    if (!check.isValidPhone(address.mobile)) {
+    if (!check.isValidPhone(address.tel)) {
       util.showErrorToast('手机号不正确');
       return false;
     }
@@ -328,13 +331,14 @@ Page({
     util.request(api.AddressSave, {
       id: address.id,
       name: address.name,
-      mobile: address.mobile,
-      provinceId: address.provinceId,
-      cityId: address.cityId,
-      areaId: address.areaId,
-      address: address.address,
+      tel: address.tel,
+      province: address.province,
+      city: address.city,
+      county: address.county,
+      areaCode: address.areaCode,
+      addressDetail: address.addressDetail,
       isDefault: address.isDefault
-    }, 'POST').then(function(res) {
+    }, 'POST').then(function (res) {
       if (res.errno === 0) {
         //返回之前,先取出上一页对象,并设置addressId
         var pages = getCurrentPages();
@@ -357,15 +361,14 @@ Page({
     });
 
   },
-  onShow: function() {
+  onShow: function () {
     // 页面显示
-
   },
-  onHide: function() {
+  onHide: function () {
     // 页面隐藏
 
   },
-  onUnload: function() {
+  onUnload: function () {
     // 页面关闭
 
   }

+ 5 - 5
renard-wx/pages/ucenter/addressAdd/addressAdd.wxml

@@ -4,13 +4,13 @@
       <input class="input" bindinput="bindinputName" placeholder="姓名" value="{{address.name}}" auto-focus/>
     </view>
     <view class="form-item">
-      <input class="input" bindinput="bindinputMobile" value="{{address.mobile}}" placeholder="手机号码" />
+      <input class="input" bindinput="bindinputMobile" value="{{address.tel}}" placeholder="手机号码" />
     </view>
     <view class="form-item">
-      <input class="input" value="{{address.provinceName +  address.cityName + address.areaName}}" disabled="true" bindtap="chooseRegion" placeholder="省份、城市、区县" />
+      <input class="input" value="{{address.province + address.city + address.county}}" disabled="true" bindtap="chooseRegion" placeholder="省份、城市、区县" />
     </view>
     <view class="form-item">
-      <input class="input" bindinput="bindinputAddress" value="{{address.address}}" placeholder="详细地址, 如街道、楼盘号等" />
+      <input class="input" bindinput="bindinputAddress" value="{{address.addressDetail}}" placeholder="详细地址, 如街道、楼盘号等" />
     </view>
     <view class="form-default">
       <text bindtap="bindIsDefault" class="default-input {{address.isDefault == 1 ? 'selected' : ''}}">设为默认地址</text>
@@ -25,13 +25,13 @@
   <view class="region-select" wx:if="{{openSelectRegion}}">
     <view class="hd">
       <view class="region-selected">
-        <view class="item {{item.id == 0 ? 'disabled' : ''}} {{(regionType -1) === index ? 'selected' : ''}}" bindtap="selectRegionType" data-region-type-index="{{index}}" wx:for="{{selectRegionList}}" wx:key="id">{{item.name}}</view>
+        <view class="item {{item.code == 0 ? 'disabled' : ''}} {{(regionType -1) === index ? 'selected' : ''}}" bindtap="selectRegionType" data-region-type-index="{{index}}" wx:for="{{selectRegionList}}" wx:key="code">{{item.name}}</view>
       </view>
       <view class="done {{selectRegionDone ? '' : 'disabled'}}" bindtap="doneSelectRegion">确定</view>
     </view>
     <view class="bd">
       <scroll-view scroll-y class="region-list">
-        <view class="item {{item.selected ? 'selected' : ''}}" bindtap="selectRegion" data-region-index="{{index}}" wx:for="{{regionList}}" wx:key="id">{{item.name}}</view>
+        <view class="item {{item.selected ? 'selected' : ''}}" bindtap="selectRegion" data-region-index="{{index}}" wx:for="{{regionList}}" wx:key="code">{{item.name}}</view>
       </scroll-view>
     </view>
   </view>

ファイルの差分が大きいため隠しています
+ 3295 - 0
renard-wx/utils/area.js