index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template>
  2. <div class="default-main ba-table-box">
  3. <el-alert class="ba-table-alert" v-if="baTable.table.remark" :title="baTable.table.remark" type="info"
  4. show-icon />
  5. <el-row>
  6. <el-col :span="24">
  7. <!-- 表格顶部菜单 -->
  8. <TableHeader :buttons="['refresh', 'add', 'edit', 'delete', 'comSearch']"
  9. quick-search-placeholder="通过标题模糊搜索"
  10. @action="baTable.onTableHeaderAction" />
  11. <!-- 表格 -->
  12. <!-- 要使用`el-table`组件原有的属性,直接加在Table标签上即可 -->
  13. <Table @action="baTable.onTableAction" />
  14. </el-col>
  15. </el-row>
  16. <!-- 表单 -->
  17. <PopupForm ref="formRef" />
  18. <sendDialog ref="sendDialogRef"></sendDialog>
  19. </div>
  20. </template>
  21. <script setup lang="ts">
  22. import { ref, onMounted, provide } from "vue";
  23. import { coupon } from "/@/api/controllerUrls";
  24. import Table from "/@/components/table/index.vue";
  25. import TableHeader from "/@/components/table/header/index.vue";
  26. import { defaultOptButtons } from "/@/components/table";
  27. import PopupForm from "./popupForm.vue";
  28. import { baTableApi } from "/@/api/common";
  29. import baTableClass from "/@/utils/baTable";
  30. import _ from "lodash";
  31. import { ElMessage } from "element-plus";
  32. import useCurrentInstance from "/@/utils/useCurrentInstance";
  33. import sendDialog from "./sendDialog.vue"
  34. //注销按钮
  35. let cancelBtn: OptButton[] = [
  36. {
  37. render: "tipButton",
  38. name: "send",
  39. title: "派发",
  40. text: "",
  41. type: "primary",
  42. icon: "el-icon-Avatar",
  43. class: "",
  44. disabledTip: false
  45. }
  46. ];
  47. let btn = defaultOptButtons(['edit','delete']);
  48. btn = btn.concat(cancelBtn);
  49. const tableRef = ref();
  50. const baTable = new baTableClass(
  51. new baTableApi(coupon),
  52. {
  53. dblClickNotEditColumn: [undefined, "status"],
  54. column: [
  55. { type: "selection", align: "center", operator: false },
  56. { label: "优惠卷名称", prop: "couponName", align: "left", operator: "LIKE" },
  57. {
  58. label: "优惠券类型",
  59. prop: "couponType",
  60. align: "center",
  61. render: "tag",
  62. operator: "=",
  63. replaceValue: { 0: "抵扣券", 1: "折扣券", 2: "特价券" }
  64. },
  65. {
  66. label: "使用场景",
  67. prop: "sceneType",
  68. align: "center",
  69. render: "tag",
  70. operator: "=",
  71. replaceValue: { 0: "不限定", 1: "首页投放", 2: "商家派发", 3: "营销活动" }
  72. },
  73. {
  74. label: "限定使用",
  75. prop: "limitedUse",
  76. align: "center",
  77. render: "tag",
  78. operator: "=",
  79. replaceValue: { 0: "否", 1: "是" }
  80. },
  81. { label: "发行数量", prop: "issuesNumber", align: "center", operator: "LIKE" },
  82. {
  83. label: "状态",
  84. prop: "couponStatus",
  85. align: "center",
  86. render: "tag",
  87. operator: "=",
  88. custom: { 0: "success", 1: "info" },
  89. replaceValue: { 0: "可用", 1: "停用" }
  90. },
  91. { label: "创建人", prop: "creatorName", align: "center", width: "120", operator: false },
  92. { label: "创建时间", prop: "createTime", align: "center", width: "180", operator: false },
  93. {
  94. label: "操作",
  95. align: "center",
  96. width: "160",
  97. render: "buttons",
  98. buttons: btn,
  99. operator: false
  100. }
  101. ]
  102. },
  103. {
  104. defaultItems: {}
  105. },
  106. {
  107. // 获得编辑数据后
  108. requestEdit: () => {
  109. if (baTable.form.items && !baTable.form.items.icon) baTable.form.items.icon = "el-icon-Minus";
  110. }
  111. }
  112. );
  113. provide("baTable", baTable);
  114. onMounted(() => {
  115. baTable.mount();
  116. baTable.getIndex();
  117. const { proxy } = useCurrentInstance();
  118. /**
  119. * 表格内的按钮响应
  120. * @param name 按钮name
  121. * @param row 被操作行数据
  122. */
  123. proxy.eventBus.on("onTableButtonClick", (data: { name: string; row: TableRow }) => {
  124. if (!baTable.activate) return;
  125. if (data.name == "send") {
  126. newButtonClick(data.row);
  127. }
  128. });
  129. });
  130. let sendDialogRef = ref();
  131. /** 点击按钮事件 */
  132. const newButtonClick = (row: TableRow) => {
  133. if (!row) {
  134. return;
  135. } else if (row.couponStatus == 1) {
  136. ElMessage({ type: "error", message: "该消费卷已停用!" ,grouping:true});
  137. return;
  138. }
  139. // 数据来自表格数据,未重新请求api,深克隆,不然可能会影响表格
  140. let rowClone = _.cloneDeep(row);
  141. sendDialogRef.value.open(rowClone);
  142. };
  143. </script>
  144. <style scoped lang="scss"></style>