123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281 |
- <!-- 使用 type="home" 属性设置首页,其他页面不需要设置,默认为page;推荐使用json5,更强大,且允许注释 -->
- <route lang="json5" type="feed">
- {
- style: {
- navigationStyle: 'custom',
- navigationBarTitleText: '%feed.records%',
- },
- }
- </route>
- <template>
- <view class="min-h-screen bg-[#F2F2F2] box-border pb-35">
- <wd-navbar
- :title="title"
- left-arrow
- fixed
- :bordered="false"
- :placeholder="true"
- :safeAreaInsetTop="true"
- @click-left="handleClickLeft"
- >
- <template v-if="show" #right>
- <view @click="handleClickRight">
- <image class="w-[40rpx] h-[40rpx]" :src="deleteSvg" mode="widthFix" />
- <!-- <wd-icon name="delete" size="40rpx" color="#FB4848"></wd-icon> -->
- </view>
- </template>
- </wd-navbar>
- <wd-form ref="formRef" :model="formData">
- <ItemForm label="记录类型">
- <template #default>
- <PickerInfo
- title="记录类型"
- :columns="columns"
- v-model:value="formData.type"
- @confirm="handleConfirm"
- />
- </template>
- </ItemForm>
- <NurseForm
- v-model:nurseMethod="formData.nurseMethod"
- v-model:type="formData.type"
- v-model:startTime="formData.startTime"
- v-model:endTime="formData.endTime"
- v-model:complementaryName="formData.complementaryName"
- v-model:milkOutput="formData.milkOutput"
- v-model:hasStool="formData.hasStool"
- />
- <ItemForm :border="false" label="备注">
- <template #default>
- <view class="px-4 mt-[16rpx] box-border">
- <view class="rounded-lg bg-[#F2F2F2]">
- <wd-textarea
- clear-trigger="focus"
- auto-height
- placeholder="填写备注信息"
- v-model="formData.remark"
- :maxlength="120"
- no-border
- show-word-limit
- />
- </view>
- </view>
- </template>
- </ItemForm>
- <wd-gap bg-color="#F2F2F2"></wd-gap>
- <ItemForm :border="false" label="图片">
- <template #default>
- <view class="px-4 mt-3">
- <wd-upload
- :file-list="formData.images"
- image-mode="aspectFill"
- :header="{
- Authorization: '1234',
- project: '123',
- }"
- :action="uploadUrl"
- multiple
- @change="handleChangeImage"
- :before-remove="beforeRemove"
- >
- <template #default>
- <view
- class="flex justify-center items-center w-[160rpx] h-[160rpx] rounded bg-[#F2F2F2]"
- >
- <wd-icon name="add" color="#666" size="48rpx"></wd-icon>
- </view>
- </template>
- </wd-upload>
- </view>
- </template>
- </ItemForm>
- <view
- class="w-full box-border fixed bottom-0 left-0 px-4 pt-2 pb-8 bg-white"
- :style="{ marginBottom: safeAreaInsets?.bottom + 'px' }"
- >
- <wd-button size="large" @click="handleSubmit" block>保存</wd-button>
- </view>
- </wd-form>
- <wd-toast />
- <wd-message-box />
- </view>
- </template>
- <script setup>
- import deleteSvg from '@/static/images/delete.svg'
- import PickerInfo from '@/components/picker-info/picker-info.vue'
- import ItemForm from '@/components/item-form/item-form.vue'
- import NurseForm from '@/components/item-form/nurse-form.vue'
- import typeDataList from '@/components/feed-wd-popup/data.json'
- import { ref, reactive } from 'vue'
- import { useToast, useMessage } from 'wot-design-uni'
- import { onLoad } from '@dcloudio/uni-app'
- const messageBox = useMessage()
- const toast = useToast()
- const uploadUrl = `${import.meta.env.VITE_UPLOAD_BASEURL}/admin/app/tourismProjectTravelNotesWrite/upload`
- // 获取屏幕边界到安全区域距离
- const { safeAreaInsets } = uni.getSystemInfoSync()
- const columns = ref(
- typeDataList.map(({ title, type }) => ({
- label: title,
- value: type,
- })),
- )
- const message = useMessage()
- const show = ref(false)
- const title = ref('')
- const formRef = ref('')
- // 表单数据
- const formData = reactive({
- id: '',
- type: 1, //记录类型
- nurseMethod: 1, // 喂奶方式
- complementaryName: '', // 辅食名称
- hasStool: 1, //有无粪便
- milkOutput: '', //吸奶量
- startTime: null,
- endTime: null,
- remark: '', //备注
- images: [], //图片
- })
- // 新增喂养记录和修改喂养记录提交按钮
- function handleSubmit() {
- // 添加宝宝的接口 /baby/bt_feed_record/add
- formRef.value
- .validate()
- .then(({ valid, errors }) => {
- console.log(valid, 'valid')
- if (valid) {
- }
- })
- .catch((error) => {
- console.log(error, 'error')
- })
- console.log(formData, 'handleSubmit')
- }
- // 删除这条数据
- function handleDelete(id) {
- console.log(id, 'handleDelete')
- toast.loading('删除中...')
- setTimeout(() => {
- toast.close()
- toast.success('删除成功')
- }, 2000)
- }
- function handleClickRight() {
- message
- .confirm({
- msg: '确定删除记录吗?',
- })
- .then(() => {
- handleDelete()
- })
- .catch((error) => {
- console.log(error)
- })
- }
- function handleClickLeft() {
- uni.navigateBack()
- }
- function handleConfirm({ value, type }) {
- formData.type = value
- }
- // 图片上传
- function handleChangeImage({ fileList: files }) {
- formData.images = files
- }
- // 移除图片
- const beforeRemove = ({ file, fileList, resolve }) => {
- console.log(file, 555)
- console.log(formData.images, 555)
- formData.images
- messageBox
- .confirm({
- msg: '确定删除这张照片吗?',
- // title: '提示',
- })
- .then(() => {
- toast.success('删除成功')
- // resolve(true)
- })
- .catch(() => {
- toast.show('取消删除操作')
- })
- }
- //
- function changeFormData(types) {
- // if (types == 1) {
- // formData = {
- // ...formData,
- // nurseMethod: 1,
- // startTime: null,
- // endTime: null,
- // }
- // }
- // nurseMethod: 1, // 喂奶方式
- // complementaryName: '', // 辅食名称
- // hasStool: 1, //有无粪便
- // milkOutput: '', //吸奶量
- // startTime: null,
- // endTime: null,
- }
- onLoad(({ type, id }) => {
- if (id) {
- show.value = true
- title.value = '记录详情'
- // 获取详情的请求
- } else {
- show.value = false
- title.value = '新增记录'
- }
- formData.type = type
- formData.id = id ? id : ''
- })
- </script>
- <style scoped>
- ::v-deep .wd-textarea__value {
- padding: 24rpx;
- background-color: transparent;
- }
- ::v-deep .wd-textarea,
- ::v-deep .wd-textarea__count {
- background-color: transparent;
- }
- ::v-deep .wd-textarea__count {
- right: 56rpx;
- }
- ::v-deep .wd-button.is-primary {
- background: linear-gradient(270deg, #f88842 0%, #ffac78 100%);
- }
- ::v-deep .wd-input.is-large {
- padding: 8rpx 24rpx;
- }
- ::v-deep .wd-upload__close {
- top: 8rpx;
- right: 8rpx;
- }
- </style>
|