YouChain_Doc/前端/页面按钮(新增,修改,删除)(添加自定义按钮)隐藏显示.md

525 lines
15 KiB
Markdown
Raw Permalink Normal View History

2023-09-20 13:52:21 +08:00
对页面 新增 修改 删除等按钮进行隐藏,添加自定义按钮
```
cruds() {
return CRUD({
title: '出库明细',
url: 'api/pickDetail',
idField: 'id',
sort: 'id,desc',
crudMethod: {...crudPickDetail},
optShow: {
add: true,
edit: false,
del: false,
reset: true,
download: true
}
})
}
```
添加自定义按钮
[:disabled="show_fp” ]()为显示状态
[@click="allocate(crud.selections)"]() 为点击时间 [crud.selections]() 选中的数据
```
<el-button
slot="right"
class="filter-item"
type="success"
icon="el-icon-edit"
size="mini"
:disabled="show_fp"
@click="allocate(crud.selections)"
>
分配
</el-button>
```
```
data() {
return {
show_fp: true,
show_jh: true,
show_cancelfp:true,
radio3: '全部',
items: [],
permission: {
add: ['admin', 'pickDetail:add'],
edit: ['admin', 'pickDetail:edit'],
del: ['admin', 'pickDetail:del']
},
rules: {
item: [
{required: true, message: '物料必填', trigger: 'blur'}
]
},
queryTypeOptions: [
{key: 'itemCode', display_name: '物料编码'},
{key: 'itemName', display_name: '物料名称'},
{key: 'po', display_name: '任务号'},
{key: 'status', display_name: '状态'}
]
}
}
```
```
allocate(datas) {
this.$confirm(`选中的${datas.length}条数据分配确认?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
const ids = [];
for (let i = 0; i < datas.length; i++) {
ids.push(datas[i].id)
}
crudPickDetail.allocate(ids).then(res => {
DonMessage.success('分配成功!')
this.crud.toQuery();
}).catch(() => {
})
}).catch(() => {
this.$refs.table.clearSelection()
DonMessage.info('取消成功!')
});
}
```
修改选择框选中事件 [@selection-change="selectionChangeHandlerTwo"]()
```
<el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small"
style="width: 100%;"
height="58vh"
@selection-change="selectionChangeHandlerTwo">
```
根据选择的数据进行判断,新加的按钮是否可用
```
selectionChangeHandlerTwo(val) {
this.crud.selections = val
if (this.crud.selections.length > 1 || this.crud.selections.length == 0) {
this.show_jh = true;
this.show_fp = true;
this.show_cancelfp=true;
}
//分配
if (this.crud.selections.length == 1 && this.crud.selections[0].orderQty > this.crud.selections[0].allocatedQty) {
this.show_jh = true;
this.show_fp = false;
}
//取消分配
if (this.crud.selections.length == 1 && this.crud.selections[0].orderQty == this.crud.selections[0].allocatedQty&&this.crud.selections[0].pickedQty==0) {
this.show_jh = true;
this.show_fp = true;
this.show_cancelfp=false;
}
//拣货
if (this.crud.selections.length == 1 && this.crud.selections[0].orderQty == this.crud.selections[0].allocatedQty) {
this.show_jh = false;
this.show_fp = true;
}
}
```
完整代码,请查看 /views/business-data/asnDetial/index
```
<template>
<div class="app-container">
<!--工具栏-->
<div class="head-container">
<!-- 查询操作-->
<el-form ref="form" :inline="true" :model="form" label-width="70px">
<el-form-item label="物料编码">
<el-input v-model="query.itemCode" clearable placeholder="请输入物料编码" style="width: 140px;"
class="filter-item"
@keyup.enter.native="crud.toQuery"/>
</el-form-item>
<el-form-item label="物料名称">
<el-input v-model="query.itemName" clearable placeholder="请输入物料名称" style="width: 140px;"
class="filter-item"
@keyup.enter.native="crud.toQuery"/>
</el-form-item>
<el-form-item label="任务号">
<el-input v-model="query.po" clearable placeholder="请输入任务号" style="width: 140px;" class="filter-item"
@keyup.enter.native="crud.toQuery"/>
</el-form-item>
<rrOperation :crud="crud"/>
</el-form>
<div class="statusButton" style="border-bottom: solid lightgray 1px;">
<el-radio-group v-model="radio3" @change="clickChange" size="small">
<el-radio-button label="全部"> 全部</el-radio-button>
<el-radio-button label="打开"> 打开</el-radio-button>
<el-radio-button label="已分配">已分配</el-radio-button>
<el-radio-button label="拣货完成"> 拣货完成</el-radio-button>
</el-radio-group>
</div>
<!-- 业务操作-->
<crudOperation :permission="permission">
<el-button
slot="right"
class="filter-item"
type="success"
icon="el-icon-edit"
size="mini"
:disabled="show_fp"
@click="allocate(crud.selections)"
>
分配
</el-button>
<el-button
slot="right"
class="filter-item"
type="success"
icon="el-icon-edit"
size="mini"
:loading="crud.delAllLoading"
:disabled="show_cancelfp"
@click="cancelAllocate(crud.selections)"
>
取消分配
</el-button>
<el-button
slot="right"
class="filter-item"
type="danger"
icon="el-icon-edit"
size="mini"
:loading="crud.delAllLoading"
:disabled="show_jh"
@click="getPickTask(crud.selections[0].id)"
>
拣货确认
</el-button>
</crudOperation>
<el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small"
style="width: 100%;"
height="58vh"
@selection-change="selectionChangeHandlerTwo">
<el-table-column type="selection" width="50"/>
<el-table-column
prop="date"
align="center"
label="序号"
:resizable="false"
type="index"
width="50"
/>
<el-table-column prop="po" label="任务号"/>
<el-table-column :show-overflow-tooltip="true" prop="itemName" label="物料编码">
<template slot-scope="scope">
<div>{{ scope.row.item.code }}</div>
</template>
</el-table-column>
<el-table-column :show-overflow-tooltip="true" prop="itemCode" label="物料名称">
<template slot-scope="scope">
<div>{{ scope.row.item.name }}</div>
</template>
</el-table-column>
<el-table-column prop="status" label="状态">
<template slot-scope="scope">
{{ dict.label.pick_status[scope.row.status] }}
</template>
</el-table-column>
<el-table-column prop="orderQty" label="订单数量"/>
<el-table-column prop="allocatedQty" label="分配数量"/>
<el-table-column prop="pickedQty" label="拣货数量"/>
<el-table-column prop="remark" label="备注"/>
<el-table-column prop="createBy" label="创建人"/>
<el-table-column prop="createTime" width="150px" label="创建时间"/>
<el-table-column v-if="checkPer(['admin','pickDetail:edit','pickDetail:del'])" label="操作" width="150px"
align="center">
<template slot-scope="scope">
<udOperation
:data="scope.row"
:permission="permission"
/>
</template>
</el-table-column>
</el-table>
<!--拣货确认界面-->
<PickTask ref="pickTask"/>
<!--表单组件-->
<el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0"
:title="crud.status.title" width="500px">
<el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
<el-form-item label="物料" prop="item">
<el-select v-model="form.item" @focus="getItem" filterable placeholder="请选择物料" value-key="id"
style="width: 370px;">
<el-option
v-for="item in items"
:key="item.id"
:label="item.code"
:value="item"
/>
</el-select>
</el-form-item>
<el-form-item label="订单数量">
<el-input v-model="form.orderQty" style="width: 370px;"/>
</el-form-item>
<el-form-item label="备注">
<el-input v-model="form.remark" :rows="3" type="textarea" style="width: 370px;"/>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="text" @click="crud.cancelCU">取消</el-button>
<el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
</div>
</el-dialog>
<!--表格渲染-->
<!--分页组件-->
<pagination/>
</div>
</div>
</template>
<script>
import crudPickDetail, {cancelAllocate} from '@/api/pickDetail'
import CRUD, {presenter, header, form, crud} from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import {getItems} from "@/api/item"
import DonMessage from "@/utils/message";
import PickTask from "@/views/business-data/pickDetail/pickTicketTask.vue"
const defaultForm = {
id: null,
pickId: null,
item: null,
lineNo: null,
po: null,
status: 'OPEN',
orderQty: 0,
allocatedQty: 0,
pickedQty: 0,
shippedQty: 0,
weight: 0,
volume: 0,
remark: null,
propC1: null,
propC2: null,
propC3: null,
propC4: null,
propC5: null,
propC6: null,
propD1: null,
propD2: null,
deptId: null,
sourceName: null,
sourceId: null,
createBy: null,
updateBy: null,
createTime: null,
updateTime: null
}
export default {
name: 'PickDetail',
components: {PickTask, pagination, crudOperation, rrOperation, udOperation},
mixins: [presenter(), header(), form(defaultForm), crud()],
dicts: ['pick_status'],
cruds() {
return CRUD({
title: '出库明细',
url: 'api/pickDetail',
idField: 'id',
sort: 'id,desc',
crudMethod: {...crudPickDetail},
optShow: {
add: true,
edit: false,
del: false,
reset: true,
download: true
}
})
},
data() {
return {
show_fp: true,
show_jh: true,
show_cancelfp:true,
radio3: '全部',
items: [],
permission: {
add: ['admin', 'pickDetail:add'],
edit: ['admin', 'pickDetail:edit'],
del: ['admin', 'pickDetail:del']
},
rules: {
item: [
{required: true, message: '物料必填', trigger: 'blur'}
]
},
queryTypeOptions: [
{key: 'itemCode', display_name: '物料编码'},
{key: 'itemName', display_name: '物料名称'},
{key: 'po', display_name: '任务号'},
{key: 'status', display_name: '状态'}
]
}
},
mounted() {
},
methods: {
// 钩子在获取表格数据之前执行false 则代表不获取数据
[CRUD.HOOK.beforeRefresh]() {
return true
},
getItem() {
getItems({}).then(res => {
this.items = res.content.map(function (obj) {
if (obj.hasChildren) {
obj.children = null
}
return obj
})
})
},
selectionChangeHandlerTwo(val) {
this.crud.selections = val
if (this.crud.selections.length > 1 || this.crud.selections.length == 0) {
this.show_jh = true;
this.show_fp = true;
this.show_cancelfp=true;
}
//分配
if (this.crud.selections.length == 1 && this.crud.selections[0].orderQty > this.crud.selections[0].allocatedQty) {
this.show_jh = true;
this.show_fp = false;
}
//取消分配
if (this.crud.selections.length == 1 && this.crud.selections[0].orderQty == this.crud.selections[0].allocatedQty&&this.crud.selections[0].pickedQty==0) {
this.show_jh = true;
this.show_fp = true;
this.show_cancelfp=false;
}
//拣货
if (this.crud.selections.length == 1 && this.crud.selections[0].orderQty == this.crud.selections[0].allocatedQty) {
this.show_jh = false;
this.show_fp = true;
}
},
allocate(datas) {
this.$confirm(`选中的${datas.length}条数据分配确认?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
const ids = [];
for (let i = 0; i < datas.length; i++) {
ids.push(datas[i].id)
}
crudPickDetail.allocate(ids).then(res => {
DonMessage.success('分配成功!')
this.crud.toQuery();
}).catch(() => {
})
}).catch(() => {
this.$refs.table.clearSelection()
DonMessage.info('取消成功!')
});
},
cancelAllocate(datas){
this.$confirm(`选中的${datas.length}条数据取消分配确认?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
const ids = [];
for (let i = 0; i < datas.length; i++) {
ids.push(datas[i].id)
}
crudPickDetail.cancelAllocate(ids).then(res => {
DonMessage.success('取消分配成功!')
this.crud.toQuery();
}).catch(() => {
})
}).catch(() => {
this.$refs.table.clearSelection()
DonMessage.info('取消成功!')
});
},
getPickTask(id) {
this.$refs.pickTask.dialog = true
this.$refs.pickTask.queryPickTask(id)
},
shuaxin() {
this.crud.toQuery();
},
clickChange(lab) {
if (lab === "全部") {
this.crud.resetQuery();
this.crud.toQuery();
}else if(lab === "打开"){
this.query.status = 'OPEN'
this.crud.toQuery();
}else if(lab === "已分配"){
this.query.status = 'ALLOCATE'
this.crud.toQuery();
}else if(lab === "拣货完成"){
this.query.status = 'PICK_ALL'
this.crud.toQuery();
}
}
}
}
</script>
<style scoped>
</style>
```