delivery_address.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <template>
  2. <div class="box" v-loading="loading">
  3. <div class="null-page" v-show="yes"></div>
  4. <el-card class="box-card">
  5. <div slot="header" class="clearfix">
  6. <span>收货地址</span>
  7. </div>
  8. <div>
  9. <div class="ns-member-address-list">
  10. <div class="text item ns-add-address" @click="addAddress('add')">
  11. <span>+ 添加收货地址</span>
  12. </div>
  13. <div class="text item" v-for="(item, index) in addressList" :key="index">
  14. <div class="text-name">
  15. <span>{{ item.name }}</span>
  16. <span v-if="item.is_default == 1" class="text-default">默认</span>
  17. </div>
  18. <div class="text-content">
  19. <p>{{ item.mobile }}</p>
  20. <p :title="item.full_address + item.address" class="ns-address-detail">{{ item.full_address }}{{ item.address }}</p>
  21. </div>
  22. <div class="text-operation">
  23. <span v-if="item.is_default != 1" @click="setDefault(item.id)">设为默认</span>
  24. <span @click="addAddress('edit', item.id)">编辑</span>
  25. <span v-if="item.is_default != 1" @click="delAddress(item.id, item.is_default)">删除</span>
  26. </div>
  27. </div>
  28. </div>
  29. <div class="pager">
  30. <el-pagination
  31. background
  32. :pager-count="5"
  33. :total="total"
  34. prev-text="上一页"
  35. next-text="下一页"
  36. :current-page.sync="currentPage"
  37. :page-size.sync="pageSize"
  38. @size-change="handlePageSizeChange"
  39. @current-change="handleCurrentPageChange"
  40. hide-on-single-page
  41. ></el-pagination>
  42. </div>
  43. </div>
  44. </el-card>
  45. </div>
  46. </template>
  47. <script>
  48. import { addressList, setDefault, deleteAddress } from "@/api/member/member"
  49. export default {
  50. name: "delivery_address",
  51. layout: "member",
  52. components: {},
  53. data: () => {
  54. return {
  55. addressList: [],
  56. total: 0,
  57. currentPage: 1,
  58. pageSize: 8,
  59. loading: true,
  60. yes: true
  61. }
  62. },
  63. created() {
  64. this.getListData()
  65. },
  66. mounted() {
  67. let self = this;
  68. setTimeout(function() {
  69. self.yes = false
  70. }, 300)
  71. },
  72. methods: {
  73. getListData() {
  74. addressList({
  75. page: this.currentPage,
  76. page_size: this.pageSize
  77. })
  78. .then(res => {
  79. const { count, page_count, list } = res.data
  80. this.total = count
  81. this.addressList = list
  82. this.loading = false
  83. })
  84. .catch(err => {
  85. this.loading = false
  86. this.$message.error(err.message)
  87. })
  88. },
  89. handlePageSizeChange(size) {
  90. this.pageSize = size
  91. this.refresh()
  92. },
  93. handleCurrentPageChange(page) {
  94. this.currentPage = page
  95. this.refresh()
  96. },
  97. refresh() {
  98. this.loading = true
  99. this.getListData()
  100. },
  101. /**
  102. * 设为默认
  103. */
  104. setDefault(id) {
  105. setDefault({
  106. id: id
  107. })
  108. .then(res => {
  109. this.refresh()
  110. this.$message({
  111. message: "修改默认地址成功",
  112. type: "success"
  113. })
  114. })
  115. .catch(err => {
  116. this.$message.error(err.message)
  117. })
  118. },
  119. /**
  120. * 添加/编辑地址
  121. */
  122. addAddress(type, id) {
  123. if (type == "edit") {
  124. this.$router.push({ path: "/member/address_edit", query: { id: id } })
  125. } else {
  126. this.$router.push({ path: "/member/address_edit" })
  127. }
  128. },
  129. /**
  130. * 删除地址
  131. */
  132. delAddress(id, is_default) {
  133. this.$confirm("确定要删除该地址吗?", "提示", {
  134. confirmButtonText: "确定",
  135. cancelButtonText: "取消",
  136. type: "warning"
  137. }).then(() => {
  138. if (is_default == 1) {
  139. this.$message({
  140. type: "warning",
  141. message: "默认地址,不能删除!"
  142. })
  143. return
  144. }
  145. deleteAddress({
  146. id: id
  147. })
  148. .then(res => {
  149. this.refresh()
  150. this.$message({ message: res.message, type: "success" })
  151. })
  152. .catch(err => {
  153. this.$message.error(err.message)
  154. })
  155. })
  156. }
  157. }
  158. }
  159. </script>
  160. <style lang="scss" scoped>
  161. .box {
  162. width: 100%;
  163. position: relative;
  164. }
  165. .null-page {
  166. width: 100%;
  167. height: 730px;
  168. background-color: #FFFFFF;
  169. position: absolute;
  170. top: 0;
  171. left: 0;
  172. z-index: 9;
  173. }
  174. .el-card.is-always-shadow,
  175. .el-card.is-hover-shadow:focus,
  176. .el-card.is-hover-shadow:hover {
  177. box-shadow: unset;
  178. }
  179. .el-card {
  180. border: 0;
  181. }
  182. .ns-member-address-list {
  183. display: flex;
  184. flex-wrap: wrap;
  185. .text {
  186. width: 32%;
  187. height: 140px;
  188. margin-right: 2%;
  189. border-radius: 5px;
  190. border: 1px solid #d8d8d8;
  191. margin-bottom: 20px;
  192. padding: 0 15px;
  193. box-sizing: border-box;
  194. .text-name {
  195. height: 37px;
  196. line-height: 40px;
  197. padding: 0 10px;
  198. border-bottom: 1px solid #eeeeee;
  199. }
  200. .text-default {
  201. display: inline-block;
  202. margin-left: 10px;
  203. background: $base-color;
  204. color: #ffffff;
  205. width: 35px;
  206. height: 20px;
  207. line-height: 20px;
  208. text-align: center;
  209. border-radius: 3px;
  210. }
  211. .text-content {
  212. padding: 10px;
  213. }
  214. .ns-address-detail {
  215. overflow: hidden;
  216. text-overflow: ellipsis;
  217. white-space: nowrap;
  218. }
  219. .text-operation {
  220. // 操作
  221. text-align: right;
  222. span {
  223. margin: 0 5px;
  224. color: #999999;
  225. cursor: pointer;
  226. }
  227. span:hover {
  228. color: $base-color;
  229. }
  230. }
  231. }
  232. .text:nth-child(3n) {
  233. margin-right: 0;
  234. }
  235. .ns-add-address {
  236. border: 1px dashed #d8d8d8;
  237. text-align: center;
  238. color: #999999;
  239. line-height: 140px;
  240. cursor: pointer;
  241. }
  242. .ns-add-address:hover {
  243. border-color: $base-color;
  244. color: $base-color;
  245. }
  246. }
  247. </style>