index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  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. this.addrRequest.shop_type = 1;
  192. } else {
  193. if (!item.shop_type) item.shop_type = 1;
  194. this.addrRequest = item;
  195. }
  196. // 显示下单弹出层
  197. this.$refs.addrForm.open("bottom");
  198. },
  199. // 默认开关
  200. defaultSwitch(e) {
  201. this.addrRequest.is_default = e.detail.value ? 1 : 0;
  202. },
  203. // 弹出层
  204. popupChange(e) {
  205. // 禁止滚动穿透
  206. this.show = e.show;
  207. },
  208. // 城市修改
  209. cityChange(e) {
  210. // 替换三个选项
  211. this.cityValue.splice(e.detail.column, 1, e.detail.value);
  212. // 下一级设置为0
  213. if (e.detail.column == 0) {
  214. this.cityValue.splice(1, 1, 0);
  215. this.cityValue.splice(2, 1, 0);
  216. }
  217. if (e.detail.column == 1) {
  218. this.cityValue.splice(2, 1, 0);
  219. }
  220. // 替换对应的数据
  221. this.cityArray.splice(0, 1, getProvinces());
  222. this.cityArray.splice(1, 1, getMyCity(this.cityValue[0]));
  223. this.cityArray.splice(2, 1, getAreas(this.cityValue[0], this.cityValue[1]));
  224. },
  225. // 城市选择
  226. cityFinish(e) {
  227. this.addrRequest.contact_province = this.cityArray[0][this.cityValue[0]];
  228. this.addrRequest.contact_city = this.cityArray[1][this.cityValue[1]];
  229. this.addrRequest.contact_area = this.cityArray[2][this.cityValue[2]];
  230. },
  231. // 城市选中
  232. cityFinish(e) {
  233. this.addrRequest.contact_province = this.cityArray[0][this.cityValue[0]];
  234. this.addrRequest.contact_city = this.cityArray[1][this.cityValue[1]];
  235. this.addrRequest.contact_area = this.cityArray[2][this.cityValue[2]];
  236. },
  237. // 保存地址
  238. saveAddr() {
  239. // 判断姓名
  240. if (!this.addrRequest.contact_name) {
  241. uni.showToast({ icon: "none", title: "请填写收件人" });
  242. return;
  243. }
  244. if (this.addrRequest.contact_name.length < 2) {
  245. uni.showToast({ icon: "none", title: "请填写收件人完整姓名" });
  246. return;
  247. }
  248. if (!this.addrRequest.contact_shop) {
  249. uni.showToast({ icon: "none", title: "请填写店铺名称" });
  250. return;
  251. }
  252. if (!this.addrRequest.contact_phone) {
  253. uni.showToast({ icon: "none", title: "请填写收件人手机号" });
  254. return;
  255. }
  256. if (!this.addrRequest.contact_addr) {
  257. uni.showToast({ icon: "none", title: "请填写联系地址" });
  258. return;
  259. }
  260. if (this.addrRequest.contact_addr.length < 3) {
  261. uni.showToast({ icon: "none", title: "请填写可用联系地址" });
  262. return;
  263. }
  264. // 请求状态
  265. uni.showLoading({ mask: true });
  266. // 请求路径
  267. var url = this.addrRequest.id ? "api/custom_addr/edit" : "api/custom_addr/add";
  268. // 授权成功以后,调用绑定
  269. this.$http.request(url, this.addrRequest, "post").then((re) => {
  270. // 关闭
  271. uni.hideLoading();
  272. // 成功的话
  273. if (re.code != "success") {
  274. // 跳转
  275. uni.showToast({ title: re.msg, icon: "none" });
  276. return;
  277. }
  278. // 地址变动
  279. this.getList();
  280. // 显示下单弹出层
  281. this.$refs.addrForm.close();
  282. });
  283. },
  284. // 删除地址
  285. removeAddr(index) {
  286. // 授权成功以后,调用绑定
  287. this.$http.request("api/custom_addr/del", { id: this.addrList[index].id }, "post").then((re) => {
  288. // 关闭
  289. uni.hideLoading();
  290. // 成功的话
  291. if (re.code != "success") {
  292. // 跳转
  293. uni.showToast({ title: re.msg, icon: "none" });
  294. return;
  295. }
  296. // 成功删除该项
  297. this.addrList.splice(index, 1);
  298. // 通知地址变更
  299. if (this.AddrEmit) uni.$emit("addr_list_change", { list: this.addrList });
  300. });
  301. },
  302. // 设置默认
  303. setDefault(index) {
  304. // 如果已经是默认状态
  305. if (this.addrList[index].is_default) return;
  306. // 授权成功以后,调用绑定
  307. this.$http.request("api/custom_addr/set_default", { id: this.addrList[index].id }, "post").then((re) => {
  308. // 关闭
  309. uni.hideLoading();
  310. // 成功的话
  311. if (re.code != "success") {
  312. // 跳转
  313. uni.showToast({ title: re.msg, icon: "none" });
  314. return;
  315. }
  316. // 更新其他的默认项
  317. for (let i in this.addrList) {
  318. this.addrList[i].is_default = 0;
  319. }
  320. // 成功修改值
  321. this.addrList[index].is_default = 1;
  322. // 通知地址变更
  323. if (this.AddrEmit) uni.$emit("addr_list_change", { list: this.addrList });
  324. });
  325. },
  326. handleRadioChange(key) {
  327. this.addrRequest.shop_type = Number(key);
  328. },
  329. },
  330. };
  331. </script>
  332. <style lang="less">
  333. .addr_list {
  334. width: 730rpx;
  335. display: block;
  336. overflow: hidden;
  337. margin: 0rpx auto;
  338. .addr_item {
  339. display: block;
  340. font-size: 24rpx;
  341. overflow: hidden;
  342. line-height: 40rpx;
  343. padding: 15rpx 10rpx;
  344. border-radius: 15rpx;
  345. padding-bottom: 0rpx;
  346. margin-bottom: 10rpx;
  347. background-color: #ffffff;
  348. .contact_user {
  349. display: block;
  350. font-size: 24rpx;
  351. line-height: 50rpx;
  352. .contact_name {
  353. font-size: 26rpx;
  354. font-weight: bold;
  355. margin-right: 16rpx;
  356. }
  357. .contact_shop {
  358. float: right;
  359. }
  360. }
  361. .contact_addr {
  362. display: block;
  363. font-size: 24rpx;
  364. line-height: 30rpx;
  365. padding: 10rpx 5rpx;
  366. border-bottom: 2rpx solid #dddddd;
  367. }
  368. .contact_handler {
  369. height: 60rpx;
  370. display: block;
  371. line-height: 60rpx;
  372. font-size: 20rpx;
  373. .radio_label {
  374. float: left;
  375. height: 60rpx;
  376. line-height: 60rpx;
  377. .radio_icon {
  378. width: 40rpx;
  379. height: 40rpx;
  380. vertical-align: middle;
  381. }
  382. .radioed_text {
  383. color: #e03519;
  384. }
  385. }
  386. .addr_right_btn {
  387. float: right;
  388. height: 40rpx;
  389. display: block;
  390. line-height: 40rpx;
  391. padding: 10rpx 35rpx;
  392. }
  393. }
  394. }
  395. }
  396. .create_box {
  397. left: 0rpx;
  398. width: 750rpx;
  399. height: 140rpx;
  400. display: block;
  401. position: fixed;
  402. bottom: var(--window-bottom);
  403. .create_addr {
  404. width: 700rpx;
  405. height: 80rpx;
  406. display: block;
  407. color: #ffffff;
  408. font-size: 30rpx;
  409. overflow: hidden;
  410. line-height: 80rpx;
  411. padding: 0rpx 0rpx;
  412. text-align: center;
  413. margin: 0rpx auto;
  414. margin-top: 20rpx;
  415. border-radius: 40rpx;
  416. background-color: #e03519;
  417. }
  418. }
  419. .popup {
  420. .info_form {
  421. display: block;
  422. overflow: hidden;
  423. padding: 20rpx 0rpx;
  424. padding-top: 80rpx;
  425. background: #ffffff;
  426. .form_group {
  427. display: block;
  428. overflow: hidden;
  429. line-height: 60rpx;
  430. padding: 20rpx 35rpx;
  431. .group_title {
  432. float: left;
  433. width: 160rpx;
  434. display: block;
  435. overflow: hidden;
  436. font-size: 30rpx;
  437. margin-right: 20rpx;
  438. }
  439. .group_box {
  440. float: left;
  441. width: 480rpx;
  442. display: block;
  443. .radio_icon {
  444. width: 50rpx;
  445. height: 50rpx;
  446. vertical-align: middle;
  447. }
  448. .form_ctrl {
  449. height: 56rpx;
  450. font-size: 24rpx;
  451. padding: 0rpx 20rpx;
  452. line-height: 56rpx;
  453. border: 2rpx solid #dddddd;
  454. }
  455. .area_text {
  456. width: 446rpx;
  457. font-size: 20rpx;
  458. overflow: hidden;
  459. white-space: nowrap;
  460. text-overflow: ellipsis;
  461. }
  462. .group_image {
  463. width: 200rpx;
  464. height: 200rpx;
  465. }
  466. .choose_image {
  467. display: block;
  468. width: 200rpx;
  469. height: 200rpx;
  470. font-size: 38rpx;
  471. text-align: center;
  472. line-height: 200rpx;
  473. border: 2rpx solid #dddddd;
  474. }
  475. .terminalType_radio {
  476. display: flex;
  477. justify-content: space-around;
  478. }
  479. }
  480. }
  481. .submit_btn {
  482. width: 700rpx;
  483. height: 80rpx;
  484. display: block;
  485. color: #ffffff;
  486. font-size: 30rpx;
  487. overflow: hidden;
  488. line-height: 80rpx;
  489. padding: 0rpx 0rpx;
  490. text-align: center;
  491. margin: 20rpx auto;
  492. margin-top: 40rpx;
  493. border-radius: 40rpx;
  494. background-color: #e03519;
  495. }
  496. }
  497. }
  498. </style>