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

454 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. itemOrderID.value = options.itemID
  199. serviceId.value = options.serviceId;
  200. GetByOrderId()
  201. });
  202. const orderId = ref(0)
  203. const itemOrderID = ref(0)
  204. const serviceId = ref(0)
  205. const isRead = ref(false)
  206. const fileList = reactive({
  207. // glove: [],//手套
  208. // ShoeCover: [],//鞋套
  209. // food: [],//粮碗
  210. // water: [],//水碗
  211. // urinal: [],//猫砂盆、尿盆
  212. })
  213. const form = ref({})
  214. const petList = ref([
  215. // {
  216. // title: '小汪'
  217. // },
  218. // {
  219. // title: '大黄'
  220. // },
  221. ])
  222. // 删除图片
  223. const deletePic = (event) => {
  224. if (fileList[event.name]) {
  225. fileList[event.name].splice(event.index, 1);
  226. }
  227. };
  228. // 新增图片
  229. const afterRead = (event) => {
  230. if (!fileList[event.name]) {
  231. fileList[event.name] = []
  232. }
  233. event.file.forEach(n => {
  234. ossUpload(n.url)
  235. .then(url => {
  236. fileList[event.name].push({
  237. url
  238. })
  239. })
  240. })
  241. };
  242. function submit() {
  243. // 参数效验
  244. if (!fileList.glove || fileList.glove.length == 0) {
  245. return msg('请上传鞋套照片')
  246. }
  247. if (!fileList.ShoeCover || fileList.ShoeCover.length == 0) {
  248. return msg('请上传鞋套照片')
  249. }
  250. for (let i = 0; i < petList.value.length; i++) {
  251. if (!fileList['pet' + i] || fileList['pet' + i].length < 2) {
  252. return msg(`请上传${petList.value[i].title}照片`)
  253. }
  254. }
  255. if (!fileList.foodA || fileList.foodA.length < 1 ||
  256. !fileList.foodB || fileList.foodB.length < 1) {
  257. return msg('请上传粮碗前后照片')
  258. }
  259. if (!fileList.waterA || fileList.waterA.length < 1 ||
  260. !fileList.waterB || fileList.waterB.length < 1) {
  261. return msg('请上传水碗前后照片')
  262. }
  263. if (!fileList.urinalA || fileList.urinalA.length < 1 ||
  264. !fileList.urinalB || fileList.urinalB.length < 1) {
  265. return msg('请上传猫砂盆、尿盆照片')
  266. }
  267. saveDraft(true)
  268. }
  269. function GetByOrderId(){
  270. orderItemLogGetByOrderId(serviceId.value)
  271. .then(res => {
  272. if(res.code == 200 && res.data) {
  273. const data = res.data;
  274. form.value = data
  275. // 回显手套照片
  276. if(data.glovePhoto) {
  277. fileList.glove = data.glovePhoto.split(',').map(url => ({ url }));
  278. }
  279. // 回显鞋套照片
  280. if(data.shoeCoverPhoto) {
  281. fileList.ShoeCover = data.shoeCoverPhoto.split(',').map(url => ({ url }));
  282. }
  283. // 回显宠物照片
  284. if(data.petPhoto) {
  285. const pets = JSON.parse(data.petPhoto);
  286. petList.value = pets;
  287. pets.forEach((pet, index) => {
  288. if(pet.fileList) {
  289. fileList['pet' + index] = pet.fileList.split(',').map(url => ({ url }));
  290. }
  291. });
  292. }
  293. // 回显粮碗照片
  294. if(data.grainBowlFront) fileList.foodA = data.grainBowlFront.split(',').map(url => ({ url }));
  295. if(data.grainBowlAfter) fileList.foodB = data.grainBowlAfter.split(',').map(url => ({ url }));
  296. // 回显水碗照片
  297. if(data.waterBowlFront) fileList.waterA = data.waterBowlFront.split(',').map(url => ({ url }));
  298. if(data.waterBowlAfter) fileList.waterB = data.waterBowlAfter.split(',').map(url => ({ url }));
  299. // 回显猫砂盆/尿垫照片
  300. if(data.basinFront) fileList.urinalA = data.basinFront.split(',').map(url => ({ url }));
  301. if(data.basinAfter) fileList.urinalB = data.basinAfter.split(',').map(url => ({ url }));
  302. // 回显定制服务照片
  303. if(data.workDogImage) fileList.testa = data.workDogImage.split(',').map(url => ({ url }));
  304. if(data.workPalyImage) fileList.testb = data.workPalyImage.split(',').map(url => ({ url }));
  305. }else{
  306. getOrderPetByIdFN()
  307. }
  308. })
  309. }
  310. function getOrderPetByIdFN(){
  311. getOrderPetById(orderId.value)
  312. .then(res => {
  313. if(res.code == 200){
  314. res.data.forEach((n, i) => {
  315. fileList['pet' + i] = []
  316. })
  317. res.data.forEach((n, i) => {
  318. petList.value.push({
  319. title : n.name,
  320. id : n.id,
  321. })
  322. })
  323. }
  324. })
  325. }
  326. function saveDraft(flag) {
  327. // 将所有图片数组转换为逗号分隔的字符串
  328. const params = {
  329. orderId: orderId.value,
  330. itemOrderId : itemOrderID.value,
  331. itemDateId : serviceId.value,
  332. glovePhoto: fileList.glove?.map(item => item.url).join(',') || '',
  333. shoeCoverPhoto: fileList.ShoeCover?.map(item => item.url).join(',') || '',
  334. // 合并所有宠物照片
  335. petPhoto: JSON.stringify(
  336. petList.value.map((pet, index) => {
  337. return {
  338. id : pet.id,
  339. title : pet.title,
  340. fileList: fileList['pet' + index]?.map(item => item.url).join(',') || ''
  341. };
  342. })
  343. ),
  344. // 粮碗照片
  345. grainBowlFront: fileList.foodA?.map(item => item.url).join(',') || '',
  346. grainBowlAfter: fileList.foodB?.map(item => item.url).join(',') || '',
  347. // 水碗照片
  348. waterBowlFront: fileList.waterA?.map(item => item.url).join(',') || '',
  349. waterBowlAfter: fileList.waterB?.map(item => item.url).join(',') || '',
  350. // 猫砂盆/尿垫照片
  351. basinFront: fileList.urinalA?.map(item => item.url).join(',') || '',
  352. basinAfter: fileList.urinalB?.map(item => item.url).join(',') || '',
  353. // 定制服务照片
  354. workDogImage: fileList.testa?.map(item => item.url).join(',') || '',
  355. workPalyImage: fileList.testb?.map(item => item.url).join(',') || '',
  356. // 备注信息
  357. notes: form.value.notes || '',
  358. submitFlag : 1,
  359. }
  360. if(form.value.id) {
  361. params.id = form.value.id
  362. }
  363. if(flag) {
  364. params.submitFlag = 2
  365. }
  366. orderItemLogAddOrUpdate(params)
  367. .then(res => {
  368. if(res.code === 200) {
  369. uni.showToast({
  370. title: '提交成功',
  371. icon: 'success'
  372. })
  373. // 如果是确认提交(非草稿),则返回上一页
  374. setTimeout(() => {
  375. uni.navigateBack()
  376. }, 1500)
  377. } else {
  378. uni.showToast({
  379. title: res.msg || '提交失败',
  380. icon: 'none'
  381. })
  382. }
  383. })
  384. .catch(err => {
  385. uni.showToast({
  386. title: '提交失败',
  387. icon: 'none'
  388. })
  389. })
  390. }
  391. function msg(content) {
  392. uni.showToast({
  393. title: content,
  394. icon: 'none'
  395. })
  396. }
  397. </script>
  398. <style scoped lang="scss">
  399. @import"index.scss"
  400. </style>