'use strict';

/**
 * cld接口模型
 *
 * @author EllisRan.
 * @date 2018/9/25
 * @version
 */

import Request from "request";
import BaseModel from "../../common/base/base_model";

class CLDModel extends BaseModel {

    CLDUrl = 'http://cld.smartcost.com.cn';

    /**
     * 获取办事处人员信息
     *
     * @param cid
     * @return {Promise}
     */
    async getCategoryStaff(cid) {
        let postData = {
            url: this.CLDUrl + '/api/building/category/staff/' + cid,
            encoding: 'utf8'
        };
        return new Promise(function (resolve, reject) {
            try {
                // 请求接口
                Request.post(postData, function (err, postResponse, body) {
                    if (err) {
                        throw '请求错误';
                    }
                    if (postResponse.statusCode !== 200) {
                        throw 'CLD通讯失败！';
                    }
                    resolve(body);
                });
            } catch (error) {
                reject([]);
            }
        });
    }
}

export default CLDModel;