index.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. <script lang="ts" setup>
  2. import type { VbenFormProps } from '@vben/common-ui';
  3. import type { VxeGridListeners, VxeGridProps } from '#/adapter/vxe-table';
  4. import type { OrdersQueryParams } from '#/api/orders';
  5. import { h, onMounted, ref } from 'vue';
  6. import { Page, useVbenModal } from '@vben/common-ui';
  7. import { MdiCheckboxMultipleMarked, MdiDetail } from '@vben/icons';
  8. import { useUserStore } from '@vben/stores';
  9. // import { ElMessage, ElMessageBox, ElTag } from 'element-plus';
  10. import { ElTag } from 'element-plus';
  11. import { useVbenVxeGrid } from '#/adapter/vxe-table';
  12. // import { deleteOrdersApi, getOrdersListApi } from '#/api/orders';
  13. import { getOrdersListApi } from '#/api/orders';
  14. import { getCustomerListApi } from '#/api/user';
  15. import { $t } from '#/locales';
  16. import OrdersAuditForm from './audit-form.vue';
  17. import OrdersForm from './form.vue';
  18. const dealerOptions = ref<Array<{ label: string; value: string }>>([]);
  19. const userStore = useUserStore();
  20. const fetchDealerOptions = async () => {
  21. try {
  22. const result = await getCustomerListApi({
  23. usersnature: '经销商',
  24. pageindex: 1,
  25. rows: 999,
  26. });
  27. if (result && result.Data) {
  28. dealerOptions.value = result.Data.map((item: any) => ({
  29. label: item.usersname,
  30. value: item.usersid,
  31. }));
  32. }
  33. } catch (error) {
  34. console.error('Failed to fetch dealer options:', error);
  35. dealerOptions.value = [];
  36. }
  37. };
  38. onMounted(async () => {
  39. await fetchDealerOptions();
  40. });
  41. const formOptions: VbenFormProps = {
  42. // 默认展开
  43. collapsed: true,
  44. // 控制表单是否显示折叠按钮
  45. showCollapseButton: true,
  46. // 按下回车时是否提交表单
  47. submitOnEnter: true,
  48. schema: [
  49. {
  50. component: 'Input',
  51. fieldName: 'ordersnumber',
  52. label: '订单号',
  53. componentProps: {
  54. placeholder: $t('ui.placeholder.input'),
  55. allowClear: true,
  56. },
  57. },
  58. {
  59. component: 'Input',
  60. fieldName: 'ordersproductname',
  61. label: '产品名称',
  62. componentProps: {
  63. placeholder: $t('ui.placeholder.input'),
  64. allowClear: true,
  65. },
  66. },
  67. {
  68. component: 'Select',
  69. fieldName: 'ordersuserid1',
  70. label: '经销商',
  71. // 如果是代理商且非管理员,设置默认值为当前用户的workeruserid
  72. defaultValue: userStore.isDLSNotAdmin
  73. ? userStore.userInfo?.workeruserid
  74. : undefined,
  75. componentProps: {
  76. options: dealerOptions,
  77. placeholder: $t('ui.placeholder.select'),
  78. allowClear: true,
  79. filterable: true,
  80. // 如果是代理商且非管理员,禁用该字段
  81. disabled: userStore.isDLSNotAdmin,
  82. },
  83. },
  84. {
  85. component: 'DatePicker',
  86. fieldName: 'ordersorderdate',
  87. label: '下单时间',
  88. componentProps: {
  89. type: 'daterange',
  90. startPlaceholder: '开始日期',
  91. endPlaceholder: '结束日期',
  92. valueFormat: 'YYYY-MM-DD', // 根据后端接口调整日期格式
  93. allowClear: true,
  94. },
  95. },
  96. ],
  97. wrapperClass: 'grid-cols-1 md:grid-cols-3 lg:grid-cols-5',
  98. };
  99. const gridOptions: VxeGridProps<any> = {
  100. toolbarConfig: {
  101. custom: true,
  102. export: true,
  103. // import: true,
  104. refresh: true,
  105. zoom: true,
  106. },
  107. height: 'auto',
  108. exportConfig: {},
  109. pagerConfig: {},
  110. rowConfig: {
  111. isHover: true,
  112. },
  113. stripe: true,
  114. proxyConfig: {
  115. response: {
  116. result: 'Data',
  117. total: 'Total',
  118. },
  119. ajax: {
  120. query: async ({ page }, formValues) => {
  121. const params: Record<string, any> = {
  122. pageindex: page.currentPage,
  123. rows: page.pageSize,
  124. ...formValues,
  125. };
  126. return await getOrdersListApi(params as OrdersQueryParams);
  127. },
  128. },
  129. },
  130. columns: [
  131. { title: '订单号', field: 'ordersnumber', sortable: true },
  132. // { title: '订单关联用户id', field: 'ordersuserid', sortable: true },
  133. // { title: '订单关联产品id', field: 'ordersproductid', sortable: true },
  134. { title: '产品名称', field: 'ordersproductname', sortable: true },
  135. { title: '产品型号', field: 'productsmodel', sortable: true },
  136. { title: '产品sn', field: 'ordersproductsn', sortable: true },
  137. { title: '订单总金额', field: 'orderstotalprice', sortable: true },
  138. { title: '订单优惠后金额', field: 'ordersdiscountprice', sortable: true },
  139. { title: '优惠金额', field: 'ordersyhprice', sortable: true },
  140. { title: '优惠卷id', field: 'orderscouponid', sortable: true },
  141. { title: '经销商', field: 'jxsname', sortable: true },
  142. {
  143. title: '订单状态',
  144. field: 'ordersorderstatus',
  145. sortable: true,
  146. slots: {
  147. default: ({ row }) => {
  148. const type = row.ordersorderstatus as 0 | 1 | 2;
  149. const typeMap = {
  150. 0: { text: '待审核', type: 'info' },
  151. 1: { text: '已支付', type: 'success' },
  152. 2: { text: '已完成', type: 'warning' },
  153. 3: { text: '审核不通过', type: 'danger' },
  154. } as const;
  155. return h(
  156. ElTag,
  157. { type: typeMap[type]?.type },
  158. () => typeMap[type]?.text,
  159. );
  160. },
  161. },
  162. },
  163. // {
  164. // title: '审核状态',
  165. // field: 'ordsesshzt',
  166. // sortable: true,
  167. // slots: {
  168. // default: ({ row }) => {
  169. // const type = row.ordsesshzt as 0 | 1 | 2;
  170. // const typeMap = {
  171. // 0: { text: '待审核', type: 'info' },
  172. // 1: { text: '审核通过', type: 'success' },
  173. // 2: { text: '审核不通过', type: 'danger' },
  174. // } as const;
  175. // return h(
  176. // ElTag,
  177. // { type: typeMap[type]?.type },
  178. // () => typeMap[type]?.text,
  179. // );
  180. // },
  181. // },
  182. // },
  183. { title: '下单时间', field: 'ordersorderdate', sortable: true },
  184. {
  185. title: '操作',
  186. field: 'action',
  187. fixed: 'right',
  188. slots: { default: 'action' },
  189. width: 200,
  190. },
  191. ],
  192. };
  193. const gridEvents: VxeGridListeners<any> = {
  194. cellDblclick: ({ row }) => {
  195. handleDetail(row);
  196. },
  197. };
  198. const [Grid, gridApi] = useVbenVxeGrid({
  199. gridEvents,
  200. gridOptions,
  201. formOptions,
  202. });
  203. const [Modal, modalApi] = useVbenModal({
  204. fullscreenButton: false,
  205. closeOnClickModal: false,
  206. closeOnPressEscape: false,
  207. connectedComponent: OrdersForm,
  208. });
  209. const [AuditModal, auditModalApi] = useVbenModal({
  210. fullscreenButton: false,
  211. closeOnClickModal: false,
  212. closeOnPressEscape: false,
  213. connectedComponent: OrdersAuditForm,
  214. });
  215. /* 创建 */
  216. function handleCreate() {
  217. modalApi.setState({ showCancelButton: true });
  218. modalApi.setData({ formType: 'create' }).open();
  219. }
  220. /* 编辑 */
  221. // function handleEdit(row: any) {
  222. // modalApi.setState({ showCancelButton: true });
  223. // modalApi.setData({ formType: 'edit', row }).open();
  224. // }
  225. /* 详情 */
  226. function handleDetail(row: any) {
  227. modalApi.setState({ showCancelButton: false });
  228. modalApi.setData({ formType: 'detail', row }).open();
  229. }
  230. function handleFinish() {
  231. gridApi.reload();
  232. }
  233. /* 审核 */
  234. function handleAudit(row: any) {
  235. auditModalApi.setData({ row }).open();
  236. }
  237. /* 删除 */
  238. // async function handleDelete(row: any) {
  239. // try {
  240. // await ElMessageBox.confirm('确认要删除该订单吗?', '提示', {
  241. // confirmButtonText: '确定',
  242. // cancelButtonText: '取消',
  243. // type: 'warning',
  244. // });
  245. // await deleteOrdersApi({ 'ordersid.value': row.ordersid });
  246. // ElMessage.success('删除成功');
  247. // gridApi.reload();
  248. // } catch (error) {
  249. // console.error(error);
  250. // }
  251. // }
  252. </script>
  253. <template>
  254. <Page auto-content-height>
  255. <Grid table-title="订单列表">
  256. <template #toolbar-tools>
  257. <el-button
  258. type="primary"
  259. @click="handleCreate"
  260. v-if="!userStore.isDLSNotAdmin"
  261. >
  262. 新增
  263. </el-button>
  264. </template>
  265. <template #action="{ row }">
  266. <el-tooltip
  267. class="box-item"
  268. effect="dark"
  269. content="详情"
  270. placement="top"
  271. >
  272. <el-button
  273. round
  274. @click="() => handleDetail(row)"
  275. :icon="MdiDetail"
  276. class="!p-2"
  277. />
  278. </el-tooltip>
  279. <!-- <el-tooltip
  280. class="box-item"
  281. effect="dark"
  282. content="编辑"
  283. placement="top"
  284. >
  285. <el-button
  286. round
  287. @click="() => handleEdit(row)"
  288. :icon="MdiEdit"
  289. class="!p-2"
  290. />
  291. </el-tooltip> -->
  292. <el-tooltip
  293. class="box-item"
  294. effect="dark"
  295. content="审核"
  296. placement="top"
  297. v-if="!userStore.isDLSNotAdmin"
  298. >
  299. <el-button
  300. round
  301. @click="() => handleAudit(row)"
  302. :icon="MdiCheckboxMultipleMarked"
  303. class="!p-2"
  304. :disabled="row.ordersorderstatus !== 0"
  305. />
  306. </el-tooltip>
  307. <!-- <el-tooltip
  308. class="box-item"
  309. effect="dark"
  310. content="删除"
  311. placement="top"
  312. >
  313. <el-button
  314. round
  315. @click="() => handleDelete(row)"
  316. :icon="MdiDelete"
  317. class="!p-2"
  318. />
  319. </el-tooltip> -->
  320. </template>
  321. </Grid>
  322. <Modal @finish="handleFinish" />
  323. <AuditModal @finish="handleFinish" />
  324. </Page>
  325. </template>