TraceabilityAPP/pages/addLand/addLand.vue

589 lines
13 KiB
Vue
Raw Permalink Normal View History

2023-11-21 18:54:33 +08:00
<template>
<view class="content">
<view class="card">
2023-12-13 18:30:45 +08:00
<up-form labelWidth='100' :model="data.formData" ref="form1">
<!-- <up-form-item label="姓名" prop="name"><u-input v-model="data.formData.name" /></up-form-item>
<up-form-item label="简介" prop="intro"><u-input v-model="data.formData.intro" /></up-form-item> -->
2023-12-17 19:34:37 +08:00
<view class="c-title">土地信息</view>
<view class="c-box">
<up-form-item label="土地名称" prop="title" borderBottom required>
<up-input input-align="right" placeholder="请输入土地名称" border="none"
v-model="data.formData.title"></up-input>
</up-form-item>
<up-form-item label="土地面积" prop="area" borderBottom required>
<up-input input-align="right" placeholder="请输入土地面积" border="none"
v-model="data.formData.area"></up-input>
</up-form-item>
<up-form-item label="土地负责人" prop="master_name" borderBottom required>
<up-input input-align="right" placeholder="请输入土地负责人名称" border="none"
v-model="data.formData.master_name"></up-input>
</up-form-item>
<up-form-item label="负责人电话" prop="master_phone" borderBottom required>
<up-input input-align="right" placeholder="请输入负责人电话" type="number" border="none"
v-model="data.formData.master_phone"></up-input>
</up-form-item>
</view>
<view class="c-title">地址信息</view>
2023-12-13 18:30:45 +08:00
<view class="c-box">
2023-12-17 19:34:37 +08:00
<up-form-item label="所在省份" prop="province_code" borderBottom required @click="isshow1">
<up-input input-align="right" placeholder="请选择所在省份" suffixIcon="arrow-down"
suffix-icon-style="color: #b6b6b6;" border="none" v-model="province_name" readonly
style="pointer-events: none;"></up-input>
</up-form-item>
<up-form-item label="所在城市" prop="city_code" borderBottom required @click="isshow2">
<up-input input-align="right" placeholder="请选择所在城市" suffixIcon="arrow-down"
suffix-icon-style="color: #b6b6b6;" border="none" v-model="city_name" readonly
style="pointer-events: none;"></up-input>
</up-form-item>
<up-form-item label="所在区县" prop="county_code" borderBottom required @click="isshow3">
<up-input input-align="right" placeholder="请选择所在区县" suffixIcon="arrow-down"
suffix-icon-style="color: #b6b6b6;" border="none" v-model="county_name" readonly
style="pointer-events: none;"></up-input>
</up-form-item>
2024-01-03 19:11:45 +08:00
<up-form-item label="土地详细地址" prop="town_code" style="position: relative;width: 93%;" borderBottom
required>
<up-input input-align="right" placeholder="请输入土地详细地址" style="width: 80%;" border="none"
v-model="data.formData.address">
2023-12-17 19:34:37 +08:00
</up-input>
2024-01-03 19:11:45 +08:00
<view style="position: absolute;right: -50rpx;width: 50rpx; height: 100%;" @click="location">
<u--image src='/static/main/index/dw.png'
style="position: absolute;top: 50%;left: 50%;transform: translate(-50%,-50%);"
width="25.06rpx" height="32rpx"></u--image>
2023-12-18 18:48:57 +08:00
</view>
2023-12-17 19:34:37 +08:00
</up-form-item>
</view>
2023-11-21 18:54:33 +08:00
<view class="card-li">
2023-12-17 19:34:37 +08:00
<view class="c-title">土地图片</view>
<view class="c-box c-box-p">
<view class="code-img1">
<view class="" v-if="pic.length>0"
style="display: flex;flex-direction: row;flex-wrap: wrap;margin-bottom: 30rpx;">
2024-01-03 19:11:45 +08:00
<view class="" v-for="(item,i) in pic" style="margin-right: 30rpx;" :key="i">
2023-12-17 19:34:37 +08:00
<view class="">
<u-icon name="close" size="15" style="margin-left:120.85rpx;"
@click="delimg(i)"></u-icon>
<u-image :src="item" width="150.85rpx" height="150.85rpx"></u-image>
</view>
</view>
</view>
</view>
<view class="code-img">
<view class="" @click="updateImgFn">
<view class="carime-icon">
2024-01-03 19:11:45 +08:00
<u-image src="/static/main/index/upload.png" width="82rpx" height="68rpx"></u-image>
<view class="" style="font-weight: 500;margin-top: 20rpx;">
2023-12-17 19:34:37 +08:00
点击上传图片
</view>
</view>
</view>
</view>
</view>
2023-11-21 18:54:33 +08:00
</view>
2023-12-13 18:30:45 +08:00
</up-form>
2023-11-25 16:18:54 +08:00
<u-action-sheet :show="show" keyName="name" closeOnClickOverlay :actions="columns" title="请选择"
@close="show = false" @select="leavaType1">
2023-11-21 18:54:33 +08:00
2023-11-25 16:18:54 +08:00
</u-action-sheet>
<u-action-sheet :show="show1" keyName="name" :actions="columns1" title="请选择" @close="show1 = false"
@select="leavaType2">
</u-action-sheet>
<u-action-sheet :show="show2" keyName="name" :actions="columns2" title="请选择" @close="show2 = false"
@select="leavaType3">
</u-action-sheet>
<u-action-sheet :show="show3" keyName="name" :actions="columns3" title="请选择" @close="show3 = false"
@select="leavaType4">
</u-action-sheet>
<u-action-sheet :show="show4" keyName="name" :actions="columns4" title="请选择" @close="show4 = false"
@select="leavaType5">
</u-action-sheet>
<u-action-sheet :show="show5" keyName="name" :actions="columns5" title="请选择" @close="show5 = false"
@select="leavaType6">
</u-action-sheet>
2023-12-13 18:30:45 +08:00
<u-button class="btn" @click="submit">提交</u-button>
2023-11-21 18:54:33 +08:00
</view>
</view>
</template>
<script setup>
import {
2023-11-25 16:18:54 +08:00
ref,
2023-11-21 18:54:33 +08:00
reactive,
2023-11-25 16:18:54 +08:00
onMounted,
unref,
computed,
watch
} from 'vue';
2023-11-21 18:54:33 +08:00
import {
2023-11-25 16:18:54 +08:00
onLoad,
2023-12-20 23:41:00 +08:00
onReady,
onShow
2023-11-25 16:18:54 +08:00
} from '@dcloudio/uni-app';
import {
Uploads
} from "@/api/upload.js"
import {
addland,
province,
city,
county,
towns,
villages,
groups
} from '@/api/api.js'
2023-11-21 18:54:33 +08:00
2023-11-25 16:18:54 +08:00
const form1 = ref(null);
const data = reactive({
formData: {
title: '',
area: '',
province_code: '',
city_code: '',
county_code: '',
2023-11-30 17:51:39 +08:00
address: '',
2023-12-20 23:41:00 +08:00
latitude: "20",
longitude: "20",
2023-11-25 16:18:54 +08:00
master_name: '',
master_phone: '',
2023-12-20 23:41:00 +08:00
pic: [
2023-11-25 16:18:54 +08:00
]
},
rules: {
// name: [{
// required: true,
// message: '请输入姓名',
// // 可以单个或者同时写两个触发验证方式
// trigger: ['change', 'blur'],
// }],
// intro: [{
// min: 5,
// message: '简介不能少于5个字',
// trigger: 'change'
// }],
title: [{
type: 'string',
required: true,
message: '请填写土地名称',
trigger: ['blur', 'change']
}],
area: [{
type: 'string',
required: true,
message: '请填写土地面积',
trigger: ['blur', 'change']
}],
province_code: [{
type: 'string',
required: true,
message: '请请选择所在省份',
trigger: 'change'
}],
city_code: [{
type: 'string',
required: true,
message: '请选择所在城市',
trigger: 'change'
}],
county_code: [{
type: 'string',
required: true,
message: '请选择所在区县',
trigger: 'change'
}],
2023-11-30 17:51:39 +08:00
address: [{
2023-11-25 16:18:54 +08:00
type: 'string',
required: true,
2023-11-30 17:51:39 +08:00
message: '请输入土地详细地址',
trigger: ['blur', 'change']
2023-11-25 16:18:54 +08:00
}],
master_name: [{
type: 'string',
required: true,
message: '请输入土地负责人名称',
2023-11-25 16:18:54 +08:00
trigger: ['blur', 'change']
}],
master_phone: [{
required: true,
message: '请输入手机号',
trigger: ['change', 'blur'],
},
{
validator: (rule, value, callback) => {
// 上面有说返回true表示校验通过返回false表示不通过
// uni.$u.test.mobile()就是返回true或者false的
return uni.$u.test.mobile(value);
},
message: '手机号码不正确',
// 触发器可以同时用blur和change
trigger: ['change', 'blur'],
}
],
2023-11-21 18:54:33 +08:00
2023-11-25 16:18:54 +08:00
}
});
const pic = reactive([]);
const province_name = ref(null)
const city_name = ref(null)
const county_name = ref(null)
2023-11-30 17:51:39 +08:00
2023-11-25 16:18:54 +08:00
const show = ref(false)
const show1 = ref(false)
const show2 = ref(false)
const columns = reactive([])
const columns1 = reactive([])
const columns2 = reactive([])
2023-11-30 17:51:39 +08:00
2023-11-25 16:18:54 +08:00
const provincen = () => {
province().then((res) => {
columns.splice(0, columns.length, ...res.data.map((step, index) => {
return {
name: step.province_name,
id: step.province_code,
};
}));
2023-11-21 18:54:33 +08:00
2023-11-25 16:18:54 +08:00
});
}
2023-11-21 18:54:33 +08:00
2023-11-25 16:18:54 +08:00
const cityn = (id) => {
2023-11-30 17:51:39 +08:00
2023-11-25 16:18:54 +08:00
city({
province_code: id
}).then((res) => {
columns1.splice(0, columns.length, ...res.data.map((step, index) => {
return {
name: step.city_name,
id: step.city_code,
};
}));
2023-11-21 18:54:33 +08:00
2023-11-25 16:18:54 +08:00
});
2023-11-21 18:54:33 +08:00
}
2023-11-25 16:18:54 +08:00
const countyn = (id) => {
county({
city_code: id
}).then((res) => {
columns2.splice(0, columns.length, ...res.data.map((step, index) => {
return {
name: step.county_name,
id: step.county_code,
};
}));
});
2023-11-21 18:54:33 +08:00
}
2023-11-27 18:23:17 +08:00
//图片删除
const delimg = (i) => {
pic.splice(i, 1);
}
2023-11-25 16:18:54 +08:00
//图片上传
2023-11-21 18:54:33 +08:00
const updateImgFn = async () => {
2023-11-25 16:18:54 +08:00
uni.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success: (res) => {
Uploads(res.tempFilePaths[0], 'img').then(res => {
2023-11-30 17:51:39 +08:00
// console.log(res)
2023-11-25 16:18:54 +08:00
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
2023-11-21 18:54:33 +08:00
}
2023-11-25 16:18:54 +08:00
// 地址 省 市 街道 乡村 小队
const isshow1 = () => {
show.value = true
}
const isshow2 = () => {
show1.value = true
}
const isshow3 = () => {
show2.value = true
}
const isshow4 = () => {
show3.value = true
}
const isshow5 = () => {
show4.value = true
}
const isshow6 = () => {
show5.value = true
}
const leavaType1 = (e) => {
2023-11-30 17:51:39 +08:00
2023-11-25 16:18:54 +08:00
province_name.value = e.name
data.formData.province_code = e.id
cityn(e.id)
}
const leavaType2 = (e) => {
city_name.value = e.name
data.formData.city_code = e.id
countyn(e.id)
}
const leavaType3 = (e) => {
county_name.value = e.name
data.formData.county_code = e.id
}
2023-11-30 17:51:39 +08:00
const location = () => {
2023-12-20 08:42:32 +08:00
uni.navigateTo({
url: '/pages/addLand/select_address_n'
})
return
2023-12-17 20:52:19 +08:00
uni.showLoading({
title: '获取位置中'
})
2023-11-30 17:51:39 +08:00
uni.getLocation({
2023-12-20 08:42:32 +08:00
2023-11-30 17:51:39 +08:00
type: 'gcj02',
geocode: true,
isHighAccuracy: true,
success: async (res) => {
2023-12-17 19:34:37 +08:00
console.log(res)
2023-12-18 18:48:57 +08:00
data.formData.lat = res.latitude
data.formData.lon = res.longitude
data.formData.address = res.address.street + res
2023-12-17 20:52:19 +08:00
.address.streetNum + res.address.poiName
2023-12-17 19:34:37 +08:00
2023-12-17 20:52:19 +08:00
uni.hideLoading();
2023-12-18 18:48:57 +08:00
2023-12-17 20:52:19 +08:00
console.log(data.formData)
2023-11-30 17:51:39 +08:00
},
fail: (err) => {
2023-12-17 19:34:37 +08:00
// uni.hideLoading();
2023-11-30 17:51:39 +08:00
console.log(err)
2023-12-17 19:34:37 +08:00
console.log("erer")
2023-11-30 17:51:39 +08:00
}
});
2023-11-25 16:18:54 +08:00
2023-12-17 19:34:37 +08:00
2023-11-25 16:18:54 +08:00
}
onReady(() => {
form1.value.setRules(data.rules);
});
const submit = async () => {
try {
const valid = await form1.value.validate();
if (valid) {
// console.log('表单通过', data.formData);
2023-11-30 17:51:39 +08:00
if (pic.length == 0) {
2023-11-25 16:18:54 +08:00
uni.$u.toast('请上传图片')
return
}
2023-11-30 17:51:39 +08:00
data.formData.pic = JSON.stringify(pic)
2023-11-25 16:18:54 +08:00
// 表单验证通过,执行提交操作
addland(data.formData).then((res) => {
console.log(res)
if (res.code == 1) {
uni.navigateBack({
delta: 1
})
uni.$u.toast(res.msg)
// console.log('提交通过');
}
})
} else {
// 表单验证不通过
console.log('表单验证未通过');
}
} catch (error) {
// 捕获验证过程中的错误
console.error(error);
}
2023-11-21 18:54:33 +08:00
}
2023-12-20 23:41:00 +08:00
onShow((e) => {
console.log(e)
})
2023-11-25 16:18:54 +08:00
onLoad((options) => {
2023-12-20 23:41:00 +08:00
uni.$on('setData', function(datas) {
let address = JSON.parse(datas)
data.formData.address = address.address
data.formData.longitude = address.lon
data.formData.latitude = address.lat
});
2023-11-25 16:18:54 +08:00
provincen()
2023-11-30 17:51:39 +08:00
2023-11-25 16:18:54 +08:00
})
</script>
<style lang="scss">
2023-12-17 19:34:37 +08:00
page {
background-color: #f7fffc;
}
.card {
background-color: #f7fffc;
padding: 0;
padding-bottom: 80rpx;
.c-title {
font-weight: bold;
display: flex;
align-items: center;
padding: 30rpx;
padding-bottom: 15rpx;
&:before {
content: '';
display: inline-block;
height: 0.8rem;
width: 6rpx;
margin-top: 0.2rem;
margin-right: 10rpx;
background-color: #35d190;
border-radius: 6rpx;
}
}
.c-box {
background-color: #fff;
padding-left: 30rpx;
padding-right: 20rpx;
padding-bottom: 20rpx;
box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.1);
}
.c-box-p {
padding: 20rpx;
}
.btn {
margin: 20rpx auto;
width: 694rpx;
height: 80rpx;
border-radius: 80rpx;
background-color: #4ad69b;
color: #fff;
}
}
2023-11-21 18:54:33 +08:00
.card-li-tit {
2023-12-09 17:07:42 +08:00
position: relative;
2023-12-17 19:34:37 +08:00
2023-12-09 17:07:42 +08:00
span {
position: absolute;
left: -9px;
color: #f56c6c;
line-height: 20px;
font-size: 20px;
top: 3px;
}
2023-12-17 19:34:37 +08:00
2023-11-21 18:54:33 +08:00
margin-bottom: 20rpx;
}
2023-12-17 19:34:37 +08:00
2023-11-21 18:54:33 +08:00
.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;
2024-01-03 19:11:45 +08:00
height: 340.47rpx;
2023-11-21 18:54:33 +08:00
position: relative;
2024-01-03 19:11:45 +08:00
width: 680rpx;
margin: 0 auto;
2023-11-21 18:54:33 +08:00
.carime-icon {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-direction: column;
align-items: center;
}
}
</style>