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

450 lines
14 KiB

  1. <template>
  2. <!-- <view>打卡</view> -->
  3. <view class="box box-size">
  4. <view class="top box-size" :style="{borderRadius:'16rpx'}">
  5. <view class="form-title">
  6. 个人准备
  7. </view>
  8. <view class="mt32 ml10">
  9. <span :style="{fontSize:'30rpx',fontWeight:'400'}">手套照片</span>
  10. <span :style="{fontSize:'22rpx',color:'#C7C7C7'}">(至少1张)</span>
  11. </view>
  12. <view class="level">
  13. <view class="mt20 ml10">
  14. <up-upload :fileList="fileList.glove" @afterRead="afterRead" @delete="deletePic" name="glove"
  15. multiple :maxCount="2" width="131rpx" height="131rpx" :disabled="isRead">
  16. <image src="/static/images/ydd/add_photo.png" mode="" :style="{width:'131rpx',height:'131rpx'}">
  17. </image>
  18. </up-upload>
  19. </view>
  20. </view>
  21. <view class="mt32 ml10">
  22. <span :style="{fontSize:'30rpx',fontWeight:'400'}">鞋套照片</span>
  23. <span :style="{fontSize:'22rpx',color:'#C7C7C7'}">(至少1张)</span>
  24. </view>
  25. <view class="level">
  26. <view class="mt20 ml10">
  27. <up-upload :fileList="fileList.ShoeCover" @afterRead="afterRead" @delete="deletePic"
  28. name="ShoeCover" multiple :maxCount="2" width="131rpx" height="131rpx" :disabled="isRead">
  29. <image src="/static/images/ydd/add_photo.png" mode="" :style="{width:'131rpx',height:'131rpx'}">
  30. </image>
  31. </up-upload>
  32. </view>
  33. </view>
  34. </view>
  35. <view class="top mt24 box-size" :style="{borderRadius:'16rpx'}">
  36. <view class="form-title">
  37. 宠物状态记录
  38. </view>
  39. <view v-for="(pet, index) in petList" :key="index">
  40. <view class="mt32 ml10">
  41. <span :style="{fontSize:'30rpx',fontWeight:'400'}">{{ pet.title }}照片</span>
  42. <span :style="{fontSize:'22rpx',color:'#C7C7C7'}">(至少2张)</span>
  43. </view>
  44. <view class="level">
  45. <view class="mt20 ml10 mr20">
  46. <up-upload :fileList="fileList['pet' + index]" @afterRead="afterRead" @delete="deletePic"
  47. :name="'pet' + index" multiple :maxCount="2" width="131rpx" height="131rpx" :disabled="isRead">
  48. <image src="/static/images/ydd/add_photo.png" mode=""
  49. :style="{width:'131rpx',height:'131rpx'}">
  50. </image>
  51. </up-upload>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. <view class="top mt24 box-size" :style="{borderRadius:'16rpx'}">
  57. <view class="form-title">
  58. 基础服务记录
  59. </view>
  60. <view class="mt32 ml10" :style="{fontSize:'30rpx',fontWeight:'400'}">粮碗前后对比 </view>
  61. <view class="level">
  62. <view class="mt20 ml10">
  63. <up-upload :fileList="fileList.foodA" @afterRead="afterRead" @delete="deletePic" name="foodA"
  64. multiple :maxCount="1" width="131rpx" height="131rpx" :disabled="isRead">
  65. <image src="/static/images/ydd/add_photo.png" mode="" :style="{width:'131rpx',height:'131rpx'}">
  66. </image>
  67. </up-upload>
  68. <view class="jus-center level" :style="{color:'#999999',fontSize:'22rpx',width:'131rpx'}"></view>
  69. </view>
  70. <view class="mt20 ml10 ml28">
  71. <up-upload :fileList="fileList.foodB" @afterRead="afterRead" @delete="deletePic" name="foodB"
  72. multiple :maxCount="1" width="131rpx" height="131rpx" :disabled="isRead">
  73. <image src="/static/images/ydd/add_photo.png" mode="" :style="{width:'131rpx',height:'131rpx'}">
  74. </image>
  75. </up-upload>
  76. <view class="jus-center level" :style="{color:'#999999',fontSize:'22rpx',width:'131rpx'}"></view>
  77. </view>
  78. </view>
  79. <view class="mt32 ml10" :style="{fontSize:'30rpx',fontWeight:'400'}">水碗前后对比 </view>
  80. <view class="level">
  81. <view class="mt20 ml10">
  82. <up-upload :fileList="fileList.waterA" @afterRead="afterRead" @delete="deletePic" name="waterA"
  83. multiple :maxCount="1" width="131rpx" height="131rpx" :disabled="isRead">
  84. <image src="/static/images/ydd/add_photo.png" mode="" :style="{width:'131rpx',height:'131rpx'}">
  85. </image>
  86. </up-upload>
  87. <view class="jus-center level" :style="{color:'#999999',fontSize:'22rpx',width:'131rpx'}"></view>
  88. </view>
  89. <view class="mt20 ml10 ml28">
  90. <up-upload :fileList="fileList.waterB" @afterRead="afterRead" @delete="deletePic" name="waterB"
  91. multiple :maxCount="1" width="131rpx" height="131rpx" :disabled="isRead">
  92. <image src="/static/images/ydd/add_photo.png" mode="" :style="{width:'131rpx',height:'131rpx'}">
  93. </image>
  94. </up-upload>
  95. <view class="jus-center level" :style="{color:'#999999',fontSize:'22rpx',width:'131rpx'}"></view>
  96. </view>
  97. </view>
  98. <view class="mt32 ml10" :style="{fontSize:'30rpx',fontWeight:'400'}">猫砂盆尿垫前后对比 </view>
  99. <view class="level">
  100. <view class="mt20 ml10">
  101. <up-upload :fileList="fileList.urinalA" @afterRead="afterRead" @delete="deletePic" name="urinalA"
  102. multiple :maxCount="1" width="131rpx" height="131rpx" :disabled="isRead">
  103. <image src="/static/images/ydd/add_photo.png" mode="" :style="{width:'131rpx',height:'131rpx'}">
  104. </image>
  105. </up-upload>
  106. <view class="jus-center level" :style="{color:'#999999',fontSize:'22rpx',width:'131rpx'}"></view>
  107. </view>
  108. <view class="mt20 ml10 ml28">
  109. <up-upload :fileList="fileList.urinalB" @afterRead="afterRead" @delete="deletePic" name="urinalB"
  110. multiple :maxCount="1" width="131rpx" height="131rpx" :disabled="isRead">
  111. <image src="/static/images/ydd/add_photo.png" mode="" :style="{width:'131rpx',height:'131rpx'}">
  112. </image>
  113. </up-upload>
  114. <view class="jus-center level" :style="{color:'#999999',fontSize:'22rpx',width:'131rpx'}"></view>
  115. </view>
  116. </view>
  117. </view>
  118. <view class="top mt24 box-size" :style="{borderRadius:'16rpx'}">
  119. <view class="form-title">
  120. 定制服务记录
  121. </view>
  122. <view class="mt32 ml10">
  123. <span :style="{fontSize:'30rpx',fontWeight:'400'}">遛狗</span>
  124. <span :style="{fontSize:'22rpx',color:'#C7C7C7'}">(2-3)</span>
  125. </view>
  126. <view class="level">
  127. <view class="mt20 ml10 mr20">
  128. <up-upload :fileList="fileList.testa" @afterRead="afterRead" @delete="deletePic" name="testa"
  129. multiple :maxCount="3" width="131rpx" height="131rpx" :disabled="isRead">
  130. <image src="/static/images/ydd/add_photo.png" mode="" :style="{width:'131rpx',height:'131rpx'}">
  131. </image>
  132. </up-upload>
  133. </view>
  134. </view>
  135. <view class="mt32 ml10">
  136. <span :style="{fontSize:'30rpx',fontWeight:'400'}">陪玩</span>
  137. <span :style="{fontSize:'22rpx',color:'#C7C7C7'}">(2-3)</span>
  138. </view>
  139. <view class="level">
  140. <view class="mt20 ml10 mr20">
  141. <up-upload :fileList="fileList.testb" @afterRead="afterRead" @delete="deletePic" name="testb"
  142. multiple :maxCount="3" width="131rpx" height="131rpx" :disabled="isRead">
  143. <image src="/static/images/ydd/add_photo.png" mode="" :style="{width:'131rpx',height:'131rpx'}">
  144. </image>
  145. </up-upload>
  146. </view>
  147. </view>
  148. </view>
  149. <view class="top mt24 box-size" :style="{borderRadius:'16rpx'}">
  150. <view class="form-title">
  151. 其他补充信息(非必填)
  152. </view>
  153. <view class="mt32 ml10" :style="{color:'#999999',fontSize:'30rpx'}">
  154. 可记录一下今日趣事宠物状况提醒事项等
  155. </view>
  156. <view class="mt24">
  157. <textarea name="" id="" cols="30" rows="10" placeholder="请输入内容"
  158. :style="{color:'#999999',fontSize:'30rpx',backgroundColor:'#F5F5F5',borderRadius:'16rpx',width:'681rpx',height:'180rpx'}"
  159. class="pd20 box-size" :disabled="isRead"></textarea>
  160. </view>
  161. </view>
  162. <view class="buttom mt60 box-size"
  163. style="display: flex;gap: 20rpx;"
  164. >
  165. <view class="buttom-item buttom-item-2 level size-30"
  166. @click="saveDraft(false)"
  167. :style="{borderRadius:'41rpx',color:'#ff842c'}">
  168. 保存草稿
  169. </view>
  170. <view class="buttom-item level size-30"
  171. @click="submit"
  172. :style="{borderRadius:'41rpx',color:'#fff'}">
  173. 确定提交
  174. </view>
  175. </view>
  176. </view>
  177. </template>
  178. <script setup>
  179. import {
  180. onMounted,
  181. reactive,
  182. ref,
  183. } from "vue";
  184. import {
  185. onLoad
  186. } from '@dcloudio/uni-app'
  187. import {
  188. ossUpload
  189. } from '@/utils/oss-upload/oss/index.js'
  190. import { orderItemLogGetByOrderId } from '@/api/order/order.js'
  191. import {
  192. getOrderPetById,
  193. orderItemLogAddOrUpdate,
  194. } from "@/api/order/order.js";
  195. onLoad((options) => {
  196. orderId.value = options.id || null;
  197. isRead.value = options.isRead || false;
  198. GetByOrderId()
  199. });
  200. const orderId = ref(0)
  201. const isRead = ref(false)
  202. const fileList = reactive({
  203. // glove: [],//手套
  204. // ShoeCover: [],//鞋套
  205. // food: [],//粮碗
  206. // water: [],//水碗
  207. // urinal: [],//猫砂盆、尿盆
  208. })
  209. const form = ref({})
  210. const petList = ref([
  211. // {
  212. // title: '小汪'
  213. // },
  214. // {
  215. // title: '大黄'
  216. // },
  217. ])
  218. // 删除图片
  219. const deletePic = (event) => {
  220. if (fileList[event.name]) {
  221. fileList[event.name].splice(event.index, 1);
  222. }
  223. };
  224. // 新增图片
  225. const afterRead = (event) => {
  226. if (!fileList[event.name]) {
  227. fileList[event.name] = []
  228. }
  229. event.file.forEach(n => {
  230. ossUpload(n.url)
  231. .then(url => {
  232. fileList[event.name].push({
  233. url
  234. })
  235. })
  236. })
  237. };
  238. function submit() {
  239. // 参数效验
  240. if (!fileList.glove || fileList.glove.length == 0) {
  241. return msg('请上传鞋套照片')
  242. }
  243. if (!fileList.ShoeCover || fileList.ShoeCover.length == 0) {
  244. return msg('请上传鞋套照片')
  245. }
  246. for (let i = 0; i < petList.value.length; i++) {
  247. if (!fileList['pet' + i] || fileList['pet' + i].length < 2) {
  248. return msg(`请上传${petList.value[i].title}照片`)
  249. }
  250. }
  251. if (!fileList.foodA || fileList.foodA.length < 1 ||
  252. !fileList.foodB || fileList.foodB.length < 1) {
  253. return msg('请上传粮碗前后照片')
  254. }
  255. if (!fileList.waterA || fileList.waterA.length < 1 ||
  256. !fileList.waterB || fileList.waterB.length < 1) {
  257. return msg('请上传水碗前后照片')
  258. }
  259. if (!fileList.urinalA || fileList.urinalA.length < 1 ||
  260. !fileList.urinalB || fileList.urinalB.length < 1) {
  261. return msg('请上传猫砂盆、尿盆照片')
  262. }
  263. saveDraft(true)
  264. }
  265. function GetByOrderId(){
  266. orderItemLogGetByOrderId(orderId.value)
  267. .then(res => {
  268. if(res.code == 200 && res.data) {
  269. const data = res.data;
  270. form.value = data
  271. // 回显手套照片
  272. if(data.glovePhoto) {
  273. fileList.glove = data.glovePhoto.split(',').map(url => ({ url }));
  274. }
  275. // 回显鞋套照片
  276. if(data.shoeCoverPhoto) {
  277. fileList.ShoeCover = data.shoeCoverPhoto.split(',').map(url => ({ url }));
  278. }
  279. // 回显宠物照片
  280. if(data.petPhoto) {
  281. const pets = JSON.parse(data.petPhoto);
  282. petList.value = pets;
  283. pets.forEach((pet, index) => {
  284. if(pet.fileList) {
  285. fileList['pet' + index] = pet.fileList.split(',').map(url => ({ url }));
  286. }
  287. });
  288. }
  289. // 回显粮碗照片
  290. if(data.grainBowlFront) fileList.foodA = data.grainBowlFront.split(',').map(url => ({ url }));
  291. if(data.grainBowlAfter) fileList.foodB = data.grainBowlAfter.split(',').map(url => ({ url }));
  292. // 回显水碗照片
  293. if(data.waterBowlFront) fileList.waterA = data.waterBowlFront.split(',').map(url => ({ url }));
  294. if(data.waterBowlAfter) fileList.waterB = data.waterBowlAfter.split(',').map(url => ({ url }));
  295. // 回显猫砂盆/尿垫照片
  296. if(data.basinFront) fileList.urinalA = data.basinFront.split(',').map(url => ({ url }));
  297. if(data.basinAfter) fileList.urinalB = data.basinAfter.split(',').map(url => ({ url }));
  298. // 回显定制服务照片
  299. if(data.workDogImage) fileList.testa = data.workDogImage.split(',').map(url => ({ url }));
  300. if(data.workPalyImage) fileList.testb = data.workPalyImage.split(',').map(url => ({ url }));
  301. }else{
  302. getOrderPetByIdFN()
  303. }
  304. })
  305. }
  306. function getOrderPetByIdFN(){
  307. getOrderPetById(orderId.value)
  308. .then(res => {
  309. if(res.code == 200){
  310. res.data.forEach((n, i) => {
  311. fileList['pet' + i] = []
  312. })
  313. res.data.forEach((n, i) => {
  314. petList.value.push({
  315. title : n.name,
  316. id : n.id,
  317. })
  318. })
  319. }
  320. })
  321. }
  322. function saveDraft(flag) {
  323. // 将所有图片数组转换为逗号分隔的字符串
  324. const params = {
  325. orderId: orderId.value,
  326. glovePhoto: fileList.glove?.map(item => item.url).join(',') || '',
  327. shoeCoverPhoto: fileList.ShoeCover?.map(item => item.url).join(',') || '',
  328. // 合并所有宠物照片
  329. petPhoto: JSON.stringify(
  330. petList.value.map((pet, index) => {
  331. return {
  332. id : pet.id,
  333. title : pet.title,
  334. fileList: fileList['pet' + index]?.map(item => item.url).join(',') || ''
  335. };
  336. })
  337. ),
  338. // 粮碗照片
  339. grainBowlFront: fileList.foodA?.map(item => item.url).join(',') || '',
  340. grainBowlAfter: fileList.foodB?.map(item => item.url).join(',') || '',
  341. // 水碗照片
  342. waterBowlFront: fileList.waterA?.map(item => item.url).join(',') || '',
  343. waterBowlAfter: fileList.waterB?.map(item => item.url).join(',') || '',
  344. // 猫砂盆/尿垫照片
  345. basinFront: fileList.urinalA?.map(item => item.url).join(',') || '',
  346. basinAfter: fileList.urinalB?.map(item => item.url).join(',') || '',
  347. // 定制服务照片
  348. workDogImage: fileList.testa?.map(item => item.url).join(',') || '',
  349. workPalyImage: fileList.testb?.map(item => item.url).join(',') || '',
  350. // 备注信息
  351. notes: form.value.notes || '',
  352. submitFlag : 1,
  353. }
  354. if(form.value.id) {
  355. params.id = form.value.id
  356. }
  357. if(flag) {
  358. params.submitFlag = 2
  359. }
  360. orderItemLogAddOrUpdate(params)
  361. .then(res => {
  362. if(res.code === 200) {
  363. uni.showToast({
  364. title: '提交成功',
  365. icon: 'success'
  366. })
  367. // 如果是确认提交(非草稿),则返回上一页
  368. if(flag) {
  369. setTimeout(() => {
  370. uni.navigateBack()
  371. }, 1500)
  372. }
  373. } else {
  374. uni.showToast({
  375. title: res.msg || '提交失败',
  376. icon: 'none'
  377. })
  378. }
  379. })
  380. .catch(err => {
  381. uni.showToast({
  382. title: '提交失败',
  383. icon: 'none'
  384. })
  385. })
  386. }
  387. function msg(content) {
  388. uni.showToast({
  389. title: content,
  390. icon: 'none'
  391. })
  392. }
  393. </script>
  394. <style scoped lang="scss">
  395. @import"index.scss"
  396. </style>