editAddres.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <template>
  2. <view id="editAddres">
  3. <view class="editBox">
  4. <view class="inBox dfsb">
  5. <text>收货人</text>
  6. <input focus type="text" v-model="newsInfo.name" placeholder="请填写收货人姓名" />
  7. </view>
  8. <view class="inBox dfsb">
  9. <text>手机号码</text>
  10. <input type="text" v-model="newsInfo.phone" placeholder="请填写收货人手机号码" />
  11. </view>
  12. <view @tap="addressShow = true" class="inBox dfsb">
  13. <text>所在地区</text>
  14. <input disabled type="text" v-model="newsInfo.address" placeholder="省市区、乡镇" />
  15. <pickerAddress v-model="addressShow" @confirm="addresspick" />
  16. <u-icon size="16" name="arrow-right"></u-icon>
  17. </view>
  18. <view class="inBox spec dffd">
  19. <text class="specbot">详细地址</text>
  20. <input type="text" v-model="newsInfo.detail" placeholder="街道、、小区、楼牌号、单元室等" />
  21. </view>
  22. </view>
  23. <view @tap="newsInfo.is_check = !newsInfo.is_check" class="editBox dfsb specbox">
  24. <text>设为默认</text>
  25. <u-switch activeColor="#5FB25A" v-model="value"></u-switch>
  26. <!-- <image :src="newsInfo.is_check == 1 ? require('@/static/img/common/mraddsel.svg') : require('@/static/img/common/mradd.svg')" mode=""></image> -->
  27. </view>
  28. <!-- #ifdef MP -->
  29. <view v-if="state" @click="delAdd" class="clickbtn delbtn promain ">删除收货地址</view>
  30. <view @click="saveAdd" class="clickbtn">保存</view>
  31. <!-- #endif -->
  32. <!-- #ifndef MP -->
  33. <view v-if="state" @click="delAdd" class="delbtn promain">删除收货地址</view>
  34. <view @click="saveAdd" class="clickbtn">保存</view>
  35. <!-- #endif -->
  36. </view>
  37. </template>
  38. <script>
  39. import pickerAddress from '@/common/othCom/liudx-pickerAddress/index.vue';
  40. export default {
  41. data() {
  42. return {
  43. newsInfo: {
  44. name: '',
  45. phone: '',
  46. address: '',
  47. detail: '',
  48. //选中地址
  49. is_check: false // true选中 false 未选中
  50. },
  51. value: '',
  52. //添加还是编辑
  53. state: true, //false 添加 true编辑
  54. //三级联动
  55. addressShow: false,
  56. form: {
  57. province: '',
  58. city: '',
  59. area: ''
  60. }
  61. };
  62. },
  63. onNavigationBarButtonTap() {
  64. this.saveAdd();
  65. },
  66. onLoad(opt) {
  67. console.log(opt);
  68. if (opt.type == 'edit') {
  69. this.state = true;
  70. uni.setNavigationBarTitle({
  71. title: '编辑地址'
  72. });
  73. this.id = opt.id;
  74. this.onload();
  75. } else {
  76. this.state = false;
  77. uni.setNavigationBarTitle({
  78. title: '添加地址'
  79. });
  80. }
  81. },
  82. methods: {
  83. // /、选择地址
  84. addresspick(obj) {
  85. let arr = ['province', 'city', 'area'];
  86. let place = '';
  87. arr.map(key => {
  88. this.form[key] = obj[key].id;
  89. place += obj[key].name;
  90. });
  91. this.newsInfo.address = place;
  92. },
  93. saveAdd() {
  94. let url = '';
  95. if (!this.newsInfo.name) return this.$api.toast('请输入姓名');
  96. if (!this.newsInfo.phone) return this.$api.toast('请输入手机号');
  97. if (!this.form) return this.$api.toast('请选择地址');
  98. if (!this.newsInfo.detail) return this.$api.toast('请输入详细地址');
  99. this.$api
  100. .request('user_address/setAddress', {
  101. name: this.newsInfo.name,
  102. phone: this.newsInfo.phone,
  103. province_id: this.form.province,
  104. city_id: this.form.city,
  105. area_id: this.form.area,
  106. detail: this.newsInfo.detail,
  107. is_default: this.newsInfo.is_check ? 1 : 0, //1 默认 2 不默认
  108. id: this.id || ''
  109. })
  110. .then(data => {
  111. if (data.code == 200) {
  112. // this.newsInfo=data.data.address;
  113. this.$api.toast(data.msg);
  114. setTimeout(res=>{
  115. uni.navigateBack({
  116. delta: 1
  117. });
  118. },600)
  119. } else {
  120. this.$api.toast(data.msg);
  121. }
  122. })
  123. },
  124. delAdd() {
  125. this.$api
  126. .request('user_address/addressDel', {
  127. id: this.id
  128. })
  129. .then(data => {
  130. this.$api.toast(data.msg);
  131. if (data.code == 200) {
  132. setTimeout(res => {
  133. uni.navigateBack({
  134. delta: 1
  135. });
  136. }, 800);
  137. }
  138. })
  139. },
  140. onload() {
  141. this.$api
  142. .request('user_address/addressInfo', {
  143. id: this.id
  144. })
  145. .then(data => {
  146. if (data.code == 200) {
  147. this.newsInfo.name = data.data.name;
  148. this.newsInfo.phone = data.data.phone;
  149. this.form.province = data.data.province_id;
  150. this.form.city = data.data.city_id;
  151. this.form.area = data.data.area_id;
  152. this.newsInfo.address = data.data.mergename;
  153. this.newsInfo.detail = data.data.detail;
  154. this.newsInfo.is_check = data.data.is_default == 1 ? true : false;
  155. } else {
  156. this.$api.toast(data.msg);
  157. }
  158. })
  159. }
  160. },
  161. components: {
  162. pickerAddress
  163. }
  164. };
  165. </script>
  166. <style lang="scss" scoped>
  167. #editAddres {
  168. padding: 30rpx 0rpx;
  169. .editBox {
  170. background-color: #fff;
  171. padding: 0 30rpx;
  172. .inBox {
  173. padding: 30rpx 0;
  174. border-bottom: 1px solid $bordermain;
  175. text {
  176. min-width: 140rpx;
  177. font-size: 30rpx;
  178. }
  179. input {
  180. width: 100%;
  181. flex: 1;
  182. font-size: 30rpx;
  183. text-align: right;
  184. }
  185. .specbot {
  186. margin-bottom: 30rpx;
  187. }
  188. }
  189. .spec {
  190. input {
  191. text-align: left;
  192. }
  193. }
  194. }
  195. .specbox {
  196. margin: 30rpx 0;
  197. padding: 30rpx;
  198. image {
  199. width: 90rpx;
  200. height: 40rpx;
  201. }
  202. }
  203. .clickbtn {
  204. width: 690rpx;
  205. margin: 30rpx 32rpx;
  206. border-radius: 11rpx;
  207. }
  208. .delbtn {
  209. background: #fff;
  210. padding: 30rpx;
  211. }
  212. }
  213. </style>