lanan-system-vue/src/views/repair/stockOperate/Components/WaresItem.vue

867 lines
32 KiB
Vue
Raw Normal View History

<template>
<div>
<!-- 搜索 -->
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
<el-form-item label="关键字" prop="query">
<el-input style="width: 20rem" type="text" placeholder="工单号、车牌号、联系电话" v-model="queryParams.query"/>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<!-- 操作 -->
<el-row :gutter="10" class="mb8">
2024-12-03 18:03:39 +08:00
<el-col :span="1.5">
2024-12-05 16:29:40 +08:00
<el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
:loading="exportLoading"
>导出
</el-button>
2024-12-03 18:03:39 +08:00
</el-col>
<right-toolbar :showSearch.sync="showSearch"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
<el-table-column label="序号" align="center" width="80">
<template scope="scope">
<span>{{ scope.$index + 1 }}</span>
</template>
</el-table-column>
2024-10-22 15:57:07 +08:00
<el-table-column label="单据号" align="center" prop="no" width="200"/>
2024-11-12 17:44:44 +08:00
<el-table-column label="客户信息" align="center">
<el-table-column label="姓名" align="center" prop="userName" width="180"/>
<el-table-column label="联系电话" align="center" prop="userMobile" width="180"/>
<el-table-column label="车牌号" align="center" prop="licenseNumber" width="180"/>
</el-table-column>
<el-table-column label="申请人" align="center" prop="repairName" width="180"/>
<el-table-column label="岗位" align="center" prop="repairWork" width="180">
<template slot-scope="scope">
<dict-tag :type="DICT_TYPE.REPAIR_WORK_TYPE" :value="scope.row.repairWork"/>
</template>
</el-table-column>
2024-11-12 17:44:44 +08:00
<el-table-column label="服务顾问" align="center" prop="adviserName" width="180"/>
<el-table-column label="备注" align="center" prop="remark" width="180" :show-overflow-tooltip="true"/>
<el-table-column label="操作" align="center" fixed="right" width="180">
<template slot-scope="scope">
2024-11-12 17:44:44 +08:00
<el-button type="text" size="mini" icon="el-icon-view" @click="handleView(scope.row)">
查看
</el-button>
<el-button type="text" size="mini" @click="handleDispose(scope.row)" icon="el-icon-edit">
处理
</el-button>
</template>
</el-table-column>
</el-table>
<!-- 分页组件 -->
<pagination style="margin-bottom: 2rem" v-show="total > 0" :total="total" :page.sync="queryParams.pageNo"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
<el-dialog title="单据处理" :visible.sync="dialogVisible" width="80%" v-dialogDrag append-to-body>
<el-form :inline="true">
<el-form-item label="名称" prop="query">
<el-input v-model="query"/>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" @click="searchByQuery">搜索</el-button>
<el-button icon="el-icon-refresh" @click=resetByQuery>重置</el-button>
</el-form-item>
</el-form>
2024-12-05 16:29:40 +08:00
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
2024-12-06 10:00:34 +08:00
<el-button type="primary" v-if="type" plain icon="el-icon-plus" size="mini" @click="handleAddWares"
2024-12-05 16:29:40 +08:00
>添加配件</el-button>
</el-col>
</el-row>
2024-10-19 22:55:25 +08:00
<el-table
@cell-mouse-enter="handleCellEnter"
@cell-mouse-leave="handleCellLeave"
@cell-click="handleCellClick"
el-table v-loading="dialogLoading"
:data="items" :stripe="true"
:show-overflow-tooltip="true"
:row-class-name="getRowClass"
@selection-change="handleSelect"
:key="tableKey"
ref="tableRef"
2024-10-19 22:55:25 +08:00
>
2024-10-26 12:01:55 +08:00
<el-table-column type="selection" width="80" align="center"/>
<el-table-column label="名称" align="center" prop="waresName" :show-overflow-tooltip="true"/>
2024-12-05 16:29:40 +08:00
<el-table-column label="配件添加人" align="center" prop="addUserName" width="180"/>
2024-10-21 21:37:07 +08:00
<el-table-column label="领料数量" v-if="type" align="center" prop="waresCount" width="180">
<div class="item" slot-scope="scope">
<el-input @blur="save(scope.row)" class="item__input" v-model="scope.row.waresCount"
placeholder="请输入数量"></el-input>
<span class="item__txt">{{ scope.row.waresCount }}</span>
</div>
</el-table-column>
<el-table-column label="库存数量" v-if="type" align="center" prop="wares.stock" width="180"/>
<el-table-column label="已领数量" v-if="!type" align="center" prop="waresAlreadyCount" width="180"/>
<el-table-column label="退料数量" v-if="!type" align="center" prop="waresCount" width="180">
2024-10-19 22:55:25 +08:00
<div class="item" slot-scope="scope">
<el-input @blur="save(scope.row)" class="item__input" v-model="scope.row.waresCount"
placeholder="请输入数量"></el-input>
<span class="item__txt">{{ scope.row.waresCount }}</span>
</div>
</el-table-column>
</el-table>
<div slot="footer" class="dialog-footer">
2025-01-09 12:08:51 +08:00
<el-button type="primary" @click="handleConfirmOver">
申领完成
</el-button>
<el-button type="primary" v-if="type" @click="handlePassBefore"
2024-11-20 20:23:24 +08:00
:disabled="allSelectRows.length === 0 || allSelectRows.filter(item => !item.isStock).length !== 0">
2024-10-21 21:37:07 +08:00
通知领料
</el-button>
<el-button type="primary" v-else @click="handlePassBefore"
2024-11-20 20:23:24 +08:00
:disabled="allSelectRows.length === 0 || allSelectRows.filter(item => !item.isStock).length !== 0">
2024-10-21 21:37:07 +08:00
通知退料
2024-10-19 22:55:25 +08:00
</el-button>
2024-11-20 20:23:24 +08:00
<el-button v-if="type" type="primary" @click="handleCreate" :disabled="allSelectRows.length === 0">
2024-10-19 22:55:25 +08:00
采购
</el-button>
</div>
</el-dialog>
2024-10-17 12:10:33 +08:00
<el-dialog title="采购单" :visible.sync="inStockDialog" width="80%" v-dialogDrag append-to-body>
2024-11-29 11:40:29 +08:00
<el-form :inline="true">
<el-form-item label="供应商">
<SupplierChoose v-model="chooseSupplier"/>
</el-form-item>
</el-form>
<el-descriptions class="margin-top" title="车辆信息" :column="3" border>
<el-descriptions-item>
<template slot="label">
车牌号
2024-10-17 12:10:33 +08:00
</template>
{{ carInfo.licenseNumber }}
</el-descriptions-item>
<el-descriptions-item>
<template slot="label">
品牌
2024-10-17 12:10:33 +08:00
</template>
{{ carInfo.carBrand }}
</el-descriptions-item>
<el-descriptions-item>
<template slot="label">
型号
</template>
{{ carInfo.carModel }}
</el-descriptions-item>
</el-descriptions>
<el-collapse>
2024-11-20 15:37:48 +08:00
<el-collapse-item v-for="[key, value] in partList" :title="key + `(${value.length})`">
<el-table
:data="value"
:stripe="true"
:show-overflow-tooltip="true"
show-summary
:summary-method="getSummaries"
@cell-mouse-enter="handleCellEnter"
@cell-mouse-leave="handleCellLeave"
@cell-click="handleCellClick"
>
<el-table-column label="序号" align="center">
<template scope="scope">
<span>{{ scope.$index + 1 }}</span>
</template>
</el-table-column>
<el-table-column label="商品名称" align="center" prop="waresName" width="200"/>
<el-table-column label="规格" align="center" width="180" prop="wares.model">
<div class="item" slot-scope="scope">
<el-input @blur="save(scope.row)" class="item__input" v-model="scope.row.wares.model"
placeholder="请输入规格"></el-input>
<span class="item__txt">{{ scope.row.wares.model }}</span>
</div>
</el-table-column>
<el-table-column label="分类" align="center" width="180" prop="wares.type">
<div class="item" slot-scope="scope">
2024-11-23 17:11:09 +08:00
<el-select class="item__input" clearable ref="selectTree" v-model="scope.row.wares.type"
@change="save(scope.row)">
<el-option v-for="server in optionData(serverList)"
:key="server.value"
:label="server.label"
:value="server.value" style="display: none"/>
<el-tree class="item__input" ref="selectedTree"
:data="serverList"
:props="treeProps"
highlight-current
@node-click="handleNodeClick($event, scope.row)"
:expand-on-click-node="expandOnClickNode"
2024-11-23 17:11:09 +08:00
default-expand-all/>
</el-select>
<span class="item__txt">{{ getTypeById(scope.row.wares.type) }}</span>
</div>
</el-table-column>
<el-table-column label="商品编码" align="center" width="180" prop="wares.code">
<div class="item" slot-scope="scope">
<el-input @blur="save(scope.row)" class="item__input" v-model="scope.row.wares.code"
placeholder="请输入内容"></el-input>
<span class="item__txt">{{ scope.row.wares.code }}</span>
</div>
</el-table-column>
<el-table-column label="仓库" align="center" width="150" prop="wares.warehouse">
<div class="item" slot-scope="scope">
<WarehouseChoose @input-blur="save(scope.row)" class="item__input" v-model="scope.row.wares.ware"
@change="changeWare(scope.row)"/>
<span class="item__txt">{{ scope.row.wares?.ware?.name }}</span>
</div>
</el-table-column>
<el-table-column label="库存" align="center" width="150" prop="wares.stock"/>
<el-table-column label="单位" align="center" width="150" prop="wares.unit">
<div class="item" slot-scope="scope">
<el-select class="item__input" v-model="scope.row.wares.unit" @blur="save(scope.row)">
<el-option v-for="dict in getDictDatasToType(DICT_TYPE.REPAIR_UNIT)" :key="dict.value"
:label="dict.label"
:value="dict.value"/>
</el-select>
<span class="item__txt">
<dict-tag :type="DICT_TYPE.REPAIR_UNIT" v-model="scope.row.wares.unit"/>
</span>
</div>
</el-table-column>
<el-table-column label="数量" align="center" width="150" prop="waresCount">
<div class="item" slot-scope="scope">
<el-input @blur="save(scope.row)" class="item__input" v-model="scope.row.waresCount"
placeholder="请输入内容"></el-input>
<span class="item__txt">{{ scope.row.waresCount }}</span>
</div>
</el-table-column>
<el-table-column label="进价" align="center" width="150" prop="wares.purPrice">
<div class="item" slot-scope="scope">
<el-input @blur="save(scope.row)" class="item__input" v-model="scope.row.wares.purPrice"
placeholder="请输入内容"></el-input>
<span class="item__txt">{{ scope.row.wares.purPrice }}</span>
</div>
</el-table-column>
<el-table-column label="售价" align="center" width="150" prop="wares.price">
<div class="item" slot-scope="scope">
<el-input @blur="save(scope.row)" class="item__input" v-model="scope.row.wares.price"
placeholder="请输入内容"></el-input>
<span class="item__txt">{{ scope.row.wares.price }}</span>
</div>
</el-table-column>
<el-table-column label="总金额" align="center" width="150" prop="totalPrice"/>
<el-table-column label="备注" align="center" width="180" prop="remark">
<div class="item" slot-scope="scope">
<el-input @blur="save(scope.row)" class="item__input" v-model="scope.row.remark"
placeholder="请输入内容"></el-input>
<span class="item__txt">{{ scope.row.remark }}</span>
</div>
</el-table-column>
<el-table-column label="操作" fixed="right" align="center" width="150">
<template v-slot="scope">
<el-button size="mini" type="text" icon="el-icon-delete" @click="deleteItem(scope.$index)"
>删除
</el-button>
</template>
</el-table-column>
</el-table>
</el-collapse-item>
</el-collapse>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="handleSubmit">保存</el-button>
<el-button @click="inStockDialog = false">取消</el-button>
</div>
2024-10-17 12:10:33 +08:00
</el-dialog>
2024-11-12 17:44:44 +08:00
<el-dialog :title="type ? '通知领料' : '通知退料'" :visible.sync="inPhoto" width="40%" v-dialogDrag append-to-body>
2024-11-23 17:11:09 +08:00
<el-form :inline="true" label-width="15rem">
<el-form-item :label="type ? '领料人' : '退料人'">
2024-11-23 17:11:09 +08:00
<el-select v-model="chooseStaff" multiple clearable filterable>
2024-12-05 16:29:40 +08:00
<el-option v-for="staff in staffs" :key="staff.id" :value="staff.userId" :label="staff.userName"/>
2024-11-23 17:11:09 +08:00
</el-select>
</el-form-item>
<el-form-item label="图片上传">
<ImageUpload v-model="images"/>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="handlePass">确定</el-button>
<el-button type="primary" @click="inPhoto = false">取消</el-button>
</div>
</el-dialog>
2024-11-12 17:44:44 +08:00
<TicketWaresShow ref="ticketWaresShow" :user-role="'repair_warehouse'" @success="getList" :type="false"/>
2024-12-05 16:29:40 +08:00
<TWIAdd ref="twiAdd" @success="handleSuccess" :if-house-add="true"/>
</div>
</template>
<script>
2025-01-09 12:08:51 +08:00
import {getPage, pass, passBackTicketWares, getByIds, exportData,confirmOver} from "@/api/repair/tickets/TicketWares";
import {listTwItem} from "@/api/repair/tickets/TWItem";
import {createUniqueCodeByHead} from "@/utils/createUniqueCode";
import {parseTime} from "@/utils/ruoyi";
2024-10-17 12:10:33 +08:00
import SoTable from "@/views/repair/stockOperate/Components/SoTable.vue";
import WarehouseChoose from "@/views/repair/Components/WarehouseChoose.vue";
import {createRepairSo} from "@/api/repair/stockOperate/stockOperate";
import {getUserProfile} from "@/api/system/user";
2024-11-12 17:44:44 +08:00
import TicketWaresShow from "@/views/repair/tickets/Components/TicketWaresShow.vue";
import {getCusAndCarById} from "@/api/repair/tickets/Tickets";
import {getCarBrand} from "@/api/base/carbrand";
import {listGoods} from "@/views/partner/api/workOrder";
import {getBaseTypeList} from "@/api/base/type";
2024-11-23 17:11:09 +08:00
import {listByTicketId} from "@/api/repair/repairworker";
2024-11-29 11:40:29 +08:00
import StaffChoose from "@/views/repair/Components/StaffChoose.vue";
import SupplierChoose from "@/views/repair/Components/SupplierChoose.vue";
2024-12-05 16:29:40 +08:00
import TWIAdd from "@/views/repair/tickets/Components/TWIAdd.vue";
export default {
name: "WaresItem",
2024-12-05 16:29:40 +08:00
components: {TWIAdd, SupplierChoose, StaffChoose, TicketWaresShow, WarehouseChoose, SoTable},
2024-10-26 12:01:55 +08:00
props: {
type: Boolean,
},
2024-10-26 12:01:55 +08:00
data() {
return {
queryParams: {
pageNo: 1,
pageSize: 10,
query: null,
2024-11-12 17:44:44 +08:00
isBack: !this.type,
},
showSearch: true,
loading: false,
2024-10-26 12:01:55 +08:00
list: [],
total: 0,
dialogVisible: false,
2024-10-26 12:01:55 +08:00
items: [],
dialogLoading: false,
2024-10-26 12:01:55 +08:00
selections: [],
selectionIds: [],
2024-10-26 12:01:55 +08:00
formData: {},
2024-10-17 12:10:33 +08:00
inStockDialog: false,
partList: [],
includeColumn: ['waresCount', 'totalPrice'],
2024-10-17 12:10:33 +08:00
// 保存进入编辑的cell
clickCellMap: {},
// 需要编辑的属性
editProp: ['wares.warehouse', 'wares.type', 'waresCount', 'wares.purPrice', 'wares.price', 'remark', 'wares.code', 'waresCount', 'wares.model', 'wares.unit'],
2024-10-17 12:10:33 +08:00
remark: null,
2024-10-19 22:55:25 +08:00
tableKey: 0,
query: null,
twId: null,
carInfo: {},
ticketId: null,
expandOnClickNode: true,
serverList: [],
2024-11-23 17:11:09 +08:00
treeProps: {
label: "name",
children: "children"
},
typeMap: null,
2024-11-20 20:23:24 +08:00
allSelectRows: [],
isRefresh: false,
inPhoto: false,
2024-11-23 17:11:09 +08:00
images: null,
chooseStaff: [],
staffs: [],
2024-12-03 18:03:39 +08:00
chooseSupplier: null,
// 导出遮罩层
exportLoading: false,
}
},
mounted() {
this.getList()
},
2024-10-26 12:01:55 +08:00
methods: {
2024-12-05 16:29:40 +08:00
handleAddWares(){
this.$refs.twiAdd.open({id: this.twId})
},
handleSuccess(data){
this.getTwitemList({twId: this.twId})
},
2024-11-23 17:11:09 +08:00
getTypeById(id) {
return this.typeMap.get(id)
},
2024-11-23 17:11:09 +08:00
async listServer() {
if (!this.serverList || this.serverList.length === 0) {
const res = await getBaseTypeList({type: "02"})
2024-11-23 17:11:09 +08:00
this.serverList = this.handleTree(res.data, 'id', 'parentId', "children", "0")
this.typeMap = new Map()
this.extractNodesToMap(this.serverList, this.typeMap)
}
},
extractNodesToMap(nodes, map) {
nodes.forEach(node => {
map.set(node.id, node.name);
if (node.children && node.children.length > 0) {
this.extractNodesToMap(node.children, map);
}
});
},
2024-11-23 17:11:09 +08:00
handleNodeClick(data, scopeRow) {
scopeRow.wares.type = data.id;
this.save(scopeRow)
},
2024-11-23 17:11:09 +08:00
optionData(array, result = []) {
array.forEach(item => {
result.push({label: item.name, value: item.id})
2024-11-23 17:11:09 +08:00
if (item.children && item.children.length !== 0) {
this.optionData(item.children, result)
}
})
return JSON.parse(JSON.stringify(result))
},
searchByQuery() {
2024-11-20 20:23:24 +08:00
this.isRefresh = true
const data = {
twId: this.twId,
query: this.query
}
this.getTwitemList(data).then(() => {
this.setSelectedRows();
})
},
setSelectedRows() {
this.$nextTick(() => {
this.$refs.tableRef.clearSelection(); // 清除所有选择
2024-11-20 20:23:24 +08:00
const ids = this.allSelectRows.map(item => item.id)
this.items.forEach(row => {
2024-11-20 20:23:24 +08:00
if (ids.includes(row.id)) {
this.$refs.tableRef.toggleRowSelection(row, true); // 选中行
}
});
});
},
resetByQuery() {
2024-11-20 20:23:24 +08:00
this.allSelectRows = []
this.query = null
this.searchByQuery()
},
getDictDatasToType(type) {
2024-11-12 17:44:44 +08:00
return this.getDictDatas(type)
},
2024-11-23 17:11:09 +08:00
handlePassBefore() {
this.chooseStaff = []
this.staffs = []
this.getTicketStaff()
this.images = null
this.inPhoto = true
},
2025-01-09 12:08:51 +08:00
/** 申领完成 */
async handleConfirmOver() {
await this.$modal.confirm('确定所有配件均已申领完成?')
try {
await confirmOver(this.twId);
await this.getList();
this.dialogVisible = false
this.$modal.msgSuccess("操作成功");
} catch {
}
},
2024-12-05 16:29:40 +08:00
async getTicketStaff() {
2024-11-23 17:11:09 +08:00
const res = await listByTicketId(this.ticketId)
this.staffs = res.data
this.chooseStaff.push(this.formData.repairId)
},
// 通过 true是全部、false是选择
2024-10-26 12:01:55 +08:00
async handlePass() {
2024-11-23 17:11:09 +08:00
if (this.images) {
this.formData.images = this.images.split(",").map(item => {
return item.replace(process.env.VUE_APP_FILE_API, "")
}).join(",")
}
2024-12-05 16:29:40 +08:00
if ((!this.chooseStaff || this.chooseStaff.length === 0)) {
this.$modal.msgError(`请选择${this.type ? '领' : '退'}料人!`)
2024-11-23 17:11:09 +08:00
return
}
2024-10-21 21:37:07 +08:00
// 生成领料单、退料单
2024-10-26 12:01:55 +08:00
this.formData.repairSo = {
soType: this.type ? "02" : "04",
soNo: createUniqueCodeByHead(this.type ? "LL" : "TL"),
userId: this.formData.repairId,
userName: this.formData.repairName,
soTime: parseTime(Date.now(), '{y}-{m}-{d}'),
soStatus: this.type ? "04" : "07",
userIds: this.chooseStaff.join(",")
2024-10-26 12:01:55 +08:00
// purchaseType: "01"
}
2024-11-20 20:23:24 +08:00
this.formData.repairSois = [...this.allSelectRows.map(item => {
2024-10-26 12:01:55 +08:00
return {
soiType: this.type ? '02' : "04",
goodsId: item.waresId,
goodsCount: item.waresCount,
2024-10-17 23:39:54 +08:00
}
2024-10-26 12:01:55 +08:00
})]
2024-12-05 16:29:40 +08:00
this.formData.ids = this.allSelectRows.map(item => item.id)
2024-10-26 12:01:55 +08:00
if (this.type) {
2024-11-20 20:23:24 +08:00
this.formData.items = [...this.allSelectRows.map(item => {
2024-10-19 22:55:25 +08:00
return {
2024-10-26 12:01:55 +08:00
id: item.id,
2024-10-19 22:55:25 +08:00
}
})]
2024-10-26 12:01:55 +08:00
}
try {
await pass(this.formData)
this.$modal.msgSuccess("处理成功")
await this.getList()
} finally {
this.dialogVisible = false
this.inPhoto = false
2024-10-26 12:01:55 +08:00
}
},
2024-10-17 12:10:33 +08:00
// 生成采购 true是全部、false是选择
2024-10-26 12:01:55 +08:00
async handleCreate() {
try {
const carRes = await getCusAndCarById(this.ticketId)
this.carInfo = carRes.data.carInfo
if (this.carInfo.carBrand) {
const brandRes = await getCarBrand(this.carInfo.carBrand)
this.carInfo.carBrand = brandRes.data.brandName
2024-10-26 12:01:55 +08:00
}
2024-11-20 20:23:24 +08:00
const ids = this.allSelectRows.map(item => item.id)
const res = await getByIds(ids)
this.partList = Object.entries(res.data)
const values = this.partList.map(([key, value]) => value)
values.forEach(item => {
item.forEach(i => {
i.totalPrice = i.waresCount * i.wares.price
})
})
2024-11-29 11:40:29 +08:00
this.chooseSupplier = null
this.inStockDialog = true
this.dialogVisible = false
} catch {
}
},
2024-10-26 12:01:55 +08:00
async getList() {
try {
this.loading = true
const res = await getPage(this.queryParams)
2024-10-26 12:01:55 +08:00
if (res.data) {
this.list = res.data.records
this.total = res.data.total
}
2024-10-26 12:01:55 +08:00
} finally {
this.loading = false
}
},
2024-10-26 12:01:55 +08:00
handleQuery() {
this.queryParams.pageNo = 1
this.getList()
},
2024-10-26 12:01:55 +08:00
resetQuery() {
this.resetForm('queryForm')
this.handleQuery()
},
handleDispose(row) {
2024-11-20 20:23:24 +08:00
this.allSelectRows = []
this.query = null
this.listServer()
this.formData = {}
this.formData = {
...row
}
this.dialogVisible = true
const data = {twId: row.id}
this.twId = row.id
this.ticketId = row.ticketId
this.getTwitemList(data)
},
async getTwitemList(data) {
try {
2024-10-17 23:39:54 +08:00
const res = await listTwItem(data)
this.items = res.data
2024-11-12 17:44:44 +08:00
this.items = this.items.filter(item => item.waresStatus === '1')
this.items.forEach(item => {
2024-10-26 12:01:55 +08:00
const count = item.waresAlreadyCount ? parseInt(item.waresCount) - parseInt(item.waresAlreadyCount) : item.waresCount
item.waresCount = this.type ? count : item.waresAlreadyCount
item.isStock = this.type ? count <= item.wares.stock : true
})
2024-11-15 16:23:07 +08:00
this.items = this.items.filter(item => this.type ? item.waresCount > 0 : item.waresAlreadyCount > 0)
} catch {
}
},
2024-10-26 12:01:55 +08:00
getRowClass(row) {
if (this.type && !row.row.isStock) {
return 'stock'
}
return ''
},
2024-10-26 12:01:55 +08:00
handleSelect(row) {
this.selections = row
2024-11-20 20:23:24 +08:00
this.selectionIds = row.map(item => item.id);
// 更新选择的数据
this.allSelectRows = [...this.allSelectRows, ...row]
// 更新自身的数据
// 点搜索不走下面逻辑
2024-11-23 17:11:09 +08:00
if (!this.isRefresh) {
2024-11-20 20:23:24 +08:00
// 如果本页没有选中数据,那就把属于本页的数据全部删掉
const ids = this.$refs.tableRef.data.map(item => item.id);
2024-11-23 17:11:09 +08:00
if (!row || row.length === 0) {
2024-11-20 20:23:24 +08:00
this.allSelectRows = this.allSelectRows.filter(item => !ids.includes(item.id))
2024-11-23 17:11:09 +08:00
} else {
2024-11-20 20:23:24 +08:00
// 把属于本页但是之前选中了本次没有选中的删掉
const rowIds = row.map(item => item.id)
const exIds = ids.filter(id => !rowIds.includes(id))
this.allSelectRows = this.allSelectRows.filter(item => !exIds.includes(item.id))
}
}
2024-11-20 20:23:24 +08:00
this.isRefresh = false
// 可能重复,去重
this.allSelectRows = this.allSelectRows.reduce((acc, item) => {
const flag = acc.find(i => i.id === item.id)
2024-11-23 17:11:09 +08:00
if (!flag) {
2024-11-20 20:23:24 +08:00
return acc.concat([item])
2024-11-23 17:11:09 +08:00
} else {
2024-11-20 20:23:24 +08:00
return acc
}
}, [])
2024-10-17 12:10:33 +08:00
},
// 设置不统计的字段
getSummaries(param) {
const {columns, data} = param
const sums = []
columns.forEach((column, index) => {
if (index === 0) {
sums[index] = '合计';
return;
}
const values = data.map(item => Number(item[column.property]));
if (this.includeColumn.includes(column.property)) {
sums[index] = values.reduce((prev, curr) => {
const value = Number(curr);
if (!isNaN(value)) {
return prev + curr;
} else {
return prev;
}
}, 0);
sums[index];
}
});
return sums
},
/** 鼠标移入cell */
handleCellEnter(row, column, cell, event) {
const property = column.property
if (this.editProp.includes(property)) {
cell.querySelector('.item__txt').classList.add('item__txt--hover')
}
},
/** 鼠标移出cell */
handleCellLeave(row, column, cell, event) {
const property = column.property
if (this.editProp.includes(property)) {
cell.querySelector('.item__txt').classList.remove('item__txt--hover')
}
},
/** 点击cell */
handleCellClick(row, column, cell, event) {
const property = column.property
if (this.editProp.includes(property)) {
// 保存cell
this.saveCellClick(row, cell)
cell.querySelector('.item__txt').style.display = 'none'
cell.querySelector('.item__input').style.display = 'inline'
cell.querySelector('input').focus()
}
},
/** 取消编辑状态 */
cancelEditable(cell) {
cell.querySelector('.item__txt').style.display = 'inline'
cell.querySelector('.item__input').style.display = 'none'
},
/** 保存进入编辑的cell */
saveCellClick(row, cell) {
const id = row.id
if (this.clickCellMap[id] !== undefined) {
if (!this.clickCellMap[id].includes(cell)) {
this.clickCellMap[id].push(cell)
}
} else {
this.clickCellMap[id] = [cell]
}
},
/** 保存数据 */
save(row) {
// 更新表格的数据
2024-10-26 21:30:12 +08:00
if (row.wares) {
row.isStock = this.type ? row.waresCount <= row.wares.stock : row.waresCount <= row.waresAlreadyCount
}
2024-10-26 12:01:55 +08:00
if (!this.type && !row.isStock) {
2024-10-21 21:37:07 +08:00
this.$modal.msgWarning("退料数量不能超过领取数量")
row.waresCount = row.waresAlreadyCount
}
this.partList.forEach(([key, value]) => {
const flag = value.findIndex(f => f.id === row.id)
2024-11-23 17:11:09 +08:00
if (flag !== -1) {
row.totalPrice = row.waresCount * row.wares.price
this.$set(value, flag, row)
}
})
2024-10-17 12:10:33 +08:00
const id = row.id
// 取消本行所有cell的编辑状态
this.clickCellMap[id].forEach(cell => {
this.cancelEditable(cell)
})
this.clickCellMap[id] = []
2024-10-21 21:37:07 +08:00
this.selections = []
2024-10-19 22:55:25 +08:00
this.tableKey++
2024-10-17 12:10:33 +08:00
},
changeWare(row) {
// if (row.wares.ware) {
// row['wareId'] = row.ware.id
// row['warehouse'] = row.ware.id
// row['warehouseName'] = row.ware.name
// }
2024-10-17 12:10:33 +08:00
},
// 通知父组件,删除数据
deleteItem(index) {
this.partList.splice(index, 1)
},
// 提交
2024-10-26 12:01:55 +08:00
async handleSubmit() {
2024-10-17 12:10:33 +08:00
try {
2024-11-20 20:23:24 +08:00
// const isNull = this.validateNull();
// if (!isNull) return;
// const names = this.validateZero()
// if (names) {
// await this.$modal.confirm("确认配件:" + names + "的采购价格为0吗")
// }
2024-10-17 12:10:33 +08:00
await this.createInit()
await createRepairSo(this.formData)
this.inStockDialog = false
this.$modal.msgSuccess("新增成功")
await this.getList()
2024-10-26 12:01:55 +08:00
} catch {
2024-10-17 12:10:33 +08:00
}
},
// 提交前的构建
2024-10-26 12:01:55 +08:00
async createInit() {
const values = this.partList.map(([key, value]) => value).reduce((acc, value) => acc.concat(value))
2024-10-17 12:10:33 +08:00
const res = await getUserProfile()
this.formData = {}
this.formData = {
soType: '01',
purchaseType: '01',
soNo: createUniqueCodeByHead("CG"),
userId: res.data.id,
userName: res.data.nickname,
soTime: parseTime(Date.now(), '{y}-{m}-{d}'),
itemCount: values.length,
totalPrice: values.reduce((x, y) => {
2024-10-26 12:01:55 +08:00
return x + y.totalPrice
}, 0),
soStatus: "02",
2024-10-17 12:10:33 +08:00
remark: this.remark,
}
2024-12-05 16:29:40 +08:00
if (this.chooseSupplier) {
2024-11-29 11:40:29 +08:00
this.formData.supplierId = this.chooseSupplier.id
this.formData.supplierName = this.chooseSupplier.name
}
this.formData.goodsList = [...values.map(item => {
2024-10-17 12:10:33 +08:00
return {
soiType: '01',
goodsId: item.wares.id,
2024-10-17 12:10:33 +08:00
goodsType: '0',
wareId: item.wares?.ware?.id,
goodsCount: item.waresCount,
goodsPrice: item.wares.price,
2024-10-17 12:10:33 +08:00
remark: item.remark
}
})]
this.formData.waresList = [...values.map(item => {
2024-11-23 17:11:09 +08:00
if (item.wares.ware) {
item.wares.warehouse = item.wares.ware.id
}
return item.wares
})]
this.formData.twId = this.twId
2024-10-17 12:10:33 +08:00
},
validateNull() {
2024-10-30 20:37:33 +08:00
const flag = this.partList.map(item => {
const price = item.newPrice
if (price === null || price === "") {
2024-10-30 20:37:33 +08:00
this.$modal.msgError("配件:" + item.name + "采购价格为空")
return false
} else {
2024-10-30 20:37:33 +08:00
return true
}
})
let count = 0
flag.forEach(item => {
if (!item) {
2024-10-30 20:37:33 +08:00
count++
}
})
return count === 0
},
validateZero() {
2024-10-30 20:37:33 +08:00
const flag = this.partList.map(item => {
const price = parseFloat(item.newPrice)
if (price === 0) {
2024-10-30 20:37:33 +08:00
return item.name
} else {
2024-10-30 20:37:33 +08:00
return ""
}
})
return flag.filter(item => item !== "").join(",")
2024-11-12 17:44:44 +08:00
},
handleView(row) {
2024-11-12 17:44:44 +08:00
this.$refs.ticketWaresShow.open(row)
2024-12-03 18:03:39 +08:00
},
/** 导出按钮操作 */
handleExport() {
this.$modal.confirm('是否确认导出当前查询条件所有数据项?').then(() => {
// 处理查询参数
let params = {...this.queryParams};
params.pageNo = undefined;
params.pageSize = undefined;
this.exportLoading = true;
return exportData(params);
}).then(response => {
this.$download.excel(response, this.type ? '领配件数据.xls' : "退配件数据.xls");
}).finally(() => {
this.exportLoading = false;
});
},
}
}
</script>
<style scoped lang="scss">
2024-10-26 12:01:55 +08:00
::v-deep .el-table .stock td {
2024-10-22 15:57:07 +08:00
color: #ff0000 !important; /* 红色背景 */
}
2024-10-26 12:01:55 +08:00
2024-10-17 12:10:33 +08:00
.item {
.item__input {
display: none;
width: 100px;
/* 调整elementUI中样式 如果不需要调整请忽略 */
.el-input__inner {
height: 24px !important;
}
/* 调整elementUI中样式 如果不需要调整请忽略 */
.el-input__suffix {
i {
font-size: 12px !important;
line-height: 26px !important;
}
}
}
.item__txt {
box-sizing: border-box;
border: 1px solid transparent;
width: 100px;
line-height: 24px;
padding: 0 8px;
}
.item__txt--hover {
border: 1px solid #dddddd;
border-radius: 4px;
cursor: text;
}
}
</style>