index.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <script>
  2. import { REMOVE } from "@/api/business/purchase/apply";
  3. export default {
  4. name: "DeleteDialog",
  5. props: {
  6. selectData: {
  7. type: [Array],
  8. require: true,
  9. },
  10. },
  11. data() {
  12. return {
  13. title: "删 除",
  14. visible: false,
  15. loading: false,
  16. };
  17. },
  18. computed: {
  19. disabled: {
  20. get() {
  21. const { selectData } = this;
  22. if (selectData.length < 1) {
  23. return true;
  24. }
  25. if (
  26. selectData.length >= 1 &&
  27. selectData.findIndex(({ status }) => status === "1") > -1
  28. ) {
  29. return true;
  30. }
  31. if (
  32. selectData.length >= 1 &&
  33. selectData.findIndex(({ status }) => status === "2") > -1
  34. ) {
  35. return true;
  36. }
  37. },
  38. set() {},
  39. },
  40. },
  41. watch: {},
  42. methods: {
  43. //
  44. open() {
  45. this.visible = true;
  46. },
  47. //
  48. hide() {
  49. this.visible = false;
  50. },
  51. //
  52. async submit(prop) {
  53. try {
  54. // try
  55. this.loading = true;
  56. const ids = prop.map((item) => item.id).join(",");
  57. const { msg, code } = await REMOVE(ids);
  58. if (code === 200) {
  59. this.hide();
  60. this.$emit("success");
  61. this.$notify.success(msg);
  62. }
  63. } catch (err) {
  64. // catch
  65. console.error(err);
  66. } finally {
  67. // finally
  68. this.loading = false;
  69. }
  70. },
  71. },
  72. created() {},
  73. mounted() {},
  74. destroyed() {},
  75. };
  76. </script>
  77. <template>
  78. <el-button
  79. v-bind="$attrs"
  80. v-on="$listeners"
  81. :disabled="disabled"
  82. @click="open"
  83. >
  84. {{ title }}
  85. <el-dialog
  86. :title="title"
  87. :visible.sync="visible"
  88. width="25%"
  89. append-to-body
  90. @close="hide"
  91. >
  92. <div slot="footer">
  93. <el-button
  94. :size="$attrs.size"
  95. :loading="loading"
  96. @click="visible = false"
  97. >取 消</el-button
  98. >
  99. <el-button
  100. type="primary"
  101. :size="$attrs.size"
  102. :loading="loading"
  103. @click="submit(selectData)"
  104. >确 认</el-button
  105. >
  106. </div>
  107. <el-alert
  108. title="是否删除数据项?"
  109. type="info"
  110. show-icon
  111. :closable="false"
  112. style="margin-bottom: 10px"
  113. >
  114. </el-alert>
  115. </el-dialog>
  116. </el-button>
  117. </template>