zouyu
2023-11-17 d8ac6057eaad648687699e25a575f3b7b8c1b102
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
<template>
  <div>
    <basic-container>
      <div class="task-div-title">
        <div style="margin-left:15px;">
          <span style="font-size: 17px;font-weight: bold;color: #2d2d2d;"
            >数据录入</span
          >
        </div>
      </div>
      <div
        style="margin-bottom: 10px;margin-left: 15px; display:inline-block;width: 80%;margin-top: 30px"
      >
        <el-form
          :model="formData"
          class="l-mes"
          style="margin-left: 10px"
          ref="form"
          :rules="rules"
          label-width="70px"
        >
          <el-form-item prop="barCode" label="19条码">
            <el-input
              placeholder="请输入19条码"
              v-model="formData.barCode"
              clearable
            ></el-input>
          </el-form-item>
          <el-form-item prop="codeBox" label="箱码">
            <el-input
              placeholder="请输入箱码"
              v-model="formData.codeBox"
              clearable
            ></el-input>
          </el-form-item>
 
          <el-form-item prop="codeCer" label="合格证">
            <el-input
              placeholder="请输入合格证"
              v-model="formData.codeCer"
              clearable
            ></el-input>
          </el-form-item>
          <el-form-item prop="grossWei" label="毛重" class="flexOne">
            <el-input
              placeholder="请输入毛重"
              v-model="formData.grossWei"
              clearable
            >
            </el-input>
            <el-button @click.prevent="autoWeight" size="mini"
              >自动称重</el-button
            >
          </el-form-item>
          <el-form-item prop="weighingApiAddress" label="地磅选择">
            <el-select
              placeholder="请进行地磅选择"
              v-model="formData.weighingApiAddress"
              clearable
            >
              <el-option
                v-for="item in weighbridgeSelect"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <el-row type="flex" justify="space-around" style="margin-top: 50px">
          <el-button type="primary" @click="submitForm()">提交</el-button>
          <el-button @click="resetForm">清除</el-button>
        </el-row>
      </div>
    </basic-container>
  </div>
</template>
 
<script>
import { addCode19gross, getWeight } from '@/api/huawei/code19gross'
import { remote } from '@/api/admin/dict'
export default {
  name: 'genForm',
  data() {
    return {
      weighbridgeSelect: [],
      formData: {
        barCode: '',
        codeBox: '',
        codeCer: '',
        grossWei: '',
        weighingApiAddress: ''
      },
      rules: {
        barCode: [{ required: true, message: '请输入19条码', trigger: 'blur' }],
        codeBox: [{ required: true, message: '请输入箱码', trigger: 'blur' }],
        codeCer: [{ required: true, message: '请输入合格证', trigger: 'blur' }],
        grossWei: [{ required: true, message: '请输入毛重', trigger: 'blur' }],
        weighingApiAddress: [
          { required: true, message: '请进行地磅选择', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.initOptions()
  },
  methods: {
    initOptions() {
      remote('weighing_api_address').then((response) => {
        if (response.data.code === 0) {
          this.weighbridgeSelect = response.data.data
        }
      })
    },
    submitForm() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          if (this.formData.grossWei > 200 || this.formData.grossWei < 0) {
            this.$message.error('毛重需在(0,200]范围内')
            return
          }
          addCode19gross(this.formData)
            .then((data) => {
              this.$message.success('提交成功')
              // 刷新列表
              this.$emit('updateList')
            })
            .catch(() => {
              this.$message.error('提交失败')
            })
        }
      })
    },
    resetForm() {
      this.$refs.form.resetFields()
    },
    // 自动称重
    autoWeight() {
      if (this.formData.weighingApiAddress) {
        const id = 1
        getWeight(this.formData.weighingApiAddress)
          .then((res) => {
            this.formData.grossWei = res.data.data
          })
          .catch(() => {})
      } else {
        this.$message.error('地磅选择不能为空')
      }
    }
  }
}
</script>
 
<style scoped lang="scss">
.flexOne {
  >>> .el-form-item__content {
    display: flex;
    .el-input {
      flex: 1;
    }
  }
}
</style>