index.vue 16 KB

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