addres.tsx 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import { Cell, Icon, Tag } from 'vant'
  2. import { defineComponent, computed, PropType, reactive, onMounted } from 'vue'
  3. import styles from './address.module.less'
  4. import iconAddress from '@common/images/icon-address.png'
  5. import { useRouter } from 'vue-router'
  6. export default defineComponent({
  7. name: 'cart-address',
  8. props: {
  9. item: {
  10. type: Object as PropType<any>,
  11. default: () => ({})
  12. },
  13. isLink: {
  14. type: Boolean,
  15. default: true
  16. },
  17. setAddress: {
  18. type: Function,
  19. default: (n: any) => {}
  20. }
  21. },
  22. setup(props) {
  23. const router = useRouter()
  24. const addressInfo = computed(() => {
  25. return [
  26. props.item.provinceName,
  27. props.item.cityName,
  28. props.item.regionName,
  29. props.item.detailAddress
  30. ].join('')
  31. })
  32. const selectAddress = () => {
  33. if (!props.isLink) return
  34. router.push('/shopAddress')
  35. }
  36. return () => (
  37. <>
  38. {props.item && props.item.phoneNumber ? (
  39. <Cell
  40. class={styles.cell}
  41. is-link={props.isLink}
  42. onClick={() => selectAddress()}
  43. titleStyle={{ marginLeft: '0' }}
  44. v-slots={{
  45. title: () => (
  46. <div>
  47. <span class={styles.userName}>{props.item.name}</span>
  48. <span class={styles.phone}>
  49. {props.item &&
  50. props.item.phoneNumber &&
  51. props.item.phoneNumber.replace(/^(\d{3})\d{4}(\d+)/, '$1****$2')}
  52. </span>
  53. {props.item.defaultStatus && (
  54. <Tag
  55. type="primary"
  56. round
  57. style={{
  58. 'vertical-align': 'text-top',
  59. marginLeft: '10px',
  60. padding: '1px 8px'
  61. }}
  62. >
  63. 默认
  64. </Tag>
  65. )}
  66. </div>
  67. ),
  68. label: () => <span class={styles.addressInfo}>{addressInfo.value}</span>
  69. }}
  70. ></Cell>
  71. ) : (
  72. <Cell
  73. class={styles.cell}
  74. is-link={props.isLink}
  75. onClick={() => selectAddress()}
  76. v-slots={{
  77. icon: () => <Icon name={iconAddress} size={28} />,
  78. title: () => <div class={styles.emtry}>去填写收货地址</div>
  79. }}
  80. ></Cell>
  81. )}
  82. </>
  83. )
  84. }
  85. })