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

460 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:'26rpx',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:'26rpx',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:'26rpx',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:'26rpx',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:'26rpx',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 cols="30" rows="10"
  158. placeholder="请输入内容"
  159. v-model="content"
  160. :style="{color:'#999999',fontSize:'30rpx',backgroundColor:'#F5F5F5',borderRadius:'16rpx',width:'681rpx',height:'180rpx'}"
  161. class="pd20 box-size" :disabled="isRead"></textarea>
  162. </view>
  163. </view>
  164. <view class="buttom mt60 box-size"
  165. style="display: flex;gap: 20rpx;"
  166. >
  167. <view class="buttom-item buttom-item-2 level size-30"
  168. @click="saveDraft(false)"
  169. :style="{borderRadius:'41rpx',color:'#ff842c'}">
  170. 保存草稿
  171. </view>
  172. <view class="buttom-item level size-30"
  173. @click="submit"
  174. :style="{borderRadius:'41rpx',color:'#fff'}">
  175. 确定提交
  176. </view>
  177. </view>
  178. </view>
  179. </template>
  180. <script setup>
  181. import {
  182. onMounted,
  183. reactive,
  184. ref,
  185. } from "vue";
  186. import {
  187. onLoad
  188. } from '@dcloudio/uni-app'
  189. import {
  190. ossUpload
  191. } from '@/utils/oss-upload/oss/index.js'
  192. import { orderItemLogGetByOrderId } from '@/api/order/order.js'
  193. import {
  194. getOrderPetById,
  195. orderItemLogAddOrUpdate,
  196. } from "@/api/order/order.js";
  197. onLoad((options) => {
  198. orderId.value = options.id || null;
  199. isRead.value = options.isRead || false;
  200. itemOrderID.value = options.itemID
  201. serviceId.value = options.serviceId;
  202. GetByOrderId()
  203. });
  204. const orderId = ref(0)
  205. const itemOrderID = ref(0)
  206. const serviceId = ref(0)
  207. const isRead = ref(false)
  208. const content = ref('')
  209. const fileList = reactive({
  210. // glove: [],//手套
  211. // ShoeCover: [],//鞋套
  212. // food: [],//粮碗
  213. // water: [],//水碗
  214. // urinal: [],//猫砂盆、尿盆
  215. })
  216. const form = ref({})
  217. const petList = ref([
  218. // {
  219. // title: '小汪'
  220. // },
  221. // {
  222. // title: '大黄'
  223. // },
  224. ])
  225. // 删除图片
  226. const deletePic = (event) => {
  227. if (fileList[event.name]) {
  228. fileList[event.name].splice(event.index, 1);
  229. }
  230. };
  231. // 新增图片
  232. const afterRead = (event) => {
  233. if (!fileList[event.name]) {
  234. fileList[event.name] = []
  235. }
  236. event.file.forEach(n => {
  237. ossUpload(n.url)
  238. .then(url => {
  239. fileList[event.name].push({
  240. url
  241. })
  242. })
  243. })
  244. };
  245. function submit() {
  246. // 参数效验
  247. if (!fileList.glove || fileList.glove.length == 0) {
  248. return msg('请上传鞋套照片')
  249. }
  250. if (!fileList.ShoeCover || fileList.ShoeCover.length == 0) {
  251. return msg('请上传鞋套照片')
  252. }
  253. for (let i = 0; i < petList.value.length; i++) {
  254. if (!fileList['pet' + i] || fileList['pet' + i].length < 2) {
  255. return msg(`请上传${petList.value[i].title}照片`)
  256. }
  257. }
  258. if (!fileList.foodA || fileList.foodA.length < 1 ||
  259. !fileList.foodB || fileList.foodB.length < 1) {
  260. return msg('请上传粮碗前后照片')
  261. }
  262. if (!fileList.waterA || fileList.waterA.length < 1 ||
  263. !fileList.waterB || fileList.waterB.length < 1) {
  264. return msg('请上传水碗前后照片')
  265. }
  266. if (!fileList.urinalA || fileList.urinalA.length < 1 ||
  267. !fileList.urinalB || fileList.urinalB.length < 1) {
  268. return msg('请上传猫砂盆、尿盆照片')
  269. }
  270. if(!content.value){
  271. return msg('请填写补充信息')
  272. }
  273. saveDraft(true)
  274. }
  275. function GetByOrderId(){
  276. orderItemLogGetByOrderId(serviceId.value)
  277. .then(res => {
  278. if(res.code == 200 && res.data) {
  279. const data = res.data;
  280. form.value = data
  281. // 回显手套照片
  282. if(data.glovePhoto) {
  283. fileList.glove = data.glovePhoto.split(',').map(url => ({ url }));
  284. }
  285. // 回显鞋套照片
  286. if(data.shoeCoverPhoto) {
  287. fileList.ShoeCover = data.shoeCoverPhoto.split(',').map(url => ({ url }));
  288. }
  289. // 回显宠物照片
  290. if(data.petPhoto) {
  291. const pets = JSON.parse(data.petPhoto);
  292. petList.value = pets;
  293. pets.forEach((pet, index) => {
  294. if(pet.fileList) {
  295. fileList['pet' + index] = pet.fileList.split(',').map(url => ({ url }));
  296. }
  297. });
  298. }
  299. // 回显粮碗照片
  300. if(data.grainBowlFront) fileList.foodA = data.grainBowlFront.split(',').map(url => ({ url }));
  301. if(data.grainBowlAfter) fileList.foodB = data.grainBowlAfter.split(',').map(url => ({ url }));
  302. // 回显水碗照片
  303. if(data.waterBowlFront) fileList.waterA = data.waterBowlFront.split(',').map(url => ({ url }));
  304. if(data.waterBowlAfter) fileList.waterB = data.waterBowlAfter.split(',').map(url => ({ url }));
  305. // 回显猫砂盆/尿垫照片
  306. if(data.basinFront) fileList.urinalA = data.basinFront.split(',').map(url => ({ url }));
  307. if(data.basinAfter) fileList.urinalB = data.basinAfter.split(',').map(url => ({ url }));
  308. // 回显定制服务照片
  309. if(data.workDogImage) fileList.testa = data.workDogImage.split(',').map(url => ({ url }));
  310. if(data.workPalyImage) fileList.testb = data.workPalyImage.split(',').map(url => ({ url }));
  311. }else{
  312. getOrderPetByIdFN()
  313. }
  314. })
  315. }
  316. function getOrderPetByIdFN(){
  317. getOrderPetById(orderId.value)
  318. .then(res => {
  319. if(res.code == 200){
  320. res.data.forEach((n, i) => {
  321. fileList['pet' + i] = []
  322. })
  323. res.data.forEach((n, i) => {
  324. petList.value.push({
  325. title : n.name,
  326. id : n.id,
  327. })
  328. })
  329. }
  330. })
  331. }
  332. function saveDraft(flag) {
  333. // 将所有图片数组转换为逗号分隔的字符串
  334. const params = {
  335. orderId: orderId.value,
  336. itemOrderId : itemOrderID.value,
  337. itemDateId : serviceId.value,
  338. glovePhoto: fileList.glove?.map(item => item.url).join(',') || '',
  339. shoeCoverPhoto: fileList.ShoeCover?.map(item => item.url).join(',') || '',
  340. // 合并所有宠物照片
  341. petPhoto: JSON.stringify(
  342. petList.value.map((pet, index) => {
  343. return {
  344. id : pet.id,
  345. title : pet.title,
  346. fileList: fileList['pet' + index]?.map(item => item.url).join(',') || ''
  347. };
  348. })
  349. ),
  350. // 粮碗照片
  351. grainBowlFront: fileList.foodA?.map(item => item.url).join(',') || '',
  352. grainBowlAfter: fileList.foodB?.map(item => item.url).join(',') || '',
  353. // 水碗照片
  354. waterBowlFront: fileList.waterA?.map(item => item.url).join(',') || '',
  355. waterBowlAfter: fileList.waterB?.map(item => item.url).join(',') || '',
  356. // 猫砂盆/尿垫照片
  357. basinFront: fileList.urinalA?.map(item => item.url).join(',') || '',
  358. basinAfter: fileList.urinalB?.map(item => item.url).join(',') || '',
  359. // 定制服务照片
  360. workDogImage: fileList.testa?.map(item => item.url).join(',') || '',
  361. workPalyImage: fileList.testb?.map(item => item.url).join(',') || '',
  362. // 备注信息
  363. notes: form.value.notes || '',
  364. }
  365. if(form.value.id) {
  366. params.id = form.value.id
  367. }
  368. if(flag) {
  369. params.submitFlag = 1
  370. }
  371. orderItemLogAddOrUpdate(params)
  372. .then(res => {
  373. if(res.code === 200) {
  374. uni.showToast({
  375. title: '提交成功',
  376. icon: 'success'
  377. })
  378. // 如果是确认提交(非草稿),则返回上一页
  379. setTimeout(() => {
  380. uni.navigateBack()
  381. }, 1500)
  382. } else {
  383. uni.showToast({
  384. title: res.msg || '提交失败',
  385. icon: 'none'
  386. })
  387. }
  388. })
  389. .catch(err => {
  390. uni.showToast({
  391. title: '提交失败',
  392. icon: 'none'
  393. })
  394. })
  395. }
  396. function msg(content) {
  397. uni.showToast({
  398. title: content,
  399. icon: 'none'
  400. })
  401. }
  402. </script>
  403. <style scoped lang="scss">
  404. @import"index.scss"
  405. </style>