adressManger.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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. changeshow() {
  87. this.adress = '';
  88. this.area_id = '';
  89. this.getadress();
  90. this.show = !this.show;
  91. },
  92. cancelCity() {
  93. this.addressData.addressName = this.adress;
  94. this.show = false;
  95. },
  96. upper(e) {
  97. console.log(e)
  98. console.log("顶部")
  99. },
  100. // 滚到底部
  101. lower(e) {
  102. console.log("底部")
  103. },
  104. // 滚动时触发
  105. scroll(e) {
  106. this.old.scrollTop = e.detail.scrollTop
  107. },
  108. getadress() {
  109. this.request({
  110. url:'/v2/entry/areaList',
  111. method: 'get',
  112. data: {
  113. area_parent_id: this.area_id
  114. },
  115. success: (res) => {
  116. this.areaList = res.data.data.area_list;
  117. if(this.areaList.length == 0 && this.area_id != '' && this.manageType != 'edit') {
  118. this.addressData.addressName = this.adress;
  119. this.show = false;
  120. }
  121. }
  122. })
  123. },
  124. switchChange(e){
  125. this.addressData.default = e.detail;
  126. },
  127. // choseCity(e) {
  128. // console.log(e);
  129. // this.show = false;
  130. // },
  131. //提交
  132. confirm(){
  133. let data = this.addressData;
  134. if(!data.addressName){
  135. this.$msg('请选择省市区');
  136. return;
  137. }
  138. if(!data.area){
  139. this.$msg('请输入详细地址');
  140. return;
  141. }
  142. if(!data.name){
  143. this.$msg('请输入姓名');
  144. return;
  145. }
  146. if(!/(^1[3|4|5|7|8][0-9]{9}$)/.test(data.mobile)){
  147. this.$msg('请输入正确的手机号码');
  148. return;
  149. }
  150. let url = '';
  151. let params = {};
  152. params.area_id = this.area_id;
  153. params.address_detail= data.area; // 详细地址
  154. params.address_mob_phone= data.mobile;
  155. params.address_realname= data.name;
  156. params.area_info= data.addressName;
  157. params.is_free=0;
  158. if(this.manageType == 'edit') {
  159. url = '/v1/member/address_edit';
  160. params.address_id = this.address_id;
  161. }else {
  162. url = '/v2/address/add';
  163. }
  164. this.request({
  165. url: url,
  166. method: 'post',
  167. data: params,
  168. success: (res) => {
  169. console.log(res.data.code);
  170. if(res.data.code == 1000) {
  171. uni.$emit('refeshadress')
  172. setTimeout(()=>{
  173. uni.navigateBack();
  174. }, 800)
  175. }else {
  176. }
  177. }
  178. })
  179. //this.$api.prePage()获取上一页实例,可直接调用上页所有数据和方法,在App.vue定义
  180. // this.$api.prePage().refreshList(data, this.manageType);
  181. // this.$api.msg(`地址${this.manageType=='edit' ? '修改': '添加'}成功`);
  182. // setTimeout(()=>{
  183. // uni.navigateBack()
  184. // }, 800)
  185. },
  186. }
  187. }
  188. </script>
  189. <style lang="scss">
  190. page{
  191. background: $page-color-base;
  192. padding-top: 16upx;
  193. }
  194. .row{
  195. display: flex;
  196. align-items: center;
  197. position: relative;
  198. padding:0 30upx;
  199. height: 110upx;
  200. background: #fff;
  201. .tit{
  202. flex-shrink: 0;
  203. width: 120upx;
  204. font-size: 30upx;
  205. color: $font-color-dark;
  206. }
  207. .input{
  208. flex: 1;
  209. font-size: 30upx;
  210. color: $font-color-dark;
  211. }
  212. .icon-shouhuodizhi{
  213. font-size: 36upx;
  214. color: $font-color-light;
  215. }
  216. }
  217. .default-row{
  218. margin-top: 16upx;
  219. .tit{
  220. flex: 1;
  221. }
  222. switch{
  223. transform: translateX(16upx) scale(.9);
  224. }
  225. }
  226. .add-btn{
  227. display: flex;
  228. align-items: center;
  229. justify-content: center;
  230. width: 690upx;
  231. height: 80upx;
  232. margin: 60upx auto;
  233. font-size: $font-lg;
  234. color: #fff;
  235. background-color: #D9332E;
  236. border-radius: 10upx;
  237. box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  238. }
  239. .over {
  240. position:absolute;left:0px;top:0px;
  241. background:rgba(0, 0, 0, 0.4);
  242. width:100%; /*宽度设置为100%,这样才能使隐藏背景层覆盖原页面*/
  243. height:100%;
  244. filter:alpha(opacity=60); /*设置透明度为60%*/
  245. opacity:0.6; /*非IE浏览器下设置透明度为60%*/
  246. z-Index:100;
  247. }
  248. .overadress {
  249. position: fixed;
  250. bottom: 0;
  251. left: 0;
  252. z-index: 999;
  253. width: 100%;
  254. }
  255. </style>