saveAddress.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <view class="body">
  3. <view class="content">
  4. <view style="margin-left: 4vw;">收获地址</view>
  5. <view class="model">
  6. <p style="margin-left: -4vw;">姓名</p>
  7. <p> <input type="text" v-model="name" placeholder="请输入收获人手机号"> </p>
  8. </view>
  9. <view class="model">
  10. <p style="margin-left: -3vw;">手机号</p>
  11. <p> <input type="text" v-model="tel" placeholder="请输入收货人手机号"> </p>
  12. </view>
  13. <view class="model" @click="city">
  14. <p style="margin-left: 4vw;">地区</p>
  15. <p> <input style="margin-left: 16vw;" v-model="area" type="text" disabled="true" placeholder="请选择省/市/区"> </p>
  16. <p>
  17. <image style="width: 5vw; height: 5vw;" src="../../static/dingwei.png"></image>
  18. </p>
  19. </view>
  20. <view class="Textmodel">
  21. <p style="margin-left: 4vw;">详细地址</p>
  22. <p> <textarea
  23. style="width: 60vw; height: 15vh; background-color: #f8f8f8; font-size: 0.9rem; padding: 1vw; "
  24. type="text" v-model="addr" placeholder="街道门牌,楼道等信息"></textarea> </p>
  25. </view>
  26. </view>
  27. <view class="setaddress">
  28. <view>
  29. <p style="font-size: 1rem;">设置默认地址</p>
  30. <p style="font-size: 0.8rem; color: lightgrey; margin-top: 2vw; ">每次下单会默认推荐使用该地址</p>
  31. </view>
  32. <view>
  33. <u-switch size="40" v-model="checked" @change="change"></u-switch>
  34. </view>
  35. </view>
  36. <view class="button" @click="saveAddress"> 保存 </view>
  37. <u-toast ref="uToast" />
  38. <u-picker mode="region" v-model="show" @cancel="cancel" @confirm="confirm"
  39. :area-code='["13", "1303", "130304"]'></u-picker>
  40. </view>
  41. </template>
  42. <script>
  43. export default {
  44. data() {
  45. return {
  46. value: '',
  47. show: false,
  48. checked: false,
  49. name:'',
  50. tel:'',
  51. area:'',
  52. addr:'',
  53. default:false,
  54. addressInfo:""
  55. }
  56. },
  57. onLoad(option) {
  58. if(option.addressInfo){
  59. this.addressInfo=JSON.parse(decodeURIComponent(option.addressInfo))
  60. console.log('-------',this.addressInfo)
  61. this.name=this.addressInfo.name
  62. this.tel=this.addressInfo.tel
  63. this.area=this.addressInfo.area
  64. this.addr=this.addressInfo.addr
  65. this.default=this.addressInfo.default
  66. }
  67. },
  68. methods: {
  69. change(status) {
  70. this.default=status
  71. },
  72. saveAddress(){
  73. if(this.addressInfo!=''){
  74. this.$api.postEdimtAddress(this.addressInfo.id,{name:this.name,tel:this.tel,addr:this.addr,area:this.area,default:this.default},res=>{
  75. if(res.code==0){
  76. this.successToast('操作成功')
  77. uni.navigateBack({
  78. url:1
  79. });
  80. }else{
  81. this.errorToast(res.msg)
  82. }
  83. })
  84. }else{
  85. this.$api.postAddress({name:this.name,tel:this.tel,addr:this.addr,area:this.area,default:this.default},res=>{
  86. if(res.code==0){
  87. this.successToast('操作成功')
  88. uni.navigateBack({
  89. url:1
  90. });
  91. }else{
  92. this.errorToast(res.msg)
  93. }
  94. })
  95. }
  96. },
  97. city() {
  98. this.show = true
  99. },
  100. confirm(e) {
  101. this.area= e.province.label+e.city.label +e.area.label
  102. },
  103. cancel(e) {
  104. this.show=false
  105. console.log("取消")
  106. },
  107. successToast(msg) {
  108. this.$refs.uToast.show({
  109. title: msg,
  110. type: 'success',
  111. duration: 1000
  112. })
  113. },
  114. errorToast(msg) {
  115. this.$refs.uToast.show({
  116. title: msg,
  117. type: 'error',
  118. duration: 1000
  119. })
  120. },
  121. }
  122. }
  123. </script>
  124. <style lang="scss" scoped>
  125. .body {
  126. width: 100vw;
  127. height: 100vh;
  128. background-color: #f8f8f8;
  129. box-sizing: border-box;
  130. padding: 0 5vw;
  131. .content {
  132. width: 90vw;
  133. height: 50vh;
  134. background-color: white;
  135. border-radius: 5px;
  136. box-sizing: border-box;
  137. padding: 3vw;
  138. .model {
  139. width: 84vw;
  140. height: 15vw;
  141. display: flex;
  142. justify-content: space-around;
  143. align-items: center;
  144. border-bottom: 1px solid #f8f8f8;
  145. }
  146. .Textmodel {
  147. width: 84vw;
  148. height: 30vh;
  149. display: flex;
  150. justify-content: space-around;
  151. border-bottom: 1px solid #f8f8f8;
  152. }
  153. }
  154. .button {
  155. width: 90vw;
  156. height: 12vw;
  157. text-align: center;
  158. line-height: 12vw;
  159. background-color: #f83036;
  160. color: white;
  161. border-radius: 32px;
  162. margin-top: 5vw;
  163. }
  164. .setaddress {
  165. width: 90vw;
  166. height: 10vh;
  167. background-color: white;
  168. border-radius: 5px;
  169. margin-top: 2vw;
  170. display: flex;
  171. justify-content: space-between;
  172. align-items: center;
  173. box-sizing: border-box;
  174. padding: 0 2vw;
  175. }
  176. }
  177. </style>