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

183 lines
6.1 KiB
Vue
Raw Normal View History

2023-04-12 09:10:35 +08:00
<template>
2023-05-25 10:10:22 +08:00
<Cn-page :loading="loading">
<view slot="body">
<view class="new">
2023-04-12 09:10:35 +08:00
<view class="content">
2023-08-10 09:18:17 +08:00
<page-meta :page-style="'overflow:'+(show?'hidden':'visible')"></page-meta>
2023-04-12 09:10:35 +08:00
<uni-forms :label-width="80">
<uni-forms-item label="工程名称">
2023-08-17 09:24:59 +08:00
<uni-easyinput type="text" v-model="formData.name" placeholder="请输入工程名称"/>
2023-04-12 09:10:35 +08:00
</uni-forms-item>
<uni-forms-item label="位置">
2023-04-12 18:39:52 +08:00
<!-- <view style="display:flex;">
2023-04-12 09:10:35 +08:00
<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-04-12 18:39:52 +08:00
</view> -->
2023-08-17 09:24:59 +08:00
<uni-data-picker :localdata="localdata" @change="areaChange" v-model="value"
@popupopened="show=true" @popupclosed="show=false">
2023-07-24 08:47:20 +08:00
</uni-data-picker>
2023-04-12 09:10:35 +08:00
</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-04-12 09:10:35 +08:00
</uni-forms-item>
</uni-forms>
</view>
<view class="btn-wrap">
2023-08-17 09:24:59 +08:00
<view class="btn-wrap-item" @click="submit"> 提交</view>
2023-04-12 09:10:35 +08:00
</view>
</view>
</view>
</Cn-page>
</template>
<script>
2023-08-17 09:24:59 +08:00
import {addEngineering, auditEngineering} from '../../common/api/engineering'
2023-04-12 18:39:52 +08:00
import area from '../../common/js/area.json'
2023-08-17 09:24:59 +08:00
2023-04-12 09:10:35 +08:00
export default {
2023-04-12 18:39:52 +08:00
data() {
2023-04-12 09:10:35 +08:00
return {
2023-04-12 18:39:52 +08:00
localdata: area,
2023-04-12 09:10:35 +08:00
loading: false,
2023-07-24 08:47:20 +08:00
value: '',
2023-04-12 09:10:35 +08:00
formData: {
2023-05-25 10:10:22 +08:00
city: '',
description: '',
name: '',
province: '',
2023-04-12 09:10:35 +08:00
},
2023-07-24 08:47:20 +08:00
engineering: {},
2023-08-10 09:18:17 +08:00
show: false,
2023-08-17 09:24:59 +08:00
options: {}
2023-04-12 09:10:35 +08:00
}
},
2023-07-24 08:47:20 +08:00
onLoad(options) {
2023-08-17 09:24:59 +08:00
this.options = options
2023-07-24 08:47:20 +08:00
if (options.engineering) {
this.engineering = JSON.parse(decodeURIComponent(options.engineering))
console.log(this.engineering)
for (let key in this.formData) {
if (this.engineering[key]) {
this.formData[key] = this.engineering[key]
}
}
this.value = this.engineering.city
this.formData.id = this.engineering.id
2023-08-17 09:24:59 +08:00
uni.setNavigationBarTitle({title: '工程编辑'})
2023-07-24 08:47:20 +08:00
}
2023-09-06 18:13:08 +08:00
if (options.from === 'index') {
2023-08-29 16:14:09 +08:00
this.$util.toast('请先创建一个工程')
}
2023-04-12 09:10:35 +08:00
// console.log(area);
2023-07-24 08:47:20 +08:00
console.log(this.$util.prePage())
2023-04-12 09:10:35 +08:00
},
methods: {
2023-08-17 09:24:59 +08:00
toJSON() {
},
2023-04-12 18:39:52 +08:00
areaChange(e) {
2023-07-24 08:47:20 +08:00
if (e.detail.value.length) {
this.formData.province = e.detail.value[0].value
this.formData.city = e.detail.value[1].value
} else {
this.formData.province = ''
this.formData.city = ''
}
2023-04-12 18:39:52 +08:00
},
select(e) {
2023-05-25 10:10:22 +08:00
console.log(e)
2023-04-12 09:10:35 +08:00
},
2025-08-13 10:42:31 +08:00
// chooseLocation() {
// uni.chooseLocation({
// success: function (res) {
// this.address = res.name
// console.log('位置名称:' + res.name)
// console.log('详细地址:' + res.address)
// console.log('纬度:' + res.latitude)
// console.log('经度:' + res.longitude)
// },
// })
// },
2023-04-12 18:39:52 +08:00
async submit() {
2023-05-25 10:10:22 +08:00
console.log(this.formData)
2023-04-12 09:10:35 +08:00
if (!this.formData.name) {
this.$util.toast('请输入工程名称')
return
}
2023-05-25 10:10:22 +08:00
2023-04-12 18:39:52 +08:00
if (!this.formData.province) {
this.$util.toast('请选择区域信息')
2023-04-12 09:10:35 +08:00
return
}
if (!this.formData.description) {
this.$util.toast('请输入工程描述')
return
}
2023-07-24 08:47:20 +08:00
if (this.formData.id) {
await auditEngineering(this.formData)
this.$util.toast('工程修改成功')
2023-07-31 09:00:30 +08:00
this.$util.refreshPrePage(2)
2023-07-24 08:47:20 +08:00
} else {
2023-08-17 09:24:59 +08:00
let res = await addEngineering(this.formData)
2023-07-24 08:47:20 +08:00
this.$util.toast('工程创建成功')
2023-08-17 09:24:59 +08:00
if (this.options.from === 'index') {
uni.setStorageSync('engineering', res.data)
uni.redirectTo({
2023-09-06 18:13:08 +08:00
url: '/pages/device/new?type=' + this.options.type,
2023-08-17 09:24:59 +08:00
})
return
} else {
this.$util.refreshPrePage()
}
2023-07-24 08:47:20 +08:00
}
2023-05-25 10:10:22 +08:00
},
},
2023-04-12 09:10:35 +08:00
}
</script>
2023-05-25 10:10:22 +08:00
<style lang="scss">
2023-04-12 09:10:35 +08:00
.new {
padding: 34rpx;
.content {
.content-des {
font-size: 28rpx;
color: #666;
margin-bottom: 20rpx;
}
margin-bottom: 20rpx;
padding: 34rpx;
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-04-12 09:10:35 +08:00
color: #fff;
height: 80rpx;
border-radius: 12rpx;
}
}
}
/deep/ .uni-drawer__content {
width: 100vw !important;
}
2023-05-25 10:10:22 +08:00
</style>