# -*- encoding=utf8 -*-

__author__ = "xiaohesheng"

"""
case_tag:api,herp-web,a_b3_手工采购计划_混合产品_提交,id2297,id2297-13,sit,on
内网:a_b3_手工采购计划_混合产品_提交 
"""

from common.common_func import commonFuc
from air_case.b1_herp3_login.登录内网系统.登录内网系统 import login_system
from airtest.core.api import using
import sys


def test1():
    module = "b3_herp3_purchase"
    """
     场景:a_b3_手工采购计划_混合产品_提交
     用例名称：a_b3_手工采购计划_混合产品_提交
     输入：无
     输出："rtn_msg": {"code": 0, "msg": null,    "data": true}
    """
    # 内网登录
    username = commonFuc().get_business_data(module, "username")
    # print('医院名称',username)
    password = commonFuc().get_business_data(module, "password")
    # print(username, password,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
    # 获取token和projectCode
    token, projectCode, uxid, corpId, info = login_system(username, password).get_token()
    # print( token,projectCode,uxid,corpId,info)
    # 获取暂存的单号
    pro_path = commonFuc().get_pro_path()
    sys.path.append(pro_path + r'\\air_case\\b3_herp3_purchase\\a_a9_手工采购计划_混合明细产品_暂存.air')
    using(pro_path + r'\\air_case\\b3_herp3_purchase\\a_a9_手工采购计划_混合明细产品_暂存.air')
    from a_a9_手工采购计划_混合明细产品_暂存 import test1
    pid = test1()

    # 获取采购计划详情中的id
    url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "herpService_purPlan_listVo_url")
    print(url)
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))
    print('headers', headers)
    # # 请求体
    request_body = commonFuc().get_business_data(module, "payload11", pid)

    # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('resultaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', result)
    data = commonFuc().analysis_json('data', result)
    id1 = commonFuc().analysis_json('id', data[0])
    id2= commonFuc().analysis_json('id', data[1])
    id3= commonFuc().analysis_json('id', data[2])
    # =====================================

    url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "herpService_purPlan_submitPurPlan_url")
    print(url)
    # 获取请求头信息
    headers = commonFuc().get_business_data(module, "json_headers2",
                                            commonFuc().get_business_data(module, "json_contentType"), token,
                                            commonFuc().get_business_data(module, "X-APP-CODE"))
    print('headers', headers)
    # # 请求体
    request_body = commonFuc().get_business_data(module, "payload15", pid, id1,id2,id3)
    # 发送请求
    result = commonFuc().http_post(url, request_body, headers)
    print('resultbbbbbbbbbbbbbbbbbbbb', result)
    # 断言
    code = commonFuc().analysis_json('code', result)
    data = commonFuc().analysis_json('data', result)
    if code == 0 and data == None:
        commonFuc().check_text_exist(0, result)
    else:
        commonFuc().check_text_exist('error', result)


test1()
