addAddress.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <view>
  3. <u-navbar :border-bottom="false" :is-back="true" title="收货地址"></u-navbar>
  4. <view class="u-m-20">
  5. <u-toast ref="uToast"/>
  6. <view>
  7. <u-field
  8. v-model="model.userName"
  9. focus
  10. iconColor="#d5d5d5"
  11. label="收货人"
  12. label-width="120"
  13. placeholder="请输入收货人姓名"
  14. >
  15. </u-field>
  16. <u-field
  17. v-model="model.phone"
  18. iconColor="#d5d5d5"
  19. label="手机号"
  20. label-width="120"
  21. placeholder="请输入收货人姓名"
  22. >
  23. </u-field>
  24. <u-field
  25. v-model="model.address"
  26. iconColor="#d5d5d5"
  27. label="地址"
  28. label-width="120"
  29. placeholder="请输入详细收货地址"
  30. type="textarea"
  31. >
  32. </u-field>
  33. <view class="defaultAddress">
  34. <text class="title">设置默认地址</text>
  35. <u-switch v-model="model.isDefault" active-color="#FF536F"></u-switch>
  36. </view>
  37. </view>
  38. </view>
  39. <view class="bottomView">
  40. <u-button :custom-style="customStyle" class="u-m-40" hover-class="none" shape="circle" @tap="submit">提交
  41. </u-button>
  42. </view>
  43. </view>
  44. </template>
  45. <script>
  46. export default {
  47. data() {
  48. return {
  49. model: {
  50. userName: '',
  51. phone: '',
  52. address: '',
  53. isDefault: true,
  54. normalDisable: '1',
  55. },
  56. customStyle: {
  57. marginTop: '20px', // 注意驼峰命名,并且值必须用引号包括,因为这是对象
  58. color: '#FFF',
  59. backgroundColor: '#ff536f'
  60. }
  61. }
  62. },
  63. onLoad: function (option) {
  64. if (option.addressId) {
  65. let addressId = option.addressId
  66. // 渲染当前地址
  67. this.findAddressById(addressId);
  68. }
  69. },
  70. methods: {
  71. submit() {
  72. if (!this.model.userName) {
  73. return this.$mytip.toast('请输入收货人')
  74. }
  75. if (!this.model.phone) {
  76. return this.$mytip.toast('请输入手机号')
  77. }
  78. if (!this.model.address) {
  79. return this.$mytip.toast('请输入地址')
  80. }
  81. let url = "/api/mallApi/insertAddress";
  82. if (this.model.id) {
  83. url = "/api/mallApi/updateAddress";
  84. }
  85. this.$u.post(url, this.model).then(result => {
  86. this.$u.route('/pages/address/address')
  87. });
  88. },
  89. findAddressById(addressId) {
  90. let url = "api/mallApi/findAddressById";
  91. this.$u.get(url, {
  92. id: addressId
  93. }).then(result => {
  94. let address = result.data
  95. if (address.isDefault == '0') {
  96. address.isDefault = false
  97. } else if (address.isDefault == '1') {
  98. address.isDefault = true
  99. }
  100. this.model = address
  101. });
  102. },
  103. }
  104. };
  105. </script>
  106. <style>
  107. page {
  108. background-color: #fff;
  109. }
  110. </style>
  111. <style lang="scss" scoped>
  112. page {
  113. overflow: hidden;
  114. }
  115. .logo {
  116. display: flex;
  117. justify-content: center;
  118. align-items: center;
  119. width: 100%;
  120. height: 550 rpx;
  121. img {
  122. text-align: center;
  123. }
  124. }
  125. .version {
  126. position: fixed;
  127. bottom: 0;
  128. width: 100%;
  129. text-align: center;
  130. padding: 15 rpx;
  131. }
  132. .defaultAddress {
  133. display: flex;
  134. justify-content: space-between;
  135. margin-top: 30 rpx;
  136. .title {
  137. margin-left: 20 rpx;
  138. }
  139. }
  140. .bottomView {
  141. position: fixed;
  142. left: 0;
  143. right: 0;
  144. bottom: 0;
  145. z-index: 999;
  146. }
  147. </style>