---
name: "batchSaveConsumeBudget"
mode: "api"
versionRequirements:
  - { name: "@tuya-miniapp/cloud-api", version: "1.3.0" }
---

## batchSaveConsumeBudget

> [VERSION] @tuya-miniapp/cloud-api >= 1.3.0

> 💡 接口依赖云能力，需在[小程序开发者平台](https://platform.tuya.com/miniapp/)开发设置 - 云能力进行授权配置。使用本接口前，请确保设备所属产品已在[涂鸦 IoT 开发平台](https://iot.tuya.com/)开启**电量统计**高级能力。未启用该能力的产品无法采集电量/电费数据，接口将返回空数据或报错。如需使用，请创建带有电量/电费统计功能的产品，并在产品详情中启用相应高级能力。

### 描述

批量保存设备电量预算。支持一次性更新多个时间维度（日、周、月）的用电量预算配置，不传的维度不会被重置。

### 参数

`Params`

| 参数 | 类型 | 必填 | 描述 |
| --- | --- | --- | --- |
| `params` | `BatchSaveConsumeBudgetParams` | 是 | 请求参数 |

### 返回值

类型: `Promise<boolean>`

是否保存成功

### 引用对象

##### `interface` BatchSaveConsumeBudgetParams

| 属性 | 类型 | 描述 |
| --- | --- | --- |
| `devId` | `string` | 设备 ID |
| `budgetConfig` | `BudgetConfigItem[]` | 预算项列表，支持多个时间维度同时更新 |

##### `enum` BudgetDataType

| 枚举值 | 实际值 | 描述 |
| --- | --- | --- |
| `BudgetDataType.Day` | `day` | 按天 |
| `BudgetDataType.Week` | `week` | 按周 |
| `BudgetDataType.Month` | `month` | 按月 |

##### `type` BudgetConfigItem

| 属性 | 类型 | 描述 |
| --- | --- | --- |
| `dateType` | `"BudgetDataType.Day" \\| "BudgetDataType.Week" \\| "BudgetDataType.Month"` | 预算时间维度，推荐使用 `BudgetDataType` 枚举 |
| `budget` | `string` | 预算值，字符串数值，保留整数或一位小数 |


### 示例代码

#### 请求示例

```javascript
import { batchSaveConsumeBudget, BudgetDataType } from '@tuya-miniapp/cloud-api';

batchSaveConsumeBudget({
  devId: 'vdevo123',
  budgetConfig: [
    { dateType: BudgetDataType.Day, budget: '5' },
    { dateType: BudgetDataType.Week, budget: '20' },
    { dateType: BudgetDataType.Month, budget: '80' },
  ],
})
  .then(result => {
    console.log('电量预算保存成功:', result);
  })
  .catch(error => {
    console.error('电量预算保存失败:', error);
  });
```

#### 返回示例

```json
true
```


### 常见问题

#### 为什么调用云能力会出现失败的情况？

使用本接口前，请确保设备所属产品已在[涂鸦 IoT 开发平台](https://iot.tuya.com/)开启**电量统计**高级能力。未启用该能力的产品无法采集电量/电费数据，接口将返回空数据或报错。如需使用，请创建带有电量/电费统计功能的产品，并在产品详情中启用相应高级能力。同时，接口依赖云能力，需在[小程序开发者平台](https://platform.tuya.com/miniapp/)`开发设置` - `云能力`进行授权配置。
