ny
昨天 282fbc6488f4e8ceb5fda759f963ee88fbf7b999
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<script lang="ts" setup>
import type { TreeActionType } from '@jnpf/ui';
import type { BasicColumn } from '@jnpf/ui/vxeTable';
 
import { nextTick, reactive, ref, unref } from 'vue';
 
import { BasicLeftTree } from '@jnpf/ui';
import { ModalClose } from '@jnpf/ui/modal';
import { BasicVxeTable, useVxeTable } from '@jnpf/ui/vxeTable';
 
import { Modal as AModal, Form } from 'ant-design-vue';
 
import { getGoodsList, getProductClassify } from '#/api/extend/saleOrder';
 
defineOptions({ inheritAttrs: false });
const emit = defineEmits(['update:value', 'change']);
const formItemContext = Form.useInjectFormItemContext();
const visible = ref(false);
const columns: BasicColumn[] = [
  { title: '产品编码', dataIndex: 'code' },
  { title: '产品名称', dataIndex: 'fullName' },
  { title: '库存', dataIndex: 'qty' },
];
const searchInfo = reactive({
  classifyId: '',
});
const leftTreeRef = ref<Nullable<TreeActionType>>(null);
const treeLoading = ref(false);
const treeData = ref<any[]>([]);
const [registerTable, { getForm, getSelectRows, getSelectRowKeys }] = useVxeTable({
  api: getGoodsList,
  columns,
  immediate: false,
  useSearchForm: true,
  formConfig: {
    baseColProps: { span: 8 },
    schemas: [
      {
        field: 'code',
        label: '产品编号',
        component: 'Input',
        componentProps: {
          placeholder: '请输入',
        },
      },
      {
        field: 'fullName',
        label: '产品名称',
        component: 'Input',
        componentProps: {
          placeholder: '请输入',
        },
      },
    ],
  },
  tableSetting: { size: false, setting: false },
  rowSelection: { type: 'checkbox' },
});
 
async function openSelectModal() {
  visible.value = true;
  treeLoading.value = true;
  getProductClassify().then((res) => {
    treeLoading.value = false;
    treeData.value = res.data.list || [];
    searchInfo.classifyId = treeData.value[0].children[0].id;
    nextTick(() => {
      const leftTree = unref(leftTreeRef);
      leftTree?.setSelectedKeys([searchInfo.classifyId]);
      getForm().resetFields();
    });
  });
}
function handleTreeSelect(id) {
  if (!id || searchInfo.classifyId === id) return;
  searchInfo.classifyId = id;
  getForm().resetFields();
}
function handleCancel() {
  visible.value = false;
}
function handleSubmit() {
  if (!getSelectRowKeys().length && !getSelectRows().length) return;
  if (!getSelectRows().length) {
    emit('change', getSelectRows(), searchInfo.classifyId);
    formItemContext.onFieldChange();
    handleCancel();
    return;
  }
  const selectRow = getSelectRows();
  emit('change', selectRow, searchInfo.classifyId);
  formItemContext.onFieldChange();
  handleCancel();
}
</script>
 
<template>
  <div class="common-container">
    <a-button type="primary" pre-icon="icon-ym icon-ym-btn-add" @click="openSelectModal">选择产品</a-button>
    <AModal
      v-model:open="visible"
      title="选择产品"
      :width="1000"
      class="common-container-modal"
      @ok="handleSubmit"
      @cancel="handleCancel"
      :mask-closable="false"
      destroy-on-close>
      <template #closeIcon>
        <ModalClose :can-fullscreen="false" @cancel="handleCancel" />
      </template>
      <div class="jnpf-content-wrapper">
        <div class="jnpf-content-wrapper-left">
          <BasicLeftTree ref="leftTreeRef" :show-search="false" :tree-data="treeData" :loading="treeLoading" @select="handleTreeSelect" />
        </div>
        <div class="jnpf-content-wrapper-center">
          <div class="jnpf-content-wrapper-content">
            <BasicVxeTable @register="registerTable" :search-info="searchInfo" class="jnpf-sub-table" />
          </div>
        </div>
      </div>
    </AModal>
  </div>
</template>