爱简收旧衣按件回收前端代码仓库
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.

569 lines
17 KiB

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. <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}}</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">新建地址</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. this.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. uni.navigateTo({
  244. url: '/pages/component/add'
  245. })
  246. },
  247. goToAddAddress() {
  248. this.showAddressModal = true
  249. this.form = {
  250. name: '',
  251. phone: '',
  252. region: [],
  253. address: '',
  254. addressDetails: ''
  255. }
  256. this.regionIndex = [0, 0, 0]
  257. this.cities = this.provinces[0]?.children || []
  258. this.districts = this.cities[0]?.children || []
  259. },
  260. selectAddress(address) {
  261. if (this.mode === 'select') {
  262. uni.$emit('addressSelected', {
  263. name: address.name,
  264. phone: address.phone,
  265. address: address.address
  266. })
  267. uni.navigateBack()
  268. }
  269. },
  270. closeAddressModal() {
  271. this.showAddressModal = false
  272. },
  273. saveAddress() {
  274. if (!this.form.name) return uni.showToast({ title: '请输入联系人', icon: 'none' })
  275. if (!this.form.phone) return uni.showToast({ title: '请输入手机号', icon: 'none' })
  276. if (!this.form.address) return uni.showToast({ title: '请选择地区', icon: 'none' })
  277. if (!this.form.addressDetails) return uni.showToast({ title: '请输入详细地址', icon: 'none' })
  278. this.$api('saveOrUpdateAddress',{
  279. name:this.form.name,
  280. phone:this.form.phone,
  281. address:this.form.address,
  282. addressDetails:this.form.addressDetails
  283. },(res)=>{
  284. if(res.code == 200){
  285. uni.showToast({ title: '保存成功', icon: 'success' })
  286. this.closeAddressModal()
  287. this.$forceUpdate();
  288. }
  289. })
  290. },
  291. onRegionChange(e) {
  292. let [pIdx, cIdx, dIdx] = e.detail.value
  293. if (pIdx !== this.regionIndex[0]) {
  294. cIdx = 0
  295. dIdx = 0
  296. } else if (cIdx !== this.regionIndex[1]) {
  297. dIdx = 0
  298. }
  299. this.regionIndex = [pIdx, cIdx, dIdx]
  300. },
  301. confirmRegion() {
  302. const province = this.provinces[this.regionIndex[0]]
  303. const city = this.cities[this.regionIndex[1]]
  304. const district = this.districts[this.regionIndex[2]]
  305. this.form.region = [
  306. province?.code || '',
  307. city?.code || '',
  308. district?.code || ''
  309. ]
  310. this.form.address = [
  311. province?.name || '',
  312. city?.name || '',
  313. district?.name || ''
  314. ].filter(Boolean).join(' ')
  315. this.showRegionPicker = false
  316. },
  317. setDefault(id) {
  318. this.$api('updateDefaultAddress',{id:id},(res)=>{
  319. console.log(res)
  320. if(res.code == 200){
  321. this.$api('getAddressList', {}, res => {
  322. console.log(res,'res');
  323. this.addressList = res.result.records
  324. })
  325. }
  326. })
  327. },
  328. deleteAddress(id) {
  329. uni.showModal({
  330. title: '提示',
  331. content: '确定要删除该地址吗?',
  332. success: (res) => {
  333. if (res.confirm) {
  334. this.$api('deleteAddress', {id:id}, res => {
  335. console.log(res);
  336. })
  337. }
  338. }
  339. })
  340. },
  341. initRegionPicker() {
  342. if (this.form.region.length > 0) {
  343. const [provinceCode, cityCode, districtCode] = this.form.region
  344. const provinceIndex = this.provinces.findIndex(p => p.code === provinceCode)
  345. if (provinceIndex > -1) {
  346. this.cities = this.provinces[provinceIndex].children || []
  347. if (this.cities.length === 0) {
  348. this.cities = [{ code: '', name: '请选择' }]
  349. }
  350. const cityIndex = this.cities.findIndex(c => c.code === cityCode)
  351. if (cityIndex > -1) {
  352. this.districts = this.cities[cityIndex].children || []
  353. if (this.districts.length === 0) {
  354. this.districts = [{ code: '', name: '请选择' }]
  355. }
  356. const districtIndex = this.districts.findIndex(d => d.code === districtCode)
  357. this.regionIndex = [
  358. provinceIndex,
  359. cityIndex,
  360. districtIndex > -1 ? districtIndex : 0
  361. ]
  362. return
  363. }
  364. }
  365. }
  366. this.cities = this.provinces[0]?.children || []
  367. if (this.cities.length === 0) {
  368. this.cities = [{ code: '', name: '请选择' }]
  369. }
  370. this.districts = this.cities[0]?.children || []
  371. if (this.districts.length === 0) {
  372. this.districts = [{ code: '', name: '请选择' }]
  373. }
  374. this.regionIndex = [0, 0, 0]
  375. }
  376. },
  377. }
  378. </script>
  379. <style lang="scss" scoped>
  380. .container {
  381. min-height: 100vh;
  382. background: #f8f8f8;
  383. padding-bottom: calc(140rpx + env(safe-area-inset-bottom));
  384. }
  385. .nav-bar {
  386. display: flex;
  387. align-items: center;
  388. background: #fff;
  389. padding: 0 30rpx;
  390. position: fixed;
  391. top: 0;
  392. left: 0;
  393. right: 0;
  394. z-index: 999;
  395. .back {
  396. padding: 20rpx;
  397. margin-left: -20rpx;
  398. }
  399. .title {
  400. flex: 1;
  401. text-align: center;
  402. font-size: 34rpx;
  403. font-weight: 500;
  404. color: #222;
  405. }
  406. .right-btns {
  407. display: flex;
  408. align-items: center;
  409. gap: 30rpx;
  410. .more, .target {
  411. font-size: 40rpx;
  412. color: #333;
  413. }
  414. }
  415. }
  416. .address-list {
  417. padding: 32rpx;
  418. margin-top: calc(88rpx + var(--status-bar-height));
  419. min-height: calc(100vh - 88rpx - var(--status-bar-height) - 140rpx - env(safe-area-inset-bottom));
  420. box-sizing: border-box;
  421. .address-item {
  422. background: #fff;
  423. border-radius: 24rpx;
  424. margin-bottom: 24rpx;
  425. padding: 32rpx 28rpx 0 28rpx;
  426. box-shadow: 0 4rpx 24rpx rgba(0,0,0,0.04);
  427. .address-header {
  428. display: flex;
  429. align-items: center;
  430. .name { font-size: 32rpx; color: #222; font-weight: 500; margin-right: 20rpx; }
  431. .phone { font-size: 32rpx; color: #222; }
  432. .default-tag {
  433. margin-left: 18rpx;
  434. font-size: 24rpx;
  435. color: #FF9500;
  436. border: 1rpx solid #FF9500;
  437. border-radius: 8rpx;
  438. padding: 2rpx 12rpx;
  439. background: #FFF7E6;
  440. vertical-align: middle;
  441. }
  442. }
  443. .address-text {
  444. font-size: 28rpx;
  445. color: #888;
  446. margin: 16rpx 0 0 0;
  447. line-height: 1.5;
  448. }
  449. .dashed-line {
  450. border-bottom: 1rpx dashed #eee;
  451. margin: 24rpx 0 0 0;
  452. }
  453. .address-actions {
  454. display: flex;
  455. align-items: center;
  456. justify-content: space-around;
  457. padding: 0 0 18rpx 0;
  458. .action {
  459. display: flex;
  460. align-items: center;
  461. margin-right: 48rpx;
  462. .circle {
  463. width: 36rpx; height: 36rpx; border-radius: 50%;
  464. border: 2rpx solid #FF9500; margin-right: 8rpx;
  465. display: flex; align-items: center; justify-content: center;
  466. &.active {
  467. background: #FF9500; border: none;
  468. .check { color: #fff; font-size: 24rpx; }
  469. }
  470. }
  471. text { font-size: 26rpx; color: #bbb; }
  472. .active-text { color: #FF9500; }
  473. }
  474. }
  475. }
  476. }
  477. .bottom-bar {
  478. position: fixed;
  479. left: 0; right: 0; bottom: 0;
  480. background: #fff;
  481. padding: 24rpx 32rpx env(safe-area-inset-bottom);
  482. z-index: 10;
  483. }
  484. .main-btn {
  485. width: 100%;
  486. height: 90rpx;
  487. background: linear-gradient(90deg, #FFB74D 0%, #FF9500 100%);
  488. color: #fff;
  489. font-size: 32rpx;
  490. border-radius: 45rpx;
  491. font-weight: bold;
  492. margin: 0 auto;
  493. display: flex; align-items: center; justify-content: center;
  494. box-shadow: 0 4rpx 16rpx rgba(255, 149, 0, 0.08);
  495. }
  496. .modal-mask {
  497. position: fixed; left: 0; right: 0; top: 0; bottom: 0;
  498. background: rgba(0,0,0,0.5); z-index: 1000;
  499. }
  500. .address-modal, .region-modal {
  501. position: fixed; left: 0; right: 0; bottom: 0; z-index: 1001;
  502. background: #fff; border-radius: 32rpx 32rpx 0 0;
  503. box-shadow: 0 -4rpx 32rpx rgba(0,0,0,0.08);
  504. padding-bottom: env(safe-area-inset-bottom);
  505. animation: slideUp 0.2s;
  506. }
  507. @keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
  508. .modal-header {
  509. display: flex; align-items: center; justify-content: space-between;
  510. padding: 32rpx 32rpx 0 32rpx;
  511. .close-btn { color: #bbb; font-size: 30rpx; }
  512. .modal-title { flex: 1; text-align: center; font-size: 34rpx; font-weight: bold; color: #222; }
  513. }
  514. .modal-form {
  515. padding: 0 32rpx;
  516. .form-item {
  517. border-bottom: 1rpx solid #f2f2f2;
  518. padding: 28rpx 0 10rpx 0;
  519. .label { color: #222; font-size: 28rpx; margin-bottom: 8rpx; }
  520. .input, .region-input {
  521. width: 100%; font-size: 28rpx; color: #222; background: none; border: none; outline: none;
  522. &.placeholder { color: #ccc; }
  523. }
  524. .region-input { display: flex; align-items: center; justify-content: space-between; }
  525. .arrow { color: #ccc; font-size: 28rpx; margin-left: 10rpx; }
  526. }
  527. }
  528. .region-picker {
  529. padding: 32rpx 0 0 0;
  530. .picker-view {
  531. width: 100%; height: 300rpx; display: flex; justify-content: center; align-items: center;
  532. .active { color: #222; font-weight: bold; }
  533. view { color: #ccc; font-size: 28rpx; text-align: center; }
  534. }
  535. .item {
  536. // line-height: 100upx;
  537. text-align: center;
  538. display: flex;
  539. align-items: center;
  540. justify-content: center;
  541. // height: 100upx;
  542. font-size: 30rpx;
  543. color: #222;
  544. }
  545. }
  546. </style>