adressManger.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <template>
  2. <view class="content">
  3. <view class="row b-b">
  4. <input class="input" type="text" @click="changeshow" 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. <van-area v-if="show" class="overadress" @confirm="choseCity" @cancel="cancelCity" :area-list="areaList" />
  17. <view v-if="show" class="over"></view>
  18. </view>
  19. </template>
  20. <script>
  21. import mpvueCityPicker from '@/component/mpvue-citypicker/mpvueCityPicker.vue'
  22. export default {
  23. components: {
  24. mpvueCityPicker
  25. },
  26. data() {
  27. return {
  28. addressData: {
  29. name: '',
  30. mobile: '',
  31. address: '',
  32. area: '',
  33. default: false
  34. },
  35. show: false,
  36. areaList:{
  37. province_list: {
  38. 110000: '北京市',
  39. 120000: '天津市'
  40. },
  41. city_list: {
  42. 110100: '北京市',
  43. 110200: '县',
  44. 120100: '天津市',
  45. 120200: '县'
  46. },
  47. county_list: {
  48. 110101: '东城区',
  49. 110102: '西城区',
  50. 110105: '朝阳区',
  51. 110106: '丰台区',
  52. 120101: '和平区',
  53. 120102: '河东区',
  54. 120103: '河西区',
  55. 120104: '南开区',
  56. 120105: '河北区'
  57. }
  58. }
  59. }
  60. },
  61. onLoad(option){
  62. let title = '新增收货地址';
  63. if(option.type==='edit'){
  64. title = '编辑收货地址'
  65. this.addressData = JSON.parse(option.data)
  66. }
  67. this.manageType = option.type;
  68. uni.setNavigationBarTitle({
  69. title
  70. })
  71. },
  72. methods: {
  73. switchChange(e){
  74. this.addressData.default = e.detail;
  75. },
  76. changeshow() {
  77. this.show = !this.show;
  78. },
  79. cancelCity() {
  80. this.show = false;
  81. },
  82. choseCity(e) {
  83. console.log(e);
  84. this.show = false;
  85. },
  86. //提交
  87. confirm(){
  88. let data = this.addressData;
  89. if(!data.name){
  90. this.$api.msg('请填写收货人姓名');
  91. return;
  92. }
  93. if(!/(^1[3|4|5|7|8][0-9]{9}$)/.test(data.mobile)){
  94. this.$api.msg('请输入正确的手机号码');
  95. return;
  96. }
  97. if(!data.address){
  98. this.$api.msg('请在地图选择所在位置');
  99. return;
  100. }
  101. if(!data.area){
  102. this.$api.msg('请填写门牌号信息');
  103. return;
  104. }
  105. //this.$api.prePage()获取上一页实例,可直接调用上页所有数据和方法,在App.vue定义
  106. this.$api.prePage().refreshList(data, this.manageType);
  107. this.$api.msg(`地址${this.manageType=='edit' ? '修改': '添加'}成功`);
  108. setTimeout(()=>{
  109. uni.navigateBack()
  110. }, 800)
  111. },
  112. }
  113. }
  114. </script>
  115. <style lang="scss">
  116. page{
  117. background: $page-color-base;
  118. padding-top: 16upx;
  119. }
  120. .row{
  121. display: flex;
  122. align-items: center;
  123. position: relative;
  124. padding:0 30upx;
  125. height: 110upx;
  126. background: #fff;
  127. .tit{
  128. flex-shrink: 0;
  129. width: 120upx;
  130. font-size: 30upx;
  131. color: $font-color-dark;
  132. }
  133. .input{
  134. flex: 1;
  135. font-size: 30upx;
  136. color: $font-color-dark;
  137. }
  138. .icon-shouhuodizhi{
  139. font-size: 36upx;
  140. color: $font-color-light;
  141. }
  142. }
  143. .default-row{
  144. margin-top: 16upx;
  145. .tit{
  146. flex: 1;
  147. }
  148. switch{
  149. transform: translateX(16upx) scale(.9);
  150. }
  151. }
  152. .add-btn{
  153. display: flex;
  154. align-items: center;
  155. justify-content: center;
  156. width: 690upx;
  157. height: 80upx;
  158. margin: 60upx auto;
  159. font-size: $font-lg;
  160. color: #fff;
  161. background-color: #D9332E;
  162. border-radius: 10upx;
  163. box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  164. }
  165. .over {
  166. position:absolute;left:0px;top:0px;
  167. background:rgba(0, 0, 0, 0.4);
  168. width:100%; /*宽度设置为100%,这样才能使隐藏背景层覆盖原页面*/
  169. height:100%;
  170. filter:alpha(opacity=60); /*设置透明度为60%*/
  171. opacity:0.6; /*非IE浏览器下设置透明度为60%*/
  172. z-Index:100;
  173. }
  174. .overadress {
  175. position: fixed;
  176. bottom: 0;
  177. left: 0;
  178. z-index: 999;
  179. width: 100%;
  180. }
  181. </style>