Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

159 rindas
3.5 KiB

  1. <template>
  2. <view class="content">
  3. <view class="row b-b">
  4. <text class="tit">联系人</text>
  5. <input class="input" type="text" v-model="addressData.name" placeholder="收货人姓名" placeholder-class="placeholder" />
  6. </view>
  7. <view class="row b-b">
  8. <text class="tit">手机号</text>
  9. <input class="input" type="number" v-model="addressData.mobile" placeholder="收货人手机号码" placeholder-class="placeholder" />
  10. </view>
  11. <view class="row b-b">
  12. <text class="tit">地址</text>
  13. <input class="input" type="text" v-model="addressData.address" placeholder="详细地址,楼号" placeholder-class="placeholder" />
  14. </view>
  15. <view class="row b-b">
  16. <text class="tit">邮箱</text>
  17. <input class="input" type="text" v-model="addressData.email" placeholder="邮箱" placeholder-class="placeholder" />
  18. </view>
  19. <view class="row default-row">
  20. <text class="tit">设为默认</text>
  21. <switch :checked="addressData.is_default" color="#fa436a" @change="switchChange" />
  22. </view>
  23. <button class="add-btn" @click="confirm">提交</button>
  24. </view>
  25. </template>
  26. <script>
  27. export default {
  28. data() {
  29. return {
  30. addressData: {
  31. name: '',
  32. mobile: '',
  33. address: '',
  34. email: '',
  35. is_default: false
  36. }
  37. }
  38. },
  39. onLoad(option) {
  40. let title = '新增收货地址';
  41. if (option.type === 'edit') {
  42. this.getInfo(option.id);
  43. title = '编辑收货地址'
  44. } else {
  45. }
  46. this.manageType = option.type;
  47. uni.setNavigationBarTitle({
  48. title
  49. })
  50. },
  51. methods: {
  52. // 获取地址详情
  53. async getInfo(id){
  54. let addressData = await this.$api.request(`/address/info?id=${id}`);
  55. if (addressData) {
  56. console.log(addressData);
  57. this.addressData = addressData;
  58. }
  59. },
  60. //默认地址
  61. switchChange(e) {
  62. this.addressData.is_default = e.detail.value;
  63. },
  64. //提交
  65. async confirm() {
  66. //Deep Clone
  67. let data = JSON.parse(JSON.stringify(this.addressData));
  68. if (!data.name) {
  69. this.$api.msg('请填写收货人姓名');
  70. return;
  71. }
  72. if (!/(^1[3|4|5|7|8][0-9]{9}$)/.test(data.mobile)) {
  73. this.$api.msg('请输入正确的手机号码');
  74. return;
  75. }
  76. if (!data.address) {
  77. this.$api.msg('请填详细地址信息');
  78. return;
  79. }
  80. console.log(data.is_default);
  81. data.is_default = data.is_default == true ? 1 : 0;
  82. let action = this.manageType == 'edit' ? 'edit' : 'add';
  83. let result = await this.$api.request('/address/' + action, 'POST', data);
  84. if (result) {
  85. this.$api.prePage().refreshList(data, this.manageType);
  86. setTimeout(() => {
  87. uni.navigateBack()
  88. }, 800)
  89. }
  90. },
  91. }
  92. }
  93. </script>
  94. <style lang="scss">
  95. page {
  96. background: $page-color-base;
  97. padding-top: 16upx;
  98. }
  99. .row {
  100. display: flex;
  101. align-items: center;
  102. position: relative;
  103. padding: 0 30upx;
  104. height: 110upx;
  105. background: #fff;
  106. .tit {
  107. flex-shrink: 0;
  108. width: 120upx;
  109. font-size: 30upx;
  110. color: $font-color-dark;
  111. }
  112. .input {
  113. flex: 1;
  114. font-size: 30upx;
  115. color: $font-color-dark;
  116. }
  117. .icon-shouhuodizhi {
  118. font-size: 36upx;
  119. color: $font-color-light;
  120. }
  121. }
  122. .default-row {
  123. margin-top: 16upx;
  124. .tit {
  125. flex: 1;
  126. }
  127. switch {
  128. transform: translateX(16upx) scale(.9);
  129. }
  130. }
  131. .add-btn {
  132. display: flex;
  133. align-items: center;
  134. justify-content: center;
  135. width: 690upx;
  136. height: 80upx;
  137. margin: 60upx auto;
  138. font-size: $font-lg;
  139. color: #fff;
  140. background-color: $base-color;
  141. border-radius: 10upx;
  142. box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  143. }
  144. </style>