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

283 lines
6.9 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
  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. getDetail()
  121. });
  122. const setAddress = (res) => {
  123. form.value.latitude = res.latitude
  124. form.value.longitude = res.longitude
  125. if (!res.address && res.name) { //用户直接选择城市的逻辑
  126. return form.value.area = res.name
  127. }
  128. if (res.address || res.name) {
  129. return form.value.area = res.address + res.name
  130. }
  131. form.value.area = '' //用户啥都没选就点击勾选
  132. }
  133. const selectAddr = () => {
  134. uni.chooseLocation({
  135. success: function(res) {
  136. setAddress(res)
  137. },
  138. fail(e) {
  139. console.log("获取位置信息失败!", e)
  140. }
  141. })
  142. }
  143. const onSwitch = (e) => {
  144. form.value.status = e.detail.value
  145. }
  146. const onSave = async () => {
  147. // 验证接单范围是否在3-15公里之间
  148. if (isNaN(form.value.rangeNo - 1) || form.value.rangeNo < 3 || form.value.rangeNo > 15) {
  149. uni.showToast({
  150. title: '接单范围必须是3-15公里之间的数字',
  151. icon: 'none'
  152. })
  153. return
  154. }
  155. //必须选择地区
  156. if (!form.value.area) {
  157. uni.showToast({
  158. title: '请选择地区',
  159. icon: 'none'
  160. })
  161. return
  162. }
  163. let code = null;
  164. if (eidtItem?.value?.id) {
  165. let result = await udpateAddress({
  166. ...form.value,
  167. userId : userInfo.value.userId,
  168. })
  169. code = result.code
  170. } else {
  171. // 新增地址
  172. let result = await insertAddress({
  173. ...form.value,
  174. userId : userInfo.value.userId,
  175. })
  176. code = result.code
  177. }
  178. if (code == 200) {
  179. uni.navigateBack()
  180. }
  181. }
  182. function getDetail(){
  183. if(!addressId.value){
  184. return
  185. }
  186. addressDetail(addressId.value).
  187. then(res => {
  188. console.log(res.data);
  189. eidtItem.value = res.data
  190. form.value = {
  191. id: eidtItem?.value?.id || null,
  192. area: eidtItem?.value?.area || null,
  193. address: eidtItem?.value?.address || null,
  194. status: eidtItem?.value?.status == 'true' || null,
  195. latitude: form.value.latitude || eidtItem?.value?.latitude || null,
  196. longitude: form.value.latitude || eidtItem?.value?.longitude || null,
  197. rangeNo: form.value.rangeNo || eidtItem?.value?.rangeNo || null
  198. }
  199. })
  200. }
  201. const getDisabledDateDesc = (dateArr) => {
  202. if (!dateArr?.length) {
  203. return '暂无不可接单日期'
  204. }
  205. return dateArr.map(date => dayjs(date.date).format('MM-DD')).join('、')
  206. }
  207. const toNoOrderDate = () => {
  208. if (eidtItem?.value?.id) {
  209. uni.navigateTo({
  210. url: `/otherPages/myOrdersManage/date/detail?addressId=${eidtItem.value.id}`
  211. });
  212. }
  213. }
  214. </script>
  215. <style lang="scss" scoped>
  216. .page {
  217. padding: 35rpx 37rpx 144rpx 37rpx;
  218. min-height: calc(100vh - 200rpx);
  219. background-color: #fff;
  220. }
  221. .info {
  222. color: #707070;
  223. font-size: 30rpx;
  224. line-height: 40rpx;
  225. &-header {
  226. color: #000000;
  227. }
  228. .placeholder {
  229. color: #707070;
  230. }
  231. .textarea {
  232. margin-top: 16rpx;
  233. background-color: #F3F3F3;
  234. padding: 26rpx 8rpx;
  235. border-radius: 15rpx;
  236. height: 200rpx;
  237. overflow: scroll;
  238. textarea{
  239. height: 200rpx;
  240. }
  241. }
  242. :deep(.u-form-item__body__left__content__label) {
  243. color: #707070;
  244. }
  245. }
  246. .text-ellipsis {
  247. text-align: right;
  248. overflow: hidden; //超出的文本隐藏
  249. text-overflow: ellipsis; //溢出用省略号显示
  250. white-space: nowrap; //溢出不换行
  251. width: 330rpx;
  252. }
  253. </style>