index.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <script setup lang="ts">
  2. import router from '@/router'
  3. definePage({
  4. name: 'common-editAddress',
  5. islogin: true,
  6. style: {
  7. navigationBarTitleText: '编辑新增收获地址',
  8. navigationStyle: 'custom',
  9. },
  10. })
  11. const route = useRoute()
  12. const title = computed(() => {
  13. if (route.query?.type === '1')
  14. return '新增收获地址'
  15. return '编辑收获地址'
  16. })
  17. const modelForm = ref<Api.addressList>({
  18. consigneeName: '',
  19. consigneeMobile: '',
  20. detailAddress: '',
  21. defaulted: 1,
  22. latitude: 0,
  23. longitude: 0,
  24. province: '',
  25. city: '',
  26. id: 0,
  27. })
  28. function handleSelectAddress() {
  29. uni.chooseLocation({
  30. success: (res) => {
  31. modelForm.value.latitude = res.latitude
  32. modelForm.value.longitude = res.longitude
  33. modelForm.value.province = res.address
  34. modelForm.value.city = res.name
  35. console.log(modelForm.value, '地址')
  36. },
  37. fail: (e) => {
  38. console.log('获取地址失败', e)
  39. },
  40. })
  41. }
  42. async function getData() {
  43. const res = await Apis.sys.addressesDetail({ pathParams: { addressId: Number(route.query?.id) } })
  44. modelForm.value = res
  45. }
  46. onMounted(() => {
  47. if (route.query?.type === '2') {
  48. getData()
  49. }
  50. })
  51. async function handleSubmit() {
  52. if (!modelForm.value.consigneeName) {
  53. useGlobalToast().show('请输入收货人姓名')
  54. return
  55. }
  56. if (!modelForm.value.consigneeMobile) {
  57. useGlobalToast().show('请输入手机号码')
  58. return
  59. }
  60. if (!modelForm.value.province) {
  61. useGlobalToast().show('请选择所在地区')
  62. return
  63. }
  64. if (!modelForm.value.detailAddress) {
  65. useGlobalToast().show('请输入详细地址')
  66. }
  67. if (Number(route.query?.type) === 1) {
  68. await Apis.sys.Addaddresses({ data: modelForm.value })
  69. useGlobalToast().show({ msg: '添加成功' })
  70. }
  71. else {
  72. await Apis.sys.updateAddresses({ pathParams: modelForm.value.id, data: modelForm.value })
  73. useGlobalToast().show({ msg: '修改成功' })
  74. }
  75. setTimeout(() => {
  76. router.back()
  77. }, 2000)
  78. }
  79. async function handleDel() {
  80. useGlobalMessage().confirm({
  81. title: '删除地址',
  82. msg: '确定要删除该地址吗?',
  83. success: async () => {
  84. await Apis.sys.deleteAddresses({ pathParams: { ids: route.query?.id } })
  85. useUserStore().getSelectedAddress()
  86. router.back()
  87. },
  88. })
  89. }
  90. </script>
  91. <template>
  92. <view>
  93. <wd-navbar
  94. :title="title" :bordered="false" :z-index="99"
  95. safe-area-inset-top left-arrow placeholder fixed @click-left="router.back()"
  96. />
  97. <view class="px24rpx py20rpx">
  98. <view class="rounded-16rpx bg-white p24rpx">
  99. <view class="flex items-center">
  100. <view class="mr40rpx w112rpx flex-shrink-0 text-28rpx">
  101. 收货人
  102. </view>
  103. <view class="flex-1">
  104. <wd-input v-model="modelForm.consigneeName" no-border placeholder="姓名" />
  105. </view>
  106. </view>
  107. <view class="mt28rpx flex items-center">
  108. <view class="mr40rpx w112rpx flex-shrink-0 text-28rpx">
  109. 手机号码
  110. </view>
  111. <view class="flex-1">
  112. <wd-input v-model="modelForm.consigneeMobile" :maxlength="11" no-border placeholder="11位手机号码" />
  113. </view>
  114. </view>
  115. <view class="mt28rpx flex items-center">
  116. <view class="mr40rpx w112rpx flex-shrink-0 text-28rpx">
  117. 所在地区
  118. </view>
  119. <view class="flex flex-1 items-center justify-between" @click="handleSelectAddress">
  120. <view v-if="!modelForm.province" class="text-28rpx text-[var(--them-color)]">
  121. 点击选择地址
  122. </view>
  123. <view v-else class="text-24rpx">
  124. <view class="font-semibold">
  125. {{ modelForm.province }}
  126. </view>
  127. <view class="mt12rpx text-#AAAAAA">
  128. {{ modelForm.city }}
  129. </view>
  130. </view>
  131. <wd-icon name="arrow-right" size="22px" color="#aaa" />
  132. </view>
  133. </view>
  134. <view class="mt28rpx flex items-center">
  135. <view class="mr40rpx w112rpx flex-shrink-0 text-28rpx">
  136. 详细地址
  137. </view>
  138. <view class="flex-1">
  139. <wd-input v-model="modelForm.detailAddress" no-border placeholder="如楼号/单元号/门牌号" />
  140. </view>
  141. </view>
  142. </view>
  143. <view class="mt84rpx px100rpx">
  144. <wd-button type="primary" block size="large" @click="handleSubmit">
  145. 保存收货地址
  146. </wd-button>
  147. <view v-if="title == '编辑收获地址'" class="mt24rpx">
  148. <wd-button plain block size="large" @click="handleDel">
  149. 删除收获地址
  150. </wd-button>
  151. </view>
  152. </view>
  153. </view>
  154. </view>
  155. </template>
  156. <style scoped>
  157. </style>