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

275 lines
6.6 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
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="2"></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" type="number" 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 && 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. rangeNo: 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. // 验证接单范围是否在3-15公里之间
  150. if (form.value.rangeNo < 3 || form.value.rangeNo > 15) {
  151. uni.showToast({
  152. title: '接单范围必须在3-15公里之间',
  153. icon: 'none'
  154. })
  155. return
  156. }
  157. let code = null;
  158. if (eidtItem?.value?.id) {
  159. let result = await udpateAddress({
  160. ...form.value,
  161. userId : userInfo.value.userId,
  162. })
  163. code = result.code
  164. } else {
  165. // 新增地址
  166. let result = await insertAddress({
  167. ...form.value,
  168. userId : userInfo.value.userId,
  169. })
  170. code = result.code
  171. }
  172. if (code == 200) {
  173. uni.navigateBack()
  174. }
  175. }
  176. function getDetail(){
  177. if(!addressId.value){
  178. return
  179. }
  180. addressDetail(addressId.value).
  181. then(res => {
  182. console.log(res.data);
  183. eidtItem.value = res.data
  184. form.value = {
  185. id: eidtItem?.value?.id || null,
  186. area: eidtItem?.value?.area || null,
  187. address: eidtItem?.value?.address || null,
  188. status: eidtItem?.value?.status == 'true' || null,
  189. latitude: form.value.latitude || eidtItem?.value?.latitude || null,
  190. longitude: form.value.latitude || eidtItem?.value?.longitude || null
  191. }
  192. })
  193. }
  194. const getDisabledDateDesc = (dateArr) => {
  195. if (!dateArr?.length) {
  196. return '暂无不可接单日期'
  197. }
  198. return dateArr.map(date => dayjs(date.date).format('MM-DD')).join('、')
  199. }
  200. const toNoOrderDate = () => {
  201. if (eidtItem?.value?.id) {
  202. uni.navigateTo({
  203. url: `/otherPages/myOrdersManage/date/detail?addressId=${eidtItem.value.id}`
  204. });
  205. }
  206. }
  207. </script>
  208. <style lang="scss" scoped>
  209. .page {
  210. padding: 35rpx 37rpx 144rpx 37rpx;
  211. min-height: calc(100vh - 200rpx);
  212. background-color: #fff;
  213. }
  214. .info {
  215. color: #707070;
  216. font-size: 30rpx;
  217. line-height: 40rpx;
  218. &-header {
  219. color: #000000;
  220. }
  221. .placeholder {
  222. color: #707070;
  223. }
  224. .textarea {
  225. margin-top: 16rpx;
  226. background-color: #F3F3F3;
  227. padding: 26rpx 8rpx;
  228. border-radius: 15rpx;
  229. height: 200rpx;
  230. overflow: scroll;
  231. textarea{
  232. height: 200rpx;
  233. }
  234. }
  235. :deep(.u-form-item__body__left__content__label) {
  236. color: #707070;
  237. }
  238. }
  239. .text-ellipsis {
  240. text-align: right;
  241. overflow: hidden; //超出的文本隐藏
  242. text-overflow: ellipsis; //溢出用省略号显示
  243. white-space: nowrap; //溢出不换行
  244. width: 330rpx;
  245. }
  246. </style>