wenzheng.yang
2023-04-27 31e64e0e144815e6176c1b6b81eae8dc68688570
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<!-- 标签分配表单组件 -->
<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>