| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598 |
- <!-- @desc:分组粘贴 @auth:寇珊珊 @time:2023年4月20日16:00:36 -->
- <template>
- <div class="main-div" ref="mainDiv">
- <!--加载中-->
- <loading :loading="loading" v-if="!modalVisible"></loading>
- <DkPageButton :total="editKeys?editKeys.length:0"
- :current="editIndex"
- v-if="editKeys && editKeys.length > 1"
- @pageChange="editPageChange"></DkPageButton>
- <DkCollapse ref="collapse" @on-change="changeCollapse">
- <DkPanel prop="essentialInformation">
- <!-- 下拉区域 -->
- <DkForm slot="content" ref="formInline" v-model="formData" style="width: 95%">
- <!--成型日期-->
- <DkFormItem prop="moldingDate">
- <DatePickerPop ref="moldingDate" v-model="formData.moldingDate" :readonly="true"/>
- </DkFormItem>
- <!--起始条码-->
- <DkFormItem prop="produceBarCode">
- <InputPop :readonly="productUniqueCodeCount==moldingRecordList.length" ref="produceBarCode"
- v-model="formData.produceBarCode"/>
- </DkFormItem>
- <!-- 绑定条码 -->
- <DkButton :disabled="productUniqueCodeCount==moldingRecordList.length" type="primary"
- @click="bindBarcodeButton" style="margin-right: 10px">{{ $v('bindBarcode') }}
- </DkButton>
- <!-- 清空条码 -->
- <DkButton :disabled="productUniqueCodeCount==moldingRecordList.length"
- style="margin-right: 10px" @click="clearBindBarcode">{{
- $v('clearBindBarcode') }}
- </DkButton>
- <!-- 撤销条码 -->
- <DkButton :disabled="productUniqueCodeCount==0" @click="revokeBindBarcode">{{
- $v('revokeBindBarcode') }}
- </DkButton>
- </DkForm>
- </DkPanel>
- <DkPanel prop="moldingRecordRelation">
- <div slot="content" :style="'height: ' + tableHeight + 'px'">
- <!--添加行按钮-->
- <DkButton slot="content" type="success" @click="openAddDetailModal" size="small" :disabled="addRowFlag"
- style="float: left;position: absolute; top: 95px;left: 140px;">{{ $v('saveDetail') }}
- </DkButton>
- <!--型记录信息-->
- <EditTreeTable ref="moldingRecord" :data="moldingRecordList" showFooter
- major-field="id"
- :operate-flag="false"
- :height="tableHeight"
- :new-row-flag="false"
- @changeValue="changeValue"
- :columns="moldingRecordTreeColumns"
- exchangeField="pdtModelId"
- controlId="pdtModelId"
- :bindBarCodeFlag="true"
- @current-change="getDetailAdd"
- @check-detail-by-bind-bar-code="checkDetail"
- @add-detail-by-bind-bar-code="addDetail"
- ></EditTreeTable>
- </div>
- </DkPanel>
- </DkCollapse>
- <!-- 下部分按钮区域-->
- <DkSaveButton ref="saveButton" :loading="loading" @save="save" @close="close"></DkSaveButton>
- </div>
- </template>
- <script>
- import { formMixin } from '@/mixins/form'
- export default {
- name: 'bind-barcode-grouping',
- mixins: [formMixin],
- data() {
- let self = this
- return {
- tableData: [],
- loading: false,
- tableHeight: 620,
- params: null,
- // 画面表单数据
- formData: {
- moldingDate: new Date().toDateStr(),
- ftyId: this.$store.state.user.ftyId,
- produceBarCode: null,//起始条码
- },
- moldingRecordList: [],// 成型记录明细信息
- // 成型记录明细列表
- productUniqueCodeCount: 0,//绑定条码个数(如果长度和查询数据长度一致则不能进行绑定条码)
- //成型记录明细列表
- moldingRecordTreeColumns: [
- {
- field: 'checkBoxFlag', type: 'checkbox', width: 'auto', childCanInput: false, equal: true,
- },
- // 分组序号
- {
- field: 'moldlineItemNo', title: self.$t('bondingNo'),
- dataType: self.$config.tableSelectType.product, controlId: 'pdtModelId',
- treeNode: true, type: 'disabled', width: 'auto'
- },
- // 分组名称 todo
- // { field: 'moldlineItemCode', title: self.$t('repPdtModelName'), type: 'disabled', width: 'auto' },
- // 成型线编码
- { field: 'uniqueCode', title: self.$t('moldlineCode'), type: 'disabled', width: 'auto' },
- // 成型线名称
- { field: 'moldlineName', type: 'disabled', width: 'auto' },
- // 成型班长
- { field: 'manageUserName', type: 'disabled', width: 'auto' },
- // 成型工号
- { field: 'moldingUserName', type: 'disabled', width: 'auto' },
- // 产品编码
- { field: 'modelCode', title: self.$t('productCode'), type: 'disabled', width: 'auto' },
- // 产品名称
- { field: 'modelName', title: self.$t('productName'), type: 'disabled', width: 'auto' },
- // 模具状态
- { field: 'moldlineItemKindName', title: self.$t('mouldKindName'), type: 'disabled', width: 'auto' },
- // 绑码标识
- // {field: 'flgBindUnique', type: 'switch', width: 'auto'},
- // 绑定条码
- {
- field: 'productUniqueCode',
- title: self.$t('pdtUniqueCode'),
- childCanInput: false,
- equal: true,
- type: 'text',
- width: 'auto'
- },
- // 成型批次
- { field: 'moldingBatch', type: 'disabled', width: 'auto' },
- // 成型标识
- { field: 'flgMolding', type: 'disabled', switch: true, controlId: 'flgMolding', width: '120px' },
- // { field: 'flgMolding', type: 'switch', controlId: 'flgMolding', width: '120px' },
- // 未成型原因
- { field: 'unmoldedReasonName', type: 'disabled', width: 'auto' },
- // 产品商标
- { field: 'logoName', type: 'disabled', width: 'auto' },
- // 釉色
- { field: 'colourName', type: 'disabled', width: 'auto' },
- // 损坯标识
- { field: 'flgScrap', type: 'disabled', switch: true, width: '120px' },
- // 损坯原因
- { field: 'scrapReasonName', type: 'disabled', width: 'auto' },
- // 备注
- { field: 'productRemarks', type: 'text', width: 'auto' },
- ],
- //商品条码-数字正则
- checkProduceBarCode: function (value) {
- const reg = /^.*\d+.*$/
- if (value === '' || value === undefined || value === null) {
- return true
- } else {
- if ((!reg.test(value)) && value !== '') {
- return false
- } else {
- return true
- }
- }
- },
- addRowFlag: true,//保存至明细可用标识
- row: {},//记录当前选择行数据
- }
- },
- methods: {
- /**
- * @desc : 绑定条码
- * @date : 2023/2/28 13:03
- * @author : 寇珊珊
- */
- bindBarcodeButton() {
- if (!this.formData.produceBarCode) {
- this.$Message.warning(this.$t('W_109'))
- return
- }
- if (!this.checkProduceBarCode(this.formData.produceBarCode)) {
- this.$Message.warning(this.$t('W_104'))
- return
- }
- let reg = /(\d+)/g
- let match = null
- //截取的数字
- let lastNum = null
- let beforeStr = null
- let lastStr = null
- while ((match = reg.exec(this.formData.produceBarCode)) !== null) {
- lastNum = match[1]
- // 数字下标
- let lastNumIndex = parseInt(this.formData.produceBarCode.lastIndexOf(lastNum))
- //截取下标前字符
- beforeStr = this.formData.produceBarCode.substr(0, lastNumIndex)
- //截取下标后字符
- lastStr = this.formData.produceBarCode.substr(lastNumIndex + parseInt(lastNum.length)).toString()
- }
- let index = 0
- let zeroFlag = true
- let zeroStr = ''
- if (lastNum.length > 1 && lastNum.substring(0, 1) == '0') {
- zeroFlag = false
- for (let it of lastNum) {
- if (it == '0') {
- zeroStr += '0'
- } else {
- break
- }
- }
- }
- //条码数字长度
- let indexLength = (parseInt(lastNum) + parseInt(index)).toString().length
- for (let i = 0; i < this.moldingRecordList.length; i++) {
- if (this.moldingRecordList[i].productUniqueCodeFlag || this.moldingRecordList[i].canProductUniqueCode) {
- let number = parseInt(lastNum) + parseInt(index)
- //每次多一位数,就去掉前面一个0
- if (indexLength != number.toString().length) {
- if (zeroStr.length == 0) {
- break
- }
- zeroStr = zeroStr.substring(0, zeroStr.length - 1)
- indexLength = number.toString().length
- }
- //数字在前
- if (beforeStr.length == 0) {
- if (zeroFlag) {
- this.$set(this.moldingRecordList[i], 'productUniqueCode', number + beforeStr + lastStr)
- } else {
- this.$set(this.moldingRecordList[i], 'productUniqueCode', zeroStr + number + beforeStr + lastStr)
- }
- }
- //数字在后
- else if (lastStr.length == 0) {
- if (zeroFlag) {
- this.$set(this.moldingRecordList[i], 'productUniqueCode', beforeStr + lastStr + number)
- } else {
- this.$set(this.moldingRecordList[i], 'productUniqueCode', beforeStr + lastStr + zeroStr + number)
- }
- }
- //数字在中
- else {
- if (zeroFlag) {
- this.$set(this.moldingRecordList[i], 'productUniqueCode', beforeStr + number + lastStr)
- } else {
- this.$set(this.moldingRecordList[i], 'productUniqueCode', beforeStr + zeroStr + number + lastStr)
- }
- }
- this.$set(this.moldingRecordList[i], 'productUniqueCodeFlag', true)
- this.$set(this.moldingRecordList[i], 'productUniqueFlag', true)
- index++
- //给每个总单下的明细【绑定条码赋值】
- for (let item = 0; item < this.moldingRecordList[i].bomItems.length; item++) {
- //从后台数据查出来绑定条码已经存在的不需要赋值
- if (!this.moldingRecordList[i].bomItems[item].readOnlyUniqueCode) {
- this.$set(this.moldingRecordList[i].bomItems[item], 'productUniqueCode', this.moldingRecordList[i].productUniqueCode)
- this.$set(this.moldingRecordList[i].bomItems[item], 'productUniqueCodeFlag', true)
- this.$set(this.moldingRecordList[i].bomItems[item], 'productUniqueFlag', true)
- }
- }
- }
- }
- this.$refs.moldingRecord.tableData = this.moldingRecordList
- // 处理子级数据
- this.$refs.moldingRecord.loadChildrenInit(this.moldingRecordList, ['productUniqueCode'])
- // 重新刷新
- this.$refs.moldingRecord.reloadTreeTable(this.moldingRecordList)
- },
- /**
- * @desc : 清空条码
- * @date : 2023/2/28 13:04
- * @author : 寇珊珊
- */
- clearBindBarcode() {
- this.formData.produceBarCode = null
- for (let i of this.moldingRecordList) {
- if (!i.readOnlyUniqueCode) {
- i.productUniqueCode = null
- i.productUniqueCodeFlag = false
- i.productUniqueFlag = false
- }
- //清空每条总单下明细的绑定条码
- for (let item of i.bomItems) {
- if (!item.readOnlyUniqueCode) {
- item.productUniqueCode = null
- item.productUniqueCodeFlag = false
- item.productUniqueFlag = false
- }
- }
- }
- // 处理子级数据
- this.$refs.moldingRecord.loadChildrenInit(this.moldingRecordList, ['productUniqueCode'])
- this.$refs.moldingRecord.reloadData(this.moldingRecordList)
- },
- /**
- * @desc : 撤销条码
- * @date : 2023/5/8 9:53
- * @author : 寇珊珊
- */
- revokeBindBarcode() {
- let list = this.$refs['moldingRecord'].tableData.filter(it=>it.checkBoxFlag)
- let pdtUniqueIdList = []
- for (let item of list) {
- for (let it of item.bomItems) {
- if (it.pdtUniqueId) {
- pdtUniqueIdList.push(it.pdtUniqueId)
- }
- }
- }
- if (pdtUniqueIdList.length == 0) {
- this.$Message.warning(this.$t('W_150'))
- return
- }
- this.excute(this.$service.productService, this.$service.productService.undo, pdtUniqueIdList).then(res => {
- if (res.code === this.$config.SUCCESS_CODE) {
- this.$Message.success(res.message)
- this.detail(this.$route.params.id)
- } else {
- this.$Message.warning(res.message)
- }
- })
- },
- /**
- * @desc : 值改变
- * @date : 2023/2/28 11:23
- * @author : 寇珊珊
- */
- changeValue(value) {
- if (value && value.field) {
- let field = value.field
- let row = value.row
- let rowIndex = value.rowIndex
- if (value.field == 'productUniqueCode') {
- this.$set(this.moldingRecordList[rowIndex], field, row[field])
- this.$set(this.moldingRecordList[rowIndex], 'productUniqueFlag', true)
- row.productUniqueFlag = true
- //改变每条总单下明细的绑定条码
- for (let item = 0; item < row.bomItems.length; item++) {
- //从后台数据查出来绑定条码已经存在的不需要赋值;
- if (!row.bomItems[item].readOnlyUniqueCode) {
- this.$set(row.bomItems[item], 'productUniqueFlag', true)
- this.$set(row.bomItems[item], 'productUniqueCode', row[field])
- }
- //修改备注也要修改productUniqueFlag标识 用于后续保存数据过滤
- if (field == 'productRemarks') {
- this.$set(row.bomItems[item], 'productUniqueFlag', true)
- }
- }
- for (let i = 0; i < this.moldingRecordList.length; i++) {
- if (this.moldingRecordList[i].id == row.id) {
- this.moldingRecordList[i] = row
- }
- }
- this.$refs.moldingRecord.tableData = this.moldingRecordList
- // 处理子级数据
- this.$refs.moldingRecord.loadChildrenInit(this.moldingRecordList, ['productUniqueCode'])
- // 重新刷新
- this.$refs.moldingRecord.reloadTreeTable(this.moldingRecordList)
- }
- }
- },
- /**
- * @desc : 替换子集
- * @date : 2023/4/24 15:09
- * @author : 寇珊珊
- */
- checkDetail(oldRow, newRow) {
- for (let it of this.moldingRecordList) {
- let index = 0
- for (let item of it.bomItems) {
- if (item.id == oldRow.id) {
- newRow.moldingItemId = newRow.itemId
- item = Object.assign(item, newRow)
- index++
- break
- }
- }
- }
- this.$refs.moldingRecord.reloadData(this.moldingRecordList)
- },
- /**
- * @desc : 获取添加子集
- * @date : 2023/4/27 10:11
- * @author : 寇珊珊
- */
- getDetailAdd(e) {
- if (e && e.column && !e.column.field) {
- return
- }
- //只存父级
- if (e && e.row && e.row.hasChild == 1) {
- this.row = e.row
- this.addRowFlag = false
- } else {
- this.addRowFlag = true
- }
- },
- /**
- * @desc : 添加子集
- * @date : 2023/4/27 10:03
- * @author : 寇珊珊
- */
- openAddDetailModal() {
- //父级成型线下产品个数不存在,或者父级下成型线下产品个数和父级明细个数不相等
- if (this.row) {
- if (!this.row.modelCount || (this.row.modelCount && this.row.modelCount != this.row.bomItems.length)) {
- //赋值查询类型
- this.$refs.moldingRecord.focusedRow = this.row
- //加载数据
- this.$refs.moldingRecord.getDataTable(this.row)
- } else {
- this.$Message.warning(this.$t('W_143'))
- }
- } else {
- this.$Message.warning(this.$t('W_142'))
- }
- },
- /**
- * @desc : 将选择后的数据添加至明细
- * @date : 2023/4/27 14:41
- * @author : 寇珊珊
- */
- addDetail(row) {
- this.addRowFlag = false
- for (let it of this.moldingRecordList) {
- if (this.row.id == it.id) {
- row.parentId = it.id
- row.moldingItemId = row.itemId
- this.$set(row, 'readOnly', ['productUniqueCode'])
- it.bomItems.push(row)
- }
- it.modelCount = row.modelCount
- }
- // 处理子级数据
- this.$refs.moldingRecord.loadChildrenInit(this.moldingRecordList, ['productUniqueCode'])
- this.$refs.moldingRecord.reloadData(this.moldingRecordList)
- },
- /**
- * @desc : 通过id查询
- * @date : 2023/2/28 11:25
- * @author : 寇珊珊
- */
- detail(id) {
- //绑定条码计数 每次查询之前要清零(因为保存后要重新调用)
- this.productUniqueCodeCount = 0
- let param = {
- 'moldlineId': parseInt(id),
- 'pdtGlueKind': this.$route.query.pdtGlueKind,
- 'moldingBatch': this.$route.query.moldingBatch,
- 'moldingDate': this.$route.query.moldingDate,
- 'ftyId': this.$store.state.user.ftyId
- }
- return this.excute(this.$service.moldingRecordItemService, this.$service.moldingRecordItemService.selectByMoldineId, param).then(res => {
- if (res.code === this.$config.SUCCESS_CODE) {
- this.formData.moldingDate = this.$route.query.moldingDate
- let list = res.data
- this.moldingRecordList = list
- let index = 0
- for (let i of this.moldingRecordList) {
- i.pdtModelId = this.$config.bindBarCodePdtModelId.parentId
- i.modelCount = i.bomItems[0].modelCount
- //明细已有绑定条码个数
- let productUniqueCodeLength = 0
- //明细已有成型标识个数
- let flgMoldingLength = 0
- //明细下标
- let itemIndex = 0
- //明细第一条的绑定条码
- let zeroCode = null
- //循环明细
- for (let item of i.bomItems) {
- item.moldingItemId = item.itemId
- //如果明细第一条绑定条码有值 存起来
- if (itemIndex == 0 && item.productUniqueCode) {
- zeroCode = item.productUniqueCode
- }
- //明细的绑定条码不可以修改
- this.$set(item, 'readOnly', ['productUniqueCode'])
- //如果明细里绑定条码存在没值的情况;总单绑定条码可以输入 反之不可以;明细有值没值都要禁用
- if (item.productUniqueCode) {
- item.exchangeFlag = false
- productUniqueCodeLength++
- item.readOnlyUniqueCode = true
- }
- //明细不是成型
- if (!item.flgMolding) {
- item.exchangeFlag = false
- flgMoldingLength++
- }
- itemIndex++
- }
- //明细中每条绑定条码都有值 = 每条总单下的明细数量 或者 是成型标识数量大于0
- if (productUniqueCodeLength == i.bomItems.length || flgMoldingLength > 0) {
- i.readOnlyUniqueCode = true
- //明细第一条绑定条码赋值给父级
- this.$set(this.moldingRecordList[index], 'productUniqueCode', zeroCode)
- //不可更改绑定条码
- this.$set(this.moldingRecordList[index], 'canProductUniqueCode', false)
- //绑定条码改为只读
- this.$set(i, 'readOnly', ['productUniqueCode'])
- //绑定条码总条数累加
- this.productUniqueCodeCount++
- //总单成型标识(根据明细里是否全是成型标识)
- } else {
- //可更改绑定条码
- this.$set(this.moldingRecordList[index], 'canProductUniqueCode', true)
- //撤销条码复选框是否可用
- this.$set(i, 'disabled', true)
- }
- index++
- }
- }
- })
- },
- /**
- * @desc : 设置传参
- * @date : 2023/2/28 11:29
- * @author : 寇珊珊
- */
- setParams() {
- //productUniqueFlag 校验手动改变绑定条码标识
- let list = []
- if (this.moldingRecordList.length > 0) {
- //提取明细信息
- for (let it of this.moldingRecordList.filter(it => it.productUniqueFlag)) {
- let bomItems = it.bomItems.filter(item => item.productUniqueFlag)
- list.push({
- moldingItemIds: bomItems.map(map => map.moldingItemId),
- ftyId: bomItems[0].ftyId,
- moldingItemId: bomItems[0].moldingItemId,
- uniqueId: bomItems[0].productId,
- uniqueCode: bomItems[0].productId ? null : it.productUniqueCode,
- remarks: it.productRemarks,
- flgPdtGlue: true,
- modelId: bomItems[0].repPdtModelId,
- })
- }
- }
- this.params = list
- },
- /**
- * @desc : 保存数据
- * @date : 2023/2/28 11:28
- * @author : 寇珊珊
- */
- save() {
- //验重
- if (!this.checkData()) {
- return
- }
- this.setParams()
- let excute = this.excute(this.$service.productService, this.$service.productService.insertBatch, this.params)
- excute.then(res => {
- if (res.code === this.$config.SUCCESS_CODE) {
- this.$Message.success(res.message)
- this.detail(this.$route.params.id)
- } else {
- this.$Message.warning(res.message)
- }
- })
- return excute
- },
- /**
- * @desc : 验重
- * @date : 2023/3/3 14:30
- * @author : 寇珊珊
- */
- checkData() {
- let codeNoList = []
- //校验绑定条码
- codeNoList = codeNoList.concat(this.moldingRecordList.copy().filter(f => f.productUniqueCode).map(m => m.productUniqueCode))
- if (codeNoList.length != codeNoList.unique().length) {
- this.$Message.warning(this.$t('W_110'))
- return false
- }
- //todo 判断每组数据是否达到可保存数量
- //如果本次都不需要绑定条码
- if (this.productUniqueCodeCount != this.moldingRecordList.length) {
- //过滤掉总单中本次不需要进行绑定条码的数据
- for (let i of this.moldingRecordList.filter(it => !it.readOnlyUniqueCode)) {
- if (!i.modelCount || i.modelCount && i.modelCount != i.bomItems.length) {
- this.$Message.warning(this.$t('W_144'))
- return false
- }
- }
- }
- return true
- },
- },
- created() {
- this.resizeTableFlag = true // 计算表格高度
- },
- activated() {
- this.detail(this.$route.params.id)
- }
- }
- </script>
- <style scoped>
- </style>
|