index.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <template>
  2. <div class="address" style="padding-top: 46px">
  3. <van-nav-bar
  4. title="我的地址"
  5. class="van-nav-bar-my-fixed"
  6. left-arrow
  7. @click-left="onClickLeft"
  8. :right-text="isRes === '1' ? '' : '删除'"
  9. @click-right="onClickRight"
  10. fixed
  11. />
  12. <van-address-list
  13. v-model="chosenAddressId"
  14. :list="list"
  15. :disabled-list="[]"
  16. @add="onAdd"
  17. @select="onSelect"
  18. @edit="onEdit"
  19. />
  20. <div class="addr-null"
  21. v-if="isShowAddrNull"
  22. >
  23. <img src="@/assets/images/home/addr-null.png" alt="">
  24. <div class="addr-null-title">暂无地址~</div>
  25. </div>
  26. <div
  27. class="addmore"
  28. v-if="total > 0 && list.length < total && list.length > 0"
  29. @click="pageData"
  30. >
  31. 点击加载更多!
  32. </div>
  33. <!-- v-if="list && list.length > 0" -->
  34. <!-- <van-empty v-else description="暂无地址!" /> -->
  35. </div>
  36. </template>
  37. <script>
  38. import { Dialog } from "vant";
  39. import asyncRequest from "@/apis/address/index";
  40. import resToken from "@/mixins/resToken";
  41. export default {
  42. mixins: [resToken],
  43. data() {
  44. return {
  45. isShowAddrNull:true,
  46. delId: "",
  47. chosenAddressId: "",
  48. isRes: this.$route.query.id ? this.$route.query.id : "0",
  49. list: [],
  50. total: 0,
  51. parmValue: {
  52. page: 1, // 页码
  53. size: 10, // 每页显示条数
  54. },
  55. loading: false,
  56. };
  57. },
  58. async created() {
  59. if (this.$route && this.$route.query && this.$route.query.id) {
  60. this.isRes = "1";
  61. } else {
  62. this.isRes = "0";
  63. }
  64. },
  65. mounted() {
  66. this.searchList();
  67. },
  68. methods: {
  69. onClickLeft() {
  70. window.history.back(-1);
  71. },
  72. onClickRight() {
  73. if (!this.loading) {
  74. if (this.delId === "") {
  75. this.show_title("请选择地址!");
  76. return;
  77. }
  78. Dialog.confirm({
  79. title: "确认删除?",
  80. message: "确认删除该地址?",
  81. })
  82. .then(async () => {
  83. await this.delAddr(this.delId);
  84. })
  85. .catch(() => {
  86. // on cancel
  87. });
  88. }
  89. },
  90. customerService() {
  91. this.serviceShow = true;
  92. },
  93. gotoInfor() {
  94. this.$router.push({
  95. path: "/personalInfor",
  96. });
  97. },
  98. onAdd() {
  99. this.$router.push({
  100. path: "/addressView",
  101. });
  102. },
  103. onEdit(item) {
  104. if (!this.loading) {
  105. window.vm.$router.push({
  106. path: "/addressView",
  107. query: {
  108. id: item.id,
  109. },
  110. });
  111. }
  112. },
  113. onSelect(item) {
  114. if (this.isRes === "1") {
  115. this.$store.dispatch("user/set_ad", item).then((res) => {
  116. console.log(res);
  117. window.history.back(-1);
  118. });
  119. } else {
  120. this.delId = item.id;
  121. }
  122. },
  123. async pageData() {
  124. this.parmValue.page++;
  125. await this.searchList();
  126. },
  127. async delAddr(id) {
  128. this.loading = true;
  129. let res = await asyncRequest.del({ id: id });
  130. this.loading = false;
  131. if (res && res.code == 0) {
  132. this.show_title("地址删除成功!");
  133. await this.searchList();
  134. } else if (res && res.code >= 100 && res.code <= 104) {
  135. await this.logout();
  136. } else {
  137. this.show_title(res.msg);
  138. }
  139. },
  140. async searchList() {
  141. if (!this.loading) {
  142. if (this.parmValue.page === 1) {
  143. this.list = [];//如果没有在加载中且当前页数是1,清空list列表,防止造成上次的地址残留
  144. }
  145. let res = await asyncRequest.list(this.parmValue);//请求接口
  146. if (res && res.code == 0 && res.data) {
  147. let arr = res.data.list;//正确请求到数据,保存到新增数组
  148. arr.map((v1) => {//遍历获取数据
  149. let codeName =//判断当前城市名是不是和数据中的城市名相等
  150. v1.city_name === v1.provice_name
  151. ? v1.provice_name
  152. : v1.provice_name + v1.city_name;
  153. v1.name = v1.contector;//
  154. v1.tel = v1.mobile;
  155. v1.address = codeName + v1.area_name + v1.addr;
  156. return v1;
  157. });
  158. this.list.push(...arr);//把arr数组解构放到list列表渲染
  159. if(this.list.length != 0){
  160. this.isShowAddrNull = false;
  161. }else{
  162. this.isShowAddrNull = true;
  163. }
  164. if (this.chosenAddressId === "" && this.list.length > 0) {
  165. this.chosenAddressId = this.list[0].id;
  166. }
  167. this.total = res.data.count;
  168. console.log(this.total);
  169. } else if (res && res.code >= 100 && res.code <= 104) {
  170. await this.logout();
  171. } else {
  172. this.show_title(res.msg);
  173. if (this.parmValue.page !== 1) {
  174. this.parmValue.page--;
  175. }
  176. }
  177. }
  178. },
  179. },
  180. };
  181. </script>
  182. <style lang="scss" scoped>
  183. .address {
  184. position: relative;
  185. width: 100%;
  186. height: 100%;
  187. padding: 48px 0 0 0;
  188. box-sizing: border-box;
  189. .van-tag--danger {
  190. background: rgb(255, 131, 39);
  191. }
  192. .van-address-item .van-radio__icon--checked .van-icon {
  193. background-color: rgb(255, 131, 39);
  194. border-color: rgb(255, 131, 39);
  195. }
  196. .van-address-list__bottom {
  197. button.van-button--danger {
  198. background: linear-gradient(-180deg, #fcce56, rgb(255, 131, 39), #f9680f);
  199. border: 0;
  200. }
  201. }
  202. .addmore {
  203. text-align: center;
  204. color: #999;
  205. height: 30px;
  206. line-height: 30px;
  207. width: 100%;
  208. }
  209. }
  210. //页面中 “我的地址”的样式
  211. .van-nav-bar-my-fixed /deep/ .van-nav-bar__title.van-ellipsis{
  212. width: 72px;
  213. height: 17px;
  214. font-size: 18px;
  215. font-weight: 500;
  216. color: #1A1A1A;
  217. line-height: 16px;
  218. }
  219. //收货人及手机号信息
  220. .van-address-list /deep/ .van-address-item__name{
  221. width: 100%;
  222. height: 15px;
  223. font-size: 15px;
  224. font-weight: 500;
  225. color: #333333;
  226. line-height: 6px;
  227. }
  228. //地址栏字体样式
  229. .van-address-list /deep/ .van-address-item__address{
  230. width: 247px;
  231. height: 13px;
  232. font-size: 13px;
  233. font-weight: 400;
  234. color: #999999;
  235. line-height: 13px;
  236. }
  237. //地址栏收货人+手机号样式
  238. .van-address-list /deep/ .van-address-item__name{
  239. width: 100%;
  240. height: 22px;
  241. font-size: 15px;
  242. font-weight: 500;
  243. color: #333333;
  244. line-height: 12px;
  245. }
  246. //修改地址的图标
  247. .van-address-list /deep/ .van-icon.van-icon-edit.van-address-item__edit::before{
  248. width: 15px;
  249. height: 15px;
  250. }
  251. //每个地址栏选项之间的间隔
  252. .van-address-item{
  253. margin: 10px 0;
  254. }
  255. //整体的地址栏选项框的位置
  256. .van-radio-group{
  257. margin-top: 30px;
  258. }
  259. //默认提示
  260. .van-tag.van-tag--round.van-tag--danger.van-address-item__tag{
  261. width: 32px;
  262. height: 15px;
  263. background: #F4D022;
  264. border-radius: 15px;
  265. text-align: center;
  266. font-size: 10px;
  267. font-weight: 400;
  268. color: #333333;
  269. line-height: 15px;
  270. padding: 2px 6px;
  271. display: block;
  272. text-align: center;
  273. margin-left: 20px;
  274. }
  275. //新增地址按钮
  276. .van-button.van-button--danger.van-button--normal.van-button--block.van-button--round.van-address-list__add{
  277. width: 100%;
  278. background: #F4D022;
  279. border-radius: 30px;
  280. }
  281. //新建地址按钮
  282. .van-nav-bar__title.van-ellipsis{
  283. width: 107px;
  284. height: 17px;
  285. font-size: 18px;
  286. font-weight: 500;
  287. color: #1A1A1A;
  288. line-height: 26px;
  289. }
  290. //空地址时候的样式
  291. .addr-null{
  292. width: 73px;
  293. height: 102px;
  294. box-sizing: border-box;
  295. position: fixed;
  296. left: 50%;
  297. top: 150px;
  298. transform: translateX(-50%);
  299. text-align: center;
  300. font-size: 12px;
  301. font-weight: 400;
  302. color: #959595;
  303. // line-height: 7px;
  304. img{
  305. width: 100%;
  306. padding-bottom:10px;
  307. }
  308. }
  309. </style>