app-address-group.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <view>
  3. <tui-list-cell
  4. class="line-cell"
  5. :hover="false"
  6. :arrow="false"
  7. @click="openAddres"
  8. >
  9. <view class="tui-title ">{{ cityTitle }}</view>
  10. <view class="tui-input" v-if="form.province || form.city">
  11. {{ form.province + "-" + form.city }}
  12. </view>
  13. <view class="tui-placeholder" v-else>请选择</view>
  14. <input v-model="form.province" name="province" hidden />
  15. </tui-list-cell>
  16. <tui-list-cell
  17. class="line-cell"
  18. :hover="false"
  19. :arrow="true"
  20. @click="selRegionFn"
  21. >
  22. <view class="tui-title ">{{ detailTitle }}</view>
  23. <view class="tui-input" v-if="form.address">{{ form.address }}</view>
  24. <view class="tui-placeholder" v-else>请填写详细地址</view>
  25. <input v-model="form.address" name="address" hidden />
  26. </tui-list-cell>
  27. <tui-list-cell v-if="isFloor" class="line-cell" :hover="false">
  28. <view class="tui-title ">门牌号</view>
  29. <input
  30. v-model="form.floor"
  31. placeholder-class="phcolor"
  32. class="tui-input"
  33. name="floor"
  34. @input="changeFloor"
  35. placeholder="楼号门牌号(选填)"
  36. />
  37. </tui-list-cell>
  38. <!-- 选择地区 -->
  39. <app-area-sel
  40. :show.sync="showRegion"
  41. @change="changeAreaFn"
  42. :city="form.city"
  43. />
  44. <!-- 省市联动 -->
  45. <simple-address
  46. ref="simpleAddress"
  47. :pickerValueDefault="cityPickerValueDefault"
  48. @onConfirm="onCityConfirm"
  49. ></simple-address>
  50. </view>
  51. </template>
  52. <script>
  53. import SimpleAddress from "@/components/plugin/simple-address";
  54. import AppAreaSel from "@/components/app-area-sel";
  55. import TuiListCell from "@/components/plugin/list-cell";
  56. import { getUserDet } from "@/api/member/index";
  57. export default {
  58. name: "AppAddressGroup",
  59. components: {
  60. AppAreaSel,
  61. SimpleAddress,
  62. TuiListCell
  63. },
  64. props: {
  65. customId:'',
  66. cityTitle: {
  67. type: String,
  68. default: "所在城市"
  69. },
  70. detailTitle: {
  71. type: String,
  72. default: "地址"
  73. },
  74. isFloor: {
  75. type: Boolean,
  76. default: true
  77. },
  78. getFormObj: {
  79. type: Object,
  80. default: () => {}
  81. }
  82. },
  83. data() {
  84. return {
  85. // 省市联动
  86. regionData: [],
  87. cityPickerValueDefault: [0, 0],
  88. form: {
  89. province: "",
  90. city: "",
  91. address: "",
  92. floor: "",
  93. longitude: "",
  94. latitude: ""
  95. },
  96. showRegion: false
  97. };
  98. },
  99. mounted(){
  100. if(this.customId!=''){this.initAdress();}
  101. },
  102. methods: {
  103. initAdress(){
  104. return getUserDet({ id: this.customId }).then(res => {
  105. this.form.province = res.data.province;
  106. this.form.city = res.data.city;
  107. this.form.address = res.data.address;
  108. this.form.latitude = res.data.lat;
  109. this.form.longitude = res.data.long;
  110. this.$emit("selectAdress", this.form);
  111. })
  112. },
  113. formatForm() {
  114. Object.keys(this.form).forEach(i => {
  115. this.form[i] = this.getFormObj[i];
  116. });
  117. },
  118. selRegionFn() {
  119. if (!this.form.city) {
  120. this.$msg("请先选择城市!");
  121. return false;
  122. }
  123. this.showRegion = true;
  124. },
  125. onCityConfirm(e) {
  126. this.form.province = e.provinceName;
  127. this.form.city = e.cityName;
  128. this.$emit("selectAdress", this.form);
  129. },
  130. // 省市联动
  131. openAddres() {
  132. return;
  133. this.$refs.simpleAddress.open();
  134. },
  135. changeAreaFn(e) {
  136. this.form.address = e.title;
  137. this.form.latitude = e.location.lat;
  138. this.form.longitude = e.location.lng;
  139. this.$emit("selectAdress", this.form);
  140. },
  141. changeFloor(e) {
  142. this.$emit("selectAdress", this.form);
  143. }
  144. },
  145. watch: {
  146. getFormObj() {
  147. if (this.$util.isEmpty(this.getFormObj)) {
  148. this.formatForm();
  149. }
  150. }
  151. }
  152. };
  153. </script>
  154. <style lang="scss" scoped></style>