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

237 lines
8.0 KiB
Vue
Raw 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">
<view class="new">
2023-02-20 14:19:28 +08:00
<view class="content">
<uni-forms :label-width="80">
2023-05-24 08:58:48 +08:00
<uni-forms-item label="工程名称">
2023-05-25 10:10:22 +08:00
<uni-easyinput
v-model="formData.engineeringName"
placeholder="请输入项目名称"
@click.native="showDrawer"
:clearable="false"
/>
2023-05-24 08:58:48 +08:00
</uni-forms-item>
2023-02-20 14:19:28 +08:00
<uni-forms-item label="项目名称">
2023-05-24 08:58:48 +08:00
<uni-easyinput v-model="formData.name" placeholder="请输入项目名称" />
2023-02-20 14:19:28 +08:00
</uni-forms-item>
2023-05-24 08:58:48 +08:00
<!-- <uni-forms-item label="项目类别">
2023-03-30 09:04:07 +08:00
<uni-data-select v-model="formData.projectType" :localdata="TypeRange"></uni-data-select>
2023-05-24 08:58:48 +08:00
</uni-forms-item> -->
2023-02-20 14:19:28 +08:00
<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="请输入区域信息"
/>
<uni-icons type="location" color="#007aff" size="26" class="ml20" @click="chooseLocation"></uni-icons>
2023-02-20 14:19:28 +08:00
</view>
</uni-forms-item>
<uni-forms-item label="描述">
2023-05-24 08:58:48 +08:00
<uni-easyinput type="textarea" autoHeight v-model="formData.description" placeholder="请输入项目描述" />
2023-02-20 14:19:28 +08:00
</uni-forms-item>
2023-05-24 08:58:48 +08:00
<uni-file-picker
v-model="formData.files"
title="请上传拓扑图"
:sourceType="['album']"
@select="select"
></uni-file-picker>
2023-02-20 14:19:28 +08:00
</uni-forms>
</view>
<view class="btn-wrap">
<view class="btn-wrap-item" @click="submit"> 提交 </view>
</view>
2023-05-24 08:58:48 +08:00
<uni-drawer ref="showRight" mode="right" :mask-click="false" :width="375">
<uni-indexed-list :options="gcListFilter" :showSelect="false" @click="closeDrawer"></uni-indexed-list>
</uni-drawer>
2023-02-20 14:19:28 +08:00
</view>
</view>
</Cn-page>
</template>
<script>
2023-05-24 08:58:48 +08:00
import { pinyin } from 'pinyin-pro'
2023-03-30 09:04:07 +08:00
import { addAppProject } from '../../common/api/project'
2023-05-24 08:58:48 +08:00
import { queryEngineering } from '@/common/api/gc.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: [],
description: '',
projectType: '1',
2023-02-20 14:19:28 +08:00
name: '',
2023-03-30 09:04:07 +08:00
lat: '2',
2023-05-24 08:58:48 +08:00
lng: '3',
2023-02-20 14:19:28 +08:00
},
2023-02-28 14:03:38 +08:00
TypeRange: [
{
text: '监测',
2023-05-24 08:58:48 +08:00
value: '1',
2023-02-28 14:03:38 +08:00
},
{
text: '用能',
2023-05-24 08:58:48 +08:00
value: '2',
},
],
gcList: [],
2023-02-20 14:19:28 +08:00
}
},
2023-05-24 08:58:48 +08:00
computed: {
gcListFilter() {
let result = []
this.gcList.forEach((item) => {
let arr = pinyin(item.name[0], { toneType: 'none', type: 'array' })
let letter = arr[0][0].toUpperCase()
console.log(letter)
let index = result.findIndex((item) => item.letter === letter)
if (index === -1) {
result.push({
letter,
data: [item.name],
})
} else {
result[index].data.push(item.name)
}
})
return result
},
},
onLoad() {
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)
},
})
queryEngineering().then((res) => {
this.gcList = res.data
})
2023-03-30 09:04:07 +08:00
},
2023-02-20 14:19:28 +08:00
methods: {
2023-05-24 08:58:48 +08:00
showDrawer() {
this.$refs.showRight.open()
2023-03-30 09:04:07 +08:00
},
2023-05-24 08:58:48 +08:00
closeDrawer(e) {
console.log(e)
this.formData.engineeringName = e.item.name
this.formData.engineeringId = this.gcList.find((item) => item.name === e.item.name).id
this.$refs.showRight.close()
},
select(e) {
console.log(e)
console.log(this.formData.files)
this.formData.files = this.formData.files.concat(e.tempFiles)
},
chooseLocation() {
2023-02-20 14:19:28 +08:00
uni.chooseLocation({
success: function (res) {
this.address = res.name
2023-05-24 08:58:48 +08:00
console.log('位置名称:' + res.name)
console.log('详细地址:' + res.address)
console.log('纬度:' + res.latitude)
console.log('经度:' + res.longitude)
},
})
2023-02-20 14:19:28 +08:00
},
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.projectType) {
this.$util.toast('请选择项目类别')
return
}
if (!this.formData.area) {
this.$util.toast('请输入区域信息')
return
}
if (!this.formData.description) {
this.$util.toast('请输入项目描述')
return
}
if (!this.formData.files.length) {
this.$util.toast('请上传拓扑图')
return
}
let arr = []
for (let i = 0; i < this.formData.files.length; i++) {
let item = this.formData.files[i]
2023-05-25 10:10:22 +08:00
console.log(item);
2023-03-30 09:04:07 +08:00
arr.push({
name: 'files',
2023-05-25 10:10:22 +08:00
uri: item.url,
2023-03-30 09:04:07 +08:00
})
}
let data = JSON.parse(JSON.stringify(this.formData))
delete data.files
2023-05-24 08:58:48 +08:00
addAppProject(data, arr).then((res) => {
2023-07-03 09:16:54 +08:00
2023-05-25 10:10:22 +08:00
console.warn(res);
if (res.length === 1) {
this.$util.toast(res[0].message)
return
}
2023-03-30 09:04:07 +08:00
console.log(res)
this.$util.toast('项目创建成功')
2023-05-25 10:10:22 +08:00
this.$util.prePage().store?.reload()
2023-05-24 08:58:48 +08:00
setTimeout(() => {
uni.navigateBack({ delta: 1 })
2023-05-25 10:10:22 +08:00
}, 1500)
2023-03-30 09:04:07 +08:00
})
2023-05-24 08:58:48 +08:00
},
},
2023-02-20 14:19:28 +08:00
}
</script>
2023-05-24 08:58:48 +08:00
<style lang="scss">
2023-02-20 14:19:28 +08:00
.new {
2023-02-28 14:03:38 +08:00
padding: 34rpx;
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;
background: $uni-theme-blue;
color: #fff;
height: 80rpx;
border-radius: 12rpx;
}
}
}
/deep/ .uni-drawer__content {
width: 100vw !important;
}
2023-05-24 08:58:48 +08:00
</style>