瀏覽代碼

代码同步

yukai 1 年之前
父節點
當前提交
bec178f13f
共有 2 個文件被更改,包括 37 次插入20 次删除
  1. 36 15
      src/views/iot/property/dossier/edit.vue
  2. 1 5
      src/views/iot/property/dossier/index.vue

+ 36 - 15
src/views/iot/property/dossier/edit.vue

@@ -85,10 +85,7 @@
 			</el-row>
 
     <el-divider content-position="left">自定义属性</el-divider>
-
 			<FromData :Datalist="Datalist" @SetSaveData="SetSaveData"></FromData>
-
-
 		</el-form>
 
 
@@ -131,13 +128,15 @@ const baseForm = {
 	deviceCategory: '',
 	installTime: '',
 	deptId: '',
-	data:[],
+	data:'',
 
 };
 
 
 const SetSaveData = (data:any) => {
-	formData.data=data;
+	const jsonArray = [data];
+	const jsonString = JSON.stringify(jsonArray);
+	formData.data=jsonString;
 }
 
 const formData = reactive({
@@ -176,33 +175,55 @@ const resetForm = async () => {
 	formRef.value && formRef.value.resetFields();
 };
 
+	const getIdByKey=(key:string) =>{
+			for (let i = 0; i < productData.value.length; i++) {
+				if (productData.value[i].key === key) {
+					return productData.value[i].id;
+				}
+			}
+			return null; // 如果没有找到匹配的key,则返回null(或者其他合适的值)
+		}
+
 const open = async (row: any,productInfo:any) => {
 	resetForm();
 	showDialog.value = true;		
 	nextTick(() => {
-		Object.assign(formData, { ...row });
+
 		system.org.getList({ status: 1 }).then((res: any) => {
 			orgData.value = res || [];
 		});
 		//获取 所有的产品
 		api.product.getLists({}).then((res: any) => {
 			productData.value = res.product;
+			if(row.id){
+				productInfo={
+					id:getIdByKey(row.productKey),
+					key:row.productKey,
+				}
+			
+			}
+			//根据产品ID获取设备列表
+			api.device.allList({ productId: productInfo.id }).then((res: any) => {
+				deviceList.value = res.device || [];
+			});
+				api.dev_asset_metadata.getList({ productKey: productInfo.key,pageSize:50,pageNum:1,status:-1,total:0 }).then((res: any) => {
+        Datalist.value = res.Data || [];
+      });
+
+			//获取档案属性
 		})
-		//根据产品ID获取设备列表
-		api.device.allList({ productId: productInfo.id }).then((res: any) => {
-			deviceList.value = res.device || [];
-		});
+
+		
 		//获取部门
 		api.dept.getList({ status: -1 }).then((res: any) => {
         deptData.value = res || [];
       });
 
-			api.dev_asset_metadata.getList({ productKey: productInfo.key,pageSize:50,pageNum:1,status:-1,total:0 }).then((res: any) => {
-        Datalist.value = res.Data || [];
-      });
-
-			//获取档案属性
+		console.log(row);
+		Object.assign(formData, { ...row });
 		formData.productKey=productInfo.key
+
+
 	});
 };
 

+ 1 - 5
src/views/iot/property/dossier/index.vue

@@ -96,14 +96,12 @@ interface Tree {
 	children?: Tree[]
 }
 import { ref, onMounted } from 'vue'
-import { useRouter } from 'vue-router'
 const defaultProps = {
 	children: 'children',
 	label: 'label',
 }
 
 const queryRef = ref()
-const router = useRouter()
 const productData = ref([])
 const mergedData = ref()
 const cateData = ref()
@@ -112,9 +110,7 @@ const productIno = ref()
 
 const { params, tableData, getList, loading } = useSearch<any[]>(device.dev_asset.getList, 'Data', { keyWord: '' })
 getList()
-const toDetail = (id: number) => {
-	router.push(`/device/dossier/manage/${id}`)
-}
+
 onMounted(() => {
 	getCateList()
 })