AddressForm.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <template><page-meta :root-font-size="fontSize+'px'"></page-meta>
  2. <seller-base :show="false">
  3. <view class="div container">
  4. <view class="div common-header-wrap">
  5. <view :style="'height:'+navHeight+'px'"></view>
  6. <view class="common-header-holder"></view>
  7. <view class="common-header-fixed">
  8. <title-header />
  9. <uni-nav-bar :title="getTitle" class="common-header" left-icon="back" @clickLeft="goBack">
  10. </uni-nav-bar>
  11. </view>
  12. </view>
  13. <view class="div main-content">
  14. <flex-line class="field-line" :show-border="true"><text class="span field-name">联系人</text><view class="div field-line-right" slot="right"><input class="field-input" v-model="address_info.seller_name" /></view></flex-line>
  15. <flex-line class="field-line" :show-border="true"><text class="span field-name">手机</text><view class="div field-line-right" slot="right"><input class="field-input" v-model="address_info.daddress_telphone" /></view></flex-line>
  16. <flex-line :show-border="true">
  17. <text class="span">地区</text>
  18. <view class="div" @click="onRegion" slot="right">
  19. <text class="span">{{address_info.area_info}}</text>
  20. <text class="span iconfont right-arrow">&#xe600;</text>
  21. </view>
  22. </flex-line>
  23. <flex-line class="field-line" :show-border="true"><text class="span field-name">地址</text><view class="div field-line-right" slot="right"><input class="field-input" v-model="address_info.daddress_detail" /></view></flex-line>
  24. <flex-line :show-border="true"><text class="span line-name">默认地址</text><view class="div" slot="right"><switch @change="switchChange" :checked="!!address_info.daddress_isdefault"></switch></view></flex-line>
  25. <view class="div pt-10 pb-10"><view class="div common-btn ds-button-large" @click="submit">{{getSumitTitle}}</view></view>
  26. </view>
  27. <region-picker ref="picker" v-on:onConfirm="onPickerConfirm"></region-picker>
  28. </view>
  29. </seller-base>
  30. </template>
  31. <script>
  32. import {getFontSize} from '@/util/common'
  33. import TitleHeader from '../../TitleHeader'
  34. import SellerBase from '../SellerBase'
  35. import RegionPicker from '../../RegionPicker'
  36. import { getAddressInfo, editAddress } from '../../../api/sellerAddress'
  37. import flexLine from '../../flexLine'
  38. export default {
  39. components:{
  40. TitleHeader,
  41. SellerBase,
  42. flexLine,
  43. RegionPicker
  44. },
  45. computed:{
  46. fontSize(){
  47. return getFontSize()
  48. },
  49. isAddMode () {
  50. let mode = this.action
  51. // add: 添加地址,edit: 编辑地址
  52. if (mode === 'add') {
  53. return true
  54. } else {
  55. return false
  56. }
  57. },
  58. getTitle () {
  59. if (this.isAddMode) {
  60. return '新增地址'
  61. } else {
  62. return '修改发货地址'
  63. }
  64. },
  65. getSumitTitle () {
  66. let isFromCheckout = this.isFromCheckout
  67. if (isFromCheckout) {
  68. return '保存并使用'
  69. } else {
  70. return '保存'
  71. }
  72. }
  73. },
  74. data(){
  75. return {
  76. navHeight: 0,
  77. popMap: false,
  78. address_id: 0,
  79. action:'',
  80. isFromCheckout:'',
  81. address_info: {
  82. seller_name: '',
  83. daddress_telphone: '',
  84. daddress_detail: '',
  85. daddress_isdefault: true,
  86. area_info: '请选择地区',
  87. city_id: 0,
  88. area_id: 0
  89. }
  90. }
  91. },
  92. onLoad: function (option) {
  93. this.action = option.action
  94. if (this.action!='add') {
  95. this.address_id = option.address_id
  96. this.isFromCheckout = option.isFromCheckout
  97. this.goBackLevel = option.goBackLevel ? parseInt(option.goBackLevel) : 1
  98. getAddressInfo(this.address_id).then(res => {
  99. this.address_info = res.result.address_info
  100. if (res.result.address_info.daddress_isdefault === '1') {
  101. this.address_info.daddress_isdefault = true
  102. } else {
  103. this.address_info.daddress_isdefault = false
  104. }
  105. }).catch(function (error) {
  106. uni.showToast({icon:'none',title: error.message})
  107. })
  108. }
  109. },
  110. mounted(){
  111. // #ifdef MP-WEIXIN
  112. this.navHeight = uni.getMenuButtonBoundingClientRect().height
  113. // #endif
  114. },
  115. methods: {
  116. switchChange(e){
  117. this.address_info.daddress_isdefault=e.detail.value
  118. },
  119. goBack () {
  120. uni.navigateBack({delta:1})
  121. },
  122. submit () {
  123. if (this.address_info.seller_name === '') {
  124. uni.showToast({icon:'none',title: '请填写联系人姓名'})
  125. return
  126. }
  127. if (this.address_info.seller_name.length < 2 || this.address_info.seller_name.length > 15) {
  128. uni.showToast({icon:'none',title: '2-15个字符限制'})
  129. return
  130. }
  131. if (this.address_info.daddress_telphone === '') {
  132. uni.showToast({icon:'none',title: '请填写手机号码'})
  133. return
  134. }
  135. if (this.address_info.area_id === 0 || this.address_info.area_id === undefined) {
  136. uni.showToast({icon:'none',title: '请选择所在地区'})
  137. return
  138. }
  139. if (this.address_info.daddress_detail === '') {
  140. uni.showToast({icon:'none',title: '请填写详细地址'})
  141. return
  142. }
  143. uni.showLoading({ title: '加载中' })
  144. editAddress(this.address_info, this.isAddMode ? 0 : this.address_id).then(
  145. (response) => {
  146. uni.hideLoading()
  147. this.updateSelectedAddress()
  148. }, (error) => {
  149. uni.hideLoading()
  150. uni.showToast({icon:'none',title: error.message})
  151. })
  152. },
  153. onRegion (picker, values) {
  154. this.$refs.picker.show()
  155. },
  156. onPickerConfirm (values) {
  157. this.address_info.area_info = this.getRegionStr(values)
  158. this.address_info.area_id = values[2].area_id
  159. this.address_info.city_id = values[1].area_id
  160. },
  161. getRegionStr (values) {
  162. let title = ''
  163. for (let i = 0; i < values.length; i++) {
  164. const element = values[i]
  165. if (i !== 0) {
  166. title = title + ' ' + element.area_name
  167. } else {
  168. title = title + element.area_name
  169. }
  170. }
  171. return title
  172. },
  173. updateSelectedAddress () {
  174. let isFromCheckout = this.isFromCheckout
  175. let goBackLevel = this.goBackLevel ? parseInt(this.goBackLevel) : 1
  176. if (isFromCheckout) {
  177. uni.navigateBack({delta:goBackLevel})
  178. } else {
  179. this.goBack()
  180. }
  181. }
  182. }
  183. }
  184. </script>
  185. <style lang="scss" scoped>
  186. .main-content{background: #fff;padding:0 $pageSpace}
  187. .right-arrow{transform: rotate(-90deg);color:#ddd;font-size:$fontSize;display: inline-block;}
  188. .input-wrap{position: relative;
  189. .i{position: absolute;right:0;top:0;line-height: 2.4rem;display: block;width:2rem;text-align: center;font-size:$h1}
  190. }
  191. </style>