多租户商城-客户PC端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

415 lines
11 KiB

3 years ago
2 years ago
3 years ago
  1. <template>
  2. <div class="addressBox">
  3. <div class="addAddressBox">
  4. <span class="addAddressBtn" @click="addAddressBtn">新增收货地址</span>
  5. </div>
  6. <div class="addressList clearfix sub-main" v-loading="loading" v-if="flag">
  7. <div class="addressItem" :class="{active:item.ifDefault}" v-for="(item) of addressData.list" :key="item.receiveId">
  8. <div class="listItemInfoBox">
  9. <div class="isDefault">
  10. <span>设为默认地址</span>
  11. <el-switch
  12. v-model="item.ifDefault"
  13. :active-value="1"
  14. :inactive-value="0"
  15. @change="changeDefultAd(item)"
  16. active-color="#C5AA7B"
  17. inactive-color="#c1c1c1">
  18. </el-switch>
  19. </div>
  20. <div class="addressInfo">
  21. <div class="infoItem infoName" :title="item.receiveName">{{item.receiveName}}</div>
  22. <div class="infoItem">{{item.receiveAdress}}-{{item.address}}</div>
  23. <!-- <div class="infoItem"></div> -->
  24. <div class="infoItem infoPhone">{{item.receivePhone}}</div>
  25. <div class="btns">
  26. <span class="btnItem" @click="showDelete(item)"><i class="iconfont">&#xe62c;</i></span>
  27. <span class="btnItem" @click="changeAddress(item)"><i class="iconfont">&#xe605;</i></span>
  28. <div v-show="item.ifDefault" class="iconfont defaultActive">&#xe612;</div>
  29. </div>
  30. </div>
  31. </div>
  32. </div>
  33. <div class="clearfix"></div>
  34. <el-pagination
  35. class=""
  36. background
  37. layout="prev, pager, next, jumper"
  38. :page-size="4"
  39. :current-page="page"
  40. @current-change="handleCurrentChange"
  41. :total="addressData.total">
  42. </el-pagination>
  43. </div>
  44. <div class="nothing sub-main" v-else>
  45. <icon-svg style="width: 240px; height: 240px; margin-bottom: 20px;" icon-class="user-dingwei-nodata" />
  46. <p class="fs20 font-color-999">你还没有收货地址</p>
  47. </div>
  48. <el-dialog
  49. :title="addTitle"
  50. :visible.sync="addAddressShow"
  51. :close-on-click-modal="false"
  52. width="750px">
  53. <AddAddress @hideAddDialog="hideAddDialog" @cancelAdd="closeAdd" />
  54. </el-dialog>
  55. <el-dialog
  56. title="是否删除此项"
  57. :visible.sync="showDeleteAdd"
  58. width="30%">
  59. <div class="deleteAddInfo">
  60. <p>收货人 {{delCurrentAdd.receiveName}}</p>
  61. <p>手机号码 {{delCurrentAdd.receivePhone}}</p>
  62. <p>收货地址 {{delCurrentAdd.receiveAdress}} {{delCurrentAdd.address}}</p>
  63. </div>
  64. <span slot="footer" class="dialog-footer">
  65. <el-button type="primary" @click="deleteAdd" v-throttle> </el-button>
  66. <el-button @click="showDeleteAdd = false"> </el-button>
  67. </span>
  68. </el-dialog>
  69. </div>
  70. </template>
  71. <script>
  72. import AddAddress from '@/components/orderInfo/addAddress'
  73. import { TextToCode } from 'element-china-area-data'
  74. import {mapGetters, mapMutations} from 'vuex'
  75. import {
  76. getAllAddressList,
  77. addAddress,
  78. updateAddress,
  79. deleteAddress
  80. } from '@/api/user/address.js'
  81. export default {
  82. name: 'signingAddress',
  83. components: {
  84. AddAddress
  85. },
  86. data () {
  87. return {
  88. ifDefault: false,
  89. showDeleteAdd: false,
  90. addAddressShow: false,
  91. addTitle: '新建收货地址',
  92. page: 1,
  93. pageSize: 4,
  94. addressData: [],
  95. delCurrentAdd: {},
  96. loading: false,
  97. flag: false
  98. }
  99. },
  100. mounted () {
  101. this.getAddressList()
  102. },
  103. computed: {
  104. ...mapGetters([
  105. 'newAddress' // 新增修改收货地址
  106. ])
  107. },
  108. methods: {
  109. ...mapMutations({
  110. seNewAddress: 'SET_NEWADDRESS', // 新增修改收货地址
  111. setAreacode: 'SET_AREACODE' // 新增修改收货地址
  112. }),
  113. // 获取地址列表
  114. async getAddressList () {
  115. this.loading = true
  116. const response = await getAllAddressList({
  117. page: this.page,
  118. pageSize: this.pageSize
  119. })
  120. const res = response.data
  121. if (res.code === '200') {
  122. this.addressData = res.data
  123. if (res.data.list.length === 0) {
  124. this.flag = false
  125. } else {
  126. this.flag = true
  127. }
  128. this.loading = false
  129. } else {
  130. this.$message.warning(res.message)
  131. }
  132. },
  133. handleCurrentChange (val) {
  134. this.page = val
  135. this.getAddressList()
  136. },
  137. showDelete (item) {
  138. this.showDeleteAdd = true
  139. this.delCurrentAdd = item
  140. },
  141. // 删除地址
  142. async deleteAdd () {
  143. const response = await deleteAddress({ receiveId: this.delCurrentAdd.receiveId })
  144. const res = response.data
  145. if (res.code === '200') {
  146. this.showDeleteAdd = false
  147. this.$message.success($t('common.deletesuccess'))
  148. this.page = 0
  149. this.addressData = []
  150. this.getAddressList()
  151. } else {
  152. this.$message.error(res.message)
  153. }
  154. this.showDeleteAdd = false
  155. },
  156. // 修改默认地址
  157. changeDefultAd (item) {
  158. this.seNewAddress(item)
  159. this.updateAddressFun()
  160. },
  161. // 修改地址信息
  162. changeAddress (item) {
  163. let addressData = item.receiveAdress.split('-')
  164. let areaData = []
  165. areaData.push(TextToCode[addressData[0]].code)
  166. areaData.push(TextToCode[addressData[0]][addressData[1]].code)
  167. areaData.push(TextToCode[addressData[0]][addressData[1]][addressData[2]].code)
  168. let currentItem = JSON.parse(JSON.stringify(item))
  169. // console.log(areaData)
  170. this.seNewAddress(currentItem)
  171. this.setAreacode(areaData)
  172. this.addTitle = '修改收货地址'
  173. this.addAddressShow = true
  174. },
  175. addAddressBtn () {
  176. let obj = {
  177. receiveName: '',
  178. receivePhone: '',
  179. receiveAdress: '',
  180. address: '',
  181. label: '',
  182. isDefault: false
  183. }
  184. this.setAreacode([])
  185. this.seNewAddress(obj)
  186. this.addTitle = '新增收货地址'
  187. this.addAddressShow = true
  188. },
  189. // 新增地址
  190. async hideAddDialog () {
  191. this.addAddressShow = false
  192. if (this.newAddress.receiveId) {
  193. this.updateAddressFun()
  194. } else {
  195. const response = await addAddress({
  196. receiveName: this.newAddress.receiveName,
  197. receivePhone: this.newAddress.receivePhone,
  198. receiveAdress: this.newAddress.receiveAdress,
  199. address: this.newAddress.address,
  200. label: '',
  201. ifDefault: this.newAddress.ifDefault ? 1 : 0
  202. })
  203. const res = response.data
  204. if (res.code === '200') {
  205. this.$message({
  206. message: '地址添加成功',
  207. type: 'success'
  208. })
  209. this.page = 1
  210. this.addressData = []
  211. this.setAreacode([])
  212. this.getAddressList()
  213. } else {
  214. this.$message.error(res.message)
  215. }
  216. }
  217. },
  218. // 修改地址
  219. async updateAddressFun () {
  220. this.addAddressShow = false
  221. const response = await updateAddress({
  222. receiveId: this.newAddress.receiveId,
  223. receiveName: this.newAddress.receiveName,
  224. receivePhone: this.newAddress.receivePhone,
  225. receiveAdress: this.newAddress.receiveAdress,
  226. address: this.newAddress.address,
  227. label: '',
  228. ifDefault: this.newAddress.ifDefault ? 1 : 0
  229. })
  230. const res = response.data
  231. if (res.code === '200') {
  232. this.$message({
  233. message: '地址修改成功',
  234. type: 'success'
  235. })
  236. this.page = 1
  237. this.addressData = []
  238. this.setAreacode([])
  239. this.getAddressList()
  240. } else {
  241. this.$message.error(res.message)
  242. }
  243. },
  244. closeAdd () {
  245. this.addAddressShow = false
  246. },
  247. handleClose (done) {
  248. this.$confirm('确认关闭?')
  249. .then(_ => {
  250. done()
  251. })
  252. .catch(_ => {})
  253. }
  254. }
  255. }
  256. </script>
  257. <style lang="scss" scoped>
  258. .addressBox {
  259. border: 1px solid #E5E5E5;
  260. min-height: 500px;
  261. .addAddressBox{
  262. height: 50px;
  263. background-color: #FAFAFA;
  264. .addAddressBtn {
  265. font-size: 16px;
  266. color: $mainGlod;
  267. line-height: 50px;
  268. // background: #FFFFFF;
  269. // border: 1px solid $mainGlod;
  270. border-radius: 4px;
  271. padding: 4px 20px;
  272. cursor: pointer;
  273. }
  274. }
  275. .addressList {
  276. margin-top: 20px;
  277. .addressItem {
  278. // width: 477px;
  279. border: 2px solid #DDDDDD;
  280. border-radius: 4px;
  281. box-sizing: border-box;
  282. margin: 20px;
  283. .listItemInfoBox {
  284. padding: 20px;
  285. .isDefault {
  286. display: flex;
  287. align-items: center;
  288. height: 35px;
  289. // justify-content: flex-end;
  290. span {
  291. color: #333333;
  292. font-size: 16px;
  293. margin-right: 5px;
  294. }
  295. }
  296. .addressInfo {
  297. display: flex;
  298. .infoItem {
  299. flex: 10;
  300. color: #333333;
  301. font-size: 16px;
  302. margin: 30px;
  303. }
  304. .infoName{
  305. flex: 5;
  306. white-space: nowrap;
  307. overflow: hidden;
  308. text-overflow: ellipsis;
  309. }
  310. .infoPhone{
  311. flex: 5;
  312. }
  313. .infoItem:last-child {
  314. margin-bottom: 0;
  315. }
  316. .btns{
  317. width: 100px;
  318. display: flex;
  319. justify-content: space-between;
  320. align-items: center;
  321. i{
  322. font: 20px !important;
  323. }
  324. .btnItem{
  325. cursor: pointer;
  326. }
  327. }
  328. }
  329. }
  330. .addressChange {
  331. border-top: #CCCCCC solid 1px;
  332. height: 45px;
  333. line-height: 45px;
  334. position: relative;
  335. i {
  336. margin-right: 5px;
  337. }
  338. .defaultActive {
  339. position: absolute;
  340. right: -1px;
  341. bottom: -3px;
  342. width: 46px;
  343. height: 46px;
  344. color: $mainGlod;
  345. font-size: 46px;
  346. }
  347. span {
  348. display: block;
  349. float: left;
  350. width: 50%;
  351. color: #666666;
  352. text-align: center;
  353. cursor: pointer;
  354. }
  355. span:nth-child(2) {
  356. border-left: 1px solid #CCCCCC;
  357. color: $mainGlod;
  358. box-sizing: border-box;
  359. }
  360. }
  361. }
  362. .active {
  363. border: 2px solid $mainGlod;
  364. }
  365. }
  366. >>> .el-dialog {
  367. .el-dialog__body {
  368. // background: #F8F8F8;
  369. }
  370. .el-dialog__header {
  371. text-align: center;
  372. }
  373. .dialog-footer {
  374. display: flex;
  375. justify-content: center;
  376. width: 100%;
  377. button {
  378. width: 200px;
  379. height: 50px;
  380. }
  381. }
  382. }
  383. .deleteAddInfo {
  384. width: 70%;
  385. margin: 0 auto;
  386. p {
  387. line-height: 30px;
  388. }
  389. }
  390. >>> .el-pagination {
  391. text-align: right;
  392. margin: 20px;
  393. }
  394. }
  395. .sub-main{
  396. min-height: 400px;
  397. }
  398. .nothing{
  399. width: 100%;
  400. margin: 20px;
  401. text-align: center;
  402. min-height: 400px;
  403. p{
  404. margin-bottom: 20px;
  405. }
  406. .el-button{
  407. background-color: $mainGlod;
  408. color: #FFFFFF;
  409. font-weight: normal;
  410. border-radius: 0;
  411. }
  412. }
  413. </style>