demo.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <div class="address-box">
  3. <h4>选择自定义地址</h4>
  4. <div class="address-list init" @click="showAddress">
  5. <div class="titile">选择地址</div>
  6. <div class="choose">{{text1}}</div>
  7. </div>
  8. <h4>选择已有地址</h4>
  9. <div class="address-list other" @click="showAddressExist">
  10. <div class="titile">选择地址</div>
  11. <div class="choose">{{text2}}</div>
  12. </div>
  13. <h4>自定义图标</h4>
  14. <div class="address-list other" @click="showCustomImg">
  15. <div class="titile">选择地址</div>
  16. <div class="choose">{{text3}}</div>
  17. </div>
  18. <h4>自定义地址与已有地址切换</h4>
  19. <div class="address-list other" @click="showAddressOther">
  20. <div class="titile">选择地址</div>
  21. <div class="choose">{{text4}}</div>
  22. </div>
  23. <nut-address v-model="showPopup" :province="province" :city="city" :country="country" :town="town" @onChange="onChange1" @close="close1" customAddressTitle="请选择所在地区"></nut-address>
  24. <nut-address v-model="showPopupExist" type="exist" :existAddress="existAddress" @onChange="onChange2" @close="close2" :isShowCustomAddress="false" @selected="selected2" existAddressTitle="配送至"></nut-address>
  25. <nut-address v-model="showPopupCustomImg" type="exist" :existAddress="existAddress" @onChange="onChange3" @close="close3" :isShowCustomAddress="false" @selected="selected3" :defaultIcon="defaultIcon" :selectedIcon='selectedIcon'></nut-address>
  26. <nut-address v-model="showPopupOther" type="exist" :existAddress="existAddress" :province="province" :city="city" :country="country" :town="town" @onChange="onChange4" @close="close4" @selected="selected4"></nut-address>
  27. </div>
  28. </template>
  29. <script>
  30. export default {
  31. data() {
  32. return {
  33. showPopup:false,
  34. province:[{"id":1,"name":"北京"},{"id":2,"name":"广西"},{"id":3,"name":"江西"},{"id":4,"name":"四川"}], // 省
  35. city:[{"id":7,"name":"朝阳区"},{"id":8,"name":"崇文区"},{"id":9,"name":"昌平区"},{"id":6,"name":"石景山区"}],// 市
  36. country:[{"id":3,"name":"八里庄街道"},{"id":9,"name":"北苑"},{"id":4,"name":"常营乡"}],// 县
  37. town:[], // 镇
  38. showPopupExist:false,
  39. showPopupCustomImg:false,
  40. selectedIcon:require('../../assets/svg/checked.svg'),
  41. defaultIcon:require('../../assets/svg/unchecked.svg'),
  42. showPopupOther:false,
  43. existAddress:[
  44. {"id":1,"addressDetail":"th ","cityName":"石景山区","countyName":"城区","provinceName":"北京","selectedAddress":true,"townName":""},
  45. {"id":2,"addressDetail":"12_ ","cityName":"电饭锅","countyName":"扶绥县","provinceName":"北京","selectedAddress":false,"townName":""},
  46. {"id":3,"addressDetail":"发大水比 ","cityName":"放到","countyName":"广宁街道","provinceName":"钓鱼岛全区","selectedAddress":false,"townName":""},
  47. {"id":4,"addressDetail":"还是想吧百度吧 ","cityName":"研发","countyName":"八里庄街道","provinceName":"北京","selectedAddress":false,"townName":""},
  48. ],
  49. text1:'请选择地址',
  50. text2:'请选择地址',
  51. text3:'请选择地址',
  52. text4:'请选择地址'
  53. };
  54. },
  55. methods: {
  56. showAddress(){
  57. this.showPopup = true
  58. },
  59. onChange1(cal){
  60. console.log('change1',cal)
  61. if(this[cal.next].length < 1){
  62. this.showPopup = false
  63. }
  64. },
  65. close1(val){
  66. console.log(val)
  67. this.text1 = val.data.addressStr
  68. },
  69. showAddressExist(){
  70. this.showPopupExist = true
  71. },
  72. onChange2(cal){
  73. console.log('change2',cal)
  74. if(this[cal.next].length < 1){
  75. this.showPopupOther = false
  76. }
  77. },
  78. close2(val){
  79. console.log(val)
  80. if(val.type == 'exist'){
  81. this.text2 = val.data.provinceName+val.data.cityName+val.data.countyName+val.data.townName+val.data.addressDetail
  82. }else{
  83. this.text2 = val.data.addressStr
  84. }
  85. },
  86. selected2(prevExistAdd,nowExistAdd,arr){
  87. console.log(prevExistAdd)
  88. console.log(nowExistAdd)
  89. },
  90. showAddressOther(){
  91. this.showPopupOther = true
  92. },
  93. showCustomImg(){
  94. this.showPopupCustomImg = true
  95. },
  96. onChange3(cal){
  97. console.log('change3',cal)
  98. if(this[cal.next].length < 1){
  99. this.showPopupOther = false
  100. }
  101. },
  102. close3(val){
  103. console.log(val)
  104. if(val.type == 'exist'){
  105. this.text3 = val.data.provinceName+val.data.cityName+val.data.countyName+val.data.townName+val.data.addressDetail
  106. }else{
  107. this.text3 = val.data.addressStr
  108. }
  109. },
  110. selected3(prevExistAdd,nowExistAdd,arr){
  111. console.log(prevExistAdd)
  112. console.log(nowExistAdd)
  113. },
  114. onChange4(cal){
  115. console.log('change4',cal)
  116. if(this[cal.next].length < 1){
  117. this.showPopupOther = false
  118. }
  119. },
  120. close4(val){
  121. console.log(val)
  122. if(val.type == 'exist'){
  123. this.text4 = val.data.provinceName+val.data.cityName+val.data.countyName+val.data.townName+val.data.addressDetail
  124. }else{
  125. this.text4 = val.data.addressStr
  126. }
  127. },
  128. selected4(prevExistAdd,nowExistAdd,arr){
  129. console.log(prevExistAdd)
  130. console.log(nowExistAdd)
  131. }
  132. }
  133. };
  134. </script>
  135. <style lang="scss" scoped>
  136. .address-box{
  137. margin-top: 10px;
  138. .address-list{
  139. margin-bottom: 10px;
  140. background: #fff;
  141. border-radius: 4px;
  142. font-size: 14px;
  143. padding: 10px;
  144. &.init{
  145. display: flex;
  146. .titile{
  147. margin-right: 15px;
  148. }
  149. .choose{
  150. color: #999;
  151. }
  152. }
  153. &.other{
  154. display: flex;
  155. .titile{
  156. margin-right: 15px;
  157. }
  158. .choose{
  159. color: #999;
  160. }
  161. }
  162. }
  163. }
  164. </style>