yyb
2 天以前 868e08bf0513b2e6ad0360bc2000119a7e376548
src/views/basicData/product/index.vue
@@ -17,6 +17,9 @@
          style="margin-left: 10px"
          >新增产品大类</el-button
        >
        <el-button type="success" style="margin-left: 10px" @click="openExportDia">
          导出
        </el-button>
      </div>
      <div ref="containerRef">
        <el-tree
@@ -73,7 +76,7 @@
        <el-button type="primary" @click="openModelDia('add')">
          新增规格型号
        </el-button>
        <ImportExcel @uploadSuccess="getModelList" />
        <ImportExcel :product-id="currentId" @uploadSuccess="getModelList" />
        <el-button
          type="danger"
          @click="handleDelete"
@@ -170,6 +173,42 @@
        </div>
      </template>
    </el-dialog>
    <el-dialog
      v-model="exportDia"
      title="导出产品数据"
      width="420px"
      @keydown.enter.prevent
    >
      <el-form label-position="top">
        <el-form-item label="选择产品大类(可不选)">
          <el-select
            v-model="exportProductId"
            clearable
            filterable
            placeholder="不选则导出全部产品"
            style="width: 100%"
          >
            <el-option
              v-for="item in rootProductOptions"
              :key="item.id"
              :label="item.label"
              :value="item.id"
            />
          </el-select>
          <div class="export-tip">
            已选:导出该大类及其子类;未选:导出全部
          </div>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" :loading="exportLoading" :disabled="exportLoading" @click="handleExport">
            确认导出
          </el-button>
          <el-button @click="closeExportDia">取消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>
@@ -181,6 +220,7 @@
  addOrEditProductModel,
  delProduct,
  delProductModel,
  exportProductData,
  modelListPage,
  productTreeList,
} from "@/api/basicData/product.js";
@@ -192,14 +232,18 @@
const productDia = ref(false);
const modelDia = ref(false);
const exportDia = ref(false);
const exportLoading = ref(false);
const modelOperationType = ref("");
const search = ref("");
const currentId = ref("");
const currentParentId = ref("");
const exportProductId = ref("");
const operationType = ref("");
const treeLoad = ref(false);
const list = ref([]);
const expandedKeys = ref([]);
const rootProductOptions = ref([]);
const tableColumn = ref([
  {
    label: "规格型号",
@@ -259,6 +303,7 @@
  productTreeList()
    .then((res) => {
      list.value = res;
      rootProductOptions.value = Array.isArray(res) ? res : [];
      list.value.forEach((a) => {
        expandedKeys.value.push(a.label);
      });
@@ -425,6 +470,42 @@
      proxy.$modal.msg("已取消");
    });
};
const openExportDia = () => {
  exportDia.value = true;
};
const closeExportDia = () => {
  exportDia.value = false;
};
// 导出产品(可按大类,含子类)
const handleExport = () => {
  if (exportLoading.value) return;
  exportLoading.value = true;
  const params = exportProductId.value ? { productId: exportProductId.value } : {};
  exportProductData(params)
    .then((blobData) => {
      const blob =
        blobData instanceof Blob
          ? blobData
          : new Blob([blobData], {
              type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
            });
      const url = window.URL.createObjectURL(blob);
      const link = document.createElement("a");
      link.href = url;
      link.download = "产品数据.xlsx";
      document.body.appendChild(link);
      link.click();
      document.body.removeChild(link);
      window.URL.revokeObjectURL(url);
      closeExportDia();
    })
    .catch(() => {
      proxy.$modal.msgError("导出失败,请稍后重试");
    })
    .finally(() => {
      exportLoading.value = false;
    });
};
// 调用tree过滤方法 中文英过滤
const filterNode = (value, data, node) => {
  if (!value) {
@@ -529,4 +610,9 @@
.product-tree-scroll::-webkit-scrollbar-thumb:hover {
  background: #909399;
}
.export-tip {
  margin-top: 8px;
  font-size: 12px;
  color: #909399;
}
</style>