Files
app-govern/pages/project/new.vue

465 lines
16 KiB
Vue
Raw Permalink Normal View History

2023-02-20 14:19:28 +08:00
<template>
2023-05-24 08:58:48 +08:00
<Cn-page :loading="loading">
<view slot="body">
2023-08-24 15:35:45 +08:00
<view class="new" :class="{'project-new':!this.options.project}">
2023-02-20 14:19:28 +08:00
<view class="content">
<uni-forms :label-width="80">
2023-08-24 15:35:45 +08:00
<uni-forms-item label="工程名称" @click.native.stop.prevent="selectEngineering">
2023-05-25 10:10:22 +08:00
<uni-easyinput
v-model="formData.engineeringName"
2023-08-29 16:14:09 +08:00
placeholder="请选择工程"
2023-05-25 10:10:22 +08:00
:clearable="false"
2023-08-24 15:35:45 +08:00
:disabled="true"
2023-05-25 10:10:22 +08:00
/>
2023-05-24 08:58:48 +08:00
</uni-forms-item>
2023-02-20 14:19:28 +08:00
<uni-forms-item label="项目名称">
2023-08-17 09:24:59 +08:00
<uni-easyinput v-model="formData.name" placeholder="请输入项目名称"/>
2023-02-20 14:19:28 +08:00
</uni-forms-item>
<uni-forms-item label="区域">
2023-05-24 08:58:48 +08:00
<view style="display: flex">
<uni-easyinput
:clearable="false"
type="textarea"
autoHeight
v-model="formData.area"
placeholder="请输入区域信息"
/>
2025-08-13 10:42:31 +08:00
<!-- <uni-icons
2023-07-24 08:47:20 +08:00
type="location"
color="#007aff"
size="26"
class="ml20"
@click="chooseLocation"
2025-08-13 10:42:31 +08:00
></uni-icons> -->
2023-02-20 14:19:28 +08:00
</view>
</uni-forms-item>
<uni-forms-item label="描述">
2023-07-24 08:47:20 +08:00
<uni-easyinput
type="textarea"
autoHeight
2023-08-29 16:14:09 +08:00
maxlength="999"
2023-07-24 08:47:20 +08:00
v-model="formData.description"
placeholder="请输入项目描述"
/>
2023-02-20 14:19:28 +08:00
</uni-forms-item>
2023-07-24 08:47:20 +08:00
<view class="temp-choose">
<view class="temp-choose-title">从模版库选择拓扑图</view>
<view class="temp-choose-content">
<view class="temp-choose-content-item" v-for="(item, index) in formData.tempFiles">
<image
class="temp-choose-content-item-img"
:src="item.filePath"
mode="aspectFill"
/>
<view class="temp-choose-content-item-close" @click="deleteImg(index)">
2023-08-17 09:24:59 +08:00
<uni-icons style="font-size: 18px" type="closeempty" color="#fff" size="20"/>
2023-07-24 08:47:20 +08:00
</view>
</view>
<view class="temp-choose-content-item" @click="openTemp">
<uni-icons type="plusempty" size="70" color="#f1f1f1"></uni-icons>
</view>
</view>
</view>
2023-05-24 08:58:48 +08:00
<uni-file-picker
v-model="formData.files"
2023-07-24 08:47:20 +08:00
title="从本地上传拓扑图"
2023-05-24 08:58:48 +08:00
:sourceType="['album']"
2023-08-17 09:24:59 +08:00
:before-remove="beforeRemove"
2023-05-24 08:58:48 +08:00
@select="select"
></uni-file-picker>
2023-02-20 14:19:28 +08:00
</uni-forms>
</view>
<view class="btn-wrap">
2023-08-17 09:24:59 +08:00
<view class="btn-wrap-item" @click="submit"> 提交</view>
2023-02-20 14:19:28 +08:00
</view>
2023-07-24 08:47:20 +08:00
<uni-popup ref="showTemp" type="bottom" :mask-click="false">
<view class="popup-header">
<view class="popup-header-title">模版库</view>
<view class="popup-header-close" @click="closeTemp">
2023-08-17 09:24:59 +08:00
<uni-icons type="closeempty" color="#111" size="20"/>
2023-07-24 08:47:20 +08:00
</view>
</view>
<view class="temp-list">
<view
class="temp-list-item"
:class="{
2023-07-31 09:00:30 +08:00
'temp-list-item-active': formData.tempFiles.some(
2023-08-17 09:24:59 +08:00
(item2) => item2.id === item.id || item2.topoId === item.id,
2023-07-31 09:00:30 +08:00
),
2023-07-24 08:47:20 +08:00
}"
v-for="(item, index) in tempList"
@click="chooseTempItem(item)"
>
2023-08-17 09:24:59 +08:00
<image class="temp-list-item-img" :src="item.filePath" mode="aspectFill"/>
2023-07-24 08:47:20 +08:00
<view class="temp-list-item-name">{{ item.name }}</view>
</view>
</view>
</uni-popup>
2023-02-20 14:19:28 +08:00
</view>
</view>
</Cn-page>
</template>
<script>
2023-08-17 09:24:59 +08:00
import {pinyin} from 'pinyin-pro'
import {addAppProject, updateAppProject, checkCanDelete} from '../../common/api/project'
import {getTopoTemplate} from '../../common/api/device'
import {queryEngineering} from '@/common/api/engineering.js'
2023-02-20 14:19:28 +08:00
export default {
2023-05-24 08:58:48 +08:00
data() {
2023-02-20 14:19:28 +08:00
return {
loading: false,
formData: {
2023-05-24 08:58:48 +08:00
engineeringId: '',
engineeringName: '',
area: '',
2023-03-30 09:04:07 +08:00
files: [],
2023-07-24 08:47:20 +08:00
tempFiles: [],
topoIds: [],
2023-03-30 09:04:07 +08:00
description: '',
2023-02-20 14:19:28 +08:00
name: '',
2023-08-10 09:18:17 +08:00
lat: '',
lng: '',
2023-02-20 14:19:28 +08:00
},
2023-07-24 08:47:20 +08:00
tempList: [],
2023-07-31 09:00:30 +08:00
project: null,
2023-08-17 15:37:19 +08:00
options: {}
2023-02-20 14:19:28 +08:00
}
},
2023-08-24 15:35:45 +08:00
onShow() {
if (!this.options.project) {
2023-09-06 10:56:10 +08:00
let engineering = uni.getStorageSync('onceSelectEngineering')
2023-08-29 16:14:09 +08:00
if (engineering) {
2023-09-06 10:56:10 +08:00
uni.removeStorageSync('onceSelectEngineering')
2023-08-29 16:14:09 +08:00
this.formData.engineeringId = engineering.id
this.formData.engineeringName = engineering.name
}
2023-08-24 15:35:45 +08:00
}
2023-05-24 08:58:48 +08:00
},
2023-07-24 08:47:20 +08:00
onLoad(options) {
2023-08-17 15:37:19 +08:00
this.options = options
2023-07-24 08:47:20 +08:00
if (options.project) {
2023-07-31 09:00:30 +08:00
uni.setNavigationBarTitle({
title: '编辑项目',
})
2023-07-24 08:47:20 +08:00
this.project = JSON.parse(decodeURIComponent(options.project))
console.log(this.project)
for (let key in this.formData) {
if (this.project[key]) {
this.formData[key] = this.project[key]
}
}
2023-08-29 16:14:09 +08:00
} else {
let engineering = uni.getStorageSync('engineering')
this.formData.engineeringId = engineering.id
this.formData.engineeringName = engineering.name
2023-07-24 08:47:20 +08:00
}
2023-03-30 09:04:07 +08:00
uni.getLocation({
type: 'wgs84',
success: function (res) {
2023-05-24 08:58:48 +08:00
console.log(res)
console.log('当前位置的经度:' + res.longitude)
console.log('当前位置的纬度:' + res.latitude)
},
})
2023-07-24 08:47:20 +08:00
getTopoTemplate().then((res) => {
console.log(res)
2023-08-30 18:52:58 +08:00
this.tempList = res.data.map((item) => {
return {
...item,
filePath:this.$config.static + item.filePath
}
})
2023-07-31 09:00:30 +08:00
if (this.project) {
this.project.topologyDiagramPaths.forEach((item) => {
if (this.tempList.some((item2) => item2.id === item.topoId)) {
this.formData.tempFiles.push(item)
} else {
this.formData.files.push({
2023-08-31 16:14:15 +08:00
url: item.filePath,
2023-07-31 09:00:30 +08:00
extname: item.name.split('.')[1],
name: item.name,
...item,
})
}
})
}
2023-05-24 08:58:48 +08:00
})
2023-03-30 09:04:07 +08:00
},
2023-02-20 14:19:28 +08:00
methods: {
2023-08-24 15:35:45 +08:00
selectEngineering() {
2023-08-29 16:14:09 +08:00
console.log(123)
if (this.options.project) return this.$util.toast('项目已经创建,不能修改工程')
2023-08-24 15:35:45 +08:00
uni.navigateTo({
2023-09-06 10:56:10 +08:00
url: '/pages/home/selectEngineering?from=once',
2023-08-24 15:35:45 +08:00
})
},
2023-08-17 09:24:59 +08:00
beforeRemove(e) {
console.log(e)
if (!e.tempFile.id) {
return true
}
return new Promise((resolve, reject) => {
checkCanDelete(e.tempFile.id).then((res) => {
console.log(res)
if (res.data) {
resolve(true)
} else {
reject()
}
})
})
},
async deleteImg(index) {
await this.beforeRemove({
tempFile: this.formData.tempFiles[index],
})
2023-07-24 08:47:20 +08:00
this.formData.tempFiles.splice(index, 1)
},
2023-08-17 09:24:59 +08:00
async chooseTempItem(item) {
console.log(item)
console.log(this.formData.tempFiles)
// 编辑的时候如果已经存在就要验证topoId
let index = this.formData.tempFiles.findIndex((item2) => item2.id === item.id || item2.topoId === item.id)
if (index > -1) {
await this.beforeRemove({
tempFile: this.formData.tempFiles[index],
})
this.formData.tempFiles.splice(index, 1)
2023-07-24 08:47:20 +08:00
} else {
this.formData.tempFiles.push(item)
}
},
closeTemp() {
this.$refs.showTemp.close()
},
openTemp() {
this.$refs.showTemp.open()
},
2023-05-24 08:58:48 +08:00
select(e) {
console.log(e)
2023-08-17 09:24:59 +08:00
this.formData.files.push(...e.tempFiles)
2023-05-24 08:58:48 +08:00
console.log(this.formData.files)
},
2025-08-13 10:42:31 +08:00
// chooseLocation() {
// uni.chooseLocation({
// success: (res) => {
// this.formData.area = res.name
// this.formData.lat = res.latitudeame
// this.formData.lng = res.longitude
// console.log('位置名称:' + res.name)
// console.log('详细地址:' + res.address)
// console.log('纬度:' + res.latitude)
// console.log('经度:' + res.longitude)
// },
// })
// },
2023-05-24 08:58:48 +08:00
async submit() {
console.log(this.formData)
2023-03-30 09:04:07 +08:00
if (!this.formData.name) {
this.$util.toast('请输入项目名称')
return
}
if (!this.formData.area) {
this.$util.toast('请输入区域信息')
return
}
if (!this.formData.description) {
this.$util.toast('请输入项目描述')
return
}
2023-07-24 08:47:20 +08:00
if (!this.formData.files.length && !this.formData.tempFiles.length) {
this.$util.toast('请至少选择一张拓扑图')
2023-03-30 09:04:07 +08:00
return
}
let arr = []
for (let i = 0; i < this.formData.files.length; i++) {
let item = this.formData.files[i]
2023-07-24 08:47:20 +08:00
console.log(item)
2023-03-30 09:04:07 +08:00
arr.push({
2023-08-17 09:24:59 +08:00
...item,
2023-03-30 09:04:07 +08:00
name: 'files',
2023-05-25 10:10:22 +08:00
uri: item.url,
2023-03-30 09:04:07 +08:00
})
}
2023-08-17 09:24:59 +08:00
console.log(arr)
2023-08-17 15:37:19 +08:00
this.formData.topoIds = this.formData.tempFiles.map((item) => (item.id))
2023-03-30 09:04:07 +08:00
let data = JSON.parse(JSON.stringify(this.formData))
2023-07-31 09:00:30 +08:00
let res = {}
2023-08-10 09:18:17 +08:00
console.warn(data, arr)
2023-07-31 09:00:30 +08:00
if (this.project) {
data.id = this.project.id
2023-08-17 09:24:59 +08:00
data.newTopoIds = data.files.filter(item => item.id).map((item) => item.id)
data.newTopoIds.push(...data.tempFiles.filter(item => item.id && item.topoId).map((item) => item.id))
data.topoIds = data.tempFiles.filter(item => item.id && !item.topoId).map((item) => item.id)
delete data.tempFiles
delete data.files
arr = arr.filter(item => !item.id)
2023-07-31 09:00:30 +08:00
res = await updateAppProject(data, arr)
} else {
2023-08-17 09:24:59 +08:00
delete data.tempFiles
delete data.files
2023-07-31 09:00:30 +08:00
res = await addAppProject(data, arr)
}
2023-08-10 09:18:17 +08:00
let result = {}
if (res.code === 'A0000') {
result = res
} else {
console.warn(res)
if (res.length === 1) {
this.$util.toast(res[0].message)
return
}
result = JSON.parse(res[1].data)
2023-07-31 09:00:30 +08:00
}
if (result.code === 'A0000') {
if (this.project) {
this.$util.toast('项目修改成功')
this.$util.refreshPrePage(2)
2023-07-24 08:47:20 +08:00
} else {
2023-08-17 15:37:19 +08:00
if (this.options.from === 'newDevice') {
uni.navigateBack()
} else {
this.$util.toast('项目创建成功')
this.$util.refreshPrePage()
}
2023-07-24 08:47:20 +08:00
}
2023-07-31 09:00:30 +08:00
} else {
this.$util.toast(result.message)
}
2023-05-24 08:58:48 +08:00
},
},
2023-02-20 14:19:28 +08:00
}
</script>
2023-08-24 15:35:45 +08:00
<style lang="scss" scoped>
.project-new /deep/ .is-disabled {
background: #fff !important;
color: #111;
}
2023-08-29 16:14:09 +08:00
2023-02-20 14:19:28 +08:00
.new {
2023-02-28 14:03:38 +08:00
padding: 34rpx;
2023-08-29 16:14:09 +08:00
.project-new {
2023-02-20 14:19:28 +08:00
2023-08-24 15:35:45 +08:00
}
2023-08-29 16:14:09 +08:00
2023-02-20 14:19:28 +08:00
.content {
.content-des {
font-size: 28rpx;
color: #666;
margin-bottom: 20rpx;
}
margin-bottom: 20rpx;
2023-02-28 14:03:38 +08:00
padding: 34rpx;
2023-02-20 14:19:28 +08:00
background: $uni-theme-white;
border-radius: 12rpx;
}
.btn-wrap {
margin-top: 40rpx;
display: flex;
align-items: center;
justify-content: space-between;
.btn-wrap-item {
display: flex;
align-items: center;
justify-content: center;
flex: 1;
2023-08-03 14:51:36 +08:00
background: $uni-theme-color;
2023-02-20 14:19:28 +08:00
color: #fff;
height: 80rpx;
border-radius: 12rpx;
}
}
2023-08-17 09:24:59 +08:00
2023-07-24 08:47:20 +08:00
.temp-choose {
margin-bottom: 44rpx;
2023-08-17 09:24:59 +08:00
2023-07-24 08:47:20 +08:00
.temp-choose-title {
font-size: 14px;
color: #333;
}
2023-08-17 09:24:59 +08:00
2023-07-24 08:47:20 +08:00
.temp-choose-content {
margin-top: 20rpx;
display: grid;
grid-template-columns: repeat(3, 198rpx);
grid-gap: 10rpx;
2023-08-17 09:24:59 +08:00
2023-07-24 08:47:20 +08:00
.temp-choose-content-item {
box-sizing: border-box;
border: 1px #eee solid;
position: relative;
display: flex;
align-items: center;
justify-content: center;
height: 198rpx;
2023-08-17 09:24:59 +08:00
2023-07-24 08:47:20 +08:00
.temp-choose-content-item-img {
height: 100%;
width: 100%;
background: skyblue;
display: block;
}
2023-08-17 09:24:59 +08:00
2023-07-24 08:47:20 +08:00
.temp-choose-content-item-close {
display: flex;
align-items: center;
justify-content: center;
position: absolute;
top: 3px;
right: 3px;
border-radius: 50%;
background-color: rgba(0, 0, 0, 0.5);
z-index: 2;
height: 52rpx;
width: 52rpx;
font-size: 24rpx;
color: #666;
}
}
}
}
.temp-list {
box-sizing: border-box;
width: 750rpx;
height: 80vh;
padding: 20rpx;
overflow-y: scroll;
background: #fff;
.temp-list-item {
margin-bottom: 10rpx;
position: relative;
box-sizing: border-box;
border: 4px solid #f1f1f1;
2023-08-17 09:24:59 +08:00
2023-07-24 08:47:20 +08:00
.temp-list-item-img {
height: 280rpx;
width: 100%;
}
2023-08-17 09:24:59 +08:00
2023-07-24 08:47:20 +08:00
.temp-list-item-name {
position: absolute;
right: 0;
top: 0;
background: #fff;
padding: 4rpx 8rpx;
}
2023-08-17 09:24:59 +08:00
2023-07-24 08:47:20 +08:00
&-active {
2023-08-03 14:51:36 +08:00
border: 4rpx solid $uni-theme-color;
2023-07-24 08:47:20 +08:00
}
}
}
2023-02-20 14:19:28 +08:00
}
/deep/ .uni-drawer__content {
width: 100vw !important;
}
2023-05-24 08:58:48 +08:00
</style>