zhouwx
2024-10-09 e39acb3659c059cbedc37ff6592ef7b3355bd20c
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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
<template>
  <div class="app-container">
    <div style="display: flex;justify-content: space-between">
      <el-form :inline="true" style="display: flex;align-items: center;flex-wrap: wrap;" >
        <el-form-item label="状态:" >
          <el-select
              v-model="data.queryParams.state"
              placeholder="请选择状态"
              style="width: 240px"
          >
            <el-option
                v-for="item in data.typeList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item >
          <el-button
              type="primary"
              @click="getList"
          >查询</el-button>
          <el-button
              type="primary"
              plain
              @click="reset"
          >重置</el-button>
        </el-form-item>
      </el-form>
      <div>
        <el-button
            type="primary"
            plain
            @click="back"
        >返回</el-button>
      </div>
    </div>
    <!-- 表格数据 -->
    <el-table v-loading="loading" :data="data.dataList" :border="true" :cell-style="cellStyle">
      <el-table-column label="序号" type="index" align="center" width="80" />
      <el-table-column label="品名" prop="hazmatBasic.name" align="center"  />
      <el-table-column label="产品编号" prop="hazmatBasic.productSn" align="center" />
      <el-table-column label="CAS号" prop="hazmatBasic.cas" align="center" />
      <el-table-column label="厂家" prop="hazmatBasic.manufacturer" align="center" />
      <el-table-column label="供应商" prop="hazmatBasic.supplier" align="center" />
      <el-table-column label="二维码编号" prop="code" align="center" width="120" />
      <el-table-column label="危险性质" prop="hazmatBasic.hazmatCharacter" align="center" />
      <el-table-column label="最小包装" prop="hazmatBasic.productSn" align="center" width="120">
        <template #default="scope">
          <span>{{scope.row.hazmatBasic.metering}}{{scope.row.hazmatBasic.unit}} / {{scope.row.hazmatBasic.minPackage == 0 ? '瓶' :scope.row.hazmatBasic.minPackage == 1?'袋':scope.row.hazmatBasic.minPackage == 2?'桶 ':scope.row.hazmatBasic.minPackage == 3?'盒':scope.row.hazmatBasic.minPackage == 4?'箱':'其他'}}</span>
        </template>
      </el-table-column>
      <el-table-column label="入库时间" prop="updateTime" align="center" />
      <el-table-column label="当前状态" prop="state" align="center">
        <template #default="scope">
          <span>{{scope.row.state ===0 || scope.row.state === 1 ? '在库' : scope.row.state === 2 ? '领用中': scope.row.state === 3 ? '已用完' : scope.row.state === 4 ? '标签作废' : ''}}</span>
        </template>
      </el-table-column>
      <el-table-column label="在库余量" prop="remaining" align="center" >
        <template #default="scope">
          <span>{{scope.row.remaining}}{{scope.row.hazmatBasic.unit}}</span>
 
        </template>
      </el-table-column>
      <el-table-column label="所在仓库" prop="warehouseName" align="center" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="180" >
        <template #default="scope">
          <el-button link type="primary" v-if="scope.row.state ===0 || scope.row.state === 1" @click="editNum(scope.row)">零头修改</el-button>
          <el-button link type="primary" @click="viewFlow(scope.row)">取用记录</el-button>
          <el-button link type="danger" v-if="scope.row.state === 0 || scope.row.state === 1|| scope.row.state === 2" @click="disCard(scope.row)">标签作废</el-button>
          <el-button link type="primary" @click="viewQR(scope.row)">查看二维码</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
        v-show="data.total > 0"
        :total="data.total"
        v-model:page="data.queryParams.pageNum"
        v-model:limit="data.queryParams.pageSize"
        @pagination="getList"
    />
    <viewQRcode ref="dialogRef" @getList="getList"></viewQRcode>
    <el-dialog
        v-model="dialogVisible"
        width="650px"
        :before-close="handleClose"
        :close-on-press-escape="false"
        :close-on-click-modal="false"
    >
      <flow-deail ref="flowRef"></flow-deail>
    </el-dialog>
    <el-dialog
        v-model="editNumDialog"
        width="650px"
        title="余量修改"
        :before-close="handleCloseNum"
        :close-on-press-escape="false"
        :close-on-click-modal="false"
    >
      <el-form :model="data.form" size="default" ref="busRef" :rules="data.formRules" label-width="150px" >
        <el-form-item label="在库余量:" prop="remaining" >
          <el-input v-model.trim="data.form.remaining" @input="requiredDurationEventMetering($event)"  placeholder="请输入余量"></el-input>
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
            <el-button @click="handleCloseNum" size="default">取 消</el-button>
            <el-button type="primary"  @click="onSubmitNum" size="default" v-preReClick>确认</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>
 
<script setup>
import {nextTick, onMounted, reactive, ref} from "vue";
import {useRoute, useRouter} from "vue-router";
import flowDeail from '../../../components/flowDetail.vue'
import {disCardPro, getProDetail, getProductRecord} from "@/api/hazardousChemicals/productRecord";
import viewQRcode from './viewQR.vue'
import {ElMessage, ElMessageBox} from "element-plus";
import {changeRawRemaining, disCardRaw, getRawDetail} from "@/api/hazardousChemicals/rawRecord";
import Cookies from "js-cookie";
const route = useRoute()
const router = useRouter();
const dialogRef = ref();
const dialogVisible = ref(false)
const flowRef = ref();
const editNumDialog = ref(false)
const data = reactive({
  queryParams: {
    basicId: null,
    warehouseId: null,
    state: null,
    pageNum: 1,
    pageSize: 10,
  },
  total: 0,
  dataList: [],
  isAdmin: false,
  typeList: [
    {
      id: 0,
      name: '在库'
    },
    {
      id: 1,
      name: '领用归还在库'
    },
    {
      id: 2,
      name: '领用中'
    },
    {
      id: 3,
      name: '已用完'
    },
    {
      id: 4,
      name: '标签作废'
    },
 
  ],
  form: {
    id: '',
    remaining: ''
  },
  formRules: {
    remaining: [{ required: true, trigger: "blur", message: '请输入余量' }],
  }
});
const loading = ref(false);
const backValue = ref({})
onMounted(async ()=>{
  if(route.query.val){
    const val = JSON.parse(route.query.val)
    backValue.value.pageNum =val.pageNum;
    backValue.value.pageSize =val.pageSize;
    data.queryParams.warehouseId =val.warehouseId
    data.queryParams.basicId =val.basicId
  }
  await getList()
})
const getList = async () => {
  loading.value = true
  const res = await getRawDetail(data.queryParams)
  if(res.code == 200){
    data.dataList = res.data.list
    data.total = res.data.total
  }else{
    ElMessage.warning(res.message)
  }
  loading.value = false
}
const reset = () => {
  data.queryParams = {
    basicId: data.queryParams.basicId,
    warehouseId: data.queryParams.warehouseId,
    state: null,
    pageNum: 1,
    pageSize: 10,
  }
  getList()
}
 
const back = () =>{
  const obj = {
    pageNum: backValue.value.pageNum,
    pageSize: backValue.value.pageSize,
    type: 'raw'
  }
  const v = JSON.stringify(obj)
  Cookies.set('type','raw')
  router.push({ path: "/electronicWarehouse", query: { val: v } });
}
const viewQR = (val) => {
  dialogRef.value.openDialog('raw',val)
}
const disCard = async (val) => {
  ElMessageBox.confirm(
      '确定作废该标签?',
      '提示',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
      .then( async() => {
        const res = await disCardRaw(val.id)
        if(res.code == 200){
          ElMessage.success('操作成功')
          await getList()
        }else{
          ElMessage.warning(res.message)
        }
      })
 
 
}
const viewFlow = (val) => {
  dialogVisible.value = true
  nextTick(() => {
    flowRef.value.openDialog('raw',val)
  })
}
const handleClose = () => {
  dialogVisible.value = false
}
 
const cellStyle = ({ row, column,rowIndex, columnIndex }) => {
  let arr = []
  if (data.dataList !== null) {
    data.dataList.filter((item, index) => {
      arr.push(item.basicId)
    })
  }
  for (let i = 0; i <= arr.length; i++) {
    if (arr[i] == row.basicId) {
      if(row.state === 3 && row.remaining < row.hazmatBasic.metering){
        if (columnIndex === 11 || columnIndex === 10){
          return { color:' red' }
        }
      }else if(row.remaining < row.hazmatBasic.metering){
        if (columnIndex === 11 || columnIndex === 10){
          return { color: '#ff9900' }
        }
      }
 
    }
  }
};
 
const chooseItem = ref()
const editNum = (val) => {
  chooseItem.value = val
  data.form.id = val.id
  data.form.remaining = val.remaining
  editNumDialog.value = true
 
}
const handleCloseNum = () => {
  data.form = {
    id: '',
    remaining: ''
  }
  chooseItem.value = {}
  editNumDialog.value = false
}
 
const onSubmitNum = () => {
  if(chooseItem.value.remaining < data.form.remaining){
    ElMessage.warning('修改值不能大于等于在库余量')
    return;
  }
  ElMessageBox.confirm(
      '确定修改此条数据的余量?',
      '提示',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
      .then( async() => {
        const res = await changeRawRemaining(data.form)
        if(res.code == 200){
          ElMessage.success('数据修改成功')
          editNumDialog.value = false;
          await getList()
        }else{
          ElMessage.warning(res.message)
        }
      })
 
 
}
const requiredDurationEventMetering =(value) =>{
  let dat =
      ("" + value) // 第一步:转成字符串
          .replace(/[^\d^\.]+/g, "") // 第二步:把不是数字,不是小数点的过滤掉
          .replace(/^0+(\d)/, "$1") // 第三步:第一位0开头,0后面为数字,则过滤掉,取后面的数字
          .replace(/^\./, "0.") // 第四步:如果输入的第一位为小数点,则替换成 0. 实现自动补全
          .match(/^\d*(\.?\d{0,2})/g)[0] || ""; // 第五步:最终匹配得到结果 以数字开头,只有一个小数点,而且小数点后面只能有0到2位小数
  data.form.remaining = dat
}
</script>
 
<style scoped lang="scss">
 
</style>