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
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
331
332
<template>
  <div class="mod-config">
    <basic-container>
      <a @click="$router.go(-1)"><i class="icon-btn-back"></i></a>
      <div class="detailtitle">盘点详情</div>
      <el-form label-width="100px" class="l-mes">
        <el-form-item label="盘点编号" prop="inyNo">
          <el-input
            v-model="inyInfo.inyNo"
            placeholder="系统自动生成"
            disabled
          />
        </el-form-item>
      </el-form>
    </basic-container>
    <basic-container>
      <div class="detailtitle">盘点明细</div>
      <ttable
        :table="table"
        @handleSelectionChange="handleSelectionChange"
        :prelang="prelang"
        :options="options"
        :ajaxFun="ajaxFun"
        :paramObj="paramObj"
        :isEdit="isEdit"
        ref="checkDetailTable"
      >
        <template v-if="canEdit" #toolbar>
          <template v-if="!isEdit">
            <el-form-item class="btn-group">
              <el-button @click="goAdd" size="small" type="primary"
                >新增</el-button
              >
            </el-form-item>
            <el-form-item class="btn-group">
              <el-button @click="goEdit" size="small" type="primary"
                >编辑</el-button
              >
            </el-form-item>
            <el-form-item class="btn-group">
              <el-button @click="goDel" size="small" type="danger"
                >删除</el-button
              >
            </el-form-item>
            <el-form-item class="btn-group">
              <el-button @click="goACT1" size="small">取消未盘点的行</el-button>
            </el-form-item>
            <el-form-item class="btn-group">
              <el-button @click="goACT2" size="small">盘点没有差异</el-button>
            </el-form-item>
          </template>
          <template v-else>
            <el-form-item class="btn-group">
              <el-button @click="goSave" size="small" type="primary">
                保存
              </el-button>
            </el-form-item>
            <el-form-item class="btn-group">
              <el-button @click="goCancel" size="small">取消</el-button>
            </el-form-item>
          </template>
        </template>
        <template v-else #toolbar> </template>
      </ttable>
      <!-- 弹窗, 新增 / 修改 -->
      <table-form
        v-if="addOrUpdateVisible"
        ref="addOrUpdate"
        @refreshDataList="getData"
      ></table-form>
    </basic-container>
  </div>
</template>
 
<script>
import {
  fetchListDetail,
  putObjDetail,
  delObjDetail,
  cancelNoIny,
  noDiff
} from '@/api/warehouse/check'
import TableForm from './check-detail-form'
import ttable from '@/views/common/ztt-table.vue'
import { mapGetters } from 'vuex'
 
export default {
  data() {
    const col = (prop, label, config) => {
      const w = (label.length - 1) * 20 + 15
      return Object.assign(
        {
          minWidth: w < 140 ? 140 : w,
          prop,
          label,
          sort: true,
          isTrue: true,
          isSearch: true,
          searchInfoType: 'text'
        },
        config
      )
    }
    return {
      ajaxFun: fetchListDetail,
      multipleSelection: [],
      prelang: 'operation',
      isEdit: false,
      options: {
        height: 300, // 默认高度-为了表头固定
        stripe: true, // 是否为斑马纹 table
        highlightCurrentRow: false, // 是否要高亮当前行
        border: true, // 是否有纵向边框
        lazy: false, // 是否需要懒加载
        fit: true, // 列的宽度是否自撑开
        multiSelect: true, //
        seqNo: true,
        seqNoFix: true,
        isRefresh: true, // 是否显示刷新按钮
        isShowHide: true, // 是否显示显影按钮
        isSearch: false, // 高级查询按钮
        defaultOrderBy: { column: 'createTime', direction: 'desc' },
        cancelRunCreated: true
      },
      table: {
        total: 0,
        currentPage: 1,
        pageSize: 20,
        data: [],
        // 标题
        column: [
          // 零件
          col('partNo', '零件号'),
          col('partName', '零件名称'),
          col('planningMethod', '计划方法'),
          col('sn', 'SN号'),
          col('ifsBatchNo', 'IFS批次号'),
          col('warehouseName', '仓库'),
          col('locNo', '库位号'),
          col('stockQuantity', '库存数量'),
          col('inyQty', '盘点数量'),
          col('inyDiffQty', '盘点差异数量'),
          col('commitNum', '扫码提交次数'),
          col('unit', '单位'),
          col('updateTime', '更新时间', {
            searchInfoType: 'datetimerange'
          })
        ],
        toolbar: []
      },
      addOrUpdateVisible: false,
      inyInfo: {
        id: '',
        inyNo: ''
      },
      paramObj: {
        inventoryMainId: ''
      }
    }
  },
  components: {
    ttable,
    TableForm
  },
  computed: {
    ...mapGetters(['permissions']),
    canEdit() {
      return this.$route.query.canEdit
    }
  },
  created() {
    this.init()
  },
  methods: {
    init() {
      this.inyInfo.id = this.$route.query.id
      this.inyInfo.inyNo = this.$route.query.inyNo
      this.paramObj = {
        inventoryMainId: this.inyInfo.id
      }
      this.getData()
    },
    // 获取数据列表
    getData() {
      this.$nextTick(() => {
        this.$refs.checkDetailTable.getDataList()
      })
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    // 新增 / 修改
    goAdd() {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init()
      })
    },
    goEdit() {
      this.isEdit = true
      const col = this.table.column.find((e) => e.prop === 'inyQty')
      col.isEdit = true
      col.width = '150'
      col.noShowTip = true
    },
    goSave() {
      const data = this.$refs.checkDetailTable.getTableData()
      let validateFlag = true
      let validateMsg = ''
      const numberReg = /^\d+$|^\d+[.]?\d+$/
      data.forEach((e, i) => {
        if (e.inyQty && !numberReg.test(e.inyQty)) {
          validateFlag = false
          validateMsg += '第' + (i + 1) + '行,请输入数字。'
        }
      })
      if (!validateFlag) {
        this.$message.error(validateMsg)
        return
      }
      putObjDetail(data).then(() => {
        this.goCancel()
      })
    },
    goCancel() {
      this.isEdit = false
      const col = this.table.column.find((e) => e.prop === 'inyQty')
      col.isEdit = false
      delete col.width
      delete col.noShowTip
      this.getData()
    },
    // 删除
    goDel() {
      if (this.multipleSelection && this.multipleSelection.length > 0) {
        console.log(this.multipleSelection)
        this.$confirm(
          `是否确认删除,共${this.multipleSelection.length}条`,
          '提示',
          {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }
        )
          .then(() => {
            return delObjDetail(this.multipleSelection.map((e) => e.id))
          })
          .then((data) => {
            this.$message.success('删除成功')
            this.getData()
          })
      } else {
        this.$message.error('请选择盘点明细')
      }
    },
    // 取消未盘点的行
    goACT1() {
      this.$confirm('是否确认取消未盘点的行', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          let ids = []
          if (this.multipleSelection && this.multipleSelection.length > 0) {
            ids = this.multipleSelection.map((e) => e.id)
          }
          return cancelNoIny(ids)
        })
        .then((data) => {
          this.$message.success('删除成功')
          this.getData()
        })
    },
    // 盘点没有差异
    goACT2() {
      if (this.multipleSelection && this.multipleSelection.length > 0) {
        this.$confirm('是否确认盘点没有差异', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
          .then(() => {
            return noDiff(this.multipleSelection.map((e) => e.id))
          })
          .then((data) => {
            this.$message.success('操作成功')
            this.getData()
          })
      } else {
        this.$message.error('请选择盘点明细')
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.basic-container {
  position: relative;
  &:first-child {
    padding-bottom: 0;
    .l-mes {
      width: 30%;
      margin: 10px 0;
    }
  }
  &:last-child {
    .detailtitle {
      margin-bottom: 15px;
    }
    >>> .title-division {
      display: none;
    }
    >>> .common-table-div {
      margin-top: 0px !important;
    }
  }
}
.icon-btn-back {
  position: absolute;
  left: 15px;
  top: 13px;
  cursor: pointer;
}
.detailtitle {
  font-size: 16px;
  font-weight: 700;
  line-height: 31px;
  margin: -15px 0 0 25px;
}
</style>