index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. <template>
  2. <view>
  3. <view class="to_bottom" v-if="!addrList.length"> -----还没有地址啦-----</view>
  4. <view class="addr_list">
  5. <view class="addr_item" v-for="(item,index) in addrList" :key="index" >
  6. <view class="contact_user">
  7. <text class="contact_name">{{item.contact_name}}</text>
  8. <text class="contact_phone">{{item.contact_phone}}</text>
  9. <text class="contact_shop">{{item.contact_shop}}</text>
  10. </view>
  11. <view class="contact_addr">
  12. {{item.contact_province}} {{item.contact_city}} {{item.contact_area}} {{item.contact_addr}}
  13. </view>
  14. <view class="contact_handler">
  15. <view class="radio_label" @click="setDefault(index)">
  16. <image class="radio_icon" :src="item.is_default?'../../static/icon/radioed.png' :'../../static/icon/radio.png' " ></image>
  17. <text :class="item.is_default?'radioed_text':''">{{item.is_default?'已默认':'设为默认'}}</text>
  18. </view>
  19. <view class="addr_right_btn" @click="removeAddr(index)">
  20. 删除
  21. </view>
  22. <view class="addr_right_btn" @click="openForm(item)">
  23. 编辑
  24. </view>
  25. </view>
  26. </view>
  27. </view>
  28. <view class="create_box">
  29. <button class="create_addr" @click="openForm()">新建收货地址</button>
  30. </view>
  31. <view class="to_bottom" v-if="isLast"> -----到底啦-----</view>
  32. <uni-popup ref="addrForm" type="bottom" class="popup" background-color="#FFFFFF" @change="popupChange">
  33. <view class="contact_addr_form">
  34. <!-- 地区代表表单 -->
  35. <form class="info_form">
  36. <view class="form_group">
  37. <view class="group_title">收货人:</view>
  38. <view class="group_box">
  39. <input type="text" class="form_ctrl" placeholder="请输入收件人" maxlength="20" required="" v-model="addrRequest.contact_name" />
  40. </view>
  41. </view>
  42. <view class="form_group">
  43. <view class="group_title">手机号:</view>
  44. <view class="group_box">
  45. <input type="text" class="form_ctrl" placeholder="请输入手机号" maxlength="11" required="" v-model="addrRequest.contact_phone" />
  46. </view>
  47. </view>
  48. <view class="form_group">
  49. <view class="group_title">店铺名称:</view>
  50. <view class="group_box">
  51. <input type="text" class="form_ctrl" placeholder="请输入店铺名称" maxlength="20" required="" v-model="addrRequest.contact_shop" />
  52. </view>
  53. </view>
  54. <view class="form_group">
  55. <view class="group_title">所在地区:</view>
  56. <view class="group_box">
  57. <picker mode="multiSelector" class="form_ctrl" :range="cityArray" @columnchange="cityChange" @change="cityFinish" >
  58. <view class="area_text">
  59. <text v-if="addrRequest.contact_province">{{addrRequest.contact_province}}</text>
  60. <text v-if="addrRequest.contact_city">/{{addrRequest.contact_city}}</text>
  61. <text v-if="addrRequest.contact_area">/{{addrRequest.contact_area}}</text>
  62. </view>
  63. </picker>
  64. </view>
  65. </view>
  66. <view class="form_group">
  67. <view class="group_title">详细地址:</view>
  68. <view class="group_box">
  69. <input type="text" class="form_ctrl" placeholder="请输入详细地址:街道/小区/门牌号" maxlength="64" required="" v-model="addrRequest.contact_addr" />
  70. </view>
  71. </view>
  72. <view class="form_group">
  73. <view class="group_title">设为默认</view>
  74. <view class="group_box">
  75. <switch color="#E03519" style="transform:scale(0.6);float: right;" @change="defaultSwitch" :checked="addrRequest.is_default?true:false" />
  76. </view>
  77. </view>
  78. <button class="submit_btn" @click="saveAddr">保存地址</button>
  79. </form>
  80. </view>
  81. </uni-popup>
  82. </view>
  83. </template>
  84. <script>
  85. import {getProvinces,getMyCity,getAreas} from "../../utils/city";
  86. export default {
  87. data() {
  88. return {
  89. // 产品列表
  90. addrList:[],
  91. // 请求参数
  92. requestParam:{
  93. page:1,
  94. status:0,
  95. },
  96. // 保存地址
  97. addrRequest:{
  98. id:0,
  99. contact_name:"",
  100. contact_phone:"",
  101. contact_province:"",
  102. contact_city:"",
  103. contact_area:"",
  104. contact_addr:"",
  105. contact_shop:"",
  106. is_default:0,
  107. },
  108. // 是否最后一页
  109. isLast:false,
  110. // 是否请求中
  111. isReqing:false,
  112. // 所在地区
  113. cityArray: [[],[],[]],
  114. cityValue: [0,0,0],
  115. // 自动弹出
  116. autoShowForm: false,
  117. // 异步通知
  118. AddrEmit: false,
  119. };
  120. },
  121. onLoad(param) {
  122. this.AddrEmit = param.notify == 'addr' ? true : false;
  123. this.autoShowForm = param.type == 'create' ? true : false;
  124. // 获取列表
  125. this.getList();
  126. },
  127. onReady() {
  128. if( this.autoShowForm ){
  129. var that = this;
  130. // 500毫秒后自动弹出
  131. setTimeout(function(){
  132. that.openForm();
  133. },500)
  134. }
  135. },
  136. onShow() {
  137. // 替换对应的数据
  138. this.cityArray.splice(0,1,getProvinces());
  139. this.cityArray.splice(1,1,getMyCity(this.cityValue[0]));
  140. this.cityArray.splice(2,1,getAreas(this.cityValue[0],this.cityValue[1]));
  141. // 默认地址
  142. this.addrRequest.contact_province = this.cityArray[0][this.cityValue[0]]
  143. this.addrRequest.contact_city = this.cityArray[1][this.cityValue[1]];
  144. this.addrRequest.contact_area = this.cityArray[2][this.cityValue[2]];
  145. },
  146. methods:{
  147. // 获取列表
  148. getList(){
  149. // 登录提示
  150. if( !this.$checkAccess.alterLogin() ) return ;
  151. // 判断数据
  152. this.$http.request('api/custom_addr/get_list').then((callback)=>{
  153. // 获取成功
  154. if( callback.code == 'success' ){
  155. this.addrList = callback.data;
  156. // 通知地址变更
  157. if( this.AddrEmit ) uni.$emit('addr_list_change',{list:this.addrList});
  158. }
  159. });
  160. },
  161. // 打开弹窗
  162. openForm(item){
  163. if( !item ) {
  164. this.addrRequest.id = 0;
  165. this.addrRequest.contact_name = '';
  166. this.addrRequest.contact_phone = '';
  167. this.addrRequest.contact_shop = '';
  168. this.addrRequest.contact_addr = '';
  169. this.addrRequest.is_default = 0;
  170. }else{
  171. this.addrRequest = item;
  172. }
  173. // 显示下单弹出层
  174. this.$refs.addrForm.open('bottom');
  175. },
  176. // 默认开关
  177. defaultSwitch(e){
  178. this.addrRequest.is_default = e.detail.value ? 1 : 0;
  179. },
  180. // 弹出层
  181. popupChange(e){
  182. // 禁止滚动穿透
  183. this.show = e.show
  184. },
  185. // 城市修改
  186. cityChange(e){
  187. // 替换三个选项
  188. this.cityValue.splice(e.detail.column,1,e.detail.value);
  189. // 下一级设置为0
  190. if( e.detail.column == 0 ){
  191. this.cityValue.splice(1,1,0);
  192. this.cityValue.splice(2,1,0);
  193. }
  194. if( e.detail.column == 1 ){
  195. this.cityValue.splice(2,1,0);
  196. }
  197. // 替换对应的数据
  198. this.cityArray.splice(0,1,getProvinces());
  199. this.cityArray.splice(1,1,getMyCity(this.cityValue[0]));
  200. this.cityArray.splice(2,1,getAreas(this.cityValue[0],this.cityValue[1]));
  201. },
  202. // 城市选择
  203. cityFinish(e){
  204. this.addrRequest.contact_province = this.cityArray[0][this.cityValue[0]];
  205. this.addrRequest.contact_city = this.cityArray[1][this.cityValue[1]];
  206. this.addrRequest.contact_area = this.cityArray[2][this.cityValue[2]];
  207. },
  208. // 城市选中
  209. cityFinish(e){
  210. this.addrRequest.contact_province = this.cityArray[0][this.cityValue[0]];
  211. this.addrRequest.contact_city = this.cityArray[1][this.cityValue[1]];
  212. this.addrRequest.contact_area = this.cityArray[2][this.cityValue[2]];
  213. },
  214. // 保存地址
  215. saveAddr(){
  216. // 判断姓名
  217. if( !this.addrRequest.contact_name ){
  218. uni.showToast({icon:"none",title:"请填写收件人"});
  219. return;
  220. }
  221. if( this.addrRequest.contact_name.length < 2 ){
  222. uni.showToast({icon:"none",title:"请填写收件人完整姓名"});
  223. return;
  224. }
  225. if( !this.addrRequest.contact_shop ){
  226. uni.showToast({icon:"none",title:"请填写店铺名称"});
  227. return;
  228. }
  229. if( !this.addrRequest.contact_phone ){
  230. uni.showToast({icon:"none",title:"请填写收件人手机号"});
  231. return;
  232. }
  233. if( !this.addrRequest.contact_addr ){
  234. uni.showToast({icon:"none",title:"请填写联系地址"});
  235. return;
  236. }
  237. if( this.addrRequest.contact_addr.length < 3 ){
  238. uni.showToast({icon:"none",title:"请填写可用联系地址"});
  239. return;
  240. }
  241. // 请求状态
  242. uni.showLoading({mask:true});
  243. // 请求路径
  244. var url = this.addrRequest.id ? 'api/custom_addr/edit' : 'api/custom_addr/add';
  245. // 授权成功以后,调用绑定
  246. this.$http.request(url,this.addrRequest,'post').then((re)=>{
  247. // 关闭
  248. uni.hideLoading();
  249. // 成功的话
  250. if( re.code != 'success' ){
  251. // 跳转
  252. uni.showToast({title: re.msg,icon:"none"});
  253. return;
  254. }
  255. // 地址变动
  256. this.getList();
  257. // 显示下单弹出层
  258. this.$refs.addrForm.close();
  259. });
  260. },
  261. // 删除地址
  262. removeAddr(index){
  263. // 授权成功以后,调用绑定
  264. this.$http.request('api/custom_addr/del',{id:this.addrList[index].id},'post').then((re)=>{
  265. // 关闭
  266. uni.hideLoading();
  267. // 成功的话
  268. if( re.code != 'success' ){
  269. // 跳转
  270. uni.showToast({title: re.msg,icon:"none"});
  271. return;
  272. }
  273. // 成功删除该项
  274. this.addrList.splice(index,1);
  275. // 通知地址变更
  276. if( this.AddrEmit ) uni.$emit('addr_list_change',{list:this.addrList});
  277. });
  278. },
  279. // 设置默认
  280. setDefault(index){
  281. // 如果已经是默认状态
  282. if( this.addrList[index].is_default ) return;
  283. // 授权成功以后,调用绑定
  284. this.$http.request('api/custom_addr/set_default',{id:this.addrList[index].id},'post').then((re)=>{
  285. // 关闭
  286. uni.hideLoading();
  287. // 成功的话
  288. if( re.code != 'success' ){
  289. // 跳转
  290. uni.showToast({title: re.msg,icon:"none"});
  291. return;
  292. }
  293. // 更新其他的默认项
  294. for (let i in this.addrList) {
  295. this.addrList[i].is_default = 0;
  296. }
  297. // 成功修改值
  298. this.addrList[index].is_default = 1;
  299. // 通知地址变更
  300. if( this.AddrEmit ) uni.$emit('addr_list_change',{list:this.addrList});
  301. });
  302. },
  303. }
  304. }
  305. </script>
  306. <style lang="less">
  307. .addr_list{
  308. width: 730rpx;
  309. display: block;
  310. overflow: hidden;
  311. margin: 0rpx auto;
  312. .addr_item{
  313. display: block;
  314. font-size: 24rpx;
  315. overflow: hidden;
  316. line-height: 40rpx;
  317. padding: 15rpx 10rpx;
  318. border-radius: 15rpx;
  319. padding-bottom: 0rpx;
  320. margin-bottom: 10rpx;
  321. background-color: #FFFFFF;
  322. .contact_user{
  323. display: block;
  324. font-size: 24rpx;
  325. line-height: 50rpx;
  326. .contact_name{
  327. font-size: 26rpx;
  328. font-weight: bold;
  329. margin-right: 16rpx;
  330. }
  331. .contact_shop{
  332. float: right;
  333. }
  334. }
  335. .contact_addr{
  336. display: block;
  337. font-size: 24rpx;
  338. line-height: 30rpx;
  339. padding: 10rpx 5rpx;
  340. border-bottom: 2rpx solid #dddddd;
  341. }
  342. .contact_handler{
  343. height: 60rpx;
  344. display: block;
  345. line-height: 60rpx;
  346. font-size: 20rpx;
  347. .radio_label{
  348. float: left;
  349. height: 60rpx;
  350. line-height: 60rpx;
  351. .radio_icon{
  352. width: 40rpx;
  353. height: 40rpx;
  354. vertical-align: middle;
  355. }
  356. .radioed_text{
  357. color: #E03519;
  358. }
  359. }
  360. .addr_right_btn{
  361. float: right;
  362. height: 40rpx;
  363. display: block;
  364. line-height: 40rpx;
  365. padding: 10rpx 35rpx;
  366. }
  367. }
  368. }
  369. }
  370. .create_box{
  371. left: 0rpx;
  372. width: 750rpx;
  373. height: 140rpx;
  374. display: block;
  375. position: fixed;
  376. bottom: var(--window-bottom);
  377. .create_addr{
  378. width: 700rpx;
  379. height: 80rpx;
  380. display: block;
  381. color: #FFFFFF;
  382. font-size: 30rpx;
  383. overflow: hidden;
  384. line-height: 80rpx;
  385. padding: 0rpx 0rpx;
  386. text-align: center;
  387. margin: 0rpx auto;
  388. margin-top: 20rpx;
  389. border-radius: 40rpx;
  390. background-color: #E03519;
  391. }
  392. }
  393. .popup{
  394. .info_form{
  395. display: block;
  396. overflow: hidden;
  397. padding: 20rpx 0rpx;
  398. padding-top: 80rpx;
  399. background: #FFFFFF;
  400. .form_group{
  401. display: block;
  402. overflow: hidden;
  403. line-height: 60rpx;
  404. padding: 20rpx 35rpx;
  405. .group_title{
  406. float: left;
  407. width: 160rpx;
  408. display: block;
  409. overflow: hidden;
  410. font-size: 30rpx;
  411. margin-right: 20rpx;
  412. }
  413. .group_box{
  414. float: left;
  415. width: 480rpx;
  416. display: block;
  417. .form_ctrl{
  418. height: 56rpx;
  419. font-size: 24rpx;
  420. padding: 0rpx 20rpx;
  421. line-height: 56rpx;;
  422. border: 2rpx solid #DDDDDD;
  423. }
  424. .area_text{
  425. width: 446rpx;
  426. font-size: 20rpx;
  427. overflow: hidden;
  428. white-space: nowrap;
  429. text-overflow: ellipsis;
  430. }
  431. .group_image{
  432. width: 200rpx;
  433. height: 200rpx;
  434. }
  435. .choose_image{
  436. display: block;
  437. width: 200rpx;
  438. height: 200rpx;
  439. font-size: 38rpx;
  440. text-align: center;
  441. line-height: 200rpx;
  442. border: 2rpx solid #DDDDDD;
  443. }
  444. }
  445. }
  446. .submit_btn{
  447. width: 700rpx;
  448. height: 80rpx;
  449. display: block;
  450. color: #FFFFFF;
  451. font-size: 30rpx;
  452. overflow: hidden;
  453. line-height: 80rpx;
  454. padding: 0rpx 0rpx;
  455. text-align: center;
  456. margin: 20rpx auto;
  457. margin-top: 40rpx;
  458. border-radius: 40rpx;
  459. background-color: #E03519;
  460. }
  461. }
  462. }
  463. </style>