地块操作,差样式

master
Tuzki 2 years ago
parent 83658c86fe
commit 78ae327fb9
  1. 54
      api/system/block/block.js
  2. 10
      manifest.json
  3. 9
      pages.json
  4. 53
      pages/block/index.vue
  5. 1
      plugins/qqmap-wx-jssdk.min.js
  6. 411
      sunPages/addBlock/addBlock.vue
  7. 269
      sunPages/blockDetail/blockDetail.vue
  8. 32
      sunPages/drawMap/drawMap.vue
  9. 430
      sunPages/editBlock/editBlock.vue

@ -1,9 +1,63 @@
import request from '@/utils/request'
//地块列表分页
export function getBlockPage(query) {
return request({
url: '/traceability/block/page',
method: 'get',
params: query
})
}
// 获得农作物信息;分页
export function getCropperPage(query) {
return request({
url: '/traceability/cropper/page',
method: 'get',
params: query
})
}
// 获得种植历史分页
export function getGrowRecordPage(query) {
return request({
url: '/traceability/grow-record/page',
method: 'get',
params: query
})
}
// 获得采收记录分页
export function getRecoveryRecordPage(query) {
return request({
url: '/traceability/recovery-record/page',
method: 'get',
params: query
})
}
// 创建地块信息
export function createBlock(data) {
return request({
url: '/traceability/block/create',
method: 'post',
data: data
})
}
// 删除地块信息
export function deleteBlock(id) {
return request({
url: '/traceability/block/delete?id=' + id,
method: 'delete'
})
}
// 更新地块信息
export function updateBlock(data) {
return request({
url: '/traceability/block/update',
method: 'put',
data: data
})
}

@ -52,7 +52,15 @@
"subPackages" : true
},
"usingComponents" : true,
"permission" : {}
"permission": {
"scope.userLocation": {
"desc": "你的位置信息将用于小程序位置接口的效果展示"
},
"scope.userFuzzyLocation": {
"desc": "你的位置信息将用于小程序位置接口的效果展示"
}
},
"requiredPrivateInfos": ["chooseLocation","getLocation"]
},
"vueVersion" : "2",
"h5" : {

@ -1,5 +1,6 @@
{
"pages": [{
"pages": [
{
"path": "pages/login",
"style": {
"navigationBarTitleText": "登录"
@ -167,6 +168,12 @@
"navigationBarTitleText": "新增地块",
"enablePullDownRefresh": false
}
}, {
"path": "drawMap/drawMap",
"style": {
"navigationBarTitleText": "绘制地块",
"enablePullDownRefresh": false
}
}
]
}],

@ -1,7 +1,7 @@
<template>
<view>
<view class="m-top-bar">
<uni-search-bar v-model="queryParams.blockName" bgColor="#EEEEEE" placeholder="请输入地块名称" @confirm="search" @cancel=cacel />
<uni-search-bar v-model="queryParams.blockName" bgColor="#EEEEEE" placeholder="请输入地块名称" @confirm="search" @cancel="cacel" />
<uni-section class="m-block-pick" title="地块类型">
<uni-data-select v-model="queryParams.blockType" :localdata="range" @change="change"></uni-data-select>
</uni-section>
@ -33,7 +33,7 @@
<script>
import { getDictDatas, DICT_TYPE } from '@/utils/dict';
import { getBlockPage } from '@/api/system/block/block';
import { getBlockPage, deleteBlock } from '@/api/system/block/block';
import DictTag from '@/components/DictTag/index.vue';
export default {
@ -63,13 +63,14 @@ export default {
item.text = item.label;
});
this.range = arr;
this.queryList();
},
methods: {
search(res) {
this.queryList();
},
cacel(){
this.queryParams.blockName = null
cacel() {
this.queryParams.blockName = null;
this.queryList();
},
change(e) {
@ -81,8 +82,8 @@ export default {
//pageNopageSize
//
this_.$nextTick(() => {
this_.queryParams.pageNo = pageNo
this_.queryParams.pageSize = pageSize
this_.queryParams.pageNo = pageNo;
this_.queryParams.pageSize = pageSize;
const params = this_.queryParams;
getBlockPage(params)
.then((res) => {
@ -104,16 +105,48 @@ export default {
url: '/sunPages/addBlock/addBlock'
});
},
editBlock() {
editBlock(item) {
const data = JSON.stringify(item)
uni.navigateTo({
url: '/sunPages/editBlock/editBlock'
url: '/sunPages/editBlock/editBlock?data='+data
});
},
detailBlock(item) {
const obj = JSON.stringify(item)
const obj = JSON.stringify(item);
uni.navigateTo({
url: '/sunPages/blockDetail/blockDetail?val='+obj
url: '/sunPages/blockDetail/blockDetail?val=' + obj
});
},
deleteBlock(val) {
let this_ = this
if (val.id) {
uni.showModal({
title: '提示',
content: '确定删除编号' + val.id + '地块吗',
success: function (res) {
if (res.confirm) {
deleteBlock(val.id).then(res=>{
uni.showToast({
title:'删除成功',
icon:'none',
success() {
this_.queryList();
}
})
}).catch(err=>{
console.log(err)
})
} else if (res.cancel) {
console.log('用户点击取消');
}
}
});
} else {
uni.showToast({
icon: 'error',
title: '该条数据有问题,请检查数据。'
});
}
}
}
};

File diff suppressed because one or more lines are too long

@ -1,19 +1,416 @@
<template>
<view>
<view class="content">
<view class="map-view">
<map
id="map"
v-if="formData.positionStr && formData.positionStr != ''"
class="m-map"
:longitude="longitude"
:latitude="latitude"
:polygons="polygons"
enable-satellite="true"
></map>
<view class="no-map" v-else>
<uv-empty icon="https://cdn.uviewui.com/uview/demo/empty/history.png"></uv-empty>
</view>
<view class="map-btn-group">
<button v-if="formData.positionStr && formData.positionStr != ''" @click="reset">清除地块</button>
<button v-else @click="drawMap">绘制地块</button>
</view>
</view>
<view class="form-box">
<uni-forms label-width="80px" ref="valiForm" :rules="rules" :modelValue="formData">
<uni-forms-item label="地块名称" required name="blockName">
<uni-easyinput v-model="formData.blockName" placeholder="请输入地块名称"></uni-easyinput>
</uni-forms-item>
<uni-forms-item label="标识颜色" name="blockColor">
<view
class="color"
:style="{
background: formData.blockColor
}"
@click="openColor"
></view>
</uni-forms-item>
<uni-forms-item label="地块类型" required name="blockType">
<uni-data-select v-model="formData.blockType" :localdata="range"></uni-data-select>
</uni-forms-item>
<uni-forms-item label="地块面积" required name="blockArea">
<uni-easyinput v-model="formData.blockArea" placeholder="请输入地块面积">
<template #right>
<view class="input-slot-right"></view>
</template>
</uni-easyinput>
</uni-forms-item>
<uni-forms-item label="地块坐标" name="positionStr">
<uni-easyinput disabled v-model="formData.positionStr" placeholder="地块坐标"></uni-easyinput>
</uni-forms-item>
</uni-forms>
<button type="primary" @click="submit('valiForm')">提交</button>
</view>
<uv-pick-color ref="pickerColor" @confirm="confirm"></uv-pick-color>
</view>
</template>
<script>
export default {
data() {
return {
import { getDictDatas, DICT_TYPE } from '@/utils/dict';
import { createBlock } from '@/api/system/block/block.js';
// SDK
var QQMapWX = require('@/plugins/qqmap-wx-jssdk.min.js');
var qqmapsdk;
var self;
export default {
data() {
return {
data: [],
IsOption: false,
polygons: [],
longitude: null,
latitude: null,
range: [],
formData: {
blockName: undefined,
blockColor: undefined,
blockType: undefined,
blockArea: undefined,
positionStr: undefined,
baseId: undefined
},
rules: {
blockName: {
rules: [
{
required: true,
errorMessage: '地块名不能为空'
}
]
},
blockArea: {
rules: [
{
required: true,
errorMessage: '面积名不能为空'
}
]
},
blockType: {
rules: [
{
required: true,
errorMessage: '地块类型不能为空'
}
]
}
// positionStr: {
// rules: [
// {
// required: true,
// errorMessage: ''
// }
// ]
// }
}
};
},
onShow() {
let arr = this.getDictDatas(DICT_TYPE.LAND_TYPE);
arr.forEach((item) => {
item.text = item.label;
});
this.range = arr;
},
onLoad(options) {
if (options.val) {
console.log(JSON.parse(decodeURIComponent(options.val)));
const obj = JSON.parse(decodeURIComponent(options.val));
this.formData.blockArea = obj.blockArea;
this.formData.positionStr = obj.positionStr;
this.initmapPolygon();
}
self = this;
// self.getAuthorizeInfo();
// API
qqmapsdk = new QQMapWX({
key: 'PEFBZ-ELL64-MVDUZ-KDV4N-RISMO-VCB7A'
});
},
methods: {
openColor() {
this.$refs.pickerColor.open();
},
confirm(e) {
this.formData.blockColor = e.hex;
if (this.polygons.length > 0) {
this.polygons[0].strokeColor = e.hex;
this.polygons[0].fillColor = e.hex + '5c';
}
},
toLocation: function (obj) {
self.mapCtx.moveToLocation(obj);
self.mapCtx.translateMarker({
markerId: 1,
autoRotate: true,
duration: 100,
destination: {
latitude: obj.latitude,
longitude: obj.longitude
},
animationEnd() {
console.log('animation end');
}
});
},
//
getAuthorizeInfo() {
uni.authorize({
scope: 'scope.userLocation',
success() {
//
self.getLocationInfo();
},
fail() {
//
self.openConfirm();
console.log('你拒绝了授权,无法获得周边信息');
}
});
},
//
getLocationInfo() {
uni.getLocation({
type: 'wgs84',
success(res) {
console.log(res, '当前位置');
self.toLocation(res);
self.latitude = res.latitude;
self.longitude = res.longitude;
// uni.openLocation({
// latitude: latitude,
// longitude: longitude,
// success: function () {
// console.log('success');
// }
// })
}
});
},
//
//
openConfirm() {
uni.showModal({
title: '请求授权当前位置',
content: '需要获取您的地理位置,请确认授权',
success: (res) => {
if (res.confirm) {
uni.openSetting(); //
} else if (res.cancel) {
uni.showToast({
title: '你拒绝了授权,无法获得周边信息',
icon: 'none',
duration: 1000
});
}
}
});
},
poitap: function (e) {
console.log(e, 'poitap');
var obj = e.detail;
self.searchKey = obj.name;
// this.$api.msg(e)
self.toLocation(obj);
},
//
Cancel: function () {},
submit(ref) {
let this_ = this
if (this.formData.positionStr == undefined || this.formData.positionStr == '') {
uni.showToast({
title: `请先绘制地块`,
icon: 'error'
});
return false;
}
this.$refs[ref]
.validate()
.then((res) => {
console.log('success', res);
createBlock(res)
.then((res) => {
uni.showToast({
title: `创建成功`,
duration: 1500,
success() {
setTimeout(()=>{
this_.reset();
uni.switchTab({
url: '/pages/block/index'
});
},1500)
}
});
})
.catch((err) => {
console.log(err);
});
})
.catch((err) => {
console.log('err', err);
});
},
drawMap() {
uni.navigateTo({
url: '/sunPages/drawMap/drawMap'
});
},
reset() {
this.formData = {
blockName: undefined,
blockColor: undefined,
blockType: undefined,
blockArea: undefined,
positionStr: undefined,
baseId: undefined
};
this.polygons = [];
},
initmapPolygon() {
let this_ = this;
const mapCon = uni.createMapContext('map');
const arr = JSON.parse(this.formData.positionStr);
const center = this_.calculateCenter(arr);
let Arr = arr.map((item) => {
const obj = {
latitude: item[1],
longitude: item[0]
};
return obj;
});
console.log(Arr);
let Obj = {
points: Arr,
strokeColor: this_.formData.blockColor && this_.formData.blockColor != null ? this_.formData.blockColor : '#007969',
fillColor: this_.formData.blockColor && this_.formData.blockColor != null ? this_.formData.blockColor + '5c' : '#0079695c',
zIndex: 1
};
this_.$nextTick(() => {
this_.polygons.push(Obj);
mapCon.includePoints({
padding: [20, 20, 20, 20],
points: Arr
});
this_.longitude = center[0];
this_.latitude = center[1];
});
},
//
calculateCenter(coordinates) {
let sumLat = 0;
let sumLng = 0;
coordinates.forEach((coord) => {
sumLat += coord[0];
sumLng += coord[1];
});
const count = coordinates.length;
const centerLat = sumLat / count;
const centerLng = sumLng / count;
return [centerLat, centerLng];
}
}
};
</script>
<style lang="scss">
<style scoped lang="scss">
.content {
background-color: #f1f1f1;
overflow: hidden;
min-height: 100vh;
color: #646464;
font-size: 40rpx;
}
.option {
max-height: 300rpx;
width: 90%;
line-height: 60rpx;
position: fixed;
top: 110rpx;
z-index: 99999;
border-radius: 150rpx;
overflow: scroll;
left: 50%;
transform: translateX(-50%);
}
.column_item {
padding: 0 40rpx;
height: 60rpx;
font-size: 28rpx;
width: 100%;
overflow: hidden;
margin: 0rpx auto;
background-color: #00000080;
text-overflow: ellipsis;
color: #fff;
white-space: nowrap;
}
.column_item:active {
background-color: #8f8f94;
}
.page-section-gap {
width: 100%;
position: fixed;
top: 0;
z-index: 0;
}
.color {
width: 50rpx;
height: 50rpx;
border-radius: 6rpx;
border: solid 1rpx #d0d0d0;
background-color: transparent;
}
.input-slot-right {
background-color: #eee;
padding: 10rpx;
}
.map-view {
width: 100%;
height: 500rpx;
overflow: hidden;
position: relative;
margin-bottom: 30rpx;
.m-map {
width: 100%;
height: 110%;
}
.map-btn-group {
position: absolute;
z-index: 9;
bottom: 20rpx;
left: 50%;
transform: translateX(-50%);
}
}
.form-box {
padding: 40rpx 20rpx;
margin: 0 20rpx;
background: #fff;
box-shadow: 0 0 10px 1px #dadada;
border-radius: 15rpx;
/deep/ .uni-forms-item {
align-items: center;
&:last-child {
display: none;
}
}
}
</style>

@ -1,17 +1,103 @@
<template>
<view>
<view class="m-mapbox">
<map class="m-map" name="" :longitude="longitude" :latitude="latitude" :polygons="polygons" enable-satellite="true"></map>
<map class="m-map" name="" id="map" :longitude="longitude" :latitude="latitude" :polygons="polygons" enable-satellite="true"></map>
<view class="m-shadow">
<view class="m-mj">{{ blockData.blockArea || '0' }}</view>
<view class="m-type"><dict-tag :type="'land_type'" :value="blockData.blockType" class="m-dic-tag" /></view>
</view>
</view>
<view class="m-tabs-box">
<z-paging ref="paging" :pagingStyle="padingStyle" v-model="dataList" @query="queryList">
<!-- 需要固定在顶部不滚动的view放在slot="top"的view中如果需要跟着滚动则不要设置slot="top" -->
<!-- 注意此处的z-tabs为独立的组件可替换为第三方的tabs若需要使用z-tabs请在插件市场搜索z-tabs并引入否则会报插件找不到的错误 -->
<template #top>
<z-tabs :list="tabList" @change="tabChange" />
<template class="m-data-pick"v-if="tabIndex == 2">
<uni-datetime-picker @change='searchData' v-model="datetimerange" type="datetimerange" rangeSeparator="至" />
</template>
</template>
<!-- 如果希望其他view跟着页面滚动可以放在z-paging标签内 -->
<view class="item" v-for="(item, index) in dataList" :key="index" @click="itemClick(item, index)">
<template v-if="tabIndex == 0 && dataList.length > 0">
<view class="m-item-box">
<view class="m-item-top">
<image class="m-item-img" :mode="aspectFill" :src="item.productPic"></image>
<view class="m-pro-custrom">
<view class="m-pro-name">
{{ item.productName }}
</view>
<view class="m-pro-species">品种{{ item.speciesName }}</view>
<view class="m-pro-Type">
标准
<dict-tag class="m-dic-tag" :type="'authentication_type'" :value="item.authenticationType" />
</view>
<view class="m-pro-Time">
种植时间{{ parseTime(item.plantingTime, '{y}-{m}-{d}') }}
<view class="m-daysdiff">{{ calculateDaysDifference(item.plantingTime) }}</view>
</view>
</view>
</view>
<view class="m-item-bottom">
<view class="m-note">农事记录</view>
<view class="m-end-pro">种植结束</view>
</view>
</view>
</template>
<template v-if="tabIndex == 1 && dataList.length > 0">
<view class="m-item-box">
<view class="m-item-top">
<image class="m-item-img" :mode="aspectFill" :src="item.productPic"></image>
<view class="m-pro-custrom">
<view class="m-pro-name">
{{ item.productName }}
</view>
<view class="m-pro-species">品种{{ item.speciesName }}</view>
<view class="m-pro-Type">
标准
<dict-tag class="m-dic-tag" :type="'authentication_type'" :value="item.authenticationType" />
</view>
</view>
</view>
<view class="m-item-bottom noflex">
<uni-steps :active-color="'#3f3f3f'" :options="[{title:'种植时间',desc:parseTime(item.plantTime,'{y}-{m}-{d}')},{title:'结束时间',desc:parseTime(item.endTime,'{y}-{m}-{d}')}]" :active="3"></uni-steps>
</view>
</view>
</template>
<template v-if="tabIndex == 2 && dataList.length > 0">
<view class="m-item-box">
<view class="m-item-top no-border">
<image class="m-item-img" :mode="aspectFill" :src="item.productPic"></image>
<view class="m-pro-custrom">
<view class="m-pro-name">
{{ item.productName }}
</view>
<view class="m-pro-species">品种{{ item.speciesName }}</view>
<view class="m-pro-Type">
标准
<dict-tag class="m-dic-tag" :type="'authentication_type'" :value="item.authenticationType" />
</view>
<view class="m-pro-Time">
采收时间{{ parseTime(item.jobTime, '{y}-{m}-{d}') }}
</view>
</view>
<view class="m-big-num">
{{item.production}}<br>公斤
</view>
</view>
</view>
</template>
</view>
</z-paging>
<tempalte class="m-add-pro" v-if="tabIndex == 0 && dataList.length == 0">+新增种养品种</tempalte>
</view>
</view>
</template>
<script>
import DictTag from '@/components/DictTag/index.vue';
import { parseTime } from '@/utils/ruoyi';
import { getCropperPage,getGrowRecordPage,getRecoveryRecordPage } from '@/api/system/block/block.js';
export default {
components: {
DictTag
@ -22,7 +108,16 @@ export default {
polygons: [],
includePoints: [],
longitude: null,
latitude: null
latitude: null,
padingStyle: {
top: '500rpx',
'z-index': 9
},
datetimerange:[],
dataList: [],
tabList: ['种植产品', '种植历史', '采收记录'],
tabIndex: 0
};
},
onReady() {},
@ -36,6 +131,15 @@ export default {
this.initmapPolygon();
},
methods: {
parseTime(time, pattern) {
return parseTime(time, pattern);
},
calculateDaysDifference(val) {
console.log(val);
const timestampDate = new Date(val);
const timeDiff = new Date().getTime() - timestampDate.getTime();
return Math.floor(timeDiff / (1000 * 3600 * 24));
},
initmapPolygon() {
let this_ = this;
const mapCon = uni.createMapContext('map');
@ -77,12 +181,105 @@ export default {
const centerLat = sumLat / count;
const centerLng = sumLng / count;
return [centerLat, centerLng];
},
tabChange(index) {
this.tabIndex = index;
//tabreloadqueryList
this.$refs.paging.reload();
},
queryList(pageNo, pageSize) {
//
//pageNopageSize
//
if (this.tabIndex == 0) {
const params = {
pageNo: pageNo,
pageSize: pageSize,
baseId: null,
blockId: this.blockData.id
};
getCropperPage(params)
.then((res) => {
//z-paging
this.$nextTick(() => {
this.$refs.paging.complete(res.data.list);
});
})
.catch((res) => {
//this.$refs.paging.complete(false);
//catchz-paging
//uni.$emit('z-paging-error-emit');
this.$refs.paging.complete(false);
});
}
if (this.tabIndex == 1) {
const params = {
pageNo: pageNo,
pageSize: pageSize,
baseId: null,
blockId: this.blockData.id
};
getGrowRecordPage(params)
.then((res) => {
//z-paging
this.$nextTick(() => {
this.$refs.paging.complete(res.data.list);
});
})
.catch((res) => {
//this.$refs.paging.complete(false);
//catchz-paging
//uni.$emit('z-paging-error-emit');
this.$refs.paging.complete(false);
});
}
if (this.tabIndex == 2) {
const params = {
pageNo: pageNo,
pageSize: pageSize,
baseId: null,
blockId: this.blockData.id,
jobTime:this.datetimerange
};
getRecoveryRecordPage(params)
.then((res) => {
//z-paging
this.$nextTick(() => {
this.$refs.paging.complete(res.data.list);
});
})
.catch((res) => {
//this.$refs.paging.complete(false);
//catchz-paging
//uni.$emit('z-paging-error-emit');
this.$refs.paging.complete(false);
});
}
},
itemClick(item, index) {
console.log('点击了', item.title);
},
searchData(val){
console.log(val,this.datetimerange)
this.$refs.paging.reload();
}
}
};
</script>
<style lang="scss" scoped>
.m-add-pro {
display: block;
position: fixed;
bottom: 200rpx;
left: 50%;
transform: translate(-50%);
background-color: #32c38f;
padding: 10rpx 15rpx;
border: none;
border-radius: 10rpx;
color: #eee;
}
.m-mapbox {
width: 100%;
height: 500rpx;
@ -110,4 +307,72 @@ export default {
}
}
}
.item {
margin: 30rpx 10rpx;
box-shadow: 0 0 7px 1px #a2a2a2;
padding: 20rpx 15rpx;
.m-item-box {
.m-item-top {
border-bottom: solid 1rpx #666;
display: flex;
padding-bottom: 20rpx;
align-items: center;
.m-item-img {
width: 150rpx;
height: 150rpx;
border-radius: 50%;
margin-right: 30rpx;
}
.m-pro-custrom {
flex: 1;
.m-pro-name {
font-size: 35rpx;
font-weight: bold;
}
.m-pro-Time {
display: flex;
justify-content: space-between;
width: 100%;
.m-daysdiff {
color: #00af7f;
}
}
/deep/ .m-dic-tag .v-dict-text {
font-size: 28rpx;
}
}
.m-big-num{
width: 20%;
font-size: 35rpx;
font-weight: bold;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
text-align: center;
}
}
.m-item-bottom{
margin-top: 20rpx;
display: flex;
justify-content: flex-end;
margin-right: 20rpx;
align-items: center;
.m-note{
margin-right: 20rpx;
}
}
.noflex{
display: block;
}
.no-border{
border: none;
}
}
}
</style>

@ -0,0 +1,32 @@
<template>
<view>
<web-view :src="src"></web-view>
</view>
</template>
<script>
export default {
data() {
return {
positionStr: null,
blockColor: null,
blockName: null,
blockType: null,
id: null,
str: null,
src:''
};
},
onLoad(options) {
if (options.str) {
this.str = options.str;
this.src = 'http://192.168.130.193:8848/H5/map.html?str=' + this.str
}else{
this.src = 'http://192.168.130.193:8848/H5/map.html?str=null'
}
console.log(this.src)
}
};
</script>
<style lang="scss"></style>

@ -1,19 +1,435 @@
<template>
<view>
<view class="content">
<view class="map-view">
<map
id="map"
v-if="formData.positionStr && formData.positionStr != ''"
class="m-map"
:longitude="longitude"
:latitude="latitude"
:polygons="polygons"
enable-satellite="true"
></map>
<view class="no-map" v-else>
<uv-empty icon="https://cdn.uviewui.com/uview/demo/empty/history.png"></uv-empty>
</view>
<view class="map-btn-group">
<button v-if="formData.positionStr && formData.positionStr != ''" @click="drawMap(formData)">编辑地块</button>
<button v-else @click="drawMap(formData)">绘制地块</button>
</view>
</view>
<view class="form-box">
<uni-forms label-width="80px" ref="valiForm" :rules="rules" :modelValue="formData">
<uni-forms-item label="" required name="id">
<uni-easyinput v-model="formData.id" placeholder=""></uni-easyinput>
</uni-forms-item>
<uni-forms-item label="地块名称" required name="blockName">
<uni-easyinput v-model="formData.blockName" placeholder="请输入地块名称"></uni-easyinput>
</uni-forms-item>
<uni-forms-item label="标识颜色" name="blockColor">
<view
class="color"
:style="{
background: formData.blockColor
}"
@click="openColor"
></view>
</uni-forms-item>
<uni-forms-item label="地块类型" required name="blockType">
<uni-data-select v-model="formData.blockType" :localdata="range"></uni-data-select>
</uni-forms-item>
<uni-forms-item label="地块面积" required name="blockArea">
<uni-easyinput v-model="formData.blockArea" placeholder="请输入地块面积">
<template #right>
<view class="input-slot-right"></view>
</template>
</uni-easyinput>
</uni-forms-item>
<uni-forms-item label="地块坐标" name="positionStr">
<uni-easyinput disabled v-model="formData.positionStr" placeholder="地块坐标"></uni-easyinput>
</uni-forms-item>
</uni-forms>
<button type="primary" @click="submit('valiForm')">提交</button>
</view>
<uv-pick-color ref="pickerColor" @confirm="confirm"></uv-pick-color>
</view>
</template>
<script>
export default {
data() {
return {
import { getDictDatas, DICT_TYPE } from '@/utils/dict';
import { updateBlock } from '@/api/system/block/block.js';
// SDK
var QQMapWX = require('@/plugins/qqmap-wx-jssdk.min.js');
var qqmapsdk;
var self;
export default {
data() {
return {
data: [],
IsOption: false,
polygons: [],
longitude: null,
latitude: null,
range: [],
realName: undefined,
formData: {
id: undefined,
blockName: undefined,
blockColor: undefined,
blockType: undefined,
blockArea: undefined,
positionStr: undefined,
baseId: undefined
},
rules: {
blockName: {
rules: [
{
required: true,
errorMessage: '地块名不能为空'
}
]
},
blockArea: {
rules: [
{
required: true,
errorMessage: '面积名不能为空'
}
]
},
blockType: {
rules: [
{
required: true,
errorMessage: '地块类型不能为空'
}
]
}
// positionStr: {
// rules: [
// {
// required: true,
// errorMessage: ''
// }
// ]
// }
}
};
},
onShow() {
let arr = this.getDictDatas(DICT_TYPE.LAND_TYPE);
arr.forEach((item) => {
item.text = item.label;
});
this.range = arr;
},
onLoad(options) {
if (options.val) {
const obj = JSON.parse(decodeURIComponent(options.val));
console.log(obj);
this.formData = obj;
this.initmapPolygon();
}
if (options.data) {
const obj = JSON.parse(options.data);
this.formData = obj;
this.initmapPolygon();
console.log(this.formData);
}
// self = this;
// self.getAuthorizeInfo();
// API
qqmapsdk = new QQMapWX({
key: 'PEFBZ-ELL64-MVDUZ-KDV4N-RISMO-VCB7A'
});
},
methods: {
openColor() {
this.$refs.pickerColor.open();
},
confirm(e) {
this.formData.blockColor = e.hex;
if (this.polygons.length > 0) {
this.polygons[0].strokeColor = e.hex;
this.polygons[0].fillColor = e.hex + '5c';
}
},
toLocation: function (obj) {
self.mapCtx.moveToLocation(obj);
self.mapCtx.translateMarker({
markerId: 1,
autoRotate: true,
duration: 100,
destination: {
latitude: obj.latitude,
longitude: obj.longitude
},
animationEnd() {
console.log('animation end');
}
});
},
//
getAuthorizeInfo() {
uni.authorize({
scope: 'scope.userLocation',
success() {
//
self.getLocationInfo();
},
fail() {
//
self.openConfirm();
console.log('你拒绝了授权,无法获得周边信息');
}
});
},
//
getLocationInfo() {
uni.getLocation({
type: 'wgs84',
success(res) {
console.log(res, '当前位置');
self.toLocation(res);
self.latitude = res.latitude;
self.longitude = res.longitude;
// uni.openLocation({
// latitude: latitude,
// longitude: longitude,
// success: function () {
// console.log('success');
// }
// })
}
});
},
//
//
openConfirm() {
uni.showModal({
title: '请求授权当前位置',
content: '需要获取您的地理位置,请确认授权',
success: (res) => {
if (res.confirm) {
uni.openSetting(); //
} else if (res.cancel) {
uni.showToast({
title: '你拒绝了授权,无法获得周边信息',
icon: 'none',
duration: 1000
});
}
}
});
},
poitap: function (e) {
console.log(e, 'poitap');
var obj = e.detail;
self.searchKey = obj.name;
// this.$api.msg(e)
self.toLocation(obj);
},
//
Cancel: function () {},
submit(ref) {
let this_ = this;
if (this.formData.positionStr == undefined || this.formData.positionStr == '') {
uni.showToast({
title: `请先绘制地块`,
icon: 'error'
});
return false;
}
this.$refs[ref]
.validate()
.then((res) => {
console.log('success', res);
updateBlock(res)
.then((res) => {
uni.showToast({
title: `修改成功`,
duration: 1500,
success() {
setTimeout(() => {
this_.reset();
uni.switchTab({
url: '/pages/block/index'
});
}, 1500);
}
});
})
.catch((err) => {
console.log(err);
});
})
.catch((err) => {
console.log('err', err);
});
},
drawMap(val) {
const str = encodeURIComponent(JSON.stringify(val))
uni.navigateTo({
url:'/sunPages/drawMap/drawMap?str=' + str
});
},
reset() {
this.formData = {
id: undefined,
blockName: undefined,
blockColor: undefined,
blockType: undefined,
blockArea: undefined,
positionStr: undefined,
baseId: undefined
};
this.polygons = [];
},
resetBlock() {
this.polygons = [];
this.formData.positionStr = undefined;
},
initmapPolygon() {
let this_ = this;
const mapCon = uni.createMapContext('map');
const arr = JSON.parse(this.formData.positionStr);
const center = this_.calculateCenter(arr);
let Arr = arr.map((item) => {
const obj = {
latitude: item[1],
longitude: item[0]
};
return obj;
});
console.log(Arr);
let Obj = {
points: Arr,
strokeColor: this_.formData.blockColor && this_.formData.blockColor != null ? this_.formData.blockColor : '#007969',
fillColor: this_.formData.blockColor && this_.formData.blockColor != null ? this_.formData.blockColor + '5c' : '#0079695c',
zIndex: 1
};
this_.$nextTick(() => {
this_.polygons.push(Obj);
mapCon.includePoints({
padding: [20, 20, 20, 20],
points: Arr
});
this_.longitude = center[0];
this_.latitude = center[1];
});
},
//
calculateCenter(coordinates) {
let sumLat = 0;
let sumLng = 0;
coordinates.forEach((coord) => {
sumLat += coord[0];
sumLng += coord[1];
});
const count = coordinates.length;
const centerLat = sumLat / count;
const centerLng = sumLng / count;
return [centerLat, centerLng];
}
}
};
</script>
<style lang="scss">
<style scoped lang="scss">
.content {
background-color: #f1f1f1;
overflow: hidden;
min-height: 100vh;
color: #646464;
font-size: 40rpx;
}
.option {
max-height: 300rpx;
width: 90%;
line-height: 60rpx;
position: fixed;
top: 110rpx;
z-index: 99999;
border-radius: 150rpx;
overflow: scroll;
left: 50%;
transform: translateX(-50%);
}
.column_item {
padding: 0 40rpx;
height: 60rpx;
font-size: 28rpx;
width: 100%;
overflow: hidden;
margin: 0rpx auto;
background-color: #00000080;
text-overflow: ellipsis;
color: #fff;
white-space: nowrap;
}
.column_item:active {
background-color: #8f8f94;
}
.page-section-gap {
width: 100%;
position: fixed;
top: 0;
z-index: 0;
}
.color {
width: 50rpx;
height: 50rpx;
border-radius: 6rpx;
border: solid 1rpx #d0d0d0;
background-color: transparent;
}
.input-slot-right {
background-color: #eee;
padding: 10rpx;
}
.map-view {
width: 100%;
height: 500rpx;
overflow: hidden;
position: relative;
margin-bottom: 30rpx;
.m-map {
width: 100%;
height: 110%;
}
.map-btn-group {
position: absolute;
z-index: 9;
bottom: 20rpx;
left: 50%;
transform: translateX(-50%);
}
}
.form-box {
padding: 40rpx 20rpx;
margin: 0 20rpx;
background: #fff;
box-shadow: 0 0 10px 1px #dadada;
border-radius: 15rpx;
/deep/ .uni-forms-item {
align-items: center;
&:last-child,{
display: none;
}
&:first-child{
display: none;
}
}
}
</style>

Loading…
Cancel
Save