演示项目-图书馆
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.

182 lines
4.7 KiB

  1. <template>
  2. <div class="main">
  3. <div class="top-header">
  4. <span class="back" @click="toBack"></span>
  5. <p>添加收货地址</p>
  6. </div>
  7. <div class="address-form">
  8. <van-form ref="form" @submit="onSubmit">
  9. <van-cell-group inset>
  10. <div class="form01">
  11. <van-field
  12. v-model="username"
  13. name="收货人"
  14. label="收货人"
  15. placeholder="用户名"
  16. :rules="[{ required: true, message: '请填写用户名' }]"
  17. />
  18. <van-field
  19. v-model="phone"
  20. type="number"
  21. name="手机号码"
  22. label="手机号码"
  23. placeholder="手机号码"
  24. :rules="[{ required: true, message: '请填写手机号码' }]"
  25. />
  26. <van-field
  27. v-model="area"
  28. is-link
  29. readonly
  30. name="area"
  31. label="所在地区"
  32. placeholder="省市区县、乡镇"
  33. :rules="[{ required: true, message: '请选择所在地区' }]"
  34. @click="showArea = true"
  35. >
  36. <template v-slot:right-icon>
  37. <img style="width: 0.32rem; height: 0.32rem"
  38. src="@assets/images/address-icon6.png" alt="">
  39. <span style="color: #1C202D;">定位</span>
  40. </template>
  41. </van-field>
  42. <van-popup v-model:show="showArea" position="bottom">
  43. <van-area
  44. :area-list="areaList"
  45. @confirm="onConfirm"
  46. @cancel="showArea = false"
  47. />
  48. </van-popup>
  49. <van-field
  50. v-model="place"
  51. rows="2"
  52. autosize
  53. type="textarea"
  54. name="详细地址"
  55. label="详细地址"
  56. maxlength="50"
  57. placeholder="楼道、街牌号等"
  58. :rules="[{ required: true, message: '请填写详细地址' }]"
  59. />
  60. </div>
  61. <div class="form02">
  62. <van-field name="place" label="设为默认收货地址">
  63. <template #input>
  64. <van-checkbox v-model="isChecked" shape="square" />
  65. </template>
  66. </van-field>
  67. </div>
  68. </van-cell-group>
  69. <div style="position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%);">
  70. <van-button round block type="primary" native-type="submit">
  71. 提交
  72. </van-button>
  73. </div>
  74. </van-form>
  75. </div>
  76. </div>
  77. </template>
  78. <script>
  79. import { reactive, getCurrentInstance, toRefs, ref } from 'vue'
  80. import { areaList } from '@vant/area-data'
  81. export default {
  82. name: 'AddAddress',
  83. setup() {
  84. const { proxy } = getCurrentInstance()
  85. let data = reactive({
  86. isSetting: false,
  87. username: '',
  88. phone: '',
  89. area: '',
  90. place: '',
  91. isChecked: false,
  92. showArea: false,
  93. })
  94. let toBack = () => {
  95. proxy.$router.go(-1)
  96. }
  97. let onConfirm = (value) => {
  98. data.showArea = false
  99. data.area = value.map((item) => item.name).join(' ')
  100. }
  101. let onSubmit = (values) => {
  102. console.log('submit',values)
  103. }
  104. return {
  105. ...toRefs(data),
  106. areaList,
  107. toBack,
  108. onConfirm,
  109. onSubmit
  110. }
  111. },
  112. }
  113. </script>
  114. <style scoped lang="scss">
  115. .address-form {
  116. height: calc(100vh - 1rem);
  117. padding: 1.3rem 0.32rem 0 0.32rem;
  118. background-color: #fff;
  119. .form01{
  120. padding: 0 .3rem;
  121. background-color: #fff;
  122. box-shadow: 0px .03rem .6rem 1px rgba(0,0,0,0.08);
  123. border-radius: .08rem;
  124. :deep(.van-icon){
  125. &::before{
  126. display: none;
  127. }
  128. }
  129. :deep(.van-field__right-icon){
  130. display: flex;
  131. align-items: center;
  132. font-size: .28rem;
  133. }
  134. }
  135. .form02{
  136. margin-top: .2rem;
  137. padding: 0 .3rem;
  138. background-color: #fff;
  139. box-shadow: 0px .03rem .6rem 1px rgba(0,0,0,0.08);
  140. border-radius: .08rem;
  141. :deep(.van-field__label){
  142. width: auto;
  143. }
  144. :deep(.van-field__control--custom){
  145. justify-content: flex-end;
  146. }
  147. :deep(.van-checkbox__icon .van-icon){
  148. border-radius: 50%;
  149. }
  150. }
  151. }
  152. :deep(.van-cell-group--inset){
  153. background: transparent;
  154. border-radius: 0;
  155. margin: 0;
  156. overflow: visible;
  157. }
  158. :deep(.van-cell){
  159. padding: .32rem 0;
  160. font-size: .28rem;
  161. background: transparent;
  162. &::after{
  163. right: 0;
  164. left: 0;
  165. border-color:#C6C6E2;
  166. }
  167. .van-field__label{
  168. color: #1C202D;
  169. }
  170. }
  171. :deep(.van-button--block){
  172. width: 4.4rem;
  173. height: .98rem;
  174. font-size: .36rem;
  175. background: #5A86F4;
  176. }
  177. </style>