867 lines
32 KiB
Vue
867 lines
32 KiB
Vue
<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">
|
||
<el-col :span="1.5">
|
||
<el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
|
||
:loading="exportLoading"
|
||
>导出
|
||
</el-button>
|
||
</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>
|
||
<el-table-column label="单据号" align="center" prop="no" width="200"/>
|
||
<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>
|
||
<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">
|
||
<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>
|
||
|
||
<el-row :gutter="10" class="mb8">
|
||
<el-col :span="1.5">
|
||
<el-button type="primary" v-if="type" plain icon="el-icon-plus" size="mini" @click="handleAddWares"
|
||
>添加配件</el-button>
|
||
</el-col>
|
||
</el-row>
|
||
|
||
<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"
|
||
>
|
||
<el-table-column type="selection" width="80" align="center"/>
|
||
<el-table-column label="名称" align="center" prop="waresName" :show-overflow-tooltip="true"/>
|
||
<el-table-column label="配件添加人" align="center" prop="addUserName" width="180"/>
|
||
<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">
|
||
<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">
|
||
<el-button type="primary" @click="handleConfirmOver">
|
||
申领完成
|
||
</el-button>
|
||
<el-button type="primary" v-if="type" @click="handlePassBefore"
|
||
:disabled="allSelectRows.length === 0 || allSelectRows.filter(item => !item.isStock).length !== 0">
|
||
通知领料
|
||
</el-button>
|
||
<el-button type="primary" v-else @click="handlePassBefore"
|
||
:disabled="allSelectRows.length === 0 || allSelectRows.filter(item => !item.isStock).length !== 0">
|
||
通知退料
|
||
</el-button>
|
||
<el-button v-if="type" type="primary" @click="handleCreate" :disabled="allSelectRows.length === 0">
|
||
采购
|
||
</el-button>
|
||
</div>
|
||
</el-dialog>
|
||
|
||
<el-dialog title="采购单" :visible.sync="inStockDialog" width="80%" v-dialogDrag append-to-body>
|
||
<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">
|
||
车牌号
|
||
</template>
|
||
{{ carInfo.licenseNumber }}
|
||
</el-descriptions-item>
|
||
<el-descriptions-item>
|
||
<template slot="label">
|
||
品牌
|
||
</template>
|
||
{{ carInfo.carBrand }}
|
||
</el-descriptions-item>
|
||
<el-descriptions-item>
|
||
<template slot="label">
|
||
型号
|
||
</template>
|
||
{{ carInfo.carModel }}
|
||
</el-descriptions-item>
|
||
</el-descriptions>
|
||
<el-collapse>
|
||
<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">
|
||
<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"
|
||
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>
|
||
</el-dialog>
|
||
|
||
<el-dialog :title="type ? '通知领料' : '通知退料'" :visible.sync="inPhoto" width="40%" v-dialogDrag append-to-body>
|
||
<el-form :inline="true" label-width="15rem">
|
||
<el-form-item :label="type ? '领料人' : '退料人'">
|
||
<el-select v-model="chooseStaff" multiple clearable filterable>
|
||
<el-option v-for="staff in staffs" :key="staff.id" :value="staff.userId" :label="staff.userName"/>
|
||
</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>
|
||
|
||
<TicketWaresShow ref="ticketWaresShow" :user-role="'repair_warehouse'" @success="getList" :type="false"/>
|
||
|
||
<TWIAdd ref="twiAdd" @success="handleSuccess" :if-house-add="true"/>
|
||
</div>
|
||
</template>
|
||
|
||
<script>
|
||
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";
|
||
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";
|
||
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";
|
||
import {listByTicketId} from "@/api/repair/repairworker";
|
||
import StaffChoose from "@/views/repair/Components/StaffChoose.vue";
|
||
import SupplierChoose from "@/views/repair/Components/SupplierChoose.vue";
|
||
import TWIAdd from "@/views/repair/tickets/Components/TWIAdd.vue";
|
||
|
||
export default {
|
||
name: "WaresItem",
|
||
components: {TWIAdd, SupplierChoose, StaffChoose, TicketWaresShow, WarehouseChoose, SoTable},
|
||
props: {
|
||
type: Boolean,
|
||
},
|
||
data() {
|
||
return {
|
||
queryParams: {
|
||
pageNo: 1,
|
||
pageSize: 10,
|
||
query: null,
|
||
isBack: !this.type,
|
||
},
|
||
showSearch: true,
|
||
loading: false,
|
||
list: [],
|
||
total: 0,
|
||
dialogVisible: false,
|
||
items: [],
|
||
dialogLoading: false,
|
||
selections: [],
|
||
selectionIds: [],
|
||
formData: {},
|
||
inStockDialog: false,
|
||
partList: [],
|
||
includeColumn: ['waresCount', 'totalPrice'],
|
||
// 保存进入编辑的cell
|
||
clickCellMap: {},
|
||
// 需要编辑的属性
|
||
editProp: ['wares.warehouse', 'wares.type', 'waresCount', 'wares.purPrice', 'wares.price', 'remark', 'wares.code', 'waresCount', 'wares.model', 'wares.unit'],
|
||
remark: null,
|
||
tableKey: 0,
|
||
query: null,
|
||
twId: null,
|
||
carInfo: {},
|
||
ticketId: null,
|
||
expandOnClickNode: true,
|
||
serverList: [],
|
||
treeProps: {
|
||
label: "name",
|
||
children: "children"
|
||
},
|
||
typeMap: null,
|
||
allSelectRows: [],
|
||
isRefresh: false,
|
||
inPhoto: false,
|
||
images: null,
|
||
chooseStaff: [],
|
||
staffs: [],
|
||
chooseSupplier: null,
|
||
// 导出遮罩层
|
||
exportLoading: false,
|
||
}
|
||
},
|
||
mounted() {
|
||
this.getList()
|
||
},
|
||
methods: {
|
||
handleAddWares(){
|
||
this.$refs.twiAdd.open({id: this.twId})
|
||
},
|
||
handleSuccess(data){
|
||
this.getTwitemList({twId: this.twId})
|
||
},
|
||
getTypeById(id) {
|
||
return this.typeMap.get(id)
|
||
},
|
||
async listServer() {
|
||
if (!this.serverList || this.serverList.length === 0) {
|
||
const res = await getBaseTypeList({type: "02"})
|
||
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);
|
||
}
|
||
});
|
||
},
|
||
handleNodeClick(data, scopeRow) {
|
||
scopeRow.wares.type = data.id;
|
||
this.save(scopeRow)
|
||
},
|
||
optionData(array, result = []) {
|
||
array.forEach(item => {
|
||
result.push({label: item.name, value: item.id})
|
||
if (item.children && item.children.length !== 0) {
|
||
this.optionData(item.children, result)
|
||
}
|
||
})
|
||
return JSON.parse(JSON.stringify(result))
|
||
},
|
||
searchByQuery() {
|
||
this.isRefresh = true
|
||
const data = {
|
||
twId: this.twId,
|
||
query: this.query
|
||
}
|
||
this.getTwitemList(data).then(() => {
|
||
this.setSelectedRows();
|
||
})
|
||
},
|
||
setSelectedRows() {
|
||
this.$nextTick(() => {
|
||
this.$refs.tableRef.clearSelection(); // 清除所有选择
|
||
const ids = this.allSelectRows.map(item => item.id)
|
||
this.items.forEach(row => {
|
||
if (ids.includes(row.id)) {
|
||
this.$refs.tableRef.toggleRowSelection(row, true); // 选中行
|
||
}
|
||
});
|
||
});
|
||
},
|
||
resetByQuery() {
|
||
this.allSelectRows = []
|
||
this.query = null
|
||
this.searchByQuery()
|
||
},
|
||
getDictDatasToType(type) {
|
||
return this.getDictDatas(type)
|
||
},
|
||
|
||
handlePassBefore() {
|
||
this.chooseStaff = []
|
||
this.staffs = []
|
||
this.getTicketStaff()
|
||
this.images = null
|
||
this.inPhoto = true
|
||
},
|
||
/** 申领完成 */
|
||
async handleConfirmOver() {
|
||
await this.$modal.confirm('确定所有配件均已申领完成?')
|
||
try {
|
||
await confirmOver(this.twId);
|
||
await this.getList();
|
||
this.dialogVisible = false
|
||
this.$modal.msgSuccess("操作成功");
|
||
} catch {
|
||
}
|
||
},
|
||
async getTicketStaff() {
|
||
const res = await listByTicketId(this.ticketId)
|
||
this.staffs = res.data
|
||
this.chooseStaff.push(this.formData.repairId)
|
||
},
|
||
// 通过 true是全部、false是选择
|
||
async handlePass() {
|
||
if (this.images) {
|
||
this.formData.images = this.images.split(",").map(item => {
|
||
return item.replace(process.env.VUE_APP_FILE_API, "")
|
||
}).join(",")
|
||
}
|
||
if ((!this.chooseStaff || this.chooseStaff.length === 0)) {
|
||
this.$modal.msgError(`请选择${this.type ? '领' : '退'}料人!`)
|
||
return
|
||
}
|
||
// 生成领料单、退料单
|
||
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(",")
|
||
// purchaseType: "01"
|
||
}
|
||
this.formData.repairSois = [...this.allSelectRows.map(item => {
|
||
return {
|
||
soiType: this.type ? '02' : "04",
|
||
goodsId: item.waresId,
|
||
goodsCount: item.waresCount,
|
||
}
|
||
})]
|
||
this.formData.ids = this.allSelectRows.map(item => item.id)
|
||
if (this.type) {
|
||
this.formData.items = [...this.allSelectRows.map(item => {
|
||
return {
|
||
id: item.id,
|
||
}
|
||
})]
|
||
}
|
||
try {
|
||
await pass(this.formData)
|
||
this.$modal.msgSuccess("处理成功")
|
||
await this.getList()
|
||
} finally {
|
||
this.dialogVisible = false
|
||
this.inPhoto = false
|
||
}
|
||
},
|
||
// 生成采购 true是全部、false是选择
|
||
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
|
||
}
|
||
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
|
||
})
|
||
})
|
||
this.chooseSupplier = null
|
||
this.inStockDialog = true
|
||
this.dialogVisible = false
|
||
} catch {
|
||
}
|
||
},
|
||
async getList() {
|
||
try {
|
||
this.loading = true
|
||
const res = await getPage(this.queryParams)
|
||
if (res.data) {
|
||
this.list = res.data.records
|
||
this.total = res.data.total
|
||
}
|
||
} finally {
|
||
this.loading = false
|
||
}
|
||
},
|
||
handleQuery() {
|
||
this.queryParams.pageNo = 1
|
||
this.getList()
|
||
},
|
||
resetQuery() {
|
||
this.resetForm('queryForm')
|
||
this.handleQuery()
|
||
},
|
||
handleDispose(row) {
|
||
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 {
|
||
const res = await listTwItem(data)
|
||
this.items = res.data
|
||
this.items = this.items.filter(item => item.waresStatus === '1')
|
||
this.items.forEach(item => {
|
||
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
|
||
})
|
||
this.items = this.items.filter(item => this.type ? item.waresCount > 0 : item.waresAlreadyCount > 0)
|
||
} catch {
|
||
}
|
||
},
|
||
getRowClass(row) {
|
||
if (this.type && !row.row.isStock) {
|
||
return 'stock'
|
||
}
|
||
return ''
|
||
},
|
||
handleSelect(row) {
|
||
this.selections = row
|
||
this.selectionIds = row.map(item => item.id);
|
||
// 更新选择的数据
|
||
this.allSelectRows = [...this.allSelectRows, ...row]
|
||
// 更新自身的数据
|
||
// 点搜索不走下面逻辑
|
||
if (!this.isRefresh) {
|
||
// 如果本页没有选中数据,那就把属于本页的数据全部删掉
|
||
const ids = this.$refs.tableRef.data.map(item => item.id);
|
||
if (!row || row.length === 0) {
|
||
this.allSelectRows = this.allSelectRows.filter(item => !ids.includes(item.id))
|
||
} else {
|
||
// 把属于本页但是之前选中了本次没有选中的删掉
|
||
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))
|
||
}
|
||
}
|
||
this.isRefresh = false
|
||
// 可能重复,去重
|
||
this.allSelectRows = this.allSelectRows.reduce((acc, item) => {
|
||
const flag = acc.find(i => i.id === item.id)
|
||
if (!flag) {
|
||
return acc.concat([item])
|
||
} else {
|
||
return acc
|
||
}
|
||
}, [])
|
||
},
|
||
// 设置不统计的字段
|
||
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) {
|
||
// 更新表格的数据
|
||
if (row.wares) {
|
||
row.isStock = this.type ? row.waresCount <= row.wares.stock : row.waresCount <= row.waresAlreadyCount
|
||
}
|
||
if (!this.type && !row.isStock) {
|
||
this.$modal.msgWarning("退料数量不能超过领取数量")
|
||
row.waresCount = row.waresAlreadyCount
|
||
}
|
||
this.partList.forEach(([key, value]) => {
|
||
const flag = value.findIndex(f => f.id === row.id)
|
||
if (flag !== -1) {
|
||
row.totalPrice = row.waresCount * row.wares.price
|
||
this.$set(value, flag, row)
|
||
}
|
||
})
|
||
const id = row.id
|
||
// 取消本行所有cell的编辑状态
|
||
this.clickCellMap[id].forEach(cell => {
|
||
this.cancelEditable(cell)
|
||
})
|
||
this.clickCellMap[id] = []
|
||
this.selections = []
|
||
this.tableKey++
|
||
},
|
||
changeWare(row) {
|
||
// if (row.wares.ware) {
|
||
// row['wareId'] = row.ware.id
|
||
// row['warehouse'] = row.ware.id
|
||
// row['warehouseName'] = row.ware.name
|
||
// }
|
||
},
|
||
// 通知父组件,删除数据
|
||
deleteItem(index) {
|
||
this.partList.splice(index, 1)
|
||
},
|
||
// 提交
|
||
async handleSubmit() {
|
||
try {
|
||
// const isNull = this.validateNull();
|
||
// if (!isNull) return;
|
||
// const names = this.validateZero()
|
||
// if (names) {
|
||
// await this.$modal.confirm("确认配件:" + names + "的采购价格为0吗?")
|
||
// }
|
||
await this.createInit()
|
||
await createRepairSo(this.formData)
|
||
this.inStockDialog = false
|
||
this.$modal.msgSuccess("新增成功")
|
||
await this.getList()
|
||
} catch {
|
||
}
|
||
},
|
||
// 提交前的构建
|
||
async createInit() {
|
||
const values = this.partList.map(([key, value]) => value).reduce((acc, value) => acc.concat(value))
|
||
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) => {
|
||
return x + y.totalPrice
|
||
}, 0),
|
||
soStatus: "02",
|
||
remark: this.remark,
|
||
}
|
||
if (this.chooseSupplier) {
|
||
this.formData.supplierId = this.chooseSupplier.id
|
||
this.formData.supplierName = this.chooseSupplier.name
|
||
}
|
||
this.formData.goodsList = [...values.map(item => {
|
||
return {
|
||
soiType: '01',
|
||
goodsId: item.wares.id,
|
||
goodsType: '0',
|
||
wareId: item.wares?.ware?.id,
|
||
goodsCount: item.waresCount,
|
||
goodsPrice: item.wares.price,
|
||
remark: item.remark
|
||
}
|
||
})]
|
||
this.formData.waresList = [...values.map(item => {
|
||
if (item.wares.ware) {
|
||
item.wares.warehouse = item.wares.ware.id
|
||
}
|
||
return item.wares
|
||
})]
|
||
|
||
this.formData.twId = this.twId
|
||
},
|
||
validateNull() {
|
||
const flag = this.partList.map(item => {
|
||
const price = item.newPrice
|
||
if (price === null || price === "") {
|
||
this.$modal.msgError("配件:" + item.name + "采购价格为空")
|
||
return false
|
||
} else {
|
||
return true
|
||
}
|
||
})
|
||
let count = 0
|
||
flag.forEach(item => {
|
||
if (!item) {
|
||
count++
|
||
}
|
||
})
|
||
return count === 0
|
||
},
|
||
validateZero() {
|
||
const flag = this.partList.map(item => {
|
||
const price = parseFloat(item.newPrice)
|
||
if (price === 0) {
|
||
return item.name
|
||
} else {
|
||
return ""
|
||
}
|
||
})
|
||
return flag.filter(item => item !== "").join(",")
|
||
},
|
||
handleView(row) {
|
||
this.$refs.ticketWaresShow.open(row)
|
||
},
|
||
/** 导出按钮操作 */
|
||
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">
|
||
::v-deep .el-table .stock td {
|
||
color: #ff0000 !important; /* 红色背景 */
|
||
}
|
||
|
||
.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>
|