adressManger.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <template>
  2. <view class="content">
  3. <view class="row b-b" @click="changeshow">
  4. <input class="input" id="box" type="text" :disabled="true" v-model="addressData.addressName" placeholder="省,城市,区县" placeholder-class="placeholder" />
  5. </view>
  6. <view class="row b-b">
  7. <input class="input" type="text" v-model="addressData.area" placeholder="详细地址,如街道,楼牌号等" placeholder-class="placeholder" />
  8. </view>
  9. <view class="row b-b">
  10. <input class="input" type="text" v-model="addressData.name" placeholder="姓名" placeholder-class="placeholder" />
  11. </view>
  12. <view class="row b-b">
  13. <input class="input" type="number" v-model="addressData.mobile" placeholder="电话" placeholder-class="placeholder" />
  14. </view>
  15. <button class="add-btn" @click="confirm">保存</button>
  16. <view v-if="show" class="over"></view>
  17. <view v-if="show" class="overadress" style="position: fixed;bottom:0;width: 100%;height: 50%;background-color: #fff;">
  18. <view style="display: flex;flex-direction: row;justify-content: space-between;padding:40upx 32upx;">
  19. <view>请选择</view>
  20. <view>{{adress}}</view>
  21. <view @click="cancelCity">确定</view>
  22. </view>
  23. <scroll-view style="height: 100%;" :scroll-top="scrollTop" scroll-y="true" @scroll="scroll" @scrolltoupper="upper" @scrolltolower="lower"
  24. refresher-enabled="true">
  25. <view style="padding: 30upx 34upx;border-bottom: 1px solid #eee;" v-for="(item,index) in areaList"
  26. @click="chosecity(item)"
  27. :key="index">
  28. {{item.area_name}}
  29. </view>
  30. </scroll-view>
  31. </view>
  32. <!-- <van-area v-if="show" class="overadress" @confirm="choseCity" @cancel="cancelCity" :area-list="areaList" /> -->
  33. </view>
  34. </template>
  35. <script>
  36. import mpvueCityPicker from '@/component/mpvue-citypicker/mpvueCityPicker.vue'
  37. export default {
  38. components: {
  39. mpvueCityPicker
  40. },
  41. data() {
  42. return {
  43. address_id:'',
  44. scrollTop: 0,
  45. old: {
  46. scrollTop: 0
  47. },
  48. area_id: '',
  49. addressData: {
  50. addressName: '',
  51. mobile: '',
  52. name: '',
  53. area: '',
  54. default: false
  55. },
  56. adress:'',
  57. show: false,
  58. province_list:{},
  59. areaList:[]
  60. }
  61. },
  62. onLoad(option){
  63. let title = '新增收货地址';
  64. if(option.type==='edit'){
  65. title = '编辑收货地址'
  66. let data = JSON.parse(option.data);
  67. this.addressData.addressName = data.area_info;
  68. this.addressData.mobile = data.address_mob_phone;
  69. this.addressData.name = data.address_realname;
  70. this.addressData.area = data.address_detail;
  71. this.address_id = data.address_id;
  72. this.area_id = data.area_id;
  73. }
  74. this.manageType = option.type;
  75. uni.setNavigationBarTitle({
  76. title
  77. });
  78. this.getadress();
  79. },
  80. methods: {
  81. chosecity(item){
  82. this.adress += item.area_name;
  83. this.area_id = item.area_id;
  84. this.getadress();
  85. },
  86. upper(e) {
  87. console.log(e)
  88. console.log("顶部")
  89. },
  90. // 滚到底部
  91. lower(e) {
  92. console.log("底部")
  93. },
  94. // 滚动时触发
  95. scroll(e) {
  96. this.old.scrollTop = e.detail.scrollTop
  97. },
  98. getadress() {
  99. this.request({
  100. url:'/v2/entry/areaList',
  101. method: 'get',
  102. data: {
  103. area_parent_id: this.area_id
  104. },
  105. success: (res) => {
  106. this.areaList = res.data.data.area_list;
  107. if(this.areaList.length == 0 && this.area_id != '' && this.manageType != 'edit') {
  108. this.addressData.addressName = this.adress;
  109. this.show = false;
  110. }
  111. }
  112. })
  113. },
  114. switchChange(e){
  115. this.addressData.default = e.detail;
  116. },
  117. changeshow() {
  118. this.adress = '';
  119. this.area_id = '';
  120. this.getadress();
  121. this.show = !this.show;
  122. },
  123. cancelCity() {
  124. this.show = false;
  125. },
  126. // choseCity(e) {
  127. // console.log(e);
  128. // this.show = false;
  129. // },
  130. //提交
  131. confirm(){
  132. let data = this.addressData;
  133. if(!data.addressName){
  134. this.$msg('请选择省市区');
  135. return;
  136. }
  137. if(!data.area){
  138. this.$msg('请输入详细地址');
  139. return;
  140. }
  141. if(!data.name){
  142. this.$msg('请输入姓名');
  143. return;
  144. }
  145. if(!/(^1[3|4|5|7|8][0-9]{9}$)/.test(data.mobile)){
  146. this.$msg('请输入正确的手机号码');
  147. return;
  148. }
  149. let url = '';
  150. let params = {};
  151. params.area_id = this.area_id;
  152. params.address_detail= data.area; // 详细地址
  153. params.address_mob_phone= data.mobile;
  154. params.address_realname= data.name;
  155. params.area_info= data.addressName;
  156. params.is_free=0;
  157. if(this.manageType == 'edit') {
  158. url = '/v1/member/address_edit';
  159. params.address_id = this.address_id;
  160. }else {
  161. url = '/v2/address/add';
  162. }
  163. this.request({
  164. url: url,
  165. method: 'post',
  166. data: params,
  167. success: (res) => {
  168. uni.$emit('refeshadress')
  169. setTimeout(()=>{
  170. uni.navigateBack();
  171. }, 800)
  172. }
  173. })
  174. //this.$api.prePage()获取上一页实例,可直接调用上页所有数据和方法,在App.vue定义
  175. // this.$api.prePage().refreshList(data, this.manageType);
  176. // this.$api.msg(`地址${this.manageType=='edit' ? '修改': '添加'}成功`);
  177. // setTimeout(()=>{
  178. // uni.navigateBack()
  179. // }, 800)
  180. },
  181. }
  182. }
  183. </script>
  184. <style lang="scss">
  185. page{
  186. background: $page-color-base;
  187. padding-top: 16upx;
  188. }
  189. .row{
  190. display: flex;
  191. align-items: center;
  192. position: relative;
  193. padding:0 30upx;
  194. height: 110upx;
  195. background: #fff;
  196. .tit{
  197. flex-shrink: 0;
  198. width: 120upx;
  199. font-size: 30upx;
  200. color: $font-color-dark;
  201. }
  202. .input{
  203. flex: 1;
  204. font-size: 30upx;
  205. color: $font-color-dark;
  206. }
  207. .icon-shouhuodizhi{
  208. font-size: 36upx;
  209. color: $font-color-light;
  210. }
  211. }
  212. .default-row{
  213. margin-top: 16upx;
  214. .tit{
  215. flex: 1;
  216. }
  217. switch{
  218. transform: translateX(16upx) scale(.9);
  219. }
  220. }
  221. .add-btn{
  222. display: flex;
  223. align-items: center;
  224. justify-content: center;
  225. width: 690upx;
  226. height: 80upx;
  227. margin: 60upx auto;
  228. font-size: $font-lg;
  229. color: #fff;
  230. background-color: #D9332E;
  231. border-radius: 10upx;
  232. box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  233. }
  234. .over {
  235. position:absolute;left:0px;top:0px;
  236. background:rgba(0, 0, 0, 0.4);
  237. width:100%; /*宽度设置为100%,这样才能使隐藏背景层覆盖原页面*/
  238. height:100%;
  239. filter:alpha(opacity=60); /*设置透明度为60%*/
  240. opacity:0.6; /*非IE浏览器下设置透明度为60%*/
  241. z-Index:100;
  242. }
  243. .overadress {
  244. position: fixed;
  245. bottom: 0;
  246. left: 0;
  247. z-index: 999;
  248. width: 100%;
  249. }
  250. </style>