| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- <template>
- <ele-modal
- :title="title"
- :visible.sync="visible"
- :before-close="handleClose"
- :close-on-click-modal="false"
- :close-on-press-escape="false"
- append-to-body
- width="70%"
- :maxable="true"
- >
- <el-card shadow="never">
- <ele-split-layout
- width="236px"
- allow-collapse
- :right-style="{ overflow: 'hidden' }"
- >
- <div>
- <div class="ele-border-lighter split-layout-right-content">
- <el-tree
- :data="treeList"
- :props="defaultProps"
- ref="treeRef"
- :default-expanded-keys="categoryId ? [categoryId] : []"
- :highlight-current="true"
- node-key="id"
- @node-click="handleNodeClick"
- ></el-tree>
- </div>
- </div>
- <!-- 数据表格 -->
- <template v-slot:content>
- <seekPage :seekList="seekList" @search="reload" />
- <ele-pro-table
- height="calc(100vh - 480px)"
- ref="table"
- :columns="columns"
- :datasource="datasource"
- :selection.sync="selection"
- row-key="id"
- >
- <template #radio="{ row }">
- <el-radio
- v-model="currentId"
- :label="row.id"
- @change="current = row"
- class="radio"
- >
- <i></i>
- </el-radio>
- </template>
- </ele-pro-table>
- </template>
- </ele-split-layout>
- </el-card>
- <div class="rx-sc">
- <el-button type="primary" size="small" @click="selected">选择</el-button>
- <el-button size="small" @click="handleClose">关闭</el-button>
- </div>
- </ele-modal>
- </template>
- <script>
- import ProductSearch from './product-search.vue';
- import { getMaterialList, getProduceTreeByPid } from '@/api/material/list';
- export default {
- components: {
- ProductSearch
- },
- props: {
- // 是否多选
- multiple: {
- type: Boolean,
- default: true
- }
- },
- computed: {
- seekList() {
- return [
- {
- label: '编码',
- value: 'code',
- type: 'input',
- placeholder: '请输入'
- },
- {
- label: '名称',
- value: 'name',
- type: 'input',
- placeholder: '请输入'
- },
- {
- label: '型号',
- value: 'modelType',
- type: 'input',
- placeholder: '请输入'
- }
- ];
- },
- // 表格列配置
- columns() {
- const list = [
- {
- label: '物料名称',
- prop: 'name'
- },
- {
- label: '物料编码',
- prop: 'code'
- },
- {
- label: '牌号',
- prop: 'brandNum'
- },
- {
- label: '型号',
- prop: 'modelType'
- },
- {
- prop: 'availableCountBase',
- label: '包装库存',
- sortable: 'custom'
- },
- {
- label: '单位',
- prop: 'weightUnit'
- },
- {
- prop: 'packingCountBase',
- label: '计量库存',
- sortable: 'custom'
- },
- {
- label: '计量单位',
- prop: 'unit'
- },
- {
- label: '数量',
- prop: 'count'
- }
- ];
- if (this.multiple) {
- list.unshift({
- columnKey: 'selection',
- type: 'selection',
- width: 45,
- align: 'center',
- selectable: (row, index) => {
- return !this.processData.some((it) => row.id == it.categoryId);
- },
- reserveSelection: true,
- fixed: 'left'
- });
- } else {
- list.unshift({
- prop: 'radio',
- slot: 'radio',
- width: 50,
- align: 'center',
- fixed: 'left'
- });
- }
- return list;
- }
- },
- data() {
- return {
- visible: false,
- title: '选择工具',
- categoryLevelId: null,
- categoryId: 1,
- treeList: [],
- treeLoading: false,
- defaultProps: {
- children: 'children',
- label: 'name'
- },
- type: null,
- // 表格选中数据
- selection: [],
- processData: [],
- currentId: '',
- current: null
- };
- },
- watch: {},
- methods: {
- /* 表格数据源 */
- async datasource({ page, limit, where }) {
- const res = await getMaterialList({
- ...where,
- pageNum: page,
- size: limit,
- categoryLevelId: this.categoryLevelId
- });
- return res;
- },
- open(item, title) {
- this.processData = item || [];
- this.title = title || '选择工具';
- this.visible = true;
- this.getTreeData();
- },
- async getTreeData() {
- try {
- this.treeLoading = true;
- const res = await getProduceTreeByPid(5);
- this.treeLoading = false;
- if (res?.code === '0') {
- this.treeList = res.data;
- this.$nextTick(() => {
- // 默认高亮第一级树节点
- if (this.treeList[0]) {
- this.rootTreeId = this.treeList[0].id;
- this.$nextTick(() => {
- this.$refs.treeRef.setCurrentKey(this.treeList[0].id);
- });
- }
- });
- return this.treeList;
- }
- } catch (error) {}
- this.treeLoading = false;
- },
- handleNodeClick(data) {
- this.categoryLevelId = data.id;
- this.$refs.table.reload({ pageNum: 1, where: {} });
- },
- /* 刷新表格 */
- reload(where) {
- this.$refs.table.reload({ page: 1, where: where });
- },
- handleClose() {
- this.$refs.table.setSelectedRows([]);
- this.selection = [];
- this.current = null;
- this.currentId = '';
- this.visible = false;
- },
- selected() {
- if (!this.multiple) {
- if (!this.current) {
- this.$message.warning('请选择数据');
- return;
- }
- this.$emit('chooseModal', this.current);
- return this.handleClose();
- }
- let _arr = [];
- if (!this.selection.length) {
- this.$message.warning('请至少选择一条数据');
- return;
- }
- _arr = this.selection.map((m) => {
- m.categoryId = m.id;
- delete m.id;
- return {
- ...m
- };
- });
- this.$emit('chooseModal', _arr);
- this.handleClose();
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- .rx-sc {
- display: flex;
- align-items: center;
- justify-content: center;
- }
- .ml60 {
- margin-left: 60px;
- }
- :deep(.radio) {
- .el-radio__label {
- padding: 0;
- }
- }
- </style>
|