<!-- 标签分配表单组件 -->
|
<template>
|
<view class="m-form">
|
<view class="m-form-head"><u-icon name="close-circle" color="#fff" size="40" @click="cancel"></u-icon></view>
|
<!-- 分配 -->
|
<view class="m-form-label" v-if="tallyType == 'allot'">
|
<u--form labelPosition="left" labelAlign="right" :model="model" :rules="rules" ref="form" labelWidth="100" :labelStyle="{'color':'rgb(129, 129, 129)'}">
|
<u-form-item label="序号" prop="id" borderBottom ref="item">
|
<u--input :customStyle="{ 'background-color': 'rgb(233, 233, 233)','box-shadow':'inset 2px 1.464px 5px 0px #ccccc4, 1.464px 1.464px 5px 0px rgba(255, 255, 255, 0.75)'}" placeholderStyle="color:#000" color="#000" v-model="model.id" border="none"></u--input>
|
</u-form-item>
|
<u-form-item label="标签ID" prop="p_tagid" borderBottom ref="item">
|
<u--input :customStyle="{ 'background-color': 'rgb(233, 233, 233)','box-shadow':'inset 2px 1.464px 5px 0px #ccccc4, 1.464px 1.464px 5px 0px rgba(255, 255, 255, 0.75)'}" placeholderStyle="color:#000" color="#000" v-model="model.p_tagid" border="none"></u--input>
|
</u-form-item>
|
<u-form-item label="绑定围栏" prop="baoliu12" borderBottom ref="item">
|
<uni-data-select v-model="value_range" :localdata="range" @change="changeRange"></uni-data-select>
|
</u-form-item>
|
</u--form>
|
</view>
|
<!-- 修改 -->
|
<view class="m-form-label" v-if="tallyType == 'update'">
|
<u--form labelPosition="left" labelAlign="right" :model="model" :rules="rules" ref="form" labelWidth="100" :labelStyle="{'color':'rgb(129, 129, 129)'}">
|
<u-form-item label="所属部门" prop="p_department" borderBottom ref="item">
|
<uni-data-select v-model="value_bumen" :localdata="rangeBuMen" @change="changeRangeBuMen"></uni-data-select>
|
</u-form-item>
|
<u-form-item label="标签序号" prop="id" borderBottom ref="item">
|
<u--input :customStyle="{ 'background-color': 'rgb(233, 233, 233)','box-shadow':'inset 2px 1.464px 5px 0px #ccccc4, 1.464px 1.464px 5px 0px rgba(255, 255, 255, 0.75)'}" disabled placeholderStyle="color:#000" color="#000" v-model="model.id" border="none"></u--input>
|
</u-form-item>
|
<u-form-item label="标签ID" prop="p_tagid" borderBottom ref="item">
|
<u--input :customStyle="{ 'background-color': 'rgb(233, 233, 233)','box-shadow':'inset 2px 1.464px 5px 0px #ccccc4, 1.464px 1.464px 5px 0px rgba(255, 255, 255, 0.75)'}" readonly placeholderStyle="color:#000" color="#000" v-model="model.p_tagid" border="none"></u--input>
|
</u-form-item>
|
<u-form-item label="绑定名称" prop="p_name" borderBottom ref="item">
|
<u--input :customStyle="{ 'background-color': 'rgb(233, 233, 233)','box-shadow':'inset 2px 1.464px 5px 0px #ccccc4, 1.464px 1.464px 5px 0px rgba(255, 255, 255, 0.75)'}" placeholderStyle="color:#000" color="#000" v-model="model.p_name" border="none"></u--input>
|
</u-form-item>
|
<u-form-item label="标签高度" prop="baoliu4" borderBottom ref="item">
|
<u--input :customStyle="{ 'background-color': 'rgb(233, 233, 233)','box-shadow':'inset 2px 1.464px 5px 0px #ccccc4, 1.464px 1.464px 5px 0px rgba(255, 255, 255, 0.75)'}" placeholderStyle="color:#000" color="#000" v-model="model.baoliu4" border="none"></u--input>
|
</u-form-item>
|
</u--form>
|
</view>
|
<!-- 添加 -->
|
<view class="m-form-label" v-if="tallyType == 'add'">
|
<u--form labelPosition="left" labelAlign="right" :model="model" :rules="rules" ref="form" labelWidth="100" :labelStyle="{'color':'rgb(129, 129, 129)'}">
|
<u-form-item label="标签ID" prop="p_tagid" borderBottom ref="item">
|
<u--input :customStyle="{ 'background-color': 'rgb(233, 233, 233)','box-shadow':'inset 2px 1.464px 5px 0px #ccccc4, 1.464px 1.464px 5px 0px rgba(255, 255, 255, 0.75)'}" placeholderStyle="color:#000" color="#000" v-model="model.p_tagid" border="none"></u--input>
|
</u-form-item>
|
</u--form>
|
</view>
|
<view class="m-form-button-list"><u-button type="primary" text="确定" @click="save"></u-button></view>
|
</view>
|
</template>
|
|
<script>
|
import {connChart} from '../../../common/utils.js'
|
export default {
|
props: {
|
tallyType: String,
|
tallyFormData: Object
|
},
|
data() {
|
return {
|
model: {
|
p_tagid: ''
|
},
|
addModel: {
|
p_tagid: ''
|
},
|
rules: {
|
p_tagid: {
|
validator: (rule, value, callback) => {
|
// 返回true表示校验通过,返回false表示不通过
|
var pattern=/^((?![0-9]+$)(?![a-zA-Z]+$)|[0-9A-Za-z]{1,1000})$/;
|
console.log(pattern.test(value))
|
return pattern.test(value);
|
},
|
required: true,
|
message: '请输入字母或数字',
|
trigger: ['blur', 'change']
|
}
|
},
|
value_bumen:'',
|
rangeBuMen: [],
|
value_range:'',
|
range:[],
|
labelModel: null
|
|
};
|
},
|
methods: {
|
//保存
|
save() {
|
if (this.tallyType == 'add') {
|
//查重
|
this.labelModel.find(`p_tagid=${this.model.p_tagid}`,(e,r)=>{
|
if(r.length>0){
|
uni.$u.toast('标签ID重复')
|
}else{
|
//添加
|
this.labelModel.insert({
|
p_name: '未绑定',
|
p_tagid: this.model.p_tagid,
|
baoliu4: '150',
|
baoliu12: '未绑定',
|
p_department: '系统默认' ,
|
}, (err, results) => {
|
console.log(err,results);
|
if(!err){
|
uni.$u.toast('添加成功')
|
this.$emit('submitTallyForm');
|
}
|
});
|
}
|
})
|
} else if (this.tallyType == 'update') {
|
//修改
|
this.labelModel.update(`id='${this.model.id}'`,{
|
p_name:this.model.p_name,
|
p_department:this.model.p_department,
|
baoliu4:this.model.baoliu4
|
},(err,results)=>{
|
console.log(err,results);
|
this.$emit('submitTallyForm');
|
});
|
} else if (this.tallyType == 'allot') {
|
//分配-与修改共用接口
|
this.labelModel.update(`id='${this.model.id}'`,{
|
p_tagid:this.model.p_tagid,
|
baoliu12:this.model.baoliu12
|
},(err,results)=>{
|
console.log(err,results);
|
this.$emit('submitTallyForm');
|
});
|
}
|
},
|
//取消
|
cancel() {
|
this.$emit('cancelTallyForm');
|
},
|
//部门查询
|
jiedepartment() {
|
let labelModel = connChart('department')
|
labelModel.find((e,r)=>{
|
console.log(e,r)
|
r.forEach(e => {
|
this.rangeBuMen.push({
|
text: e.department_name,
|
value: e.department_name
|
});
|
});
|
})
|
},
|
changeRangeBuMen(e) {
|
this.model.p_department = e;
|
},
|
//围栏查询
|
fenceLista() {
|
let labelModel = connChart('fence')
|
labelModel.find((e,r)=>{
|
console.log(e,r)
|
r.forEach(e => {
|
this.range.push({
|
text: e.name,
|
value: e.name
|
});
|
});
|
})
|
},
|
changeRange(e) {
|
this.value_range = e;
|
this.model.baoliu12 = e;
|
},
|
connDB() {
|
this.labelModel = connChart('label')
|
}
|
},
|
mounted() {
|
if (this.tallyType == 'add') {
|
// this.model = this.addModel;
|
// console.log(this.model)
|
} else if (this.tallyType == 'update' || this.tallyType == 'allot') {
|
this.model = this.tallyFormData;
|
this.value_range=this.model.baoliu12
|
this.value_bumen=this.model.p_department
|
}
|
this.connDB();
|
this.jiedepartment();
|
this.fenceLista();
|
}
|
};
|
</script>
|
|
<style lang="scss" scoped>
|
.m-form {
|
position: fixed;
|
top: 50%;
|
left: 50%;
|
transform: translate(-50%, -50%);
|
background-color: rgba(233, 233, 233,0.95);
|
width: 60%;
|
display: flex;
|
flex-direction: column;
|
z-index: 99999;
|
}
|
.m-form-head {
|
width: 100%;
|
border-bottom: 1px solid #fff;
|
}
|
.m-form-head .u-icon {
|
float: right;
|
}
|
/deep/ .u-form-item__body__left__content__label {
|
color: #fff;
|
}
|
.m-form-label {
|
width: 80%;
|
margin: 0 auto;
|
margin-bottom: 0.5em;
|
}
|
input {
|
width: 50px;
|
}
|
.m-form-button-list {
|
width: 100%;
|
display: flex;
|
flex-direction: column;
|
align-items: center;
|
justify-content: center;
|
margin-bottom: 1em;
|
}
|
.m-form-button-list .u-button {
|
width: 5em;
|
}
|
.m-form-button-list .u-button:nth-child(2),
|
.m-form-button-list .u-button:nth-child(3),
|
.m-form-button-list .u-button:nth-child(4) {
|
margin-top: 2em;
|
}
|
</style>
|