record.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <!-- 使用 type="home" 属性设置首页,其他页面不需要设置,默认为page;推荐使用json5,更强大,且允许注释 -->
  2. <route lang="json5" type="feed">
  3. {
  4. style: {
  5. navigationStyle: 'custom',
  6. navigationBarTitleText: '%feed.records%',
  7. },
  8. }
  9. </route>
  10. <template>
  11. <view class="min-h-screen bg-[#F2F2F2] box-border pb-35">
  12. <wd-navbar
  13. :title="title"
  14. left-arrow
  15. fixed
  16. :bordered="false"
  17. :placeholder="true"
  18. :safeAreaInsetTop="true"
  19. @click-left="handleClickLeft"
  20. >
  21. <template v-if="show" #right>
  22. <view @click="handleClickRight">
  23. <image class="w-[40rpx] h-[40rpx]" :src="deleteSvg" mode="widthFix" />
  24. <!-- <wd-icon name="delete" size="40rpx" color="#FB4848"></wd-icon> -->
  25. </view>
  26. </template>
  27. </wd-navbar>
  28. <wd-form ref="formRef" :model="formData">
  29. <ItemForm label="记录类型">
  30. <template #default>
  31. <PickerInfo
  32. title="记录类型"
  33. :columns="columns"
  34. v-model:value="formData.type"
  35. @confirm="handleConfirm"
  36. />
  37. </template>
  38. </ItemForm>
  39. <NurseForm
  40. v-model:nurseMethod="formData.nurseMethod"
  41. v-model:type="formData.type"
  42. v-model:startTime="formData.startTime"
  43. v-model:endTime="formData.endTime"
  44. v-model:complementaryName="formData.complementaryName"
  45. v-model:milkOutput="formData.milkOutput"
  46. v-model:hasStool="formData.hasStool"
  47. />
  48. <ItemForm :border="false" label="备注">
  49. <template #default>
  50. <view class="px-4 mt-[16rpx] box-border">
  51. <view class="rounded-lg bg-[#F2F2F2]">
  52. <wd-textarea
  53. clear-trigger="focus"
  54. auto-height
  55. placeholder="填写备注信息"
  56. v-model="formData.remark"
  57. :maxlength="120"
  58. no-border
  59. show-word-limit
  60. />
  61. </view>
  62. </view>
  63. </template>
  64. </ItemForm>
  65. <wd-gap bg-color="#F2F2F2"></wd-gap>
  66. <ItemForm :border="false" label="图片">
  67. <template #default>
  68. <view class="px-4 mt-3">
  69. <wd-upload
  70. :file-list="formData.images"
  71. image-mode="aspectFill"
  72. :header="{
  73. Authorization: '1234',
  74. project: '123',
  75. }"
  76. :action="uploadUrl"
  77. multiple
  78. @change="handleChangeImage"
  79. :before-remove="beforeRemove"
  80. >
  81. <template #default>
  82. <view
  83. class="flex justify-center items-center w-[160rpx] h-[160rpx] rounded bg-[#F2F2F2]"
  84. >
  85. <wd-icon name="add" color="#666" size="48rpx"></wd-icon>
  86. </view>
  87. </template>
  88. </wd-upload>
  89. </view>
  90. </template>
  91. </ItemForm>
  92. <view
  93. class="w-full box-border fixed bottom-0 left-0 px-4 pt-2 pb-8 bg-white"
  94. :style="{ marginBottom: safeAreaInsets?.bottom + 'px' }"
  95. >
  96. <wd-button size="large" @click="handleSubmit" block>保存</wd-button>
  97. </view>
  98. </wd-form>
  99. <wd-toast />
  100. <wd-message-box />
  101. </view>
  102. </template>
  103. <script setup>
  104. import deleteSvg from '@/static/images/delete.svg'
  105. import PickerInfo from '@/components/picker-info/picker-info.vue'
  106. import ItemForm from '@/components/item-form/item-form.vue'
  107. import NurseForm from '@/components/item-form/nurse-form.vue'
  108. import typeDataList from '@/components/feed-wd-popup/data.json'
  109. import { ref, reactive } from 'vue'
  110. import { useToast, useMessage } from 'wot-design-uni'
  111. import { onLoad } from '@dcloudio/uni-app'
  112. const messageBox = useMessage()
  113. const toast = useToast()
  114. const uploadUrl = `${import.meta.env.VITE_UPLOAD_BASEURL}/admin/app/tourismProjectTravelNotesWrite/upload`
  115. // 获取屏幕边界到安全区域距离
  116. const { safeAreaInsets } = uni.getSystemInfoSync()
  117. const columns = ref(
  118. typeDataList.map(({ title, type }) => ({
  119. label: title,
  120. value: type,
  121. })),
  122. )
  123. const message = useMessage()
  124. const show = ref(false)
  125. const title = ref('')
  126. const formRef = ref('')
  127. // 表单数据
  128. const formData = reactive({
  129. id: '',
  130. type: 1, //记录类型
  131. nurseMethod: 1, // 喂奶方式
  132. complementaryName: '', // 辅食名称
  133. hasStool: 1, //有无粪便
  134. milkOutput: '', //吸奶量
  135. startTime: null,
  136. endTime: null,
  137. remark: '', //备注
  138. images: [], //图片
  139. })
  140. // 新增喂养记录和修改喂养记录提交按钮
  141. function handleSubmit() {
  142. // 添加宝宝的接口 /baby/bt_feed_record/add
  143. formRef.value
  144. .validate()
  145. .then(({ valid, errors }) => {
  146. console.log(valid, 'valid')
  147. if (valid) {
  148. }
  149. })
  150. .catch((error) => {
  151. console.log(error, 'error')
  152. })
  153. console.log(formData, 'handleSubmit')
  154. }
  155. // 删除这条数据
  156. function handleDelete(id) {
  157. console.log(id, 'handleDelete')
  158. toast.loading('删除中...')
  159. setTimeout(() => {
  160. toast.close()
  161. toast.success('删除成功')
  162. }, 2000)
  163. }
  164. function handleClickRight() {
  165. message
  166. .confirm({
  167. msg: '确定删除记录吗?',
  168. })
  169. .then(() => {
  170. handleDelete()
  171. })
  172. .catch((error) => {
  173. console.log(error)
  174. })
  175. }
  176. function handleClickLeft() {
  177. uni.navigateBack()
  178. }
  179. function handleConfirm({ value, type }) {
  180. formData.type = value
  181. }
  182. // 图片上传
  183. function handleChangeImage({ fileList: files }) {
  184. formData.images = files
  185. }
  186. // 移除图片
  187. const beforeRemove = ({ file, fileList, resolve }) => {
  188. console.log(file, 555)
  189. console.log(formData.images, 555)
  190. formData.images
  191. messageBox
  192. .confirm({
  193. msg: '确定删除这张照片吗?',
  194. // title: '提示',
  195. })
  196. .then(() => {
  197. toast.success('删除成功')
  198. // resolve(true)
  199. })
  200. .catch(() => {
  201. toast.show('取消删除操作')
  202. })
  203. }
  204. //
  205. function changeFormData(types) {
  206. // if (types == 1) {
  207. // formData = {
  208. // ...formData,
  209. // nurseMethod: 1,
  210. // startTime: null,
  211. // endTime: null,
  212. // }
  213. // }
  214. // nurseMethod: 1, // 喂奶方式
  215. // complementaryName: '', // 辅食名称
  216. // hasStool: 1, //有无粪便
  217. // milkOutput: '', //吸奶量
  218. // startTime: null,
  219. // endTime: null,
  220. }
  221. onLoad(({ type, id }) => {
  222. if (id) {
  223. show.value = true
  224. title.value = '记录详情'
  225. // 获取详情的请求
  226. } else {
  227. show.value = false
  228. title.value = '新增记录'
  229. }
  230. formData.type = type
  231. formData.id = id ? id : ''
  232. })
  233. </script>
  234. <style scoped>
  235. ::v-deep .wd-textarea__value {
  236. padding: 24rpx;
  237. background-color: transparent;
  238. }
  239. ::v-deep .wd-textarea,
  240. ::v-deep .wd-textarea__count {
  241. background-color: transparent;
  242. }
  243. ::v-deep .wd-textarea__count {
  244. right: 56rpx;
  245. }
  246. ::v-deep .wd-button.is-primary {
  247. background: linear-gradient(270deg, #f88842 0%, #ffac78 100%);
  248. }
  249. ::v-deep .wd-input.is-large {
  250. padding: 8rpx 24rpx;
  251. }
  252. ::v-deep .wd-upload__close {
  253. top: 8rpx;
  254. right: 8rpx;
  255. }
  256. </style>