address.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <template>
  2. <view>
  3. <view class="address-list">
  4. <z-paging ref="paging" show-refresher-update-time v-model="dataList" @query="queryList" :fixed="false">
  5. <view class="list-item" v-for="(item,index) in dataList" :key="index">
  6. <view class="item-left" @click="checkAddress(item)">
  7. <view class="title"><text v-if="item.is_default == 1">默认</text> {{item.region}}</view>
  8. <view class="name">{{item.address}}</view>
  9. <view class="mobile">{{item.username}}<text>{{item.mobile}}</text></view>
  10. </view>
  11. <view class="item-right">
  12. <view class="icon" @click="edit(item)"><image src="/static/image/edit.png"></image></view>
  13. <view class="icon" @click="del(item.id)"><image src="/static/image/del.png"></image></view>
  14. </view>
  15. </view>
  16. </z-paging>
  17. </view>
  18. <view class="flx-footer">
  19. <view class="check-btn"><button class="btn" :disabled="disabled" @click="add">{{disabled?'处理中...':'新增地址'}}</button></view>
  20. <view class="footer-safe"></view>
  21. </view>
  22. <uni-popup ref="popup" type="bottom" borderRadius="10px 10px 0 0" backgroundColor="#F8F8F8">
  23. <view class="time-select">
  24. <view class="title">{{mode=='add'?'新增':'编辑'}}地址
  25. <view class="close" @click="close()"><image src="/static/image/round_close.png"></image></view>
  26. </view>
  27. </view>
  28. <view class="goods-body">
  29. <view class="goods-form">
  30. <view class="form-title">会员姓名</view>
  31. <view class="form-input">
  32. <input placeholder="请输入会员姓名" v-model="formData.username" class="input" />
  33. </view>
  34. </view>
  35. <view class="goods-form">
  36. <view class="form-title">联系电话</view>
  37. <view class="form-input">
  38. <input placeholder="请输入联系电话" v-model="formData.mobile" class="input" />
  39. </view>
  40. </view>
  41. <view class="goods-form">
  42. <view class="form-title">联系地区</view>
  43. <view class="form-input">
  44. <picker @change="bindPickerChange" mode="region">
  45. <view class="region-name">{{regionName?regionName:'请选择'}}</view>
  46. </picker>
  47. </view>
  48. </view>
  49. <view class="goods-form">
  50. <view class="form-title">详细地址</view>
  51. <view class="form-input">
  52. <input placeholder="请输入详细地址" v-model="formData.address" class="input" />
  53. </view>
  54. </view>
  55. </view>
  56. <view class="time-btn">
  57. <button class="btn" :disabled="disabled" @click="submit">{{disabled?'处理中...':'确认'}}</button>
  58. </view>
  59. </uni-popup>
  60. </view>
  61. </template>
  62. <script>
  63. var app;
  64. import * as Api from "@/static/api/address.js";
  65. import form from "@/static/js/form.js";
  66. export default {
  67. data() {
  68. return {
  69. type:1,
  70. mode:"add",
  71. regionName:null,
  72. formData:{},
  73. disabled:false,
  74. dataList:[]
  75. }
  76. },
  77. onLoad({type}) {
  78. app = this;
  79. app.type = type;
  80. },
  81. methods: {
  82. queryList(pageNo, pageSize){
  83. var formData = {};
  84. formData.page = pageNo;
  85. formData.size = pageSize;
  86. Api.data(formData).then((res)=>{
  87. uni.hideLoading();
  88. if (res.code !== 1) {
  89. this.$refs.paging.complete(false);
  90. return false;
  91. }
  92. this.$refs.paging.complete(res.data.rows);
  93. })
  94. },
  95. checkAddress(data){
  96. if (app.type == 2) {
  97. var pages = getCurrentPages();
  98. //获取上一个页面实例对象
  99. let beforePage = pages[pages.length - 2];
  100. //触发上一个页面中的getUserInfo方法
  101. beforePage.$vm.getBackInfo(data);
  102. uni.navigateBack();
  103. }
  104. },
  105. del(id){
  106. app.$dialog.showError("确定要删除该地址信息吗?",function(res){
  107. if (res.confirm) {
  108. Api.del({"id":id}).then((resp)=>{
  109. if (resp.code == 0) {
  110. return app.$dialog.showSuccess(resp.msg);
  111. }
  112. app.$dialog.showSuccess(resp.msg);
  113. app.queryList(1,10);
  114. })
  115. }
  116. });
  117. },
  118. edit(data){
  119. app.formData = data;
  120. app.mode = "edit";
  121. app.regionName = data.region
  122. app.$refs.popup.open()
  123. },
  124. bindPickerChange(e){
  125. var name = "";
  126. var regionData = e.detail.value;
  127. regionData.forEach((item)=>{
  128. name += item
  129. })
  130. app.regionName = name;
  131. },
  132. close(){
  133. app.$refs.popup.close()
  134. },
  135. add(){
  136. app.mode = "add";
  137. app.$refs.popup.open()
  138. },
  139. submit(){
  140. var {formData} = this;
  141. formData.region = app.regionName;
  142. var submitData = JSON.parse(JSON.stringify(formData))
  143. var validation = form.validation(submitData,[
  144. {name:"username",rule:["required"],msg:["请输入姓名"]},
  145. {name:"mobile",rule:["required","isMobile"],msg:["请输入手机号","手机号格式错误"]},
  146. {name:"region",rule:["required"],msg:["请选择地区"]},
  147. {name:"address",rule:["required"],msg:["请输入详细地址"]}
  148. ]);
  149. if(validation) return app.$dialog.showSuccess(validation);
  150. app.disabled = true;
  151. Api.save(submitData).then((res)=>{
  152. app.disabled = false;
  153. if (res.code == 0) {
  154. return app.$dialog.showSuccess(res.msg);
  155. }
  156. app.$refs.popup.close()
  157. app.$dialog.showSuccess(res.msg);
  158. app.queryList(1,10);
  159. })
  160. }
  161. }
  162. }
  163. </script>
  164. <style>
  165. .address-list{height: 100vh;}
  166. .address-list .list-item{background-color: #fff;margin-top: 20upx;display: flex;align-items: center;justify-content: space-between;padding: 20upx;}
  167. .address-list .list-item .title{font-size: 24upx;color: #666;margin-bottom: 20upx;}
  168. .address-list .list-item .name{font-size: 28upx;color: #333;margin-bottom: 20upx;}
  169. .address-list .list-item .mobile{font-size: 28upx;color: #666;margin-bottom: 20upx;}
  170. .address-list .list-item .mobile text{margin-left: 20upx;}
  171. .address-list .list-item .item-right{display: flex;align-items: center;gap: 20upx;}
  172. .address-list .list-item .item-right .icon{width: 60upx;height: 60upx;background-color: #f8f8f8;border-radius: 30upx;text-align: center;justify-content: center;align-items: center;display: flex;}
  173. .address-list .list-item .item-right image{width: 40upx;height: 40upx;}
  174. .empty-data{
  175. display: flex;
  176. height: 80vh;
  177. align-items: center;
  178. justify-content: center;
  179. flex-direction: column;
  180. font-size: 28upx;
  181. color: #666;
  182. }
  183. .empty-data image{
  184. width: 50%;
  185. }
  186. .time-select .title{height: 100upx;line-height: 100upx;display: flex;align-items: center;justify-content: space-between;font-size: 32upx;padding: 0 20upx;font-weight: bold;}
  187. .time-select image{width: 40upx;height: 40upx;vertical-align: middle;}
  188. .time-btn{padding: 20upx;}
  189. .goods-body{padding: 20upx;}
  190. .goods-body .goods-title{font-size: 28upx;color: #333;line-height: 80upx;}
  191. .goods-body .goods-title text{color: #f00;}
  192. .goods-body .form-title{margin-top: 40upx;font-size: 28upx;color: #666;}
  193. .goods-form{margin-bottom: 20upx;}
  194. .goods-form .form-input{border: 2upx solid #ccc;height: 80upx;margin-top: 20upx;padding: 0 15upx;}
  195. .region-name{height: 80upx;line-height: 80upx;font-size: 24upx;}
  196. .goods-form .form-input .input{font-size: 24upx;height: 80upx;}
  197. .flx-footer{position: fixed;bottom: 0;background-color: #fff;padding: 20upx;border-top: 2upx solid #f8f8f8;left: 0;right: 0;}
  198. .flx-footer .footer-safe {height: env(safe-area-inset-bottom);width: 100%;}
  199. .flx-footer .btn,.time-btn .btn{font-size: 28rpx;height: 80upx;border-radius: 10upx;line-height: 80upx;text-align: center;width: 100%;color: #333;background-color: #224d7a;color: #fff;border:2upx solid #224d7a;}
  200. </style>