let system = require("../../../system")
const http = require("http")
const querystring = require('querystring');
let settings = require("../../../../config/settings");
const CtlBase = require("../../ctl.base");
const logCtl = system.getObject("web.common.oplogCtl");
// const tmtransactionPath = "/api/action/tmQuery/springBoard";
// const tmurl = settings.channelApiUrl() + tmtransactionPath;
//标源检索
class searchCtl extends CtlBase {
    constructor() {
        super("trademark", "trademarkSve");
        this.execClient = system.getObject("util.execClient");
    }

    /**
     * @api {post} /web/trademark/searchCtl/findAndCountAll 检索列表
     * @apiGroup 标源检索
     * @apiParamExample {json} 请求参数
     * {"pageInfo": {"pageNo":1,"pageSize":10}}
     * @apiSuccessExample {json} 成功示例:
     * {"success": ""}
     * @apiErrorExample {json} 失败示例:
     * {"error": ""}
     */
    async findAndCountAll(p, q, req) {
        let query = {
            "actionType": "",
            "actionBody": {
                pageSize: p.pageInfo.pageSize,
                currentPage: p.pageInfo.pageNo,
                "tmName": "",//商标名称
                "regMan": "",
                "regNum": "",
                "sqlbtabkey": "",//商标类别
                "flzttabkey": "",//法律状态
                "sqnftabkey": "",//申请年份
                "ncl": [],//尼斯大类
                "xcl": [],//尼斯群组
                "nclNum": [],//尼斯大类
            }
        };
        var tmurl = settings.channelApiUrl();
        if (Object.keys(p.search).length > 0) {
            if (p.search.sbzch) {//注册号查询
                // query.actionType = "findTrademarkzchAccurate";
                tmurl = tmurl + "/api/trademark/tmqueryApi/findTrademarkzchAccurate";
                query.actionBody.regNum = p.search.sbzch
            } else if (p.search.zcren) {//申请人查询
                // query.actionType = "findTrademarkzcr";
                tmurl = tmurl + "/api/trademark/tmqueryApi/findTrademarkzcr";
                query.actionBody.regMan = p.search.zcren
            } else if (p.search.sbmc) {//商标名称查询
                // query.actionType = "findTrademarkNameAccurate";
                tmurl = tmurl + "/api/trademark/tmqueryApi/findTrademarkNameAccurate";
                query.actionBody.tmName = p.search.sbmc
            }
        } else {
            console.log("===============search====search=======>");
            return;
        }
        // let tokenInfo = await this.service.getToken();
        // console.log("==========================>",tokenInfo)
        // console.log("==========================>",tokenInfo.data.token)
        try {
            let rtn = await this.execClient.execPostTK(query.actionBody, tmurl, "");
            console.log(rtn, "============rtn==============>");
            let data = rtn.data;
            let published = await this.service.findAll({ company_id: p.company_id });
            data.rows.forEach(item => {
                for (let t of published) {
                    if (t.tm_code == item.sbzch)
                        item._disabled = true;
                }
            });
            return system.getResultList(data.count, data.rows)
        } catch (e) {
            console.log("=======================>", e)
        }

    }
}

module.exports = searchCtl;

