address.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <view class="address">
  3. <view class="main">
  4. <van-cell-group>
  5. <van-field label="姓名" @change="onChange1" :value="addressInfo.receiver" placeholder="收货人姓名" />
  6. <van-field label="电话" :value="addressInfo.mobile" placeholder="收货人手机号" />
  7. <van-field :value="fieldValue" is-link readonly label="地区" placeholder="请选择所在地区" @tap="onClick" />
  8. <van-popup :show="show" round position="bottom">
  9. <van-cascader v-if="show" :field-names="fieldNames" :value="cascaderValue" title="请选择所在地区"
  10. :options="options" @close="onClose" @finish="onFinish" />
  11. </van-popup>
  12. <van-field label="详细地址" :value="value" placeholder="街道门牌 楼层房间号等信息" />
  13. <view class="switch">
  14. <view class="default">
  15. 默认收货地址
  16. </view>
  17. <van-switch :checked="checked" bind:change="onChange" />
  18. </view>
  19. </van-cell-group>
  20. </view>
  21. <van-button type="danger" round class="btn1">保存</van-button>
  22. <van-button round class="btn2">删除</van-button>
  23. </view>
  24. </template>
  25. <script>
  26. import addressData from '@/json/areas.json';
  27. export default {
  28. data() {
  29. return {
  30. list: {}, //存放编辑内容
  31. value: "",
  32. show: false,
  33. fieldValue: '',
  34. cascaderValue: '',
  35. options: [],
  36. checked: false,
  37. fieldNames: {
  38. text: 'label',
  39. value: 'value',
  40. children: 'children',
  41. },
  42. addressInfo: {
  43. addrId: 0,
  44. receiver: "",
  45. addr: "",
  46. postCode: "",
  47. mobile: "",
  48. provinceId: 0,
  49. cityId: 0,
  50. areaId: 0,
  51. province: "",
  52. city: "",
  53. area: ""
  54. }
  55. }
  56. },
  57. onLoad(options) {
  58. if (options.obj1) {
  59. this.list = JSON.parse(options.obj1);
  60. this.checked = this.list.commonAddr === 1 ? true : false;
  61. }
  62. },
  63. onShow() {
  64. this.options = addressData;
  65. },
  66. methods: {
  67. onClick() {
  68. this.show = true;
  69. },
  70. onClose() {
  71. this.show = false;
  72. },
  73. onFinish(e) {
  74. const {
  75. selectedOptions,
  76. value
  77. } = e.detail;
  78. const fieldValue = selectedOptions.map((option) => option.label).join('/');
  79. const newsId = selectedOptions.map((obj) =>
  80. obj[Object.keys(obj)[0]]
  81. )
  82. this.addressInfo.provinceId = newsId[0];
  83. this.addressInfo.cityId = newsId[1];
  84. this.addressInfo.areaId = newsId[2];
  85. const newsValue = selectedOptions.map((obj) =>
  86. obj[Object.keys(obj)[1]]
  87. )
  88. this.addressInfo.province = newsValue[0];
  89. this.addressInfo.city = newsValue[1];
  90. this.addressInfo.area = newsValue[2];
  91. this.fieldValue = fieldValue;
  92. this.cascaderValue = value;
  93. this.show = false;
  94. },
  95. onChange1(event) {
  96. this.addressInfo.receiver = event.detail;
  97. }
  98. }
  99. }
  100. </script>
  101. <style scoped lang="scss">
  102. .address {
  103. padding: 20rpx;
  104. .default {
  105. margin-left: 28rpx;
  106. }
  107. }
  108. .btn1 {
  109. width: 100%;
  110. position: absolute;
  111. bottom: 220rpx;
  112. left: 50%;
  113. margin-left: -40%;
  114. }
  115. .btn2 {
  116. width: 100%;
  117. position: absolute;
  118. bottom: 120rpx;
  119. left: 50%;
  120. margin-left: -40%;
  121. }
  122. ::v-deep .van-button--round {
  123. width: 80%;
  124. }
  125. .switch {
  126. display: flex;
  127. justify-content: space-between;
  128. height: 80rpx;
  129. align-items: center;
  130. }
  131. ::v-deep .van-tabs {
  132. -webkit-tap-highlight-color: transparent;
  133. position: absolute;
  134. z-index: 99;
  135. background: #fff;
  136. width: 100%;
  137. }
  138. </style>