13404089107
2025-06-23 92606a1a818d2016d9f8ddab45cc084de580d0b2
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
<template>
  <el-dialog
    :visible.sync="visible"
    title="新增接种斜面记录"
    width="700px"
    @close="handleClose"
  >
    <el-form
      :model="form"
      :rules="rules"
      ref="form"
      label-width="120px"
      label-position="top"
    >
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="分离菌落编号" prop="separateColonyCode">
            <el-input v-model="form.separateColonyCode" placeholder="请输入" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="接种斜面编号" prop="vaccinationSlopeCode">
            <el-input v-model="form.vaccinationSlopeCode" placeholder="请输入" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="保存/废弃" prop="handleType">
        <el-button
          :type="form.handleType === '保存' ? 'primary' : 'default'"
          @click="form.handleType = '保存'"
          >保存</el-button
        >
        <el-button
          :type="form.handleType === '废弃' ? 'primary' : 'default'"
          @click="form.handleType = '废弃'"
          >废弃</el-button
        >
      </el-form-item>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="菌种入库时间" prop="preserveTime">
            <el-input
              v-model="form.preserveTime"
              disabled
              placeholder="自动回填"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="接种操作时间" prop="handleTime">
            <el-input
              v-model="form.handleTime"
              disabled
              placeholder="自动填入"
            />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item>
            <template #label>
              <span>接种操作人签字</span>
              <el-button type="primary" class="sign-btn" @click="showSignature = true">签名</el-button>
            </template>
            <div class="signature-area" :class="{ 'waiting': !form.handleSignature }">
              <template v-if="form.handleSignature">
                <img :src="form.handleSignature" alt="接种操作人签字" />
              </template>
              <template v-else>
                <span class="waiting-text">等待确认</span>
              </template>
            </div>
          </el-form-item>
        </el-col>
        <!-- <el-col :span="12">
          <el-form-item label="接种操作人" prop="handleName">
            <el-input v-model="form.handleName" disabled placeholder="自动填入" />
          </el-form-item>
        </el-col> -->
      </el-row>
    </el-form>
    <div style="text-align: center; margin-top: 20px">
      <el-button @click="handleClose" style="margin-right: 16px;">取消</el-button>
      <el-button type="primary" @click="handleSave">确认</el-button>
    </div>
    <signature-canvas :visible.sync="showSignature" @confirm="handleSignatureConfirm" />
  </el-dialog>
</template>
 
<script>
import SignatureCanvas from '@/components/SignatureCanvas.vue';
 
export default {
  components: { SignatureCanvas },
  props: { 
    visible: Boolean,
    editData: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      form: {
        separateColonyCode: "",
        vaccinationSlopeCode: "",
        handleType: "保存",
        preserveTime: '',
        handleTime: this.getNowTime(),
        handleSignature: "",
        handleName: JSON.parse(sessionStorage.getItem('userInfo'))?.nickName || '',
        handleId: JSON.parse(sessionStorage.getItem('userInfo'))?.userId || '',
      },
      rules: {
        separateColonyCode: [
          { required: true, message: "请输入分离菌落编号", trigger: "blur" },
        ],
        vaccinationSlopeCode: [
          { required: true, message: "请输入接种斜面编号", trigger: "blur" },
        ],
        handleType: [
          { required: true, message: "请选择保存/废弃", trigger: "change" },
        ],
        handleSignature: [{ required: true, message: "请签名", trigger: "change" }],
      },
      showSignature: false,
    };
  },
  watch: {
    visible(val) {
      if (val && this.editData) {
        // 当对话框显示且有编辑数据时,进行数据回显
        this.form = {
          ...this.form,
          ...this.editData
        };
      }
    }
  },
  methods: {
    getNowTime() {
      const d = new Date();
      return (
        d.getFullYear() +
        "-" +
        (d.getMonth() + 1).toString().padStart(2, "0") +
        "-" +
        d.getDate().toString().padStart(2, "0") +
        " " +
        d.getHours().toString().padStart(2, "0") +
        ":" +
        d.getMinutes().toString().padStart(2, "0")
      );
    },
    handleSave() {
      console.log(this.form)
      this.$refs.form.validate((valid) => {
        if(!this.form.handleSignature){
          this.$message.error('请接种操作人签字')
          return
        }
        if (valid) {
          this.$emit("save", { ...this.form });
          
          this.handleClose();
        }
      });
    },
    handleClose() {
      this.$emit("update:visible", false);
      // 重置表单数据
      this.form = {
        separateColonyCode: "",
        vaccinationSlopeCode: "",
        handleType: "保存",
        preserveTime: '',
        handleTime: this.getNowTime(),
        handleSignature: "",
        handleName: JSON.parse(sessionStorage.getItem('userInfo'))?.nickName || '',
        handleId: JSON.parse(sessionStorage.getItem('userInfo'))?.userId || '',
      };
      // 重置表单验证
      this.$nextTick(() => {
        this.$refs.form && this.$refs.form.clearValidate();
      });
    },
    handleSignatureConfirm(dataUrl) {
      this.form.handleSignature = dataUrl;
      this.showSignature = false;
    },
  },
};
</script>
 
<style scoped>
.signature-area {
  height: 120px;
  width: 100%;
  background: #F5F7FA;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #DCDFE6;
  overflow: hidden;
  padding: 0;
}
.signature-area.waiting {
  border-style: dashed;
  background: #FAFAFA;
}
.signature-area img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.waiting-text {
  color: #909399;
  font-size: 14px;
}
.sign-btn {
  height: 32px;
  border-radius: 4px;
  font-size: 14px;
  padding: 0 20px;
  font-weight: 400;
  margin-left: 12px;
}
</style>