爱简收旧衣按件回收前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

603 lines
18 KiB

1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
5 days ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
  1. <template>
  2. <view class="container" :style="{paddingTop: (statusBarHeight + 88) + 'rpx'}">
  3. <!-- 顶部导航 -->
  4. <view class="nav-bar" :style="{height: (statusBarHeight + 88) + 'rpx', paddingTop: statusBarHeight + 'px'}">
  5. <view class="back" @tap="goBack">
  6. <uni-icons type="left" size="20"></uni-icons>
  7. </view>
  8. <text class="title">选择寄件地址</text>
  9. </view>
  10. <!-- 地址列表 -->
  11. <view class="address-list">
  12. <view
  13. class="address-item"
  14. @click="selectAddress(item)"
  15. v-for="(item, index) in addressList"
  16. :key="index"
  17. >
  18. <view class="address-header">
  19. <text class="name">{{item.name}}</text>
  20. <text class="phone">{{item.phone}}</text>
  21. <text v-if="item.defaultFlag === 'Y'" class="default-tag">默认</text>
  22. </view>
  23. <view class="address-text">{{item.address}} {{item.addressDetails}}</view>
  24. <view class="dashed-line"></view>
  25. <view class="address-actions">
  26. <view class="action" @tap="setDefault(item.id)">
  27. <view class="circle" :class="{ active: item.defaultFlag === 'Y' }">
  28. <text v-if="item.defaultFlag === 'Y'" class="check"></text>
  29. </view>
  30. <text :class="{ 'active-text': item.defaultFlag === 'Y' }">默认地址</text>
  31. </view>
  32. <view class="action" @tap="editAddress(item)">
  33. <uni-icons type="compose" size="22" color="#bbb" />
  34. <text>编辑</text>
  35. </view>
  36. <view class="action" @tap="deleteAddress(item.id)">
  37. <uni-icons type="trash" size="22" color="#bbb" />
  38. <text>删除</text>
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. <!-- 新建地址按钮 -->
  44. <view class="bottom-bar">
  45. <button class="main-btn" @tap="goToAddAddress">新建地址</button>
  46. </view>
  47. <!-- 遮罩 -->
  48. <view v-if="showAddressModal" class="modal-mask" @tap="closeAddressModal"></view>
  49. <!-- 新建地址弹窗 -->
  50. <view v-if="showAddressModal" class="address-modal">
  51. <view class="modal-header">
  52. <text class="close-btn" @tap="closeAddressModal">关闭</text>
  53. <text class="modal-title">{{form.id ? '编辑地址' : '新建地址'}}</text>
  54. </view>
  55. <view class="modal-form">
  56. <view class="form-item">
  57. <text class="label">联系人</text>
  58. <input class="input" v-model="form.name" placeholder="请输入" />
  59. </view>
  60. <view class="form-item">
  61. <text class="label">手机号</text>
  62. <input class="input" v-model="form.phone" placeholder="请输入" />
  63. </view>
  64. <view class="form-item" @tap="showRegionPicker = true">
  65. <text class="label">所在地区</text>
  66. <view class="input region-input">
  67. <text :class="{placeholder: !form.address}">
  68. {{ form.address || '选择省市区街道' }}
  69. </text>
  70. <text class="arrow">></text>
  71. </view>
  72. </view>
  73. <view class="form-item">
  74. <text class="label">详细地址</text>
  75. <input class="input" v-model="form.addressDetails" placeholder="小区楼栋、门牌号、村等" />
  76. </view>
  77. </view>
  78. <button class="main-btn" @tap="saveAddress">保存</button>
  79. </view>
  80. <!-- 地区选择器弹窗 -->
  81. <view v-if="showRegionPicker" class="region-modal">
  82. <view class="modal-header">
  83. <text class="close-btn" @tap="showRegionPicker = false">关闭</text>
  84. <text class="modal-title">所在地区</text>
  85. </view>
  86. <view class="region-picker">
  87. <picker-view style="height:300px;" :value="regionIndex" @change="onRegionChange">
  88. <picker-view-column >
  89. <view v-for="(item,index) in provinces" :key="index" class="item">{{item.name}}</view>
  90. </picker-view-column>
  91. <picker-view-column>
  92. <view v-for="(item,index) in cities" :key="index" class="item">{{item.name}}</view>
  93. </picker-view-column>
  94. <picker-view-column>
  95. <view v-for="(item,index) in districts" :key="index" class="item">{{item.name}}</view>
  96. </picker-view-column>
  97. </picker-view>
  98. </view>
  99. <button class="main-btn" @tap="confirmRegion">确认</button>
  100. </view>
  101. </view>
  102. </template>
  103. <script>
  104. import regionData from '@/pages/subcomponent/region-data.js'
  105. import pullRefreshMixin from '@/pages/mixins/pullRefreshMixin.js'
  106. export default {
  107. mixins: [pullRefreshMixin],
  108. data() {
  109. return {
  110. statusBarHeight: 0,
  111. addressList: [
  112. {
  113. name: '郑文锦',
  114. phone: '18108341643',
  115. address: '海南省海口市秀英区秀英街道5单元183室',
  116. defaultFlag: 'Y'
  117. },
  118. {
  119. name: '周俊',
  120. phone: '13293992217',
  121. address: '贵州省遵义市道真仡佬族苗族自治县洛龙镇5幢172室',
  122. defaultFlag: 'N'
  123. },
  124. {
  125. name: '何炜',
  126. phone: '18108341643',
  127. address: '新疆维吾尔自治区乌鲁木齐市沙依巴克区仓房沟片区街道4单元50室',
  128. defaultFlag: 'N'
  129. },
  130. {
  131. name: '赵晓艳',
  132. phone: '15022123314',
  133. address: '海南省海口市秀英区秀英街道5单元183室',
  134. defaultFlag: 'N'
  135. },
  136. {
  137. name: '冯云',
  138. phone: '15731435825',
  139. address: '甘肃省兰州市城关区滑源路街道13幢199室',
  140. defaultFlag: 'N'
  141. },
  142. {
  143. name: '钱皓皓',
  144. phone: '18734717201',
  145. address: '西藏自治区拉萨市堆龙德庆县东嘎镇7单元94室',
  146. defaultFlag: 'N'
  147. }
  148. ],
  149. batchMode: false,
  150. selectedIndexes: [],
  151. showAddressModal: false,
  152. showRegionPicker: false,
  153. form: {
  154. name: '',
  155. phone: '',
  156. region: [],
  157. address: '',
  158. addressDetails: ''
  159. },
  160. provinces: regionData,
  161. cities: [],
  162. districts: [],
  163. regionIndex: [0, 0, 0],
  164. mode: ''
  165. }
  166. },
  167. watch: {
  168. regionIndex: {
  169. handler(val) {
  170. let pIdx = val[0] < this.provinces.length ? val[0] : 0
  171. let cIdx = val[1] < (this.provinces[pIdx]?.children?.length || 0) ? val[1] : 0
  172. this.cities = this.provinces[pIdx]?.children || []
  173. this.districts = this.cities[cIdx]?.children || []
  174. },
  175. immediate: true
  176. }
  177. },
  178. onPullDownRefresh() {
  179. this.getAddressList(() => {
  180. uni.stopPullDownRefresh();
  181. });
  182. },
  183. onLoad(options) {
  184. this.statusBarHeight = uni.getSystemInfoSync().statusBarHeight
  185. this.cities = this.provinces[0]?.children || []
  186. this.districts = this.cities[0]?.children || []
  187. this.regionIndex = [0, 0, 0]
  188. this.getAddressList();
  189. this.mode = options.mode || ''
  190. },
  191. methods: {
  192. async onRefresh() {
  193. // 模拟刷新数据
  194. await new Promise(resolve => setTimeout(resolve, 1000))
  195. uni.stopPullRefresh()
  196. },
  197. getAddressList(callback) {
  198. this.$api('getAddressList', {}, res => {
  199. if (res && res.result && res.result.records) {
  200. this.addressList = res.result.records;
  201. }
  202. if (typeof callback === 'function') callback();
  203. });
  204. },
  205. goBack() {
  206. uni.navigateBack()
  207. },
  208. startBatchDelete() {
  209. this.batchMode = true
  210. this.selectedIndexes = []
  211. },
  212. cancelBatchDelete() {
  213. this.batchMode = false
  214. this.selectedIndexes = []
  215. },
  216. selectItem(index) {
  217. if (!this.batchMode) return
  218. const idx = this.selectedIndexes.indexOf(index)
  219. if (idx > -1) {
  220. this.selectedIndexes.splice(idx, 1)
  221. } else {
  222. this.selectedIndexes.push(index)
  223. }
  224. },
  225. confirmDelete() {
  226. if (this.selectedIndexes.length === 0) return
  227. uni.showModal({
  228. title: '提示',
  229. content: '确定要删除选中的地址吗?',
  230. success: (res) => {
  231. if (res.confirm) {
  232. // 从后往前删除,避免索引变化的问题
  233. this.selectedIndexes.sort((a, b) => b - a).forEach(index => {
  234. this.addressList.splice(index, 1)
  235. })
  236. this.batchMode = false
  237. this.selectedIndexes = []
  238. }
  239. }
  240. })
  241. },
  242. editAddress(item) {
  243. this.showAddressModal = true
  244. this.form = {
  245. id: item.id,
  246. name: item.name,
  247. phone: item.phone,
  248. region: [],
  249. address: item.address,
  250. addressDetails: item.addressDetails,
  251. defaultFlag: item.defaultFlag
  252. }
  253. this.regionIndex = [0, 0, 0]
  254. this.cities = this.provinces[0]?.children || []
  255. this.districts = this.cities[0]?.children || []
  256. },
  257. goToAddAddress() {
  258. this.showAddressModal = true
  259. this.form = {
  260. id: undefined,
  261. name: '',
  262. phone: '',
  263. region: [],
  264. address: '',
  265. addressDetails: ''
  266. }
  267. this.regionIndex = [0, 0, 0]
  268. this.cities = this.provinces[0]?.children || []
  269. this.districts = this.cities[0]?.children || []
  270. },
  271. selectAddress(address) {
  272. if (this.mode === 'select') {
  273. uni.$emit('addressSelected', {
  274. name: address.name,
  275. phone: address.phone,
  276. address: address.address,
  277. addressDetails: address.addressDetails
  278. })
  279. uni.navigateBack()
  280. }
  281. },
  282. closeAddressModal() {
  283. this.showAddressModal = false
  284. },
  285. saveAddress() {
  286. if (!this.form.name) return uni.showToast({ title: '请输入联系人', icon: 'none' })
  287. if (!this.form.phone) return uni.showToast({ title: '请输入手机号', icon: 'none' })
  288. if (!this.form.address) return uni.showToast({ title: '请选择地区', icon: 'none' })
  289. if (!this.form.addressDetails) return uni.showToast({ title: '请输入详细地址', icon: 'none' })
  290. const params = {
  291. name: this.form.name,
  292. phone: this.form.phone,
  293. address: this.form.address,
  294. addressDetails: this.form.addressDetails,
  295. defaultFlag: this.form.defaultFlag
  296. }
  297. if (this.form.id) params.id = this.form.id
  298. this.$api('saveOrUpdateAddress', params, (res) => {
  299. if(res.code == 200){
  300. uni.showToast({ title: '保存成功', icon: 'success' })
  301. this.closeAddressModal()
  302. // 保存成功后刷新地址列表
  303. this.getAddressList()
  304. }
  305. })
  306. },
  307. onRegionChange(e) {
  308. let [pIdx, cIdx, dIdx] = e.detail.value
  309. if (pIdx !== this.regionIndex[0]) {
  310. cIdx = 0
  311. dIdx = 0
  312. } else if (cIdx !== this.regionIndex[1]) {
  313. dIdx = 0
  314. }
  315. this.regionIndex = [pIdx, cIdx, dIdx]
  316. },
  317. confirmRegion() {
  318. const province = this.provinces[this.regionIndex[0]]
  319. const city = this.cities[this.regionIndex[1]]
  320. const district = this.districts[this.regionIndex[2]]
  321. this.form.region = [
  322. province?.code || '',
  323. city?.code || '',
  324. district?.code || ''
  325. ]
  326. this.form.address = [
  327. province?.name || '',
  328. city?.name || '',
  329. district?.name || ''
  330. ].filter(Boolean).join(' ')
  331. this.showRegionPicker = false
  332. },
  333. setDefault(id) {
  334. // 找到当前地址项
  335. const address = this.addressList.find(item => item.id === id)
  336. // 如果已经是默认地址,则取消默认
  337. const defaultFlag = address.defaultFlag === 'Y' ? 'N' : 'Y'
  338. this.$api('saveOrUpdateAddress', {
  339. id: id,
  340. defaultFlag: defaultFlag
  341. }, (res) => {
  342. if(res.code == 200) {
  343. uni.showToast({
  344. title: defaultFlag === 'Y' ? '设置成功' : '已取消默认',
  345. icon: 'success'
  346. })
  347. // 设置成功后刷新地址列表
  348. this.getAddressList()
  349. }
  350. })
  351. },
  352. deleteAddress(id) {
  353. uni.showModal({
  354. title: '提示',
  355. content: '确定要删除该地址吗?',
  356. success: (res) => {
  357. if (res.confirm) {
  358. this.$api('deleteAddress', {id:id}, res => {
  359. if(res.code == 200) {
  360. uni.showToast({
  361. title: '删除成功',
  362. icon: 'success'
  363. })
  364. // 删除成功后刷新地址列表
  365. this.getAddressList()
  366. }
  367. })
  368. }
  369. }
  370. })
  371. },
  372. initRegionPicker() {
  373. if (this.form.region.length > 0) {
  374. const [provinceCode, cityCode, districtCode] = this.form.region
  375. const provinceIndex = this.provinces.findIndex(p => p.code === provinceCode)
  376. if (provinceIndex > -1) {
  377. this.cities = this.provinces[provinceIndex].children || []
  378. if (this.cities.length === 0) {
  379. this.cities = [{ code: '', name: '请选择' }]
  380. }
  381. const cityIndex = this.cities.findIndex(c => c.code === cityCode)
  382. if (cityIndex > -1) {
  383. this.districts = this.cities[cityIndex].children || []
  384. if (this.districts.length === 0) {
  385. this.districts = [{ code: '', name: '请选择' }]
  386. }
  387. const districtIndex = this.districts.findIndex(d => d.code === districtCode)
  388. this.regionIndex = [
  389. provinceIndex,
  390. cityIndex,
  391. districtIndex > -1 ? districtIndex : 0
  392. ]
  393. return
  394. }
  395. }
  396. }
  397. this.cities = this.provinces[0]?.children || []
  398. if (this.cities.length === 0) {
  399. this.cities = [{ code: '', name: '请选择' }]
  400. }
  401. this.districts = this.cities[0]?.children || []
  402. if (this.districts.length === 0) {
  403. this.districts = [{ code: '', name: '请选择' }]
  404. }
  405. this.regionIndex = [0, 0, 0]
  406. }
  407. },
  408. }
  409. </script>
  410. <style lang="scss" scoped>
  411. .container {
  412. min-height: 100vh;
  413. background: #f8f8f8;
  414. padding-bottom: calc(140rpx + env(safe-area-inset-bottom));
  415. }
  416. .nav-bar {
  417. display: flex;
  418. align-items: center;
  419. background: #fff;
  420. padding: 0 30rpx;
  421. position: fixed;
  422. top: 0;
  423. left: 0;
  424. right: 0;
  425. z-index: 999;
  426. .back {
  427. padding: 20rpx;
  428. margin-left: -20rpx;
  429. }
  430. .title {
  431. flex: 1;
  432. text-align: center;
  433. font-size: 34rpx;
  434. font-weight: 500;
  435. color: #222;
  436. }
  437. .right-btns {
  438. display: flex;
  439. align-items: center;
  440. gap: 30rpx;
  441. .more, .target {
  442. font-size: 40rpx;
  443. color: #333;
  444. }
  445. }
  446. }
  447. .address-list {
  448. padding: 32rpx;
  449. margin-top: calc(88rpx + var(--status-bar-height));
  450. height: calc(100vh - 88rpx - var(--status-bar-height) - 140rpx - env(safe-area-inset-bottom));
  451. box-sizing: border-box;
  452. overflow-y: auto;
  453. -webkit-overflow-scrolling: touch;
  454. .address-item {
  455. background: #fff;
  456. border-radius: 24rpx;
  457. margin-bottom: 24rpx;
  458. padding: 32rpx 28rpx 0 28rpx;
  459. box-shadow: 0 4rpx 24rpx rgba(0,0,0,0.04);
  460. .address-header {
  461. display: flex;
  462. align-items: center;
  463. .name { font-size: 32rpx; color: #222; font-weight: 500; margin-right: 20rpx; }
  464. .phone { font-size: 32rpx; color: #222; }
  465. .default-tag {
  466. margin-left: 18rpx;
  467. font-size: 24rpx;
  468. color: #FF9500;
  469. border: 1rpx solid #FF9500;
  470. border-radius: 8rpx;
  471. padding: 2rpx 12rpx;
  472. background: #FFF7E6;
  473. vertical-align: middle;
  474. }
  475. }
  476. .address-text {
  477. font-size: 28rpx;
  478. color: #888;
  479. margin: 16rpx 0 0 0;
  480. line-height: 1.5;
  481. }
  482. .dashed-line {
  483. border-bottom: 1rpx dashed #eee;
  484. margin: 24rpx 0 0 0;
  485. }
  486. .address-actions {
  487. display: flex;
  488. align-items: center;
  489. justify-content: space-around;
  490. padding: 0 0 18rpx 0;
  491. .action {
  492. display: flex;
  493. align-items: center;
  494. margin-right: 48rpx;
  495. .circle {
  496. width: 36rpx; height: 36rpx; border-radius: 50%;
  497. border: 2rpx solid #FF9500; margin-right: 8rpx;
  498. display: flex; align-items: center; justify-content: center;
  499. &.active {
  500. background: #FF9500; border: none;
  501. .check { color: #fff; font-size: 24rpx; }
  502. }
  503. }
  504. text { font-size: 26rpx; color: #bbb; }
  505. .active-text { color: #FF9500; }
  506. }
  507. }
  508. }
  509. }
  510. .bottom-bar {
  511. position: fixed;
  512. left: 0; right: 0; bottom: 0;
  513. background: #fff;
  514. padding: 24rpx 32rpx env(safe-area-inset-bottom);
  515. z-index: 10;
  516. }
  517. .main-btn {
  518. width: 100%;
  519. height: 90rpx;
  520. background: linear-gradient(90deg, #FFB74D 0%, #FF9500 100%);
  521. color: #fff;
  522. font-size: 32rpx;
  523. border-radius: 45rpx;
  524. font-weight: bold;
  525. margin: 0 auto;
  526. display: flex; align-items: center; justify-content: center;
  527. box-shadow: 0 4rpx 16rpx rgba(255, 149, 0, 0.08);
  528. }
  529. .modal-mask {
  530. position: fixed; left: 0; right: 0; top: 0; bottom: 0;
  531. background: rgba(0,0,0,0.5); z-index: 1000;
  532. }
  533. .address-modal, .region-modal {
  534. position: fixed; left: 0; right: 0; bottom: 0; z-index: 1001;
  535. background: #fff; border-radius: 32rpx 32rpx 0 0;
  536. box-shadow: 0 -4rpx 32rpx rgba(0,0,0,0.08);
  537. padding-bottom: env(safe-area-inset-bottom);
  538. animation: slideUp 0.2s;
  539. }
  540. @keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
  541. .modal-header {
  542. display: flex; align-items: center; justify-content: space-between;
  543. padding: 32rpx 32rpx 0 32rpx;
  544. .close-btn { color: #bbb; font-size: 30rpx; }
  545. .modal-title { flex: 1; text-align: center; font-size: 34rpx; font-weight: bold; color: #222; }
  546. }
  547. .modal-form {
  548. padding: 0 32rpx;
  549. .form-item {
  550. border-bottom: 1rpx solid #f2f2f2;
  551. padding: 28rpx 0 10rpx 0;
  552. .label { color: #222; font-size: 28rpx; margin-bottom: 8rpx; }
  553. .input, .region-input {
  554. width: 100%; font-size: 28rpx; color: #222; background: none; border: none; outline: none;
  555. &.placeholder { color: #ccc; }
  556. }
  557. .region-input { display: flex; align-items: center; justify-content: space-between; }
  558. .arrow { color: #ccc; font-size: 28rpx; margin-left: 10rpx; }
  559. }
  560. }
  561. .region-picker {
  562. padding: 32rpx 0 0 0;
  563. .picker-view {
  564. width: 100%; height: 300rpx; display: flex; justify-content: center; align-items: center;
  565. .active { color: #222; font-weight: bold; }
  566. view { color: #ccc; font-size: 28rpx; text-align: center; }
  567. }
  568. .item {
  569. // line-height: 100upx;
  570. text-align: center;
  571. display: flex;
  572. align-items: center;
  573. justify-content: center;
  574. // height: 100upx;
  575. font-size: 30rpx;
  576. color: #222;
  577. }
  578. }
  579. </style>