address-operation.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import OSticky from '@/components/o-sticky'
  2. import { Button, Cell, CellGroup, Field, Picker, Popup, Switch } from 'vant'
  3. import { defineComponent, reactive } from 'vue'
  4. import request from '../request-music'
  5. import styles from './index.module.less'
  6. import { areas } from '@/helpers/area'
  7. export default defineComponent({
  8. name: 'address-operation',
  9. setup() {
  10. const state = reactive({
  11. showPicker: false,
  12. defaultStatus: false,
  13. phoneNumber: null,
  14. province: null,
  15. city: null,
  16. region: null,
  17. pcrStr: '',
  18. name: null,
  19. detailAddress: null
  20. })
  21. const onSubmit = async () => {
  22. try {
  23. await request.post('/api-student/userReceiveAddress/save', {
  24. data: {}
  25. })
  26. } catch {}
  27. }
  28. return () => (
  29. <div class={styles.operation}>
  30. <CellGroup inset class={styles.form}>
  31. <Field label="收货人" placeholder="请输入收货人姓名" v-model={state.name} />
  32. <Field label="手机号" placeholder="请输入收货人人手机号" v-model={state.phoneNumber} />
  33. <Field
  34. label="所在地区"
  35. placeholder="省、市、区、街道"
  36. readonly
  37. isLink
  38. modelValue={state.pcrStr}
  39. onClick={() => {
  40. state.showPicker = true
  41. }}
  42. />
  43. <Field
  44. label="详细地址"
  45. placeholder="小区楼栋/乡村名称"
  46. type="textarea"
  47. rows={3}
  48. v-model={state.detailAddress}
  49. />
  50. </CellGroup>
  51. <CellGroup inset style={{ marginTop: '12px' }}>
  52. <Cell title="设置为默认地址" center class={styles.default}>
  53. {{ value: () => <Switch v-model={state.defaultStatus} size="23px" /> }}
  54. </Cell>
  55. </CellGroup>
  56. <OSticky position="bottom">
  57. <div class="btnGroup">
  58. <Button type="primary" block round>
  59. 确认
  60. </Button>
  61. </div>
  62. </OSticky>
  63. <Popup v-model:show={state.showPicker} position="bottom" round>
  64. <Picker
  65. showToolbar
  66. columns={areas}
  67. columnsFieldNames={{ text: 'name', value: 'code', children: 'areas' }}
  68. onCancel={() => (state.showPicker = false)}
  69. onConfirm={(val: any) => {
  70. console.log(val, 'val')
  71. const selectedOptions = val.selectedOptions || []
  72. // 因为有的只
  73. if (selectedOptions.length === 2) {
  74. selectedOptions.forEach((item: any, index: number) => {
  75. state.pcrStr += item.name
  76. if (index === 0) {
  77. state.province = item.id
  78. } else if (index === 1) {
  79. state.city = item.id
  80. }
  81. })
  82. } else {
  83. selectedOptions.forEach((item: any, index: number) => {
  84. state.pcrStr += item.name
  85. if (index === 0) {
  86. state.province = item.id
  87. } else if (index === 1) {
  88. state.city = item.id
  89. } else if (index === 2) {
  90. state.region = item.id
  91. }
  92. })
  93. }
  94. state.showPicker = false
  95. }}
  96. />
  97. </Popup>
  98. {/*
  99. <van-popup v-model:show="showPicker" position="bottom" round>
  100. <van-picker show-toolbar :columns="columns" @cancel="showPicker = false" @confirm="onConfirm"
  101. :columns-field-names="{ text: 'name', value: 'code', children: 'areas' }" />
  102. </van-popup> */}
  103. </div>
  104. )
  105. }
  106. })