猫妈狗爸伴宠师小程序前端代码
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.

262 lines
6.3 KiB

2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
  1. <template>
  2. <view class="page">
  3. <up-form ref="formRef" :model="form" :rules="rules" labelPosition="left" labelWidth="150rpx">
  4. <view class="info">
  5. <view class="info-header">地址信息</view>
  6. <view class="info-content">
  7. <up-form-item label="接单地址" prop="area">
  8. <view plain class="flex-rowr" @click="selectAddr">
  9. <text v-if="form.area">{{ form.area }}</text>
  10. <text v-else class="placeholder">请定位选择小区或商城等</text>
  11. <up-icon style="margin-left: 22rpx;" name="arrow-down" color="#7F7F7F"
  12. size="21rpx"></up-icon>
  13. </view>
  14. </up-form-item>
  15. <up-form-item label="接单地址" prop="address" labelPosition="top">
  16. <view class="textarea">
  17. <textarea v-model="form.address" placeholder="如街道、门牌号、小区、乡镇、村等" :row="3"></textarea>
  18. </view>
  19. </up-form-item>
  20. </view>
  21. </view>
  22. <view class="info">
  23. <view class="info-header">接单信息</view>
  24. <view class="info-content">
  25. <up-form-item label="接单状态" prop="status">
  26. <view class="flex-rowr">
  27. <switch :checked="!!form.status" @change="onSwitch" color="#FFBF60"
  28. style="transform: scale(0.6);" />
  29. <text>{{ !!form.status ? '开启' : '关闭' }}</text>
  30. </view>
  31. </up-form-item>
  32. <up-form-item label="接单范围" prop="rangeNo">
  33. <up-input v-model="form.rangeNo" placeholder="请输入内容" inputAlign="right" border="none">
  34. <template #suffix>
  35. <text>Km</text>
  36. </template>
  37. </up-input>
  38. </up-form-item>
  39. <up-form-item @click="toNoOrderDate"
  40. v-if="eidtItem"
  41. label="不接单日期(选填)" prop="disabledDate" labelWidth="300rpx">
  42. <view class="" style="display: flex;width: 380rpx;">
  43. <view class="text-ellipsis"
  44. style="margin-left: auto;"
  45. v-if="eidtItem.appletOutDate && eidtItem.appletOutDate.length">
  46. {{ getDisabledDateDesc(eidtItem.appletOutDate) }}
  47. </view>
  48. <view class="text-ellipsis"
  49. style="margin-left: auto;" v-else>
  50. 暂无不可接单日期
  51. </view>
  52. >
  53. </view>
  54. </up-form-item>
  55. </view>
  56. </view>
  57. </up-form>
  58. <view style="margin-top: 40rpx;">
  59. <up-parse class="size-28" :content="configList.adress_statement.paramValueArea" containerStyle="{
  60. color: '#707070',
  61. fontSize: '22rpx',
  62. lineHeight: '35rpx',
  63. }"></up-parse>
  64. </view>
  65. <view class="footer-btn">
  66. <view class="btn" @click="onSave">
  67. {{ eidtItem ? '修改地址' : '新增地址'}}
  68. </view>
  69. </view>
  70. </view>
  71. </template>
  72. <script setup>
  73. import {
  74. ref,
  75. getCurrentInstance,
  76. computed,
  77. } from 'vue'
  78. import dayjs from 'dayjs'
  79. import {
  80. store
  81. } from '@/store'
  82. import {
  83. insertAddress,
  84. udpateAddress,
  85. addressDetail,
  86. } from "@/api/address/address.js"
  87. import {
  88. onLoad,
  89. onShow
  90. } from '@dcloudio/uni-app'
  91. const instance = getCurrentInstance();
  92. const configList = store.state.system.configList
  93. const formRef = ref()
  94. const form = ref({
  95. area: null,
  96. latitude: null,
  97. longitude: null,
  98. address: null,
  99. status: true,
  100. distance: null,
  101. disabledDate: [],
  102. })
  103. const userInfo = computed(() => {
  104. return store.getters.userInfo;
  105. })
  106. const rules = ref({})
  107. const eidtItem = ref(null);
  108. const addressId = ref(0)
  109. onLoad((options) => {
  110. addressId.value = options.addressId
  111. // eidtItem.value = options?.item ? JSON.parse(options.item) : null;
  112. // form.value = {
  113. // id: eidtItem?.value?.id || null,
  114. // area: eidtItem?.value?.area || null,
  115. // address: eidtItem?.value?.address || null,
  116. // status: eidtItem?.value?.status == 'true' || null,
  117. // latitude: eidtItem?.value?.latitude || null,
  118. // longitude: eidtItem?.value?.longitude || null
  119. // }
  120. });
  121. onShow(() => {
  122. getDetail()
  123. })
  124. const setAddress = (res) => {
  125. form.value.latitude = res.latitude
  126. form.value.longitude = res.longitude
  127. if (!res.address && res.name) { //用户直接选择城市的逻辑
  128. return form.value.area = res.name
  129. }
  130. if (res.address || res.name) {
  131. return form.value.area = res.address + res.name
  132. }
  133. form.value.area = '' //用户啥都没选就点击勾选
  134. }
  135. const selectAddr = () => {
  136. uni.chooseLocation({
  137. success: function(res) {
  138. setAddress(res)
  139. },
  140. fail(e) {
  141. console.log("获取位置信息失败!", e)
  142. }
  143. })
  144. }
  145. const onSwitch = (e) => {
  146. form.value.status = e.detail.value
  147. }
  148. const onSave = async () => {
  149. let code = null;
  150. if (eidtItem?.value?.id) {
  151. let result = await udpateAddress({
  152. ...form.value,
  153. userId : userInfo.value.userId,
  154. })
  155. code = result.code
  156. } else {
  157. // 新增地址
  158. let result = await insertAddress({
  159. ...form.value,
  160. userId : userInfo.value.userId,
  161. })
  162. code = result.code
  163. }
  164. if (code == 200) {
  165. uni.navigateBack()
  166. }
  167. }
  168. function getDetail(){
  169. if(!addressId.value){
  170. return
  171. }
  172. addressDetail(addressId.value).
  173. then(res => {
  174. console.log(res.data);
  175. eidtItem.value = res.data
  176. form.value = {
  177. id: eidtItem?.value?.id || null,
  178. area: eidtItem?.value?.area || null,
  179. address: eidtItem?.value?.address || null,
  180. status: eidtItem?.value?.status == 'true' || null,
  181. latitude: form.value.latitude || eidtItem?.value?.latitude || null,
  182. longitude: form.value.latitude || eidtItem?.value?.longitude || null
  183. }
  184. })
  185. }
  186. const getDisabledDateDesc = (dateArr) => {
  187. if (!dateArr?.length) {
  188. return '暂无不可接单日期'
  189. }
  190. return dateArr.map(date => dayjs(date.date).format('MM-DD')).join('、')
  191. }
  192. const toNoOrderDate = () => {
  193. if (eidtItem?.value?.id) {
  194. uni.navigateTo({
  195. url: `/otherPages/myOrdersManage/date/detail?addressId=${eidtItem.value.id}`
  196. });
  197. }
  198. }
  199. </script>
  200. <style lang="scss" scoped>
  201. .page {
  202. padding: 35rpx 37rpx 144rpx 37rpx;
  203. min-height: calc(100vh - 200rpx);
  204. background-color: #fff;
  205. }
  206. .info {
  207. color: #707070;
  208. font-size: 30rpx;
  209. line-height: 40rpx;
  210. &-header {
  211. color: #000000;
  212. }
  213. .placeholder {
  214. color: #707070;
  215. }
  216. .textarea {
  217. margin-top: 16rpx;
  218. background-color: #F3F3F3;
  219. padding: 26rpx 8rpx;
  220. border-radius: 15rpx;
  221. }
  222. :deep(.u-form-item__body__left__content__label) {
  223. color: #707070;
  224. }
  225. }
  226. .text-ellipsis {
  227. text-align: right;
  228. overflow: hidden; //超出的文本隐藏
  229. text-overflow: ellipsis; //溢出用省略号显示
  230. white-space: nowrap; //溢出不换行
  231. width: 330rpx;
  232. }
  233. </style>