index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <template>
  2. <el-container class="is-vertical">
  3. <sc-page-header @add="table_add()"></sc-page-header>
  4. <scTable ref="xGridTable" :apiObj="$API.sales.plan" :formConfig="formConfig" v-bind="options">
  5. <template #action="scoped">
  6. <el-button v-if="XEUtils.includes(['year', 'quarter'], scoped.row.type)" type="primary" link @click="table_add(scoped.row)">
  7. <template #icon><sc-iconify icon="ant-design:cloud-upload-outlined"></sc-iconify></template>新增
  8. </el-button>
  9. <el-button type="primary" link @click="table_edit(scoped)">
  10. <template #icon><sc-iconify icon="ant-design:edit-outlined"></sc-iconify></template>修改
  11. </el-button>
  12. <el-button v-if="!scoped.row.children.length" type="primary" link @click="table_del(scoped.row)">
  13. <template #icon><sc-iconify icon="ant-design:delete-outlined"></sc-iconify></template>删除
  14. </el-button>
  15. </template>
  16. </scTable>
  17. </el-container>
  18. <plan-detail v-if="dialog" ref="planRef" @success="refreshTable" @closed="dialog = false"></plan-detail>
  19. </template>
  20. <script setup>
  21. import moment from "moment";
  22. import XEUtils from "xe-utils";
  23. import API from "@/api";
  24. import TOOL from "@/utils/tool";
  25. import { salesDic } from "@/utils/basicDic";
  26. import { mapFormItemInput, mapFormItemSelect, mapFormItemDatePicker } from "@/components/scTable/helper";
  27. import planDetail from "./detail";
  28. const formatStatus = row => {
  29. if (moment().isBefore(row.beginDate)) return "pending";
  30. if (moment().isAfter(row.endDate)) return "finished";
  31. return "executing";
  32. }
  33. const selectConfig = reactive({
  34. options: salesDic.planType,
  35. events: {
  36. change: data => XEUtils.merge(formConfig.data, data)
  37. }
  38. });
  39. const daterangeConfig = reactive({
  40. resetValue: () => [moment().startOf("year").format("YYYY-MM-DD"), moment().format("YYYY-MM-DD")],
  41. props: {
  42. type: "daterange",
  43. startPlaceholder: "开始日期",
  44. endPlaceholder: "结束日期",
  45. valueFormat: "YYYY-MM-DD"
  46. }
  47. });
  48. const formConfig = reactive({
  49. data: {
  50. beginDate: [moment().startOf("year").format("YYYY-MM-DD"), moment().format("YYYY-MM-DD")]
  51. },
  52. items: [
  53. mapFormItemInput("nameLike", "计划名称"),
  54. mapFormItemInput("codeLike", "计划编号"),
  55. mapFormItemSelect("type", "计划类型", selectConfig),
  56. mapFormItemDatePicker("beginDate", "计划开始日期", daterangeConfig)
  57. ]
  58. });
  59. const options = reactive({
  60. paramsColums: [
  61. { column: "orderBy", defaultValue: "beginDate_asc" },
  62. { column: "nameLike" },
  63. { column: "codeLike" },
  64. { column: "type" },
  65. { column: "beginDateBegin", field: "beginDate[0]" },
  66. { column: "beginDateEnd", field: "beginDate[1]" }
  67. ],
  68. treeConfig: { transform: true },
  69. pagerConfig : { enabled: false },
  70. columns: [
  71. { type: "seq", fixed: "left", width: 80 },
  72. { type: "html", field: "name", title: "计划名称", fixed: "left", minWidth: 160, treeNode: true, headerAlign: "center", align: "left", sortable: true },
  73. { type: "html", field: "code", title: "计划编号", fixed: "left", minWidth: 150, sortable: true },
  74. { type: "html", field: "type", title: "计划类型", minWidth: 120, sortable: true, formatter: ({ cellValue }) => XEUtils.get(salesDic.planType, cellValue, cellValue) },
  75. { field: "status", title: "计划状态", minWidth: 120, editRender: { name: "$cell-tag", options: salesDic.planStatus, formatter: row => formatStatus(row) } },
  76. { type: "html", field: "beginDate", title: "计划开始日期", minWidth: 150, sortable: true },
  77. { type: "html", field: "endDate", title: "计划结束日期", minWidth: 150, sortable: true },
  78. { type: "html", field: "saleAmount", title: "计划销售金额", minWidth: 150, sortable: true, formatter: ({ cellValue }) => TOOL.amountFormat(cellValue) || cellValue },
  79. { type: "html", field: "totalActualPrice", title: "实际销售金额", minWidth: 150, sortable: true, formatter: ({ cellValue }) => TOOL.amountFormat(cellValue) || cellValue },
  80. { type: "html", field: "createTime", title: "创建日期", minWidth: 120, sortable: true, formatter: ({ cellValue }) => TOOL.dateFormat(cellValue, "YYYY-MM-DD") || cellValue },
  81. { visible: false, type: "html", field: "remark", title: "概要", minWidth: 300, sortable: true },
  82. { title: "操作", fixed: "right", width: 220, slots: { default: "action" } }
  83. ]
  84. });
  85. // 显示隐藏 筛选表单
  86. const xGridTable = ref();
  87. const refreshTable = () => xGridTable.value.searchData();
  88. const planRef = ref();
  89. const dialog = ref(false);
  90. const table_add = (parent = {}) => {
  91. dialog.value = true;
  92. nextTick(() => planRef.value?.setData(parent));
  93. }
  94. const table_edit = ({ $grid, row }) => {
  95. const parent = $grid.getTreeParentRow(row);
  96. dialog.value = true;
  97. nextTick(() => planRef.value?.setData(parent, row, "edit"));
  98. }
  99. const table_del = ({ id }) => {
  100. ElMessageBox.confirm("是否确认删除该销售计划?", "删除警告", {
  101. type: "warning",
  102. confirmButtonText: "确定",
  103. cancelButtonText: "取消"
  104. }).then(() => {
  105. API.sales.plan.del({ id }).then(() => {
  106. ElMessage.success("操作成功");
  107. refreshTable();
  108. });
  109. }).catch(() => {});
  110. }
  111. </script>