index.vue 13 KB

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