add.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <template>
  2. <view class="container">
  3. <fs-form ref="formRef" :model="formModel" class="main">
  4. <fs-form-item label="联系人">
  5. <fs-field placeholder="姓名" v-model="formModel.name"></fs-field>
  6. </fs-form-item>
  7. <fs-form-item label="手机号">
  8. <fs-field placeholder="手机号" v-model="formModel.phone"></fs-field>
  9. </fs-form-item>
  10. <fs-cell titleWidth="120rpx" title="地址" :value="formModel.address" border arrow @click="chooseAddress"></fs-cell>
  11. <fs-form-item label="门牌号">
  12. <fs-field placeholder="例:1号楼1单元101室" v-model="formModel.detail"></fs-field>
  13. </fs-form-item>
  14. <fs-cell border title="设为默认地址" justify="right">
  15. <template #value>
  16. <fs-switch checked @change="change"></fs-switch>
  17. </template>
  18. </fs-cell>
  19. </fs-form>
  20. <view class="layout-box">
  21. <fs-button block round @click="handleSubmit">添加</fs-button>
  22. </view>
  23. </view>
  24. </template>
  25. <script setup>
  26. import { ref, reactive } from 'vue'
  27. import useForm from '@/hooks/useForm'
  28. import useValidator from '@/hooks/useValidator'
  29. const validator = useValidator()
  30. const formRules = {
  31. name: {
  32. required: true,
  33. message: '请输入姓名'
  34. },
  35. phone: { validator: validator.mobile },
  36. address: {
  37. required: true,
  38. message: '请选择地址'
  39. }
  40. }
  41. const formModel = ref({
  42. name: '',
  43. phone: '',
  44. address: '',
  45. detail: '',
  46. default: true
  47. })
  48. const formRef = ref(null)
  49. if (getApp().globalData.addressDetail) {
  50. formModel.value = getApp().globalData.addressDetail
  51. }
  52. const chooseAddress = () => {
  53. uni.chooseLocation().then(res => {
  54. // const [error, data] = res
  55. console.log(res);
  56. formModel.address = res.address
  57. })
  58. }
  59. const change = e => {
  60. formModel.default = e
  61. }
  62. const form = useForm(formRules, 'formRef')
  63. const handleSubmit = () => {
  64. form.validate().then(() => {
  65. console.log('success')
  66. })
  67. }
  68. </script>
  69. <style lang="scss">
  70. page{
  71. height: 100%;
  72. background-color: #fff;
  73. }
  74. </style>