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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<script lang="ts" setup>
import type { BasicColumn } from '@jnpf/ui/vxeTable';
 
import { reactive, toRefs } from 'vue';
 
import { useMessage } from '@jnpf/hooks';
import { usePopup } from '@jnpf/ui/popup';
import { BasicVxeTable, useVxeTable } from '@jnpf/ui/vxeTable';
 
import { DownOutlined } from '@ant-design/icons-vue';
 
import { delOrder, getOrderList, getProductEntry } from '#/api/extend/saleOrder';
import { $t } from '#/locales';
 
import Form from './Form.vue';
 
defineOptions({ name: 'ExtendOrderDemo' });
 
interface State {
  activeId: string;
  productList: any[];
  productDetailList: any[];
}
 
const state = reactive<State>({
  activeId: '',
  productList: [],
  productDetailList: [],
});
const { productList, productDetailList } = toRefs(state);
const { createMessage, createConfirm } = useMessage();
const columns: BasicColumn[] = [
  { title: '订单编号', dataIndex: 'code', minWidth: 150, slots: { default: 'code' } },
  { title: '客户名称', dataIndex: 'customerName', minWidth: 150, slots: { default: 'customerName' } },
  { title: '审核状态', dataIndex: 'auditState', width: 80, slots: { default: 'auditState' } },
  { title: '发货通知状态', dataIndex: 'goodsState', width: 80, slots: { default: 'goodsState' } },
  { title: '关闭状态', dataIndex: 'closeState', width: 80, slots: { default: 'closeState' } },
  { title: '关闭日期', dataIndex: 'closeDate', width: 120, format: 'date|YYYY-MM-DD HH:mm:ss' },
  { title: '业务员', dataIndex: 'business', width: 120 },
  { title: '送货地址', dataIndex: 'address', width: 120 },
  { title: '联系方式', dataIndex: 'contactTel', width: 120 },
];
const productColumns: BasicColumn[] = [
  { title: '产品编号', dataIndex: 'productCode', width: 100, slots: { default: 'productCode' } },
  { title: '产品名称', dataIndex: 'productName', width: 100, slots: { default: 'productName' } },
  { title: '发货通知数', dataIndex: 'qty', width: 100 },
  { title: '订货类型', dataIndex: 'type', width: 100 },
  { title: '活动', dataIndex: 'activity', minWidth: 100 },
];
const productColumns_: BasicColumn[] = [
  { title: '产品规格', dataIndex: 'productSpecification', minWidth: 100 },
  { title: '数量', dataIndex: 'qty', minWidth: 100 },
  { title: '单价', dataIndex: 'price', width: 100 },
  { title: '折后单价', dataIndex: 'money', width: 100 },
  { title: '控制方式', dataIndex: 'commandType', width: 100 },
  { title: '单位', dataIndex: 'util', width: 100 },
];
const [registerTable, { reload, getSelectRows, clearSelectedRowKeys }] = useVxeTable({
  api: getOrderList,
  columns,
  useSearchForm: true,
  formConfig: {
    schemas: [
      {
        field: 'code',
        label: '订单编号',
        component: 'Input',
        componentProps: { placeholder: '请输入' },
      },
      {
        field: 'customerName',
        label: '客户名称',
        component: 'Input',
        componentProps: { placeholder: '请输入' },
      },
      {
        field: 'auditState',
        label: '审核状态',
        component: 'Select',
        componentProps: {
          placeholder: '请选择',
          options: [
            { id: 0, fullName: '全部' },
            { id: 1, fullName: '未审核' },
            { id: 2, fullName: '已审核' },
          ],
        },
      },
      {
        field: 'closeState',
        label: '关闭状态',
        component: 'Select',
        componentProps: {
          placeholder: '请选择',
          options: [
            { id: 0, fullName: '全部' },
            { id: 1, fullName: '未审核' },
            { id: 2, fullName: '已审核' },
          ],
        },
      },
      {
        field: 'creatorUser',
        label: '制单人',
        component: 'Input',
        componentProps: { placeholder: '请输入' },
      },
    ],
  },
  rowSelection: { type: 'checkbox' },
  clickToRowSelect: false,
});
const [registerProductTable] = useVxeTable({
  columns: productColumns,
  useSearchForm: false,
  immediate: false,
  showTableSetting: false,
  pagination: false,
});
const [registerProductDetailTable] = useVxeTable({
  columns: productColumns_,
  useSearchForm: false,
  immediate: false,
  showTableSetting: false,
  pagination: false,
});
const [registerForm, { openPopup: openFormPopup }] = usePopup();
 
function handleRowClick(item) {
  if (state.activeId === item.id) return;
  state.activeId = item.id;
  getProductEntry(state.activeId).then((res) => {
    state.productList = res.data.list;
  });
}
function handleProductRowClick(item) {
  state.productDetailList = item.dataList || [];
}
function handleAdd() {
  openFormPopup(true, {});
}
function handleUpdate() {
  const selectedList: any[] = getSelectRows();
  if (selectedList.length != 1) return createMessage.error('请只选择一条数据');
  openFormPopup(true, { id: selectedList[0].id });
}
function handleDel() {
  const selectedList: any[] = getSelectRows();
  if (selectedList.length != 1) return createMessage.error('请只选择一条数据');
  createConfirm({
    iconType: 'warning',
    title: $t('common.tipTitle'),
    content: $t('common.delTip'),
    onOk: () => {
      delOrder(selectedList[0].id).then((res) => {
        reload();
        state.productList = [];
        state.productDetailList = [];
        clearSelectedRowKeys();
        createMessage.success(res.msg);
      });
    },
  });
}
</script>
<template>
  <div class="jnpf-content-wrapper h-full">
    <div class="jnpf-content-wrapper-center">
      <div class="sale-order-content">
        <BasicVxeTable @register="registerTable" @row-click="handleRowClick">
          <template #tableTitle>
            <a-button type="primary" pre-icon="icon-ym icon-ym-btn-add" @click="handleAdd()">{{ $t('common.addText') }}</a-button>
            <a-button type="link" pre-icon="icon-ym icon-ym-btn-edit" @click="handleUpdate()">{{ $t('common.editText') }}</a-button>
            <a-button type="link" pre-icon="icon-ym icon-ym-delete" @click="handleDel()">{{ $t('common.delText') }}</a-button>
            <a-button type="link"><DownOutlined class="icon-more mr-[-8px]" />{{ $t('common.moreText') }} </a-button>
          </template>
          <template #code="{ record }">
            <span @click="handleRowClick(record)">{{ record.code }}</span>
          </template>
          <template #customerName="{ record }">
            <span @click="handleRowClick(record)">{{ record.customerName }}</span>
          </template>
          <template #auditState>
            <a-tag color="error">未审核</a-tag>
          </template>
          <template #goodsState>
            <a-tag color="error">未通知</a-tag>
          </template>
          <template #closeState>
            <a-tag color="error">未关闭</a-tag>
          </template>
        </BasicVxeTable>
      </div>
      <div class="sale-order-footer w-full bg-white">
        <BasicVxeTable @register="registerProductTable" :data-source="productList" @row-click="handleProductRowClick">
          <template #productCode="{ record }">
            <span @click="handleProductRowClick(record)">{{ record.productCode }}</span>
          </template>
          <template #productName="{ record }">
            <span @click="handleProductRowClick(record)">{{ record.productName }}</span>
          </template>
        </BasicVxeTable>
        <BasicVxeTable class="ml-[10px]" @register="registerProductDetailTable" :data-source="productDetailList" />
      </div>
    </div>
    <Form @register="registerForm" @reload="reload" />
  </div>
</template>
<style lang="scss" scoped>
.sale-order-content {
  height: calc(100% - 300px);
}
 
.sale-order-footer {
  display: flex;
  flex-shrink: 0;
  height: 300px;
  margin-top: 10px;
 
  .jnpf-vxe-table {
    width: 50%;
  }
}
</style>