index.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { Cell, Icon } from 'vant'
  2. import {
  3. defineComponent,
  4. computed,
  5. PropType
  6. } from 'vue'
  7. import styles from './index.module.less'
  8. import iconAddress from '@views/shop-mall/images/icon-address.png'
  9. import { addressType } from '../../cart'
  10. import {
  11. postMessage
  12. } from '@/helpers/native-message'
  13. export default defineComponent({
  14. name: 'cart-address',
  15. props: {
  16. item: {
  17. type: Object as PropType<addressType>,
  18. default: {}
  19. },
  20. isLink: {
  21. type: Boolean,
  22. default: true
  23. },
  24. setAddress:{
  25. type: Function,
  26. default: (n: any) => {}
  27. }
  28. },
  29. setup(props) {
  30. const addressInfo = computed(() => {
  31. return [
  32. props.item.province,
  33. props.item.city,
  34. props.item.region,
  35. props.item.detailAddress
  36. ].join('')
  37. })
  38. const selectAddress = () => {
  39. if (!props.isLink) return
  40. postMessage({
  41. api: 'setAddress',
  42. content: {}
  43. })
  44. }
  45. return () => (
  46. <>
  47. <Cell
  48. class={styles.cell}
  49. is-link={props.isLink}
  50. onClick={() => selectAddress()}
  51. v-slots={{
  52. icon: () => <Icon name={iconAddress} size={19} />,
  53. title: () => (
  54. <div>
  55. <span class={styles.userName}>{props.item.name}</span>
  56. <span class={styles.phone}>
  57. {props.item && props.item.phoneNumber && props.item.phoneNumber.replace(/^(\d{3})\d{4}(\d+)/,"$1****$2") || '去填写收货地址'}
  58. </span>
  59. </div>
  60. ),
  61. label: () => (
  62. <span class={styles.addressInfo}>{addressInfo.value}</span>
  63. )
  64. }}
  65. ></Cell>
  66. </>
  67. )
  68. }
  69. })