diff --git a/ant-design-vue-jeecg/src/views/shopping/components/addrView.vue b/ant-design-vue-jeecg/src/views/shopping/components/addrView.vue index f0732432..dab71ccc 100644 --- a/ant-design-vue-jeecg/src/views/shopping/components/addrView.vue +++ b/ant-design-vue-jeecg/src/views/shopping/components/addrView.vue @@ -27,7 +27,7 @@ @confirm="confirm2(item.id)" @cancel="cancel" v-if="!item.sort==0" - >将其设置为默认地址 + >将其设置为默认地址 @@ -108,6 +108,7 @@ import { httpAction, getAction } from '@/api/manage' import { deleteAction } from '@/api/manage' + import {mapGetters} from 'vuex' export default { name: "addrView", @@ -178,7 +179,9 @@ url: { getaddress: "/getuserpersion/getaddress", deleteadd: "/getuserpersion/deleteadd", - sdqx: "/getuserpersion/sdqx" + sdqx: "/getuserpersion/sdqx", + addadressress: "/getuserpersion/addadressress", + updateadressress: "/getuserpersion/updateadressress" }, }; }, @@ -188,6 +191,7 @@ }, methods: { + ...mapGetters(["nickname", "avatar","userInfo"]), reload() { this.isReload = false this.$nextTick(() => { @@ -198,8 +202,6 @@ getAction(this.url.getaddress).then((res) => { if(res.success) { this.addrList1= res.result; - console.log("===================") - console.log(res.result) } else { } }); @@ -238,20 +240,61 @@ if(this.form.flag){//修改为默认地址 this.changeDefault() this.addrList.unshift(this.form) + + //开始向后台传送数据包 + getAction(this.url.addadressress,{form : JSON.stringify(this.form)}).then((res) => { + if(res.success) { + this.$router.go(0) + } else { + } + }); + + + }else{//不修改为默认地址 this.addrList.push(this.form) + console.log(this.userInfo()) + //开始向后台传送数据包 + getAction(this.url.addadressress,{form : JSON.stringify(this.form)}).then((res) => { + if(res.success) { + this.$router.go(0) + } else { + } + }); + + } - }else if(this.flag == 'edit'){//如果是修改地址 + }else if(this.flag == 'edit'){ + //如果是修改地址 //查找当前索引 let itemIndex3 = this.addrList.findIndex(item =>item.id == this.form.id) if(this.form.flag){//如果需要修改为默认地址 this.changeDefault() this.form.flag = true this.addrList[itemIndex3] = this.form - console.log("this.addrList2") - console.log(this.addrList) + /* console.log("this.addrList2") + console.log(this.addrList)*/ + console.log(this.form) + getAction(this.url.updateadressress,{form : JSON.stringify(this.form)}).then((res) => { + if(res.success) { + this.$router.go(0) + } else { + } + }); }else{ this.addrList[itemIndex3] = this.form + + + + getAction(this.url.updateadressress,{form : JSON.stringify(this.form)}).then((res) => { + if(res.success) { + this.$router.go(0) + } else { + } + }); + + + console.log(this.form) } } //清空表单 @@ -285,7 +328,7 @@ console.log(id) deleteAction(this.url.deleteadd,{id,id}).then((res) => { if(res.success) { - this.loadData(1); + this.$router.go(0) } else { } }); diff --git a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/customerreceivingaddress/mapper/CustomerReceivingAddressMapper.java b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/customerreceivingaddress/mapper/CustomerReceivingAddressMapper.java index 908958b7..bf38c920 100644 --- a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/customerreceivingaddress/mapper/CustomerReceivingAddressMapper.java +++ b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/customerreceivingaddress/mapper/CustomerReceivingAddressMapper.java @@ -45,4 +45,10 @@ public interface CustomerReceivingAddressMapper extends BaseMapper sdqx(@RequestParam(name="id",required=true) String id) { //根据id查询需要设置成默认收货地址的收货地址 @@ -224,9 +225,75 @@ public class ApeopersionController { customerReceivingAddressService.updatec(cusm.getId(),sort); customerReceivingAddressService.updates(id); } + return Result.OK("成功!"); + } + + //这个功能是个人中心的地址添加收货地址,不是默认收货地址 + @RequestMapping(value = "/addadressress", method = RequestMethod.GET) + public Result addadressress(@RequestParam(name = "form", required = true) String form) { + System.out.println(form); + //这里方便获取当前登陆信息 + LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + //这里获取当前登陆的用户名 + String Username = loginUser.getUsername(); + //将前台传过来的json数据包转化成map + Map map = JSON.parseObject(form,Map.class); + //获取flag的数据 + String flag = map.get("flag").toString(); + //通过flag判断是否是需要的设置成默认地址 + if (flag.equals("false")){ + //寻找之前的排序的最后一个 + CustomerReceivingAddress cus = customerReceivingAddressService.getcreatbuyuser(Username); + CustomerReceivingAddress cus2 =new CustomerReceivingAddress(); + cus2.setUserId(loginUser.getId()); + cus2.setCityId((String)map.get("addr")); + cus2.setUsernamme((String)map.get("name")); + cus2.setAddress((String)map.get("detailed")); + cus2.setMobile((String)map.get("phone")); + cus2.setSort(cus.getSort()+1); + customerReceivingAddressService.save(cus2); + } else if (flag.equals("true")){ + //寻找之前的排序的最后一个 + CustomerReceivingAddress cus = customerReceivingAddressService.getcreatbuyuser(Username); + //开始寻找之前的默认地址 + CustomerReceivingAddress cusm = customerReceivingAddressService.getneedyls(Username); + //开始组装需要的新的默认地址 + CustomerReceivingAddress cus2 =new CustomerReceivingAddress(); + cus2.setUserId(loginUser.getId()); + cus2.setCityId((String)map.get("addr")); + cus2.setUsernamme((String)map.get("name")); + cus2.setAddress((String)map.get("detailed")); + cus2.setMobile((String)map.get("phone")); + cus2.setSort(0); + //将新的数据写入数据库 + customerReceivingAddressService.save(cus2); + //将老的默认收货地址放在排序的最后一个 + cusm.setSort(cus.getSort()+1); + customerReceivingAddressService.updateById(cusm); + } + + return Result.OK("成功!"); + } + + + + //这个功能是个人中心的地址添加收货地址,不是默认收货地址 + @RequestMapping(value = "/updateadressress", method = RequestMethod.GET) + public Result updateadressress(@RequestParam(name = "form", required = true) String form) { + //将前台传过来的json数据包转化成map + Map map = JSON.parseObject(form,Map.class); + //查询需要的对象 + CustomerReceivingAddress needc = customerReceivingAddressService.getById((String)map.get("id")); + needc.setMobile((String)map.get("phone")); + needc.setUsernamme((String)map.get("name")); + needc.setAddress((String)map.get("detailed")); + needc.setCityId((String)map.get("addr")); + customerReceivingAddressService.updateById(needc); return Result.OK("成功!"); } + + }