import { GET_ASSET_SUB_LIST_API, GET_ASSET_MAIN_LIST_API, DELETE_ASSET_SUB_LIST_API, POST_ASSET_SUB_LIST_API, GET_ASSET_LIST_API, GET_ASSET_SINGLE_API, GET_ASSET_FLOOR_LIST_API, POST_ASSET_FLOOR_API, DELETE_ASSET_FLOOR_API, GET_ASSET_IOT_LIST_API, DELETE_ASSET_ITEM_API, POST_ASSET_SINGLE_API, GET_ASSET_SUB_POINT_API, } from "./api"; import instance from "@/util/request"; import apihandler from "@/util/apihandler"; import { object } from "yup"; export const getAssetSubList = async () => { const res = await instance.post(GET_ASSET_SUB_LIST_API); return apihandler(res.code, res.data, { msg: res.msg, code: res.code, }); }; export const getAssetMainList = async () => { const res = await instance.post(GET_ASSET_MAIN_LIST_API); return apihandler(res.code, res.data, { msg: res.msg, code: res.code, }); }; export const postAssetSubList = async ({ system_key, system_value, system_parent_id, id, }) => { const res = await instance.post(POST_ASSET_SUB_LIST_API, { system_key, system_value, system_parent_id, id, }); return apihandler(res.code, res.data, { msg: res.msg, code: res.code, }); }; export const deleteAssetSubItem = async (id) => { const res = await instance.post(DELETE_ASSET_SUB_LIST_API, { id }); return apihandler(res.code, res.data, { msg: res.msg, code: res.code, }); }; export const getAssetList = async (variable_id) => { const res = await instance.post(GET_ASSET_LIST_API, { variable_id: parseInt(variable_id), }); return apihandler(res.code, res.data, { msg: res.msg, code: res.code, }); }; export const getAssetSingle = async (main_id) => { const res = await instance.post(GET_ASSET_SINGLE_API, { main_id }); return apihandler(res.code, res.data, { msg: res.msg, code: res.code, }); }; export const postAssetSingle = async (data) => { let formData = new FormData(); for (let [key, value] of Object.entries(data)) { console.log(key, value); if (Array.isArray(value)) { if (key === "oriFile") { value.forEach((element, index) => { formData.append(`${key}[${index}].file`, element.id ? null : element); formData.append(`${key}[${index}].orgName`, element.name); formData.append( `${key}[${index}].saveName`, element.id ? element.saveName : "" ); }); } else { value.forEach((element, index) => { formData.append(`sub_device[${index}].device_number`, element.device_number); formData.append(`sub_device[${index}].points`, element.points); }); } } else { if (key === "device_number" && value === "") { formData.append(key, "0"); } else { formData.append(key, value); } } } const res = await instance.post(POST_ASSET_SINGLE_API, formData); return apihandler(res.code, res.data, { msg: res.msg, code: res.code }); }; export const deleteAssetItem = async (main_id) => { const res = await instance.post(DELETE_ASSET_ITEM_API, { main_id }); return apihandler(res.code, res.data, { msg: res.msg, code: res.code, }); }; export const getAssetFloorList = async () => { const res = await instance.post(GET_ASSET_FLOOR_LIST_API); return apihandler(res.code, res.data, { msg: res.msg, code: res.code, }); }; export const postAssetFloor = async (formData) => { const res = await instance.post(POST_ASSET_FLOOR_API, formData); return apihandler(res.code, res.data, { msg: res.msg, code: res.code, }); }; export const deleteAssetFloor = async (formData) => { const res = await instance.post(DELETE_ASSET_FLOOR_API, formData); return apihandler(res.code, res.data, { msg: res.msg, code: res.code, }); }; export const getAssetIOTList = async (sub_system_tag, points) => { const res = await instance.post(GET_ASSET_IOT_LIST_API, { sub_system_tag, points, }); return apihandler(res.code, res.data, { msg: res.msg, code: res.code, }); }; export const getAssetSubPoint = async (sub_system_tag) => { const res = await instance.post(GET_ASSET_SUB_POINT_API, { sub_system_tag, }); return apihandler(res.code, res.data, { msg: res.msg, code: res.code, }); };