spring
2025-04-08 4f94a66bc8ad9a57295f161de9195d5528b1d181
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
<template>
  <div>
    <el-dialog :close-on-click-modal="false" :close-on-press-escape="false" :visible.sync="quarterSampleDia"
      title="可靠性抽样" width="90%" @close="quarterSampleDia = false">
      <div style="display: flex;align-items: center;justify-content: space-between;margin-bottom: 10px">
        <div style="width: 30%;display: flex;align-items: center;">
          <span style="width: 50px">编号:</span>
          <el-input v-model="quarterSampleForm.quarterNo" :disabled="operationType !== 'add'" size="small"></el-input>
        </div>
        <div v-if="operationType === 'add'">
          <el-button size="small" type="primary" @click="addQuarter">添加</el-button>
          <el-button size="small" type="danger" @click="clearTable">清空</el-button>
        </div>
      </div>
      <div>
        <el-table v-loading="tableLoading" :data="quarterItems" border height="420" style="width: 100%"
          :header-cell-style="{ background: '#f8f8f9', color: '#515a6e' }">
          <el-table-column label="产品类型" prop="productType" width="200">
            <template slot-scope="{row}">
              <template>
                <el-input v-model="row.productType" size="small" />
              </template>
            </template>
          </el-table-column>
          <el-table-column label="责任人" prop="dutyUser" width="100"></el-table-column>
          <el-table-column label="型号" prop="productModel" width="120">
            <template slot-scope="{row}">
              <template>
                <el-input v-model="row.productModel" size="small" :disabled="operationType === 'view'" />
              </template>
            </template>
          </el-table-column>
          <el-table-column label="抽样数量" min-width="340" prop="spotCheckNumber">
            <template slot-scope="{row}">
              <template>
                <el-input v-model="row.spotCheckNumber" size="small" :disabled="operationType === 'view'" />
              </template>
            </template>
          </el-table-column>
          <el-table-column v-if="operationType === 'add'" label="数量" min-width="120" prop="number">
            <template slot-scope="{row}">
              <template>
                <el-input v-model="row.number" size="small" :disabled="operationType === 'view'" />
              </template>
            </template>
          </el-table-column>
          <el-table-column v-if="operationType !== 'add'" label="抽样时间" prop="spotCheckTime" width="160">
            <template slot-scope="{row}">
              <template>
                <el-date-picker v-model="row.spotCheckTime" format="yyyy-MM-dd" :disabled="operationType === 'view'"
                  placeholder="选择日期" size="small" clearable style="width:100%" type="date" value-format="yyyy-MM-dd">
                </el-date-picker>
              </template>
            </template>
          </el-table-column>
          <el-table-column v-if="operationType !== 'add'" label="试样结论" prop="result" width="130">
            <template v-slot="scope">
              <el-select v-model="scope.row.result" placeholder="请选择" size="small" clearable
                :disabled="operationType === 'view'">
                <el-option label="合格" value="合格"></el-option>
                <el-option label="不合格" value="不合格"></el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column v-if="operationType !== 'add'" label="取样人员" prop="samplingUser" width="120">
            <template slot-scope="{row}">
              <template>
                <el-input v-model="row.samplingUser" size="small" :disabled="operationType === 'view'" />
              </template>
            </template>
          </el-table-column>
          <el-table-column label="备注" prop="itemRemark" width="200">
            <template slot-scope="{row}">
              <template>
                <el-input v-model="row.itemRemark" size="small" :disabled="operationType === 'view'" />
              </template>
            </template>
          </el-table-column>
          <el-table-column v-if="operationType !== 'view'" fixed="right" label="操作" width="100">
            <template slot-scope="scope">
              <el-button size="small" style="color: #f56c6c" type="text"
                @click="deleteScope(scope.$index)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div style="display: flex;align-items: center;margin: 10px 0">
        <span style="width: 70px">备注:</span>
        <el-input v-model="quarterSampleForm.remark" :disabled="operationType === 'view'" size="small"
          style="width: 43%" type="textarea"></el-input>
      </div>
      <div v-if="operationType !== 'add'">
        <el-form ref="form" :model="editForm" label-width="70px">
          <el-col :span="12">
            <el-form-item label="编制人:">
              <el-select v-model="editForm.writeUser" :disabled="operationType !== 'edit'" placeholder="请选择" size="small"
                style="width: 100%">
                <el-option v-for="item in userList" :key="item.id" :label="item.name" :value="item.id"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="会签人:">
              <el-select v-model="editForm.countersignUser" :disabled="operationType !== 'edit'" multiple
                placeholder="请选择" size="small" style="width: 100%">
                <el-option v-for="item in userList" :key="item.id" :label="item.name" :value="item.id"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="审核人:">
              <el-select v-model="editForm.examineUser" :disabled="operationType !== 'edit'" placeholder="请选择"
                size="small" style="width: 100%">
                <el-option v-for="item in userList" :key="item.id" :label="item.name" :value="item.id"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="批准人:">
              <el-select v-model="editForm.ratifyUser" :disabled="operationType !== 'edit'" placeholder="请选择"
                size="small" style="width: 100%">
                <el-option v-for="item in userList" :key="item.id" :label="item.name" :value="item.id"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-form>
      </div>
      <span v-if="operationType !== 'view'" slot="footer" class="dialog-footer">
        <el-button v-if="operationType !== 'add'" @click="quarterSampleDia = false">取 消</el-button>
        <el-button v-if="operationType === 'add'" @click="quarterSampleDia = false">保 存</el-button>
        <el-button type="primary" @click="handleSample">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
 
<script>
import { addQuarter, getQuarter, updateQuarterOnOrder } from "@/api/business/finishedProductSampling";
import { selectUserCondition } from "@/api/business/inspectionTask";
import { mapGetters } from "vuex";
 
export default {
  name: "addQuarterItem",
  // import 引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    // 这里存放数据
    return {
      tableLoading: false,
      quarterSampleDia: false, // 可靠性抽样弹框
      quarterSampleForm: {
        quarterNo: '', // 编号
      },
      quarterItems: [],
      quarterTemItems: [],
      operationType: '',
      editForm: {
        quarterId: '',
        writeUser: '', // 编制人
        countersignUser: [], // 会签人
        examineUser: '', // 审核人
        ratifyUser: '', // 批准人
      },
      userList: [],
      quarterRow: {},
    }
  },
  computed: {
    ...mapGetters(["nickName"]),
  },
  mounted() {
    this.getUserList()
  },
  // 方法集合
  methods: {
    openDia(quarterTemItems, type) {
      this.quarterSampleDia = true
      this.operationType = type
      if (type === 'add') {
        if (quarterTemItems.length > 0) {
          this.quarterItems = quarterTemItems
        }
        this.quarterSampleForm.quarterNo = getCurrentMonthTwoDigits()
      } else {
        this.tableLoading = true
        this.quarterRow = quarterTemItems
        getQuarter({ quarterId: quarterTemItems.quarterId }).then(res => {
          this.tableLoading = false
          if (res.code === 200) {
            this.quarterItems = res.data.quarterItems
            this.quarterSampleForm.quarterNo = res.data.quarterNo
            this.quarterSampleForm.remark = res.data.remark
            this.editForm.quarterId = res.data.quarterId
            this.editForm.writeUser = res.data.writeUser
            this.editForm.examineUser = res.data.examineUser
            this.editForm.ratifyUser = res.data.ratifyUser
            if (res.data.countersignUser) {
              this.editForm.countersignUser = res.data.countersignUser.split(",").map(Number)
            }
          }
        }).catch(err => {
          this.tableLoading = false
        })
      }
    },
    // 手动添加
    addQuarter() {
      this.quarterItems.push({
        productType: '',
        dutyUser: this.nickName,
        productModel: '',
        spotCheckNumber: '',
        number: '',
        spotCheckTime: '',
        result: '',
        samplingUser: '',
        itemRemark: '',
      })
    },
    // 提交可靠性抽样
    handleSample() {
      this.$confirm('是否提交该数据', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        if (this.operationType === 'add') {
          this.quarterSampleForm.quarterItems = JSON.parse(JSON.stringify(this.quarterItems))
          this.quarterSampleForm.quarterItems.forEach(item => {
            item.spotCheckNumber = item.spotCheckNumber + ' ' + (item.number == null ? "" : item.number)
          })
          addQuarter(this.quarterSampleForm).then(res => {
            if (res.code == 200) {
              this.$message.success('提交成功')
              this.quarterItems = []
              this.$parent.quarterTemItems = []
              this.closeQuarterSampleDia()
            }
          })
        } else {
          const params = { ...this.editForm }
          if (params.countersignUser.length > 0) {
            params.countersignUser = params.countersignUser.join(',')
          } else {
            params.countersignUser = ''
          }
          params.quarterItems = JSON.parse(JSON.stringify(this.quarterItems))
          updateQuarterOnOrder(params).then(res => {
            if (res.code == 200) {
              this.$message.success('提交成功')
              this.quarterItems = []
              this.closeQuarterSampleDia()
            }
          })
        }
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });
      });
 
    },
    // 清空抽样计划
    clearTable() {
      this.quarterItems = []
      this.$parent.quarterTemItems = []
    },
    // 手动删除
    deleteScope(index) {
      this.quarterItems.splice(index, 1)
    },
    // 关闭可靠性抽样弹框
    closeQuarterSampleDia() {
      this.quarterSampleDia = false
      if (this.operationType === 'add') {
        this.$parent.handleStockList()
      } else {
        this.$parent.refreshTable('page')
      }
    },
    getUserList() {
      selectUserCondition().then((res) => {
        this.userList = res.data;
      })
    },
  },
}
function getCurrentMonthTwoDigits() {
  const currentDate = new Date();
  const year = currentDate.getFullYear();
  const currentMonth = currentDate.getMonth() + 1;
  return year + currentMonth.toString().padStart(2, '0');
}
</script>
 
<style scoped></style>