<template>
|
<view>
|
<view class="container">
|
<uni-forms ref="baseForm" :modelValue="baseFormData">
|
<uni-forms-item label="项目名称" required name="name">
|
<uni-easyinput v-model="baseFormData.name" placeholder="请输入项目名称" />
|
</uni-forms-item>
|
<uni-forms-item label="所属公司" required name="company">
|
<view @click="autoLoad('company','')">
|
<uni-combox :candidates="companies" placeholder="请选所属公司"
|
v-model="baseFormData.company" @input="autoLoad('company',baseFormData.company)"></uni-combox>
|
</view>
|
</uni-forms-item>
|
<uni-forms-item label="甲方单位" name="cstmrId">
|
<view @click="autoLoad('cstmr','')">
|
<uni-combox :candidates="cstmrs" placeholder="请选择甲方单位"
|
v-model="baseFormData.cstmrId" @input="autoLoad('cstmr',baseFormData.cstmrId)"></uni-combox>
|
</view>
|
</uni-forms-item>
|
<uni-forms-item label="负责人" name="director">
|
<view @click="autoLoad('user','')">
|
<uni-combox :candidates="directors" placeholder="请选择负责人"
|
v-model="baseFormData.director" @input="autoLoad('user',baseFormData.director)"></uni-combox>
|
</view>
|
</uni-forms-item>
|
<uni-forms-item label="省市区" name="citysData">
|
<uni-data-picker @change="areaChange" placeholder="请选择省市区" popup-title="请选择所在地区" :localdata="citysData" v-model="baseFormData.pcd">
|
</uni-data-picker>
|
</uni-forms-item>
|
<uni-forms-item label="项目总金额" name="money">
|
<uni-easyinput v-model="baseFormData.money" placeholder="请输入项目总金额" />
|
</uni-forms-item>
|
<uni-forms-item label="项目地址" name="addr">
|
<uni-easyinput v-model="baseFormData.addr" placeholder="请输入项目地址" />
|
</uni-forms-item>
|
|
<uni-forms-item label="备注" name="remarks">
|
<uni-easyinput type="textarea" v-model="baseFormData.remarks" placeholder="请输入备注" />
|
</uni-forms-item>
|
</uni-forms>
|
<button type="primary" @click="addOrder()">添加</button>
|
</view>
|
</view>
|
</template>
|
|
<script>
|
import test from '../../../static/js/citys-data.js'
|
export default {
|
data() {
|
return {
|
cstmrTypes: [],
|
cstmrType: '',
|
companies: [],
|
directors: [],
|
director: '',
|
cstmrs: [],
|
cstmr: '',
|
cstmrTypeList: [],
|
cstmrList: [],
|
directorList: [],
|
companyList: [],
|
baseFormData: {
|
citysData: [],
|
cstmrType: '',
|
company: '',
|
director: '',
|
rela: '',
|
remarks: '',
|
cstmrId: '',
|
addr: '',
|
money: ''
|
},
|
rules: {
|
name: {
|
rules: [{
|
required: true,
|
errorMessage: '请填写客户名称',
|
}]
|
},
|
company: {
|
rules: [{
|
required: true,
|
errorMessage: '请选所属公司',
|
}]
|
},
|
},
|
// 单选数据源
|
type$: [{
|
text: '内销',
|
value: 1
|
}, {
|
text: '外销',
|
value: 2
|
}],
|
citysData: [],
|
citysDataTemp: ''
|
}
|
},
|
onReady() {
|
// 需要在onReady中设置规则
|
this.$refs.baseForm.setRules(this.rules)
|
},
|
onShow() {
|
// 获取省市区
|
this.citysData = test.citysData
|
},
|
methods: {
|
bindPickerChange: function(e) {
|
this.cstmrTypeIndex = e.detail.value
|
this.baseFormData.cstmrType = this.cstmrTypes[e.detail.value].id
|
},
|
areaChange(e) {
|
this.citysDataTemp = e.detail.value[0].value + ',' + e.detail.value[1].value + ',' + e.detail.value[2].value
|
},
|
autoLoad(type,condition) {
|
let that = this
|
that.companies = []
|
that.directors = []
|
that.cstmrs = []
|
var a = that.baseUrl + '/' + type + 'Query/auth'
|
uni.request({
|
url: that.baseUrl + '/' + type + 'Query' +'/auth',
|
header:{'token':uni.getStorageSync('token')},
|
data: {condition:condition},
|
method: 'GET',
|
success(result) {
|
var res = result.data
|
if (res.code === 200) {
|
var element;
|
if (type == 'user') {
|
for(element of res.data) {
|
that.directors.push(element.value)
|
that.directorList.push(element)
|
}
|
return
|
}
|
if (type == 'company') {
|
for (element of res.data) {
|
that.companies.push(element.name)
|
that.listAuth(type)
|
that.companyList.push(element)
|
}
|
return
|
}
|
if (type == 'cstmr') {
|
for (element of res.data) {
|
that.cstmrs.push(element.value)
|
that.cstmrList.push(element)
|
}
|
return
|
}
|
}
|
|
}
|
})
|
},
|
listAuth(type) {
|
|
},
|
// 添加跟踪项目
|
addOrder() {
|
let that = this
|
var element;
|
// 所属公司
|
for (element of that.companyList) {
|
if(element.name == that.baseFormData.company) {
|
that.baseFormData.company = element.id
|
}
|
}
|
for (element of that.cstmrList) {
|
if(element.value == that.baseFormData.cstmrId) {
|
that.baseFormData.cstmrId = element.id
|
}
|
}
|
for (element of that.directorList) {
|
if(element.value == that.baseFormData.director) {
|
that.baseFormData.director = element.id
|
}
|
}
|
this.$refs.baseForm.validate().then(res=>{
|
if (res.addr == undefined) {
|
res.addr = ''
|
}
|
if(res.money == undefined) {
|
res.money = ''
|
}
|
if(res.remarks == undefined) {
|
res.remarks = ''
|
}
|
res.pcd = this.citysDataTemp
|
uni.request({
|
url: that.baseUrl + '/order/add/auth',
|
header:{
|
'token':uni.getStorageSync('token'),
|
'content-type':'application/x-www-form-urlencoded',
|
},
|
data: res,
|
method: 'POST',
|
success(result) {
|
var res = result.data
|
if (res.code === 200) {
|
uni.navigateBack()
|
} else if (res.code === 403) {
|
uni.showToast({title: res.msg, icon: "none", position: 'top'})
|
setTimeout(() => {
|
uni.reLaunch({
|
url: '../../login/login'
|
});
|
}, 1000);
|
} else {
|
uni.showToast({title: res.msg, icon: "none",position: 'top'})
|
}
|
}
|
})
|
}).catch(err =>{
|
})
|
}
|
}
|
|
}
|
</script>
|
|
<style>
|
.container {
|
min-height: 50rpx;
|
padding: 15px;
|
background-color: #fff;
|
/* background-color: aqua; */
|
}
|
</style>
|