TraceabilityAPP/pages/husbandryForm/harvest.vue

278 lines
5.5 KiB
Vue

<template>
<!-- 播种 -->
<view class="content">
<view class="card">
<u--form labelPosition="top" labelWidth='100' :model="formData" :rules="rules" ref="form">
<!-- <u-form-item label="作业地块" prop="formData.breed" borderBottom required>
<up-input placeholder="请输入作业地块" :disabled="mode=='detail'" border="surround"
v-model="formData.breed"></up-input>
</u-form-item>
<u-form-item label="作业面积" prop="formData.breed" borderBottom required>
<up-input placeholder="请输入作业面积" :disabled="mode=='detail'" type="number" border="surround"
v-model="formData.breed"></up-input>
</u-form-item> -->
<u-form-item label="参与人" prop="user" borderBottom required>
<up-input placeholder="请输入参与人" :disabled="mode=='detail'" type="txt" border="surround"
v-model="formData.user"></up-input>
</u-form-item>
<view class="card-li">
<view class="card-li-tit">
收获图片
</view>
<view class="code-img1">
<view class="" v-if="pic.length>0"
style="display: flex;flex-direction: row;flex-wrap: wrap;margin-bottom: 30rpx;">
<view class="" v-for="(item,i) in pic" style="margin-right: 30rpx;">
<u-image :src="item" width="150.85rpx" height="150.85rpx"></u-image>
</view>
</view>
</view>
<view class="code-img" v-if="mode=='add'">
<view class="" @click="updateImgFn">
<view class="carime-icon">
<u-image src="/static/img/DJSC.png" width="91.12rpx" height="91.12rpx"></u-image>
<view class="">
点击上传图片
</view>
</view>
</view>
</view>
</view>
<u-form-item label="备注" prop="remark" borderBottom required>
<u--textarea v-model="formData.remark" :disabled="mode=='detail'" placeholder="请输入内容"></u--textarea>
</u-form-item>
</u--form>
</view>
<view class="confirm" v-if="mode=='add'">
<view class="confirm-btn" style="color: white;background-color: #0AA565;" @click="addFn">
完成添加
</view>
</view>
</view>
</template>
<script setup>
import {
Uploads
} from "@/api/upload.js"
import {
reactive,
ref
} from "vue";
import {
onLoad,
onReady
} from "@dcloudio/uni-app"
import {
addaction
} from '@/api/file.js'
const form = ref(null)
const pic = reactive([]);
const formData = reactive({
user: "",
remark: "",
pic: []
})
const dateConfirmfn = (e) => {
console.log(e)
}
const rules = {
'user': {
type: 'string',
required: true,
message: '请填写参与人',
trigger: ['blur', 'change']
},
'remark': {
type: 'string',
required: true,
message: '请填写备注',
trigger: ['blur', 'change']
},
}
onReady(() => {
form.value.setRules(rules);
});
const navgo = (url) => {
uni.navigateTo({
url
})
}
const addFn = () => {
form.value.validate().then(res => {
console.log(res)
if (res) {
formData.pic = pic
let data1 = {
plant_id: task_id.value,
type: 5,
detail: JSON.stringify(formData)
};
if (formData.pic.length == 0) {
uni.$u.toast('请上传图片')
return
}
console.log('表单通过');
// 表单验证通过,执行提交操作
addaction(data1).then((res) => {
console.log(res)
if (res.code == 1) {
uni.$u.toast(res.msg)
uni.navigateBack({
delta: 1
})
}
})
// uni.$u.toast('校验成功')
}
})
}
//图片上传
const updateImgFn = async () => {
uni.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success: (res) => {
Uploads(res.tempFilePaths[0], 'img').then(res => {
console.log(res)
if (res.code == 1) {
pic.push(res.data.url)
console.log(data.formData)
uni.$u.toast('上传成功')
}
}).catch(err => {
//console.log('err', err);
// uni.$u.toast('上传失败')
})
},
fail: function(err) {
//console.log('choose失败');
uni.$u.toast('添加失败')
}
});
// let res = await Uploads()
// data.formData.pic = res.data.image
}
const mode = ref('add')
onLoad((options) => {
if (options.task_id) {
mode.value = "detail"
}
})
</script>
<style lang='scss' scoped>
.content {
padding-bottom: 100rpx;
}
.tit {
display: flex;
justify-content: space-between;
}
.card-li-tit {
margin-bottom: 20rpx;
}
.confim-btn {
margin: 0 auto;
width: 196.26rpx;
height: 66.59rpx;
/* border: ; */
border: #00A15E 1px solid;
color: #00A15E;
display: flex;
align-items: center;
justify-content: center;
border-radius: 42.06rpx 42.06rpx 42.06rpx 42.06rpx;
}
.up-img {
width: 341.71rpx
}
.today-btn {
width: 588.79rpx;
background-color: #00A15E;
color: white;
position: fixed;
bottom: 40rpx;
/* transform: ; */
left: 50%;
transform: translateX(-50%);
background: linear-gradient(to right, #00A15E, #4CC593);
/* margin: 0 auto; */
}
.code-img {
background-color: #F4F4F4;
height: 350.47rpx;
position: relative;
/* margin-bottom: 100rpx; */
.carime-icon {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-direction: column;
align-items: center;
}
}
.confirm {
position: fixed;
height: 84.11rpx;
display: flex;
bottom: 30rpx;
width: 750rpx;
.confirm-btn {
width: 315.42rpx;
height: 84.11rpx;
border: #00A15E 1px solid;
margin: 0 auto;
border-radius: 80rpx;
text-align: center;
line-height: 84rpx;
}
}
</style>