瀏覽代碼

修改产品

yangg 6 月之前
父節點
當前提交
5920644bba

+ 54 - 20
ui/src/views/ProductMent/ProductManagement.vue

@@ -26,14 +26,40 @@
       <div class="content-header">
         <!--  <div class="breadcrumb">首页—产品库—产品管理</div> -->
         <div class="search-area">
-          <el-input
-            v-model="searchKeyword"
-            placeholder="请输入产品应用编号"
-            class="search-input"
-            @keyup.enter.native="handleSearch"
-          >
-            <el-button slot="append" icon="el-icon-search" @click="handleSearch"></el-button>
-          </el-input>
+          <el-form :inline="true" :model="searchForm" ref="searchForm">
+            <el-form-item label="产品应用编号">
+              <el-input
+                v-model="searchForm.dcp_p_no"
+                placeholder="请输入产品应用编号"
+                clearable
+              ></el-input>
+            </el-form-item>
+            <el-form-item label="产品名称">
+              <el-input
+                v-model="searchForm.dcp_name"
+                placeholder="请输入产品名称"
+                clearable
+              ></el-input>
+            </el-form-item>
+            <el-form-item label="产品类型">
+              <el-input
+                v-model="searchForm.dcp_model"
+                placeholder="请输入产品类型"
+                clearable
+              ></el-input>
+            </el-form-item>
+            <el-form-item label="OA编号">
+              <el-input
+                v-model="searchForm.dcp_oa_code"
+                placeholder="请输入OA编号"
+                clearable
+              ></el-input>
+            </el-form-item>
+            <el-form-item>
+              <el-button type="primary" @click="handleSearch">搜索</el-button>
+              <el-button @click="resetForm">重置</el-button>
+            </el-form-item>
+          </el-form>
         </div>
         <el-button type="primary" @click="handleAddProduct">新建产品</el-button>
       </div>
@@ -52,9 +78,7 @@
         </el-table-column>
         <el-table-column prop="dcp_name" label="产品名称" />
         <el-table-column prop="dcp_model" label="产品类型" />
-        <!--  <el-table-column prop="length" label="长宽比" />
-        <el-table-column prop="resolution" label="刷新率" />
-        <el-table-column prop="screenMaterial" label="屏幕材质" /> -->
+        <!--<el-table-column prop="screenMaterial" label="屏幕材质" /> -->
         <el-table-column label="操作" width="200">
           <template slot-scope="scope">
             <el-button size="mini" @click="handleEditProduct(scope.row)"
@@ -153,7 +177,12 @@ export default {
   name: "ProductManagement",
   data() {
     return {
-      searchKeyword: "",
+      searchForm: {
+        dcp_p_no: '',
+        dcp_name: '',
+        dcp_model: '',
+        dcp_oa_code: ''
+      },
       categoryData: [
         {
           id: 1,
@@ -239,17 +268,15 @@ export default {
     // 获取产品列表
     async fetchProductList() {
       try {
-        // 添加分页参数
         const params = {
           pageNum: this.pagination.currentPage,
           pageSize: this.pagination.pageSize,
-          // 可以添加搜索关键字
-          dcp_p_no: this.searchKeyword,
+          ...this.searchForm  // 展开所有搜索条件
         };
 
         productList(params).then((res) => {
           this.productList = res.rows;
-          this.pagination.total = res.total; // 设置总数
+          this.pagination.total = res.total;
         });
       } catch (error) {
         this.$message.error("获取产品列表失败");
@@ -370,10 +397,6 @@ export default {
 
     // 搜索和分页
     handleSearch() {
-      if (!this.searchKeyword.trim()) {
-        this.$message.warning('请输入搜索关键词');
-        return;
-      }
       this.pagination.currentPage = 1; // 重置到第一页
       this.fetchProductList();
     },
@@ -389,6 +412,17 @@ export default {
       this.pagination.currentPage = 1;
       this.fetchProductList();
     },
+
+    resetForm() {
+      // 重置表单引用
+      this.$refs.searchForm.resetFields();
+      // 手动清空 searchForm 对象的所有属性
+      Object.keys(this.searchForm).forEach(key => {
+        this.searchForm[key] = '';
+      });
+      this.pagination.currentPage = 1;
+      this.fetchProductList();
+    },
   },
 };
 </script>

+ 19 - 2
ui/src/views/ProductMent/newProduct/editor.vue

@@ -96,6 +96,16 @@
               <template slot="append">元</template>
             </el-input>
           </el-form-item>
+          <el-form-item label="所属文档">
+            <el-select v-model="productForm.dcm_id"  placeholder="请选择">
+              <el-option
+                v-for="item in docList"
+                :key="item.dcm_id"
+                :label="item.dcm_title"
+                :value="item.dcm_id"
+              ></el-option>
+            </el-select>
+          </el-form-item>
         </el-col>
       </el-row>
 
@@ -320,6 +330,7 @@ import {
 } from "@/api/ProductMent/product";
 import { list } from "@/api/sysCategory/sysCategory";
 import { listWork } from "@/api/worksCategory/worksCategory";
+import { searchlistDoc } from "@/api/document";
 export default {
   name: "NewProduct",
   data() {
@@ -340,6 +351,7 @@ export default {
         dcp_cost_price: "",
         dcp_model: "",
         dcp_diff: "",
+         dcm_id:""
       },
       // 规格相关数据
       specs: {
@@ -382,6 +394,8 @@ export default {
       /* id */
       dcp_id: "",
       isEdit: false, // 添加标识是否为编辑模式
+      /* 文档 */
+      docList: [],
     };
   },
   computed: {
@@ -651,10 +665,11 @@ export default {
         listWork(),
         // 编辑模式下获取产品详情,新增模式下获取规格列表
         this.isEdit ? getInfo(this.dcp_id) : getDcSpecList(),
-      ]).then(([sysRes, workRes, specRes]) => {
+        searchlistDoc({ page: 1, pageSize: 999, isContentShow: false }),
+      ]).then(([sysRes, workRes, specRes, docList]) => {
         this.systemTypes = sysRes.rows;
         this.projectTypes = workRes.rows;
-
+        this.docList = docList.data.dataList;
         if (this.isEdit) {
           // 处理编辑模式数据
           this.handleEditData(specRes.data);
@@ -689,6 +704,7 @@ export default {
         dcp_price4: content.dcp_price4,
         dcp_cost_price: content.dcp_cost_price,
         dcp_diff: content.dcp_diff,
+        dcm_id: content.dcm_id,
       };
 
       // 处理规格数据
@@ -787,6 +803,7 @@ export default {
             dcp_price4: content.dcp_price4, // 大区价
             dcp_cost_price: content.dcp_cost_price, // 成本价
             dcp_diff: content.dcp_diff, // 产品区分代码
+            dcm_id: content.dcm_id, // 产品文档分类
           };
 
           // 处理规格信息

+ 20 - 2
ui/src/views/ProductMent/newProduct/index.vue

@@ -96,6 +96,16 @@
               <template slot="append">元</template>
             </el-input>
           </el-form-item>
+          <el-form-item label="所属文档">
+            <el-select v-model="productForm.dcm_id"  placeholder="请选择">
+              <el-option
+                v-for="item in docList"
+                :key="item.dcm_id"
+                :label="item.dcm_title"
+                :value="item.dcm_id"
+              ></el-option>
+            </el-select>
+          </el-form-item>
         </el-col>
       </el-row>
 
@@ -320,6 +330,7 @@ import {
 } from "@/api/ProductMent/product";
 import { list } from "@/api/sysCategory/sysCategory";
 import { listWork } from "@/api/worksCategory/worksCategory";
+import { searchlistDoc } from "@/api/document";
 export default {
   name: "NewProduct",
   data() {
@@ -340,6 +351,7 @@ export default {
         dcp_cost_price: "",
         dcp_model: "",
         dcp_diff: "",
+        dcm_id:""
       },
       // 规格相关数据
       specs: {
@@ -382,6 +394,8 @@ export default {
       /* id */
       dcp_id: "",
       isEdit: false, // 添加标识是否为编辑模式
+      /* 文档 */
+      docList: [],
     };
   },
   computed: {
@@ -480,6 +494,7 @@ export default {
         dcp_cost_price: this.productForm.dcp_cost_price,
         dcp_diff: this.productForm.dcp_diff,
         dcp_model: this.productForm.dcp_model,
+        dcm_id: this.productForm.dcm_id,
       };
 
       // 如果是编辑模式,将 dcp_id 添加到 baseData 中
@@ -653,10 +668,11 @@ export default {
         listWork(),
         // 编辑模式下获取产品详情,新增模式下获取规格列表
         this.isEdit ? getInfo(this.dcp_id) : getDcSpecList(),
-      ]).then(([sysRes, workRes, specRes]) => {
+        searchlistDoc({ page: 1, pageSize: 999, isContentShow: false }),
+      ]).then(([sysRes, workRes, specRes, docList]) => {
         this.systemTypes = sysRes.rows;
         this.projectTypes = workRes.rows;
-
+        this.docList = docList.data.dataList;
         if (this.isEdit) {
           // 处理编辑模式数据
           this.handleEditData(specRes.data);
@@ -692,6 +708,7 @@ export default {
         dcp_price4: content.dcp_price4,
         dcp_cost_price: content.dcp_cost_price,
         dcp_diff: content.dcp_diff,
+        dcm_id: content.dcm_id,
       };
 
       // 处理规格数据
@@ -792,6 +809,7 @@ export default {
             dcp_price4: content.dcp_price4, // 大区价
             dcp_cost_price: content.dcp_cost_price, // 成本价
             dcp_diff: content.dcp_diff, // 产品区分代码
+            dcm_id: content.dcm_id, // 文档ID
           };
 
           // 处理规格信息

+ 1 - 1
ui/src/views/system/document/category/components/dataList.vue

@@ -28,7 +28,7 @@
 
       <div class="page-info">
       	<el-pagination
-      	v-model:currentPage="queryForm.page"
+      :currentPage="queryForm.page"
       	:page-size="queryForm.pageSize"
       	:total="recordCount"
       	:page-count="pageTotal"

+ 65 - 43
ui/src/views/system/document/com/editor.vue

@@ -16,7 +16,7 @@
       <transition-group style="display: block; min-height: 100vh">
         <template v-for="(it, index) in comList">
           <div
-             :key="index"
+            :key="index"
             class="layers"
             :class="comIndex == index ? 'active-layer' : ''"
           >
@@ -86,7 +86,8 @@
                     </el-form-item>
                   </el-col> -->
                   <el-col :xs="24" :sm="24" :md="12" :lg="8" :xl="8">
-                    <el-form-item ><!-- v-if="$store.state.user.roleInfo.id == 1" -->
+                    <el-form-item
+                      ><!-- v-if="$store.state.user.roleInfo.id == 1" -->
                       <div class="btn-save">
                         <el-tooltip
                           v-if="type !== 'document'"
@@ -117,11 +118,11 @@
                             icon="el-icon-document-copy"
                           >
                           </el-button>
-                        </el-tooltip> -->
+                        </el-tooltip> && type !== 'document'-->
                         <el-button
                           circle
                           size="mini"
-                          v-if="it.isEdit !== 1 && type !== 'document'"
+                          v-if="it.isEdit !== 1"
                           @click="onEdit(index, 1)"
                         >
                           <svg-icon icon-class="edit" />
@@ -134,8 +135,8 @@
                           v-else
                         >
                         </el-button>
+                        <!--  v-if="!templateId && type !== 'document'" -->
                         <el-tooltip
-                          v-if="!templateId && type !== 'document'"
                           class="item"
                           effect="dark"
                           content="删除"
@@ -145,9 +146,11 @@
                             circle
                             size="mini"
                             @click="onRemove(index)"
+                            icon="el-icon-delete"
+                          >
+                            <!--  <svg-icon icon-class="el-icon-delete" 
+                          />--></el-button
                           >
-                            <svg-icon icon-class="delete"
-                          /></el-button>
                         </el-tooltip>
                       </div>
                     </el-form-item>
@@ -260,20 +263,34 @@ export default {
     coms: {
       handler(val) {
         if (val == null) return;
-        /* const newComList = JSON.parse(JSON.stringify(val));
-
-        // 比较新旧值,只有在真正变化时才更新
-        if (JSON.stringify(this.comList) !== JSON.stringify(newComList)) {
-          this.comList = newComList;
-        } */
-         console.log("val", val);
-        this.comList = JSON.parse(JSON.stringify(val));
-        console.log("comList", this.comList);
-        /*   console.log("val", val);
-        this.comList = this.carefulCopy(val);
-        console.log("comList", this.comList); */
+
+        // 处理拖拽数据,确保属性正确转换
+        this.comList = val.map((item) => {
+          // 首先创建基础对象
+          const processedItem = {
+            ...item,
+            // 确保 attrs 是数组
+            attrs: Array.isArray(item.dcb_attrs)
+              ? item.dcb_attrs
+              : JSON.parse(item.dcb_attrs || "[]"),
+            // 同步最新内容,优先使用当前显示的内容
+            content: item.content || item.dcb_nr || "",
+            dcb_nr: item.content || item.dcb_nr || "",
+            // 确保 type 使用 dcb_type
+            type: item.dcb_type || item.type,
+            // 确保 name 使用 dcb_name
+            name: item.dcb_name || item.name,
+          };
+
+          // 确保 content 和 dcb_nr 同步
+          if (processedItem.content !== processedItem.dcb_nr) {
+            processedItem.dcb_nr = processedItem.content;
+          }
+
+          return processedItem;
+        });
       },
-      immediate: true, //立即执行
+      immediate: true,
       deep: true,
     },
     comIndex: {
@@ -421,7 +438,7 @@ export default {
     showCategoryName(item) {
       return (
         this.type == "module" &&
-       /*  this.$store.state.user.roleInfo.id == 1 && */
+        /*  this.$store.state.user.roleInfo.id == 1 && */
         !item.valDisabled
       );
     },
@@ -432,7 +449,7 @@ export default {
     showCategorySelect(item) {
       return (
         this.type === "module" &&
-       /*  this.$store.state.user.roleInfo.id === 1 && */
+        /*  this.$store.state.user.roleInfo.id === 1 && */
         !item.selDisabled
       );
     },
@@ -471,36 +488,41 @@ export default {
     /* 保存模块 */
     onSaveTemplate(e) {
       let _this = this;
-      /* e.category_id='1' */
-      let data = JSON.parse(JSON.stringify(e));
-      console.log(data);
-      if (data.category) {
-        delete data.category;
-      }
-      data.dcb_nr = data.content
-      data.dcb_attrs = JSON.stringify(data.dcb_attrs);
-      data.code = data.name;
-      data.status = 5;
-      // 检查 category_id 是否为数组
+      // 创建一个新对象来存储过滤后的数据
+      let data = {};
+
+      // 遍历原始对象,只保留 dcb_ 开头的属性
+      Object.keys(e).forEach((key) => {
+        if (key.startsWith("dcb_")) {
+          data[key] = e[key];
+        }
+      });
+
+      // 特殊字段映射
+      data.dcb_nr = e.content;
+      data.dcb_attrs = JSON.stringify(e.attrs);
+      data.dcb_type = e.type;
+      data.dcb_name = e.name; // 如果需要保存名称
+
+      // 处理分类ID
       if (Array.isArray(e.category_id)) {
-        // 如果是数组,取最后一个元素作为 category_id
         data.category_id = e.category_id[e.category_id.length - 1];
       } else {
-        // 如果不是数组,直接赋值
         data.category_id = e.category_id;
       }
 
-      if (data.dcb_id == undefined || this.saveAs) {
+      data.status = 5;
+
+      // 根据是否存在 dcb_id 决定创建还是更新
+      if (e.dcb_id == undefined || this.saveAs) {
         createTemplate(data).then((res) => {
           if (res.code != 200) return;
-          data.id = res.data;
           e.id = res.data;
-
           _this.$alert("模块信息保存成功");
           _this.$emit("onRefresh");
           this.saveAs = false;
-          data.selDisabled = false;
-          data.valDisabled = false;
+          e.selDisabled = false;
+          e.valDisabled = false;
           this.$forceUpdate();
         });
       } else {
@@ -508,8 +530,8 @@ export default {
           if (res.code != 200) return;
           _this.$alert("模块信息更新成功");
           _this.$emit("onRefresh");
-          data.selDisabled = false;
-          data.valDisabled = false;
+          e.selDisabled = false;
+          e.valDisabled = false;
           this.$forceUpdate();
         });
       }
@@ -663,7 +685,7 @@ export default {
       );
 
       // 过滤 attrs,只保留在 content 中出现的 ID
-      item.attrs = item.dcb_attrs.filter((attr) => contentIds.includes(attr.id));
+      item.attrs = item.attrs.filter((attr) => contentIds.includes(attr.id));
     },
     onAdd(e) {
       e.preventDefault();

+ 529 - 112
ui/src/views/system/document/create.vue

@@ -87,8 +87,8 @@
       <div class="left_scheme" v-if="type !== 'module'">
         <div class="scheme-header">
           <div class="title">
-            请选择可用的方案
-            <span class="count">[方案数量:47]</span>
+            请选择文档
+            <!--  <span class="count">[方案数量:47]</span> -->
             <i class="el-icon-menu"></i>
           </div>
           <div class="search">
@@ -97,19 +97,21 @@
               placeholder="请输入搜索"
               prefix-icon="el-icon-search"
               clearable
+              @keyup.enter.native="handleSearch"
+              @clear="handleClear"
             >
             </el-input>
           </div>
-          <div class="action-btns">
+          <!-- <div class="action-btns">
             <el-button type="primary" size="small" @click="createScheme"
               >新建方案</el-button
             >
             <el-button type="primary" size="small" @click="createCategory"
               >新建分类</el-button
             >
-          </div>
+          </div> -->
           <div class="current-scheme">
-            当前方案: {{ currentScheme || "已选择方案三" }}
+            当前文档: {{ currentScheme || "已选择方案三" }}
           </div>
         </div>
 
@@ -119,9 +121,11 @@
             :props="defaultProps"
             @node-click="handleNodeClick"
             :default-expanded-keys="expandedKeys"
+            node-key="id"
+            ref="documentTree"
           >
             <span class="custom-tree-node" slot-scope="{ node, data }">
-              <span>
+              <span @click="onLoadArticle(data.id)">
                 <i class="el-icon-folder" v-if="data.children"></i>
                 <i class="el-icon-document" v-else></i>
                 {{ node.label }}
@@ -135,21 +139,23 @@
       <div class="natural">
         <div class="resource-header-title">
           <div class="title-left">
-            <span>请选择可用的模块</span>
-           <!--  <span class="resource-count">[资源明细] 资源数量:474</span> -->
+            <span>请选择模块</span>
+            <!--  <span class="resource-count">[资源明细] 资源数量:474</span> -->
           </div>
           <i class="el-icon-menu"></i>
         </div>
         <div class="resource-container">
           <div class="resource-header">
             <el-input
-              v-model="resourceSearchKey"
+              v-model="templateSearchKey"
               placeholder="请输入选择"
               prefix-icon="el-icon-search"
               clearable
+               @keyup.enter.native="handleTemplateSearch"
+              @clear="handleResourceClear"
             >
             </el-input>
-           <!--  <div class="action-btns">
+            <!--  <div class="action-btns">
               <el-button type="primary" @click="createResource"
                 >新建资源</el-button
               >
@@ -185,12 +191,14 @@
                       sort: true,
                     }"
                     :disabled="type == 'module'"
+                    @end="handleDragEnd"
                   >
                     <transition-group>
                       <div
                         v-for="template in category.templates"
-                        :key="template.id"
+                        :key="template.dcb_id || template.name"
                         class="resource-item"
+                        :data-template-id="template.dcb_id"
                       >
                         <el-checkbox
                           v-model="template.selected"
@@ -198,42 +206,13 @@
                             (val) =>
                               handleTemplateSelect(category, template, val)
                           "
+                          :disabled="isTemplateUsed(template)"
                         >
-                          {{ template.name }}
+                          {{ template.dcb_name }}
                         </el-checkbox>
                       </div>
-                      <!-- <div
-                        class="sub-menus min-width-content"
-                        v-for="(it, index) in category.templates"
-                        :key="index"
-                      >
-                        <div
-                          :title="it.name"
-                          style="
-                            cursor: move;
-                            white-space: nowrap;
-                            overflow: hidden; /* 隐藏超出部分 */
-                            text-overflow: ellipsis; /* 显示省略号 */
-                            width: 100%;
-                          "
-                        >
-                          {{ it.name }}
-                        </div>
-                      </div> -->
                     </transition-group>
                   </draggable>
-                  <!-- <div
-                    v-for="template in category.templates"
-                    :key="template.id"
-                    class="resource-item"
-                  >
-                    <el-checkbox 
-                      v-model="template.selected"
-                      @change="(val) => handleTemplateSelect(category, template, val)"
-                    >
-                      {{ template.name }}
-                    </el-checkbox>
-                  </div> -->
                 </div>
               </el-collapse-item>
             </el-collapse>
@@ -522,6 +501,19 @@
             </el-tab-pane>
             <el-tab-pane label="模板内容" name="template">
               <div class="template-content">
+              
+                <!-- <div class="search-box">
+                  <el-input
+                    v-model="templateSearchKey"
+                    placeholder="搜索模板"
+                    @keyup.enter="handleTemplateSearch"
+                    clearable
+                    @clear="handleTemplateClear"
+                  >
+                    <i slot="prefix" class="el-input__icon el-icon-search"></i>
+                  </el-input>
+                </div> -->
+
                 <!-- 原有的menus和editor内容 -->
                 <div class="menus-box">
                   <menus
@@ -716,8 +708,7 @@
         :model="docForm"
         :rules="docRules"
         ref="docRef"
-        label-position="right"
-        label-width="100"
+        label-width="120px"
       >
         <el-form-item label="文档标题:" prop="dcm_title">
           <el-input
@@ -747,9 +738,21 @@
             <el-option label="共享模板" :value="3" />
           </el-select>
         </el-form-item>
-        <!-- <el-form-item label="创建人:">
-          {{ userInfo && userInfo.username }}
-        </el-form-item> -->
+        <el-form-item label="文档分类:">
+          <el-select
+            v-model="docForm.dcm_category_id"
+            style="width: 60%"
+            placeholder="请选择文档模板类别"
+            :disabled="docAttr.id > 0"
+            ><el-option
+              v-for="(item, index) in articleCategoryList"
+              :key="index"
+              :label="item.name"
+              :value="item.id"
+            />
+          </el-select>
+          <!-- {{ userInfo && userInfo.username }} -->
+        </el-form-item>
       </el-form>
       <span slot="footer" class="dialog-footer">
         <el-button @click="closeDoc">取 消</el-button>
@@ -826,7 +829,7 @@ export default {
       //文档属性
       docAttr: {
         id: 0,
-        category_id: "",
+        dcm_category_id: "",
         title: "",
         content: "",
         status: 5,
@@ -857,12 +860,16 @@ export default {
       docForm: {
         dcm_title: "",
         dcm_type: "",
+        dcm_category_id: "",
       },
       docRules: {
         dcm_title: [
           { required: true, message: "请输文档名称", trigger: "blur" },
         ],
         dcm_type: [
+          { required: true, message: "请选择文档模板分类", trigger: "change" },
+        ],
+        dcm_category_id: [
           { required: true, message: "请选择文档分类", trigger: "change" },
         ],
       },
@@ -872,30 +879,7 @@ export default {
       searchKey: "",
       currentScheme: "",
       expandedKeys: [], // 默认展开的节点
-      schemeData: [
-        {
-          label: "LED项目",
-          children: [],
-        },
-        {
-          label: "LCD项目",
-          children: [],
-        },
-        {
-          label: "集成项目",
-          children: [
-            {
-              label: "方案一",
-            },
-            {
-              label: "方案二",
-            },
-            {
-              label: "方案三",
-            },
-          ],
-        },
-      ],
+      schemeData: [],
       defaultProps: {
         children: "children",
         label: "label",
@@ -935,7 +919,7 @@ export default {
             {
               label: "1.1. 强大的显示功能",
               children: [
-                { label: "1.1.1. 计算信号显示" },
+                { label: "1.1.1. 计算���信号显示" },
                 { label: "1.1.2. 视频信号显示" },
                 { label: "1.1.3. 海量流媒体信号接入" },
                 { label: "1.1.4. 网络信号显示" },
@@ -960,6 +944,8 @@ export default {
         children: "children",
         label: "label",
       },
+      templateSearchKey: "", // 添加模板搜索关键字
+      originalTemplateList: [], // 保存原始模板列表
     };
   },
   watch: {
@@ -1017,6 +1003,8 @@ export default {
         arrow.style.margin = "0";
       });
     });
+    this.initTemplateSelection();
+    this.expandedKeys = []; // 初始化展开节点数组
   },
 
   methods: {
@@ -1094,8 +1082,9 @@ export default {
     },
     /* 方案点击 */
     handleNodeClick(data) {
+      console.log(data);
       this.currentScheme = data.label;
-      this.resourceDialogVisible = true; // 点击方案时打开资选择弹框
+      this.resourceDialogVisible = true; // 点击方案时打开资���选择弹框
     },
 
     createScheme() {
@@ -1188,6 +1177,7 @@ export default {
       this.docForm = {
         dcm_title: "",
         dcm_type: "",
+        dcm_category_id: "",
       };
     },
     /* 确定新增模块*/
@@ -1196,6 +1186,7 @@ export default {
         if (valid) {
           this.docAttr.dcm_title = this.docForm.dcm_title;
           this.docAttr.dcm_type = this.docForm.dcm_type;
+          this.docAttr.dcm_category_id = this.docForm.dcm_category_id;
           this.onSave();
         }
       });
@@ -1211,9 +1202,9 @@ export default {
       );
     },
     updateAttrs(newComs, oldComs) {
-      console.log(newComs);
       newComs.forEach((newCom, comIndex) => {
         const oldCom = oldComs[comIndex];
+        console.log("oldCom:", oldCom, "newCom:", newCom);
         if (oldCom) {
           newCom.attrs.forEach((newAttr, attrIndex) => {
             const oldAttr = oldCom.attrs[attrIndex];
@@ -1229,6 +1220,7 @@ export default {
     updateGlobalAttr(attrId, newContent) {
       // 遍历所有组件,更新匹配的属性
       this.coms.forEach((com) => {
+        console.log(com);
         com.attrs.forEach((attr) => {
           // 只更新非 variableNull 类型的属性
           if (attr.name === attrId && attr.type !== "variableNull") {
@@ -1237,7 +1229,7 @@ export default {
         });
 
         // 如果是文本区域,更新内容中的占位符
-        if (com.type === "TextArea") {
+        if (com.dcb_type === "TextArea") {
           com.content = com.content.replace(
             new RegExp(`{{${attrId}}}`, "g"),
             (match) => {
@@ -1466,7 +1458,7 @@ export default {
     viewModule() {
       this.showView = 1;
     },
-    /* 更新变 */
+    /* 更新变��� */
     /*  uptadeVariable(value) {
       for (const item of this.coms) {
         for (const el of item.attrs) {
@@ -1557,14 +1549,14 @@ export default {
       try {
         // 获取模板信息
         const { data } = await getTemplateInfo(id);
-
+        console.log(!data.dcb_attrs || !data.dcb_type);
         // 设置默认值
-        if (!data.attrs || !data.type) {
+        if (!data.dcb_attrs || !data.dcb_type) {
           Object.assign(data, {
-            attrs: "[]",
-            content: "请填写内容",
+            dcb_attrs: "[]",
+            dcb_nr: "请填写内容",
             lay_id: "textArea",
-            type: "TextArea",
+            dcb_type: "TextArea",
           });
         }
 
@@ -1574,26 +1566,31 @@ export default {
           : "新建模块-" + settings.title;
 
         // 解析属性
-        data.attrs = JSON.parse(data.attrs);
-
+        data.dcb_attrs = JSON.parse(data.dcb_attrs);
+        data.content = data.dcb_nr;
+        data.type = data.dcb_type;
+        data.name = data.dcb_name;
+        data.attrs = data.dcb_attrs;
         // 获取公式并更新属性
         const {
           data: { dataList },
         } = await searchFormula({ page: 1, pageSize: 999 });
         console.log(data);
-        data.attrs = data.attrs.map((item) => {
+        data.dcb_attrs = data.dcb_attrs.map((item) => {
           const formula = dataList.find((el) => el.id === item.id);
           return formula
             ? { ...item, formula: formula.formula, data: formula }
             : item;
         });
         // 从 content 中提取 {{}} 包裹的 ID
-        const contentIds = (data.content.match(/{{([^}]+)}}/g) || []).map(
+        const contentIds = (data.dcb_nr.match(/{{([^}]+)}}/g) || []).map(
           (match) => match.slice(2, -2).trim()
         );
 
-        // 过滤 attrs,只保留在 content 中出现的 ID
-        data.attrs = data.attrs.filter((item) => contentIds.includes(item.id));
+        // 过滤 attrs,只保留在 content 中出��的 ID
+        data.dcb_attrs = data.dcb_attrs.filter((item) =>
+          contentIds.includes(item.id)
+        );
 
         this.coms = [data];
       } catch (error) {
@@ -1666,6 +1663,9 @@ export default {
     async onLoadArticle(id) {
       try {
         this.loading = true;
+        // 在加载文档前重置所有模板状态
+        this.resetAllTemplateSelections();
+
         const res = await getDocumentInfo(id);
 
         if (res.status !== 200) {
@@ -1675,6 +1675,7 @@ export default {
         this.docAttr = {
           dcm_id: res.data.dcm_id,
           dcm_type: Number(res.data.dcm_type),
+          dcm_category_id: res.data.dcm_category_id,
           dcm_title: res.data.dcm_title,
           content: "",
           status: res.data.status,
@@ -1684,12 +1685,18 @@ export default {
           linkProject: res.data.linkProject,
           projects: res.data.projects,
         };
+        // 同时更新 docForm
+        this.docForm = {
+          dcm_title: res.data.dcm_title,
+          dcm_type: Number(res.data.dcm_type),
+          dcm_category_id: res.data.dcm_category_id, // 确保这个字段也被设置
+        };
 
         const templateData =
           typeof res.data.dcm_data === "string"
             ? JSON.parse(res.data.dcm_data)
             : res.data.dcm_data;
-        
+
         const updatedComs = await Promise.all(
           templateData.map(async (el) => {
             /* let templateInfo = { data: {} };
@@ -1727,6 +1734,7 @@ export default {
         }
 
         this.uptadeSearch();
+        this.initTemplateSelection();
       } catch (error) {
         console.error("Error in onLoadArticle:", error);
       } finally {
@@ -1737,6 +1745,9 @@ export default {
     async onTemplateInfo(id) {
       try {
         this.loading = true;
+        // 在加载模板前重置所有模板状态
+        this.resetAllTemplateSelections();
+
         // 获取文档信息
         const res = await getDocumentInfo({ id });
 
@@ -1775,7 +1786,7 @@ export default {
 
             // 使用模板的 content 作为基础
             let content = templateInfo.data.content;
-            // 使用模板的 attrs 作为基础,排除 Directory 类型
+            // 使用模板的 attrs 作为基础,���排除 Directory 类型
             let attrs = templateInfo.data.attrs
               ? JSON.parse(templateInfo.data.attrs).filter(
                   (attr) => attr.type !== "Directory"
@@ -1845,6 +1856,7 @@ export default {
           document.title = `${this.docAttr.title}-${settings.title}`;
         }
         this.uptadeSearch();
+        this.initTemplateSelection();
       } catch (error) {
         console.error("加载模板信息时出错:", error);
         this.$message.error("加载模板信息时出错,请稍后重试");
@@ -1853,7 +1865,20 @@ export default {
       }
     },
     onRemove(index) {
+      const removedComponent = this.coms[index];
+      // 移除组件
       this.coms.splice(index, 1);
+
+      // 如果是从模板创建的组件,更新对应模板的选中状态
+      if (removedComponent.dcb_id) {
+        const template = this.categoryList
+          .flatMap((category) => category.templates || [])
+          .find((t) => t.dcb_id === removedComponent.dcb_id);
+
+        if (template) {
+          this.updateTemplateSelection(template, false);
+        }
+      }
     },
     /* 目录信息 */
     onCatalogIndex(e) {
@@ -1957,6 +1982,7 @@ export default {
           _this.docForm = {
             dcm_title: "",
             dcm_type: "",
+            dcm_category_id: "",
           };
           _this.searchArticle();
         });
@@ -1970,12 +1996,13 @@ export default {
           _this.docForm = {
             dcm_title: "",
             dcm_type: "",
+            dcm_category_id: "",
           };
           _this.searchArticle();
         });
       }
     },
-    /*更  */
+    /*更��  */
     onUpload() {
       let _this = this;
       if (_this.coms.length <= 0) {
@@ -2282,8 +2309,18 @@ export default {
 
     //插入新记录
     insertNew(e) {
-      let _this = this;
-      _this.coms.push(e);
+      this.coms.push(e);
+
+      // 如果是从模板拖拽的,更新模板选中状态
+      if (e.dcb_id) {
+        const template = this.categoryList
+          .flatMap((category) => category.templates || [])
+          .find((t) => t.dcb_id === e.dcb_id);
+
+        if (template) {
+          this.updateTemplateSelection(template, true);
+        }
+      }
     },
 
     //插入分页
@@ -2374,7 +2411,7 @@ export default {
       let _this = this;
       // console.log("insertconstant");
       if (_this.comIndex < 0) {
-        _this.$alert("请选择入图层");
+        _this.$alert("请选择��入图层");
         return false;
       }
       let com = _this.coms[_this.comIndex];
@@ -2595,32 +2632,401 @@ export default {
     },
 
     //获取文档模板列表
-    searchArticle() {
-      let _this = this;
-      pageDocument({
-        page: 1,
-        pageSize: 99,
-        isContentShow: true,
-      }).then((res) => {
-        if (res.status != 200) return;
-        this.articleList = res.data.dataList;
-        /* _this.articleList = res.data.dataList.filter(
-          (el) => el.is_template == 0
-        );
-        _this.templateList = res.data.dataList.filter(
-          (el) => el.is_template == 1
-        ); */
-      });
+    async searchArticle() {
+      try {
+        // 获取文档分类
+        const categoryRes = await searchDocumentCategory({
+          page: 1,
+          pageSize: 999,
+        });
+        if (categoryRes.status !== 200) return;
+
+        // 获取文档列表
+        const documentRes = await pageDocument({
+          page: 1,
+          pageSize: 99,
+          isContentShow: true,
+        });
+        if (documentRes.status !== 200) return;
+
+        // 处理数据为树形结构
+        this.schemeData = categoryRes.data.dataList.map((category) => ({
+          label: category.name,
+          id: category.id,
+          children: documentRes.data.dataList
+            .filter((doc) => doc.dcm_category_id === category.id)
+            .map((doc) => ({
+              label: doc.dcm_title,
+              id: doc.dcm_id,
+              type: "document",
+            })),
+        }));
+
+        // 更新默认展开的节点 - 展开所有分类
+        this.expandedKeys = this.schemeData.map((category) => category.id);
+
+        console.log("Processed schemeData:", this.schemeData);
+      } catch (error) {
+        console.error("Error processing document data:", error);
+        this.$message.error("获取文档数据失败");
+      }
     },
     // 添加模板选择处理方法
-    handleTemplateSelect(category, template, value) {
+    /* handleTemplateSelect(category, template, value) {
       template.selected = value;
       console.log("Selected template:", {
         category: category.name,
-        template: template.name,
+        template: template.dcb_name,
         selected: value,
       });
       // 这里可以添加其他选择逻辑
+    }, */
+    // 检查模板是否已被使用
+    isTemplateUsed(template) {
+      const isUsed = this.coms.some((com) => com.dcb_id === template.dcb_id);
+      if (isUsed) {
+        // 如果模板被使用,设置 selected 为 true
+        template.selected = true;
+
+        // 同步其他分类中相同模板的选中状态
+        this.categoryList.forEach((category) => {
+          const sameTemplate = category.templates?.find(
+            (t) => t.dcb_id === template.dcb_id
+          );
+          if (sameTemplate) {
+            sameTemplate.selected = true;
+          }
+        });
+      }
+      /* return isUsed; */
+    },
+    // 处理模板选择
+    handleTemplateSelect(category, template, isSelected) {
+      // 更新模板选中状态
+      template.selected = isSelected;
+
+      if (isSelected) {
+        // 如果是选中,添加到组件列表
+        /*  const newComponent = {
+          ...template,
+          type: template.dcb_type || "TextArea",
+          lay_id: template.lay_id || "textArea",
+          content: template.dcb_nr || "",
+          attrs:
+            typeof template.dcb_attrs === "string"
+              ? JSON.parse(template.dcb_attrs)
+              : template.dcb_attrs || [],
+        };
+        this.coms.push(newComponent); */
+      } else {
+        // 如果取消选中,从组件列表中移除
+        const index = this.coms.findIndex(
+          (com) => com.dcb_id === template.dcb_id
+        );
+        if (index !== -1) {
+          this.coms.splice(index, 1);
+        }
+      }
+
+      // 同步其他分类中相同模板的选中状态
+      this.categoryList.forEach((cat) => {
+        if (cat.id !== category.id) {
+          const sameTemplate = cat.templates?.find(
+            (t) => t.dcb_id === template.dcb_id
+          );
+          if (sameTemplate) {
+            sameTemplate.selected = isSelected;
+          }
+        }
+      });
+    },
+    // 初始化模板选中状态
+    initTemplateSelection() {
+      // 先重置所有选中状态
+      this.resetAllTemplateSelections();
+
+      // 然后根据已渲染组件更新选中状态
+      this.coms.forEach((com) => {
+        this.categoryList.forEach((category) => {
+          const template = category.templates?.find(
+            (t) => t.dcb_id === com.dcb_id
+          );
+          if (template) {
+            template.selected = true;
+          }
+        });
+      });
+    },
+    // 修改后的 handleDragEnd 方法
+    handleDragEnd(evt) {
+      // 检查是否是克隆操作
+      if (!evt || !evt.item || evt.pullMode !== "clone") {
+        return;
+      }
+
+      // 获取拖拽的数据
+      const draggedData = evt.item.dataset;
+      if (!draggedData) {
+        return;
+      }
+
+      // 从拖拽的DOM元素中获取模板ID
+      const templateId = evt.item.getAttribute("data-template-id");
+      if (!templateId) {
+        return;
+      }
+
+      // 查找对应的模板
+      const draggedTemplate = this.categoryList
+        .flatMap((category) => category.templates || [])
+        .find((template) => template.dcb_id === templateId);
+
+      if (draggedTemplate) {
+        this.updateTemplateSelection(draggedTemplate, true);
+      }
+    },
+
+    // 更新模板选中状态的通用方法
+    updateTemplateSelection(template, isSelected) {
+      // 更新所有分类中相同模板的选中状态
+      this.categoryList.forEach((category) => {
+        const sameTemplate = category.templates?.find(
+          (t) => t.dcb_id === template.dcb_id
+        );
+        if (sameTemplate) {
+          sameTemplate.selected = isSelected;
+        }
+      });
+    },
+    // 添加重置所有模板选中状态的方法
+    resetAllTemplateSelections() {
+      this.categoryList.forEach((category) => {
+        if (category.templates) {
+          category.templates.forEach((template) => {
+            template.selected = false;
+          });
+        }
+      });
+    },
+    // 处理搜索
+    async handleSearch() {
+      if (!this.searchKey.trim()) {
+        return;
+      }
+
+      try {
+        this.loading = true;
+        const res = await pageDocument({
+          page: 1,
+          pageSize: 999,
+          dcm_title: this.searchKey.trim(),
+        });
+
+        if (res.status === 200) {
+          // 更新树形数据
+          const searchResults = res.data.dataList.map((doc) => ({
+            id: doc.dcm_id,
+            label: doc.dcm_title,
+            children: null,
+          }));
+
+          const searchResultNode = {
+            id: "search-result", // 为搜索结果节点添加唯一ID
+            label: "搜索结果",
+            children: searchResults,
+          };
+
+          // 更新树形数据
+          this.schemeData = [
+            searchResultNode,
+            /*  ...this.schemeData.filter(item => item.label !== "搜索结果") */
+          ];
+
+          // 更新需要展开的节点keys
+          this.expandedKeys = [
+            "search-result", // 展开搜索结果分类
+            ...searchResults.map((item) => item.id), // 展开所有搜索结果项
+          ];
+
+          // 强制更新树形组件
+          this.$nextTick(() => {
+            if (this.$refs.documentTree) {
+              this.$refs.documentTree.store.defaultExpandedKeys =
+                this.expandedKeys;
+              this.$refs.documentTree.updateKeyChildren();
+            }
+          });
+
+          // 如果没有搜索结果,显示提示
+          if (searchResults.length === 0) {
+            this.$message.info("未找到匹配的文档");
+          }
+        }
+      } catch (error) {
+        console.error("搜索文档失败:", error);
+        this.$message.error("搜索失败,请重试");
+      } finally {
+        this.loading = false;
+      }
+    },
+
+    // 修改清空处理方法
+    async handleClear() {
+      this.searchKey = "";
+      this.expandedKeys = []; // 清空展开的节点
+      await this.searchArticle();
+
+      // 重置树形组件的展开状态
+      this.$nextTick(() => {
+        if (this.$refs.documentTree) {
+          this.$refs.documentTree.store.defaultExpandedKeys = [];
+          this.$refs.documentTree.updateKeyChildren();
+        }
+      });
+    },
+
+    // 添加搜索处理方法
+    async handleResourceSearch() {
+      /*  const searchKey = this.resourceSearchKey.toLowerCase().trim();
+      
+      // 遍历所有分类
+      this.categoryList.forEach(category => {
+        if (category.templates) {
+          // 过滤模板列表
+          const filteredTemplates = category.templates.filter(template => 
+            template.dcb_name.toLowerCase().includes(searchKey)
+          );
+          
+          // 使用 Vue.set 确保响应式更新
+          this.$set(category, 'templates', filteredTemplates);
+        }
+      }); */
+      if (!this.templateSearchKey.trim()) {
+        return;
+      }
+
+      try {
+        // 调用搜索模板接口
+        const res = await searchTemplate({
+          page: 1,
+          pageSize: 999,
+          dcb_name: this.templateSearchKey.trim(),
+        });
+
+        if (res.status === 200) {
+          // 保存当前分类的原始模板
+          this.originalTemplateList = [...this.categoryList];
+
+          // 处理搜索结果
+          const searchResults = res.data.dataList.map((template) => {
+            // 确保模板数据格式正确
+            if (!template.attrs) {
+              template.attrs = "[]";
+            }
+            try {
+              template.attrs =
+                typeof template.attrs === "string"
+                  ? JSON.parse(template.attrs)
+                  : template.attrs;
+            } catch (error) {
+              console.error("Error parsing template attrs:", error);
+              template.attrs = [];
+            }
+            return template;
+          });
+
+          // 更新分类列表,将搜索结果放在一个特殊分类下
+          this.categoryList = [
+            {
+              id: "search-results",
+              name: "搜索结果",
+              templates: searchResults.map((template) => ({
+                ...template,
+                selected: this.coms.some(
+                  (com) => com.dcb_id === template.dcb_id
+                ),
+              })),
+            },
+          ];
+        }
+      } catch (error) {
+        console.error("搜索模板失败:", error);
+        this.$message.error("搜索失败,请重试");
+      }
+    },
+
+    // 添加清除搜索处理方法
+    handleResourceClear() {
+      // 重置搜索并恢复原始列表
+      this.resourceSearchKey = "";
+      this.initCategoryList();
+    },
+    // 处理模板搜索
+    async handleTemplateSearch() {
+     /*  if (!this.templateSearchKey.trim()) {
+        return;
+      } */
+      console.log(12);
+      try {
+        // 调用搜索模板接口
+        const res = await searchTemplate({
+          page: 1,
+          pageSize: 999,
+          dcb_name: this.templateSearchKey.trim(),
+        });
+
+        if (res.status === 200) {
+          // 保存当前分类的原始模板
+          this.originalTemplateList = [...this.categoryList];
+
+          // 处理搜索结果
+          const searchResults = res.data.dataList.map((template) => {
+            // 确保模板数据格式正确
+            if (!template.attrs) {
+              template.attrs = "[]";
+            }
+            try {
+              template.attrs =
+                typeof template.attrs === "string"
+                  ? JSON.parse(template.attrs)
+                  : template.attrs;
+            } catch (error) {
+              console.error("Error parsing template attrs:", error);
+              template.attrs = [];
+            }
+            return template;
+          });
+
+          // 更新分类列表,将搜索结果放在一个特殊分类下
+          this.categoryList = [
+            {
+              id: "search-results",
+              name: "搜索结果",
+              templates: searchResults.map((template) => ({
+                ...template,
+                selected: this.coms.some(
+                  (com) => com.dcb_id === template.dcb_id
+                ),
+              })),
+            },
+          ];
+        }
+      } catch (error) {
+        console.error("搜索模板失败:", error);
+        this.$message.error("搜索失败,请重试");
+      }
+    },
+
+    // 清空搜索
+    async handleTemplateClear() {
+      this.templateSearchKey = "";
+      // 如果有保存的原始列表,恢复它
+      if (this.originalTemplateList.length > 0) {
+        this.categoryList = [...this.originalTemplateList];
+      } else {
+        // 否则重新初始化分类列表
+        await this.initCategoryList();
+      }
     },
   },
 };
@@ -2708,4 +3114,15 @@ export default {
     }
   }
 }
+
+.template-content {
+  .search-box {
+    padding: 10px;
+    border-bottom: 1px solid #ebeef5;
+
+    .el-input {
+      width: 300px;
+    }
+  }
+}
 </style>