address.vue 7.5 KB

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