batchAddToSite.vue 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template>
  2. <div>
  3. <el-button
  4. type="primary"
  5. :size="btn_size ? btn_size : 'small'"
  6. @click="onshow"
  7. :disabled="disabled"
  8. :loading="loading"
  9. >{{ btnName ? $t(btnName) : $t(`批量添加至本站`) }}</el-button
  10. >
  11. </div>
  12. </template>
  13. <script>
  14. export default {
  15. props: ["rowData", "disabled", "btnName", "btn_size"],
  16. name: "counterExamine",
  17. data() {
  18. return {
  19. loading: false,
  20. };
  21. },
  22. methods: {
  23. onshow() {
  24. this.onCounter();
  25. },
  26. onCounter() {
  27. //根据是否传入 btnName 切换 单数/批量 文案
  28. const isSingle = !!this.btnName;
  29. const confirmText = isSingle
  30. ? this.$t("是否确定将此物料添加至本站")
  31. : this.$t("是否确定将所选物料添加至本站");
  32. const cancelText = isSingle
  33. ? this.$t("已取消添加至本站")
  34. : this.$t("已取消批量添加至本站");
  35. // 统一兼容数据格式
  36. const dataList = this.btnName ? [this.rowData] : this.rowData;
  37. this.$confirm(confirmText + "?", this.$t("提示"), {
  38. confirmButtonText: this.$t("确定"),
  39. cancelButtonText: this.$t("取消"),
  40. type: "warning",
  41. })
  42. .then(async () => {
  43. this.loading = true;
  44. let row = [];
  45. dataList.forEach(function (item, index) {
  46. row[index] = item.sc_itemid;
  47. });
  48. const sc_itemids_str = row.join(",");
  49. const res = await this.$api.requested({
  50. id: 2026051511000001,
  51. content: {
  52. sc_itemids: sc_itemids_str,
  53. },
  54. });
  55. this.loading = false;
  56. this.tool.showMessage(res, () => {
  57. this.$emit("addSuccess");
  58. });
  59. })
  60. .catch(async () => {
  61. this.$message({
  62. type: "info",
  63. message: cancelText,
  64. });
  65. });
  66. },
  67. },
  68. };
  69. </script>
  70. <style scoped>
  71. </style>