mkm
/
yanzhiAPP
Template
2
0
Fork 0
yanzhiAPP/pages/growRecord/fish.vue

649 lines
14 KiB
Vue
Raw Normal View History

2023-10-28 18:28:10 +08:00
<template>
<view :class="{popupShow:showPop}">
<view class="cont">
2023-10-31 18:40:32 +08:00
<!-- <landInfo :land_id='land_id'></landInfo> -->
2023-10-30 19:09:40 +08:00
<pondCard :id='pond_id'></pondCard>
<view class="operate" v-for="(item,index) in actionData" :key="index" v-show="title==index">
2023-10-28 18:28:10 +08:00
<view class="tit">
{{index}}
</view>
<view class="card">
<view class="operate-li" style="margin: 20rpx 0;margin-right: 20rpx;" @click="showPopFn(items.id)"
v-for="items,indexs in item.actions" :key='indexs'>
{{items.name}}
</view>
</view>
</view>
<view class="fertilize" v-for="(item,index) in actionList" :key="index">
<view class="card" style="padding-bottom: 0;">
<view class="fertilize-tit">
<view class="">
{{item.action_name}}
</view>
<view class="fertilize-tit-r">
<view class="" style="color: red;" @tap="del(item.id)">
删除
</view>
<view style="margin-left: 40rpx;color: #00A15E;" @tap='editFn(item)'>
编辑
</view>
</view>
</view>
<view class="fertilize-li">
2023-10-31 18:40:32 +08:00
<view class="fertilize-li-a" v-for="(items,indexs) in item.action_content" :key="indexs"
v-show="items[0]?.tit">
<view class="" v-for="item2 in items" :key="item2" v-show="item2.tit">
<view class="" v-if="indexs=='text'||indexs=='select'">
{{item2.tit}}: {{item2.value}}
</view>
<view v-if="indexs=='pic'">
{{item2.tit}}: <text style="color: #3274F9;"
@click="previewImage(item2.value)">图片</text>
2023-10-30 19:09:40 +08:00
</view>
2023-10-28 18:28:10 +08:00
</view>
2023-10-30 19:09:40 +08:00
2023-10-28 18:28:10 +08:00
</view>
2023-10-30 19:09:40 +08:00
</view>
2023-10-31 18:40:32 +08:00
2023-10-30 19:09:40 +08:00
</view>
2023-10-28 18:28:10 +08:00
</view>
2023-10-31 18:40:32 +08:00
<view class="" style="height: 100px">
</view>
2023-10-28 18:28:10 +08:00
</view>
2023-10-31 18:40:32 +08:00
<view class="ripe-btn" @click="finshFn">
2023-10-28 18:28:10 +08:00
完成今日操作
</view>
<!-- 组件 -->
<view class="">
2023-10-31 18:40:32 +08:00
<u-popup :show="showPop" :round="10" :closeable='true' @close="popCloseFn" @open="showPop=true">
2023-10-28 18:28:10 +08:00
<scroll-view scroll-y style="max-height: 90vh;">
<!-- 滚动内容 -->
2023-10-31 18:40:32 +08:00
<!-- 文本 -->
<view class="pop-content" v-for="item,index in popList.text" :key='index'>
<view class="">
{{item.title}}
2023-10-28 18:28:10 +08:00
</view>
2023-10-31 18:40:32 +08:00
<view class="pop-li">
<up-input placeholder="请输入" border="surround" v-model="formData1.text[index].value"
@change="change1(item.title,index)"></up-input>
</view>
</view>
<!-- 下拉 -->
<view class="pop-content" v-for="item,index in popList.select" :key='index'>
<view class="">
{{item.title}}
2023-10-28 18:28:10 +08:00
</view>
2023-10-31 18:40:32 +08:00
<view class="pop-li">
<up-input placeholder="点击选择" @change="change2(item.title,index)" border="surround"
v-model="formData1.select[index].value" @tap="choseSelect(item,index)"></up-input>
</view>
</view>
<!-- 图片 -->
<view class="pop-content" v-for="item,index in popList.pic" :key='index'>
<view class="">
{{item.title}}
</view>
<view class="pop-li" @click="updateImgFn(item.title,index)">
<view v-if="formData1.pic[index]?.value">
<u--image :src="formData1.pic[index]?.value" width="100%" height="196.26rpx"></u--image>
2023-10-28 18:28:10 +08:00
</view>
2023-10-31 18:40:32 +08:00
<view class="code-img" v-else>
<view class="carime-icon">
<u--image src="/static/img/DJSC.png" width="91.12rpx" height="91.12rpx"></u--image>
<view class="">
点击上传图片
2023-10-28 18:28:10 +08:00
</view>
</view>
</view>
</view>
2023-10-31 18:40:32 +08:00
</view>
<!-- 搜素 -->
<view class="pop-content" v-for="item,index in popList.serch" :key='index'>
<view class="">
{{item.title}}
</view>
<view class="pop-li">
<up-input placeholder="请输入品种" border="surround" v-model="formData1.serch[index].value"
@change="change4(item.title,index)"></up-input>
</view>
<view style="margin-bottom: 20rpx;" v-for="(item,index) in serchList" :key="item">
<u-swipe-action>
<u-swipe-action-item :options="options1"
style="border-radius: 20rpx;border: 1px solid #C7C6CD;" @click="swipeDel(index)">
<view class="" style="padding: 20rpx 30rpx;">
<view class="swipe-action-tit">
<view class="">
编号: {{item.animal_code}}
</view>
<view class="" style="color: #00A15E;" v-if="item.animal_status==1">
健康
</view>
<view class="" style="color: #FFD736;" v-if="item.animal_status==2">
怀孕中
</view>
<view class="" style="color: #3274F9;" v-if="item.animal_status==3">
可出栏
</view>
<view class="" style="color: #3274F9;" v-if="item.animal_status==5">
可出栏
</view>
</view>
<view class="swipe-action-li">
<view class="">
养殖品种:{{item.animal_kind}}
</view>
<view class="">
年龄: {{item.animal_age}}个月
</view>
<view class="">
体重: {{item.animal_weight}}kg
</view>
</view>
</view>
2023-10-28 18:28:10 +08:00
2023-10-31 18:40:32 +08:00
</u-swipe-action-item>
</u-swipe-action>
2023-10-28 18:28:10 +08:00
</view>
</view>
<view class="pop-confirm" @tap="confirm">
确认
</view>
</scroll-view>
</u-popup>
</view>
<!-- 组件 -->
<u-picker :show="showPicker" :columns="columns" @confirm="confirmFn" @close="showPicker=false"
@cancel="showModal=false"></u-picker>
<u-modal :show="showModal" :showCancelButton='true' :closeOnClickOverlay="true" @close="showModal=false"
content='确认删除吗?' @confirm="delFn" @cancel="showModal=false"></u-modal>
</view>
</template>
<script setup>
import {
ref,
reactive
} from "vue"
2023-10-30 19:09:40 +08:00
// import landInfo from "@/components/plant/landInfo.vue"
import pondCard from "@/components/aquatic/pondCard.vue"
2023-10-28 18:28:10 +08:00
import {
actionsListAPI,
actionsDetailAPI,
addLandCropRecordAPI,
landCropRecordListAPI,
delLandCropRecordAPI,
2023-10-30 19:09:40 +08:00
ediLandCropRecordAPI
} from "@/api/aquatic.js"
2023-10-28 18:28:10 +08:00
import {
onLoad
} from "@dcloudio/uni-app"
2023-10-30 19:09:40 +08:00
2023-10-28 18:28:10 +08:00
import {
addFishRecordAPI
} from "@/api/aquatic.js"
import uplodeImg from "@/utils/uplodeImg.js"
2023-10-31 18:40:32 +08:00
const serchList = reactive([])
2023-10-28 18:28:10 +08:00
const actionList = reactive([])
const options1 = reactive([{
text: '删除'
}])
const showPicker = ref(false)
const columns = reactive([
['中国', '美国', '日本']
], )
const confirmFn = (e) => {
showPicker.value = false
2023-10-31 18:40:32 +08:00
formData1.select[selectIndex.value].value = e.value[0]
2023-10-28 18:28:10 +08:00
}
const pond_id = ref(0)
const type = ref(0)
2023-10-30 19:09:40 +08:00
const title = ref('')
2023-10-28 18:28:10 +08:00
const actionData = reactive({})
const delIndex = ref(0)
onLoad((options) => {
pond_id.value = options.pond_id
2023-10-30 19:09:40 +08:00
title.value = options.title
getAcyionListFn()
2023-10-28 18:28:10 +08:00
})
2023-10-31 18:40:32 +08:00
const getAcyionListFn = (type) => {
2023-10-28 18:28:10 +08:00
actionList.splice(0, actionList.length)
actionsListAPI({
2023-10-30 19:09:40 +08:00
type: 4,
pond_id: pond_id.value
2023-10-28 18:28:10 +08:00
}).then(res => {
for (let key in res.data) {
2023-10-31 18:40:32 +08:00
if (key == title.value) {
actionData[key] = res.data[key]
actionData[key].action_record.forEach(item => {
item.action_content = JSON.parse(item.action_content)
})
actionList.push(...(res.data[key].action_record))
}
2023-10-28 18:28:10 +08:00
}
})
}
const showPop = ref(false)
const baseData = reactive({
text: {
value: "",
tit: ""
},
select: {
value: "",
tit: ""
},
pic: {
value: "",
tit: ""
},
serch: {
value: "",
2023-10-31 18:40:32 +08:00
tit: "",
list: [],
2023-10-28 18:28:10 +08:00
},
})
2023-10-31 18:40:32 +08:00
let formData = reactive({
text: [{
2023-10-28 18:28:10 +08:00
value: "",
tit: ""
2023-10-31 18:40:32 +08:00
}],
2023-10-28 18:28:10 +08:00
select: {
value: "",
tit: ""
},
pic: {
value: "",
tit: ""
},
serch: {
value: "",
2023-10-31 18:40:32 +08:00
tit: "",
list: [],
2023-10-28 18:28:10 +08:00
},
})
2023-10-31 18:40:32 +08:00
let formData1 = reactive({
text: [],
select: [],
pic: [],
serch: []
})
2023-10-28 18:28:10 +08:00
// 操作类型,true为添加,false为编辑
const actionType = ref(false)
const confirm = () => {
showPop.value = false
if (actionType.value) {
2023-10-31 18:40:32 +08:00
console.log(544)
2023-10-28 18:28:10 +08:00
addLandCropRecordAPI({
2023-10-30 19:09:40 +08:00
pond_id: Number(pond_id.value),
2023-10-28 18:28:10 +08:00
action_id: action_id.value,
2023-10-31 18:40:32 +08:00
action_content: JSON.stringify(formData1)
2023-10-28 18:28:10 +08:00
}).then(res => {
2023-10-31 18:40:32 +08:00
setPropertiesToNull(formData1)
2023-10-28 18:28:10 +08:00
})
} else {
ediLandCropRecordAPI({
record_id: delIndex.value,
2023-10-31 18:40:32 +08:00
action_content: JSON.stringify(formData1)
2023-10-28 18:28:10 +08:00
})
}
2023-10-31 18:40:32 +08:00
objClear(popList)
getAcyionListFn(type.value)
serchList.splice(0, serchList.length)
2023-10-28 18:28:10 +08:00
}
const navgo = (url) => {
uni.navigateTo({
url
})
}
const del = (index) => {
showModal.value = true
delIndex.value = index
}
const showModal = ref(false)
const delFn = () => {
showModal.value = false
delLandCropRecordAPI({
record_id: delIndex.value
}).then(res => {
2023-10-31 18:40:32 +08:00
getAcyionListFn(type.value)
2023-10-28 18:28:10 +08:00
})
}
const editFn = (item) => {
delIndex.value = item.id
showPopFn(item.action_id)
2023-10-31 18:40:32 +08:00
formData1 = reactive(deepCopy(item.action_content))
if (item.action_content.serch?.list?.length) {
item.action_content.serch.list.forEach(item => {
animalSearchByCodeAPI({
code: item
}).then(res => {
serchList.push(res.data)
})
})
}
2023-10-28 18:28:10 +08:00
actionType.value = false
}
2023-10-31 18:40:32 +08:00
const popList = reactive({
text: [],
serch: [],
select: [],
pic: []
})
2023-10-28 18:28:10 +08:00
const action_id = ref("")
const showPopFn = (id) => {
actionType.value = true
2023-10-31 18:40:32 +08:00
// 清除上次表单与popList数据,
objClear(formData1)
objClear(popList)
2023-10-28 18:28:10 +08:00
action_id.value = id
actionsDetailAPI({
action_id: id
}).then(res => {
res.data.forEach(item => {
2023-10-31 18:40:32 +08:00
if (item.type == 1) {
formData1.text.push({
tit: "",
value: ""
})
popList.text.push(item)
}
if (item.type == 2) {
formData1.pic.push({
tit: "",
value: ""
})
popList.pic.push(item)
}
if (item.type == 4) {
formData1.select.push({
tit: "",
value: ""
})
popList.select.push(item)
}
if (item.type == 3) {
formData1.serch.push({
value: "",
tit: "",
list: [],
})
popList.serch.push(item)
}
2023-10-28 18:28:10 +08:00
if (item.type == 4) {
2023-10-31 18:40:32 +08:00
2023-10-28 18:28:10 +08:00
}
})
2023-10-31 18:40:32 +08:00
showPop.value = true
2023-10-28 18:28:10 +08:00
})
}
2023-10-31 18:40:32 +08:00
const updateImgFn = (tit, index) => {
change3(tit, index)
2023-10-28 18:28:10 +08:00
uplodeImg().then(res => {
2023-10-31 18:40:32 +08:00
formData1.pic[index].value = res.data.image
2023-10-28 18:28:10 +08:00
})
}
const previewImage = (src) => {
uni.previewImage({
urls: [src],
})
}
2023-10-31 18:40:32 +08:00
const selectIndex = ref('')
const choseSelect = (item, index) => {
formData1.select[index].tit = item.title
selectIndex.value = index
columns[0] = item.options.split(',')
showPicker.value = true
}
const change1 = (tit, index) => {
formData1.text[index].tit = tit
2023-10-28 18:28:10 +08:00
}
const change2 = (tit) => {
formData.select.tit = tit
}
2023-10-31 18:40:32 +08:00
const change3 = (tit, index) => {
formData1.pic[index].tit = tit
2023-10-28 18:28:10 +08:00
}
const change4 = (tit) => {
formData.serch.tit = tit
2023-10-31 18:40:32 +08:00
if (formData.serch.value) {
animalSearchByCodeAPI({
code: formData.serch.value
}).then(res => {
if (res.data.id) {
serchList.push(res.data)
console.log(formData.serch, 54554)
formData.serch.list.push(formData.serch.value)
}
formData.serch.value = ''
})
}
}
function deepCopy(obj) {
if (typeof obj !== 'object' || obj === null) {
return obj;
}
var newObj = Array.isArray(obj) ? [] : {};
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
newObj[key] = deepCopy(obj[key]);
}
}
return newObj;
}
const objFn = (res, data) => {
for (let key in res) {
if (typeof res[key] === 'object') {
objFn(res[key], data[key]);
} else {
data[key] = res[key]
}
}
2023-10-28 18:28:10 +08:00
}
const setPropertiesToNull = (obj) => {
for (var prop in obj) {
if (obj.hasOwnProperty(prop)) {
if (typeof obj[prop] === 'object') {
setPropertiesToNull(obj[prop]);
} else {
obj[prop] = null;
}
}
}
}
2023-10-31 18:40:32 +08:00
const objClear = (obj) => {
for (let key in obj) {
obj[key].splice(0, obj[key].length)
2023-10-30 19:09:40 +08:00
}
}
2023-10-31 18:40:32 +08:00
const popCloseFn = () => {
showPop.value = false
serchList.splice(0, serchList.length)
objClear(popList)
objClear(formData1)
2023-10-28 18:28:10 +08:00
2023-10-31 18:40:32 +08:00
// setPropertiesToNull(formData)
}
const swipeDel = (e) => {
serchList.splice(e, 1);
formData1.serch.list.splice(e, 1)
}
const finshFn = () => {
uni.navigateTo({
url: "/pages/index/index"
})
2023-10-28 18:28:10 +08:00
}
</script>
<style lang="scss" scoped>
.cont {
padding-top: 30rpx;
background-color: #F4F4F4;
min-height: 100vh;
}
.card {
.tit {
display: flex;
padding-bottom: 20rpx;
border-bottom: 1px solid #EBF1EF;
}
.card-li {
margin-top: 20rpx;
display: flex;
}
}
.operate {
width: 693.93rpx;
margin: auto;
.tit {
margin: 20rpx 0;
}
.card {
display: flex;
flex-wrap: wrap;
.operate-li {
font-size: 29.79rpx;
padding: 0 60rpx;
background-color: #F4F4F4;
margin-bottom: 28rpx;
height: 63.08rpx;
line-height: 63rpx;
border-radius: 31.54rpx 31.54rpx 31.54rpx 31.54rpx;
}
}
}
.ripe-btn {
position: fixed;
bottom: 50rpx;
left: 50%;
transform: translateX(-50%);
width: 588.79rpx;
height: 84.11rpx;
background-color: #00A15E;
color: white;
display: flex;
justify-content: center;
align-items: center;
margin: 0 auto;
border-radius: 42.06rpx 42.06rpx 42.06rpx 42.06rpx;
background: linear-gradient(to right, #00A15E, #4CC593);
}
.fertilize {
.fertilize-tit {
display: flex;
// justify-self: center;
justify-content: space-between;
padding-bottom: 20rpx;
border-bottom: 1px solid #F4F4F4;
margin-bottom: 20rpx;
.fertilize-tit-r {
display: flex;
}
}
.fertilize-li {
display: flex;
justify-content: space-between;
margin-bottom: 20rpx;
flex-wrap: wrap;
.fertilize-li-a {
margin-bottom: 20rpx;
min-width: 40vw;
}
}
}
.pop-content {
padding: 20rpx;
padding-bottom: 0;
.pop-tit {
margin-bottom: 20rpx;
font-weight: bold;
}
.pop-li {
margin: 20rpx 0;
// margin-bottom: 40rpx;
}
}
.pop-confirm {
width: 693.93rpx;
height: 84.11rpx;
background: linear-gradient(to right, #00A15E, #4CC593);
color: white;
border-radius: 42.06rpx 42.06rpx 42.06rpx 42.06rpx;
text-align: center;
line-height: 84rpx;
margin-top: 70rpx;
margin: 0 auto;
}
.code-img {
background-color: #F4F4F4;
height: 196.26rpx;
position: relative;
.carime-icon {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-direction: column;
align-items: center;
}
2023-10-30 19:09:40 +08:00
2023-10-28 18:28:10 +08:00
}
.swipe-action-tit {
display: flex;
justify-content: space-between;
border-bottom: 1px solid #F4F4F4;
padding-bottom: 20rpx;
margin-bottom: 20rpx;
}
.swipe-action-li {
display: flex;
justify-content: space-between;
// align-items: ;
}
.popupShow {
// overflow: hidden;
position: fixed;
left: 30rpx;
}
</style>