from testcase.test_scene1.scene1_mainflow import *

SIT_URL = 'http://scdev.cmic.com.cn:8088/beta/'#SIT环境地址
#通行证
usr1,pwd1 = 'bj_01','Gyxc1234'
usr2,pwd2 = 'bj_02','Gyxc1234'
usr3,pwd3 = 'bj_03','Gyxc1234'
usr4,pwd4 = 'bj_04','Gyxc1234'
usr5,pwd5 = 'bj_05','Gyxc1234'
lendin= '103503'#借入仓库名称
lendout= '103396'#借出仓库名称
salesman = '杨春刚'#业务员名称
custname = '北京大学第三医院'#客户名称
productcode = 10005528#商品编码


ARRIVAL_TEMP = 24 #到货温度
ARRIVAL_DATE = '2023-10-01'#到货日期
ARRIVAL_TIME = '00:00:00'#到货时间
STASHIP_TEMP = 24 #启运温度
STASHIP_DATE = '2023-11-01' #启运日期
STASHIP_TIME = '00:00:00'#启运时间
TRANS_MACHINE = '冷冻车'#运输工具
surgicaldate = '2023-11-30'#手术日期
contractnumber = 40536#合同号


errmsg6 = '流程六：手术跟台及消耗结算流程异常，请检查！'#流程异常提示信息

class SurgicalOrder():
    def data_add_surgical(self):
        ###打开手术请领单###
        wait.until(ec.presence_of_element_located((By.XPATH, '//span[text()="手术请领单"]')))
        sleep(0.5)
        order_link = chrome.find_element_by_xpath('//span[text()="手术请领单"]')
        chrome.execute_script("arguments[0].click();", order_link)
        chrome.switch_to.frame(chrome.find_element_by_xpath('(//iframe[@class="metro-main-frame"])[2]'))
        sleep(0.5)
        # 点击新建按钮
        wait.until(ec.visibility_of_element_located((By.XPATH, '//span[text()="新建"]')))
        sleep(0.5)
        chrome.find_element_by_xpath('//span[text()="新建"]').click()
        sleep(4)
        chrome.switch_to.frame(chrome.find_element_by_xpath('//iframe[contains(@name,"awsui-dialog-iframe")]'))
        sleep(2)

        ###获取订单号###
        global orderno1
        wait.until(ec.presence_of_element_located((By.XPATH,'//div[text() = "请领单号 "]/following-sibling::div/span')))
        sleep(0.5)
        orderno1 = chrome.find_element_by_xpath('//div[text() = "请领单号 "]/following-sibling::div/span').text
        print('手术请领单号为:', orderno1)

        # 点击业务员名称并输入查询条件，查询出结果
        chrome.find_element_by_xpath(
            '//div[text()="业务员名称 "]/following-sibling::div/div/div/div/div/div/div/div/span/span/i').click()
        sleep(1)
        chrome.find_element_by_xpath(
            '//input[@placeholder="模糊检索:员工编码,员工名称,部门编码,部门名称"]').send_keys(salesman)
        sleep(1)
        chrome.find_element_by_xpath(
            '//input[@placeholder="模糊检索:员工编码,员工名称,部门编码,部门名称"]').send_keys(Keys.ENTER)
        sleep(1)
        # 勾选查询出的业务员并点击确定按钮
        btn_div = chrome.find_element_by_xpath(
            '//span/input[@type="radio" and @value="00d92dd7f280359138c1db7ae026525cd"]')
        chrome.execute_script("arguments[0].click();", btn_div)
        sleep(1)
        chrome.find_element_by_xpath('(//span[@class="ensureBtn"]/button[1])').click()
        sleep(1)

        # 手术类型
        chrome.find_element_by_xpath('(//input[@placeholder="请选择" and @type="text"])').click()
        sleep(1)
        chrome.find_element_by_xpath('//li[text()="初次髋"]').click()
        sleep(1)
        # 手术种类
        chrome.find_element_by_xpath('(//input[@placeholder="请选择" and @type="text"])[2]').click()
        sleep(1)
        chrome.find_element_by_xpath('//li[text()="髋关节"]').click()
        sleep(1)
        #手术日期
        chrome.find_element_by_xpath('//label[text()="手术日期 "]/following-sibling::div/div').click()
        sleep(1)
        chrome.find_element_by_xpath('//div[ @class ="el-date-table-cell"] // span[text()="31"]').click()
        sleep(1)

        #客户信息页签
        chrome.find_element_by_xpath('//div[text()="客户信息"]').click()
        #填写客户名称
        chrome.find_element_by_xpath('//div[text()="客户名称 "]/following-sibling::div/div/div/div/div/div/div/div/span/span/i').click()
        wait.until(ec.visibility_of_element_located((By.XPATH,'//input[@placeholder="模糊检索:客户编码,客户名称"]')))
        sleep(1)
        chrome.find_element_by_xpath('//input[@placeholder="模糊检索:客户编码,客户名称"]').send_keys(custname)
        sleep(1)
        chrome.find_element_by_xpath('//input[@placeholder="模糊检索:客户编码,客户名称"]').send_keys(Keys.ENTER)
        sleep(1)
        btn_div= chrome.find_element_by_xpath('//span/input[@type="radio" and @value="04bb72d56ca59576d0c205f2509d66836"]')
        chrome.execute_script("arguments[0].click();", btn_div)
        chrome.find_element_by_xpath('(//button[@class="el-button el-button--primary el-button--default"])[2]').click()
        sleep(1)

        #填写配销客户名称
        chrome.find_element_by_xpath(
            '//div[text()="配销客户名称 "]/following-sibling::div/div/div/div/div/div/div/div/span/span/i').click()
        wait.until(ec.visibility_of_element_located((By.XPATH, '//input[@placeholder="模糊检索:客户编码,客商名称"]')))
        sleep(1)
        chrome.find_element_by_xpath('//input[@placeholder="模糊检索:客户编码,客商名称"]').send_keys(custname)
        sleep(1)
        chrome.find_element_by_xpath('//input[@placeholder="模糊检索:客户编码,客商名称"]').send_keys(Keys.ENTER)
        sleep(1)
        btn_div = chrome.find_element_by_xpath(
            '//span/input[@type="radio" and @value="0c4d395678c596b20aa6c2a2fef3483d4"]')
        chrome.execute_script("arguments[0].click();", btn_div)
        chrome.find_element_by_xpath('(//button[@class="el-button el-button--primary el-button--default"])[2]').click()
        sleep(1)

        ###仓库信息页###
        chrome.find_element_by_xpath('//div[text()="仓库信息"]').click()
        sleep(1)
        #借入仓库名称
        chrome.find_element_by_xpath(
            '//div[text()="借入仓库名称 "]/following-sibling::div/div/div/div/div/div/div/div/span/span/i').click()
        # wait.until(ec.visibility_of_element_located((By.XPATH, '//input[@placeholder="模糊检索:仓库编码,仓库名称"]')))
        sleep(0.5)
        chrome.find_element_by_xpath('//input[@placeholder="模糊检索:仓库编码,仓库名称"]').send_keys(lendin)
        sleep(0.5)
        chrome.find_element_by_xpath('//input[@placeholder="模糊检索:仓库编码,仓库名称"]').send_keys(Keys.ENTER)
        sleep(1)
        btn_div = chrome.find_element_by_xpath(
            '//span/input[@type="radio" and @value="0eb35527d7e9703e44ad78fe510d37655"]')
        chrome.execute_script("arguments[0].click();", btn_div)
        chrome.find_element_by_xpath('(//button[@class="el-button el-button--primary el-button--default"])[2]').click()
        sleep(1)

        #借出仓库名称
        chrome.find_element_by_xpath(
            '//div[text()="借出仓库名称 "]/following-sibling::div/div/div/div/div/div/div/div/span/span/i').click()
        wait.until(ec.visibility_of_element_located((By.XPATH, '//input[@placeholder="模糊检索:仓库编码,仓库名称"]')))
        sleep(0.5)
        chrome.find_element_by_xpath('//input[@placeholder="模糊检索:仓库编码,仓库名称"]').send_keys(lendout)
        sleep(0.5)
        chrome.find_element_by_xpath('//input[@placeholder="模糊检索:仓库编码,仓库名称"]').send_keys(Keys.ENTER)
        sleep(0.5)
        btn_div = chrome.find_element_by_xpath(
            '//span/input[@type="radio" and @value="039a767b6a105e150f2369bb98aae2f68"]')
        chrome.execute_script("arguments[0].click();", btn_div)
        chrome.find_element_by_xpath('(//button[@class="el-button el-button--primary el-button--default"])[2]').click()
        sleep(1)

        ###子表信息录入###
        chrome.find_element_by_xpath('//div[text()="主体信息"]').click()
        sleep(1)
        # 点击添加商品并输入商品编码，查询出结果
        chrome.find_element_by_xpath('//span[text()="添加商品"]').click()
        sleep(1)
        chrome.find_element_by_xpath('//input[@placeholder="模糊检索:商品编码,商品名称"]').send_keys(productcode)
        sleep(0.5)
        chrome.find_element_by_xpath('//input[@placeholder="模糊检索:商品编码,商品名称"]').send_keys(Keys.ENTER)
        sleep(2)
        # 勾选查询出的商品并点击确定按钮
        chrome.find_element_by_xpath(
            '//th[@class="el-table_21_column_185 multiple-column el-table-column--selection is-leaf headerCellClassName el-table__cell"]/div/label/span/span').click()
        sleep(0.5)
        chrome.find_element_by_xpath('(//div[@class="el-dialog__body"]/div[2]/span/button[1]/span)[6]').click()
        sleep(3)

        ###填写数量价格###
        for i in range(1):
            wait.until(ec.visibility_of_element_located(
                (By.XPATH, '(//td[@colid="col_79" and @f="F_SALES_VOLUMES" and @i=%s])' % i)))
            # 定位数量框并输入数量
            sleep(0.5)
            element = chrome.find_element_by_xpath('(//td[@colid="col_79" and @f="F_SALES_VOLUMES" and @i=%s])' % i)
            chrome.execute_script("arguments[0].click();", element)
            sleep(1)
            chrome.find_element_by_class_name('awsui-input-number-right').send_keys('1')
            sleep(1)
            # 点击其它地方让数量框失焦，让数量真正填入数量框(平台设计如此，不用纠结为啥要此步)
            chrome.find_element_by_xpath('(//td[@colid="col_84" and @f="F_SALEUNIT_CODE" and @i=%s])' % i).click()
            sleep(1)

    def return_qltorder(self):  # 返回采购单号
        return orderno1

class SurgicalDispensing(PurchaseOrder):#配货单
    def dispensing(self,orderno):
        #打开菜单并进入表单视图
        PurchaseOrder.query_click(self,menu_name='手术配货单',orderno=orderno,el='vxe-body--column col_19 col--center col--ellipsis dw-click-cell',qrcond='请领单号')
        #自动配货
        wait.until(ec.visibility_of_element_located((By.XPATH,'//button[text()="自动配货"]')))
        sleep(0.5)
        chrome.find_element_by_xpath('//button[text()="自动配货"]').click()
        wait.until(ec.presence_of_element_located((By.XPATH,'//span[text()="分配批次"]')))
        sleep(1)
        #分配批次
        chrome.find_element_by_xpath('//span[text()="分配批次"]').click()
        wait.until(ec.visibility_of_element_located((By.XPATH,'//p[text()="分配完成"]')))
        sleep(1)
        #提交
        chrome.find_element_by_xpath('//span[text()="提交"]').click()
        sleep(2)
        chrome.find_element_by_xpath('(//span[text()="确定"])[2]').click()
        wait.until(ec.visibility_of_element_located((By.XPATH,'//p[text()="流程结束"]')))
        PurchaseOrder.closetab(self)
        print('手术请领单配货完成')

class SurgicalLending(PurchaseOrder):#手术借出单
    def lending(self,orderno):
        # 打开菜单并进入表单视图
        PurchaseOrder.query_click(self, menu_name='手术借出单', orderno=orderno,
                                  el='vxe-body--column col_19 col--center col--ellipsis dw-click-cell',
                                  qrcond='请领单号')
        ###获取订单号###
        global orderno2
        wait.until(
            ec.presence_of_element_located((By.XPATH, '//div[text() = "借出单号 "]/following-sibling::div/span')))
        sleep(0.5)
        orderno2 = chrome.find_element_by_xpath('//div[text() = "借出单号 "]/following-sibling::div/span').text
        print('手术借出单号为:', orderno2)

        # 提交订单
        wait.until(ec.visibility_of_element_located((By.XPATH,'//span[text()="提交"]')))
        sleep(0.5)
        chrome.find_element_by_xpath('//span[text()="提交"]').click()
        sleep(2)
        #确定提交
        chrome.find_element_by_xpath('(//span[text()="确定"])[4]').click()
        sleep(2)
        chrome.find_element_by_xpath('(//span[text()="确定"])[4]').click()
        wait.until(ec.presence_of_element_located((By.XPATH, '//p[text()="办理成功"]')))
        PurchaseOrder.closetab(self)
        print('手术借出单提交成功')
    def return_jctorder(self):
        return orderno2

    def button_click2(self,type=1,msg1='流程结束'):#审批/驳回订单：type=1为审批/其余为驳回订单
        wait.until(ec.visibility_of_element_located((By.XPATH, '//span[text()="审核通过"]')))
        sleep(1)
        if type == 1:#审核流程
            #点击审核通过
            chrome.find_element_by_xpath('//span[text()="审核通过"]').click()
            #点击确定按钮
            # wait.until(ec.presence_of_element_located((By.XPATH,'//span[text()="确定"]')))
            # sleep(0.5)
            # chrome.find_element_by_xpath('//span[text()="确定"]').click()

            locator = (By.XPATH, '//textarea[@placeholder="意见留言"]')
            wait.until(ec.presence_of_element_located(locator))
            sleep(0.5)
            #填写审核通过信息
            chrome.find_element_by_xpath('//textarea[@placeholder="意见留言"]').send_keys('审核通过')
            sleep(0.5)
            #点击发送按钮
            chrome.find_element_by_xpath('//span[text()="发送"]').click()
            #判断审核成功
            locator = (By.XPATH, '//p[text()="%s"]'%msg1)
            wait.until(ec.presence_of_element_located(locator))
            print('订单审核成功')
        else:#驳回流程
            #点击驳回
            chrome.find_element_by_xpath('//span[text()="审核驳回"]').click()
            locator = (By.XPATH, '//textarea[@placeholder="意见留言"]')
            wait.until(ec.presence_of_element_located(locator))
            sleep(0.5)
            #填写驳回信息
            chrome.find_element_by_xpath('//textarea[@placeholder="意见留言"]').send_keys('审核驳回')
            sleep(0.5)
            #点击发送
            chrome.find_element_by_xpath('//span[text()="发送"]').click()
            #判断驳回成功
            locator = (By.XPATH, '//p[text()="发送成功"]')
            wait.until(ec.presence_of_element_located(locator))
            print('订单驳回成功')
        self.closetab()

class Outstore1(PurchaseOrder):  # 出库三步曲
    def outbound_review1(self,orderno,type=2):#出库复核
        # 调用query_click进入表单视图
        PurchaseOrder.query_click(self,'出库复核',orderno,'vxe-body--column col_19 col--left col--ellipsis dw-click-cell')
        sleep(2)
        wait.until(ec.visibility_of_element_located((By.XPATH, '(//td[@colid="col_105" and @f="F_8VDB5FTL" and @i=0])')))
        sleep(0.5)
        #填写商品信息
        for i in range(1):
            chrome.execute_script(
                "document.getElementsByClassName('vxe-table--footer-wrapper body--wrapper')[0].scrollLeft = 1000")
            sleep(1)
            wait.until(ec.visibility_of_element_located((By.XPATH,'(//td[@colid="col_117" and @f="F_RECHECK_NUM" and @i=%s])'%i)))
            chrome.find_element_by_xpath('(//td[@colid="col_117" and @f="F_RECHECK_NUM" and @i=%s])'%i).click()
            sleep(0.5)
            chrome.find_element_by_class_name('awsui-input-number-right').send_keys('1')
            sleep(1)
            chrome.find_element_by_xpath('(//td[@colid="col_119" and @f="F_DIF_NUM" and @i=%s])'%i).click()
            sleep(1)

            chrome.execute_script(
                "document.getElementsByClassName('vxe-table--body-wrapper body--wrapper')[0].scrollLeft = 3400")
            sleep(1)
            # 填写到货温度
            chrome.find_element_by_xpath('(//td[@colid="col_135" and @f="F_ARRIVAL_TEMP" and @i=%s])' % i).click()
            sleep(0.5)
            chrome.find_element_by_class_name('awsui-input-number-right').send_keys(ARRIVAL_TEMP)
            sleep(0.5)

            # 填写到货日期
            chrome.find_element_by_xpath('(//td[@colid="col_136" and @f="F_ARRIVAL_DATE" and @i=%s])' % i).click()
            sleep(0.5)
            chrome.find_element_by_class_name('el-input__inner').send_keys(ARRIVAL_DATE)
            sleep(0.5)

            # 填写到货时间
            chrome.find_element_by_xpath('(//td[@colid="col_137" and @f="F_ARRIVAL_TIME" and @i=%s])' % i).click()
            sleep(0.5)
            chrome.find_element_by_class_name('el-input__inner').send_keys(ARRIVAL_TIME)
            sleep(0.5)

            # 填写启运温度
            chrome.find_element_by_xpath('(//td[@colid="col_138" and @f="F_STASHIP_TEMP" and @i=%s])' % i).click()
            sleep(0.5)
            chrome.find_element_by_class_name('awsui-input-number-right').send_keys(STASHIP_TEMP)
            sleep(0.5)

            # 填写启运日期
            chrome.find_element_by_xpath('(//td[@colid="col_139" and @f="F_STASHIP_DATE" and @i=%s])' % i).click()
            sleep(0.5)
            chrome.find_element_by_class_name('el-input__inner').send_keys(STASHIP_DATE)
            sleep(0.5)

            # 填写启运时间
            chrome.find_element_by_xpath('(//td[@colid="col_140" and @f="F_STASHIP_TIME" and @i=%s])' % i).click()
            sleep(0.5)
            chrome.find_element_by_class_name('el-input__inner').send_keys(STASHIP_TIME)
            sleep(0.5)

        # 调用button_click1保存/提交
        PurchaseOrder.button_click1(self,type,el2='//p[text()="流程结束"]')
        print('出库复核成功')

class SurgicalReturn(PurchaseOrder):
    def data_add_surgicalreturn(self,jctorder):
        ###打开手术还回收货单###
        wait.until(ec.presence_of_element_located((By.XPATH,'//span[text()="手术还回收货"]')))
        order_link = chrome.find_element_by_xpath('//span[text()="手术还回收货"]')
        chrome.execute_script("arguments[0].click();", order_link)
        chrome.switch_to.frame(chrome.find_element_by_xpath('(//iframe[@class="metro-main-frame"])[2]'))
        sleep(0.5)
        # 点击新建按钮
        wait.until(ec.visibility_of_element_located((By.XPATH,'//span[text()="新建"]')))
        sleep(0.5)
        chrome.find_element_by_xpath('//span[text()="新建"]').click()
        sleep(4)
        chrome.switch_to.frame(chrome.find_element_by_xpath('//iframe[contains(@name,"awsui-dialog-iframe")]'))
        sleep(2)

        ###获取手术还回订单号###
        global orderno3
        orderno3 = chrome.find_element_by_xpath('//div[text() = "收货单号 "]/following-sibling::div/span').text
        print('手术还回收货单号为:', orderno3)

        # 还回仓库名称
        chrome.find_element_by_xpath(
            '//div[text()="还回仓库名称 "]/following-sibling::div/div/div/div/div/div/div/div/span/span/i').click()
        wait.until(ec.visibility_of_element_located((By.XPATH, '//input[@placeholder="模糊检索:仓库名称,仓库编码"]')))
        sleep(0.5)
        chrome.find_element_by_xpath('//input[@placeholder="模糊检索:仓库名称,仓库编码"]').send_keys(lendout)
        sleep(0.5)
        chrome.find_element_by_xpath('//input[@placeholder="模糊检索:仓库名称,仓库编码"]').send_keys(Keys.ENTER)
        sleep(0.5)
        btn_div = chrome.find_element_by_xpath(
            '//span/input[@type="radio" and @value="0b950dc6692b193591bd8ac06876791ec"]')
        chrome.execute_script("arguments[0].click();", btn_div)
        chrome.find_element_by_xpath('(//button[@class="el-button el-button--primary el-button--default"])[2]').click()
        sleep(1)

        #填写客户名称
        chrome.find_element_by_xpath('//div[text()="客户名称 "]/following-sibling::div/div/div/div/div/div/div/div/span/span/i').click()
        wait.until(ec.visibility_of_element_located((By.XPATH,'//input[@placeholder="模糊检索:客户编码,客户名称"]')))
        sleep(1)
        chrome.find_element_by_xpath('//input[@placeholder="模糊检索:客户编码,客户名称"]').send_keys(custname)
        sleep(1)
        chrome.find_element_by_xpath('//input[@placeholder="模糊检索:客户编码,客户名称"]').send_keys(Keys.ENTER)
        sleep(1)
        btn_div= chrome.find_element_by_xpath('//span/input[@type="radio" and @value="04bb72d56ca59576d0c205f2509d66836"]')
        chrome.execute_script("arguments[0].click();", btn_div)
        chrome.find_element_by_xpath('(//button[@class="el-button el-button--primary el-button--default"])[2]').click()
        sleep(1)

        #保存主表
        chrome.find_element_by_xpath('//span[text()="保存"]').click()
        wait.until(ec.presence_of_element_located((By.XPATH,'//p[text()="保存成功"]')))
        sleep(1)

        # 点击添加商品并输入借出单号，查询出结果
        chrome.find_element_by_xpath('//span[text()="添加商品"]').click()
        sleep(1)
        chrome.find_element_by_xpath(
            '//input[@placeholder="模糊检索:还回单号,借出单号,商品编码,商品名称,序列号"]').send_keys(jctorder)
        sleep(0.5)
        chrome.find_element_by_xpath(
            '//input[@placeholder="模糊检索:还回单号,借出单号,商品编码,商品名称,序列号"]').send_keys(Keys.ENTER)
        sleep(2)
        # 勾选查询出的商品并点击确定按钮
        chrome.find_element_by_xpath(
            '//th[@class="el-table_12_column_426 multiple-column el-table-column--selection is-leaf headerCellClassName el-table__cell"]/div/label/span/span').click()
        sleep(0.5)
        chrome.find_element_by_xpath('(//div[@class="el-dialog__body"]/div[2]/span/button[1]/span)[3]').click()
        sleep(3)

        # 提交订单
        chrome.find_element_by_xpath('//span[text()="提交"]').click()
        wait.until(ec.presence_of_element_located((By.XPATH, '//p[text()="流程结束"]')))
        sleep(0.5)
        PurchaseOrder.closetab(self)

        print('手术还回收货单提交成功')


    def return_hhshtorder(self):
        return orderno3

class Instore1(Instore):
    def goods_check(self, orderno, type=2):  # 仓库验收
        # 调用query_click进入表单视图
        PurchaseOrder.query_click(self, '仓库验收', orderno,
                                  'vxe-body--column col_19 col--left col--ellipsis dw-click-cell',qrcond='收货单号')
        wait.until(ec.visibility_of_element_located((By.XPATH, '//span[text()="提交"]')))
        sleep(1.5)

        ###获取手术还回订单号###
        global orderno5
        orderno5 = chrome.find_element_by_xpath('//div[text() = "订单号 "]/following-sibling::div/span').text
        print('手术还回订单号为:', orderno5)

        # chrome.execute_script("document.getElementsByClassName('vxe-table--footer-wrapper body--wrapper')[0].scrollLeft = 2000")
        # chrome.execute_script("document.getElementsByClassName('vxe-table--body-wrapper body--wrapper')[0].scrollTop = %s*30;" % i)
        # 填写商品信息
        for i in range(1):
            # 填写验收数量
            chrome.find_element_by_xpath('(//td[@colid="col_150" and @f="F_ACCEPTANCE_NUM" and @i=%s])' % i).click()
            sleep(0.5)
            chrome.find_element_by_class_name('awsui-input-number-right').send_keys(1)
            sleep(0.5)
            chrome.find_element_by_xpath('(//td[@colid="col_152" and @f="F_MAINUNIT_CODE" and @i=%s])' % i).click()
            sleep(0.5)

            # 浏览器页面右滑
            chrome.execute_script(
                "document.getElementsByClassName('vxe-table--body-wrapper body--wrapper')[0].scrollLeft = 5300")
            sleep(1)

            #填写启运温度
            chrome.find_element_by_xpath('(//td[@colid="col_185" and @f="F_STASHIP_TEMP" and @i=%s])' % i).click()
            sleep(0.5)
            chrome.find_element_by_class_name('el-input__inner').send_keys(STASHIP_TEMP)
            sleep(0.5)

            #填写到货温度
            chrome.find_element_by_xpath('(//td[@colid="col_186" and @f="F_ARRIVAL_TEMP" and @i=%s])' % i).click()
            sleep(0.5)
            chrome.find_element_by_class_name('el-input__inner').send_keys(ARRIVAL_TEMP)
            sleep(0.5)

            #填写启运日期
            chrome.find_element_by_xpath('(//td[@colid="col_187" and @f="F_STASHIP_DATE" and @i=%s])' % i).click()
            sleep(0.5)
            chrome.find_element_by_class_name('el-input__inner').send_keys(STASHIP_DATE)
            sleep(0.5)

            #填写启运时间
            chrome.find_element_by_xpath('(//td[@colid="col_188" and @f="F_STASHIP_TIME" and @i=%s])' % i).click()
            sleep(0.5)
            chrome.find_element_by_class_name('el-input__inner').send_keys(STASHIP_TIME)
            sleep(0.5)

            # 填写到货日期
            chrome.find_element_by_xpath('(//td[@colid="col_189" and @f="F_ARRIVAL_DATE" and @i=%s])' % i).click()
            sleep(0.5)
            chrome.find_element_by_class_name('el-input__inner').send_keys(ARRIVAL_DATE)
            sleep(0.5)

            #填写到货时间
            chrome.find_element_by_xpath('(//td[@colid="col_190" and @f="F_ARRIVAL_TIME" and @i=%s])' % i).click()
            sleep(0.5)
            chrome.find_element_by_class_name('el-input__inner').send_keys(ARRIVAL_TIME)
            sleep(0.5)

            #填写运输工具
            chrome.find_element_by_xpath('(//td[@colid="col_191" and @f="F_TRANS_MACHINE" and @i=%s])' % i).click()
            sleep(0.5)
            # chrome.find_element_by_class_name('el-input__inner').send_keys(TRANS_MACHINE)
            chrome.find_element_by_xpath('//li[text()="%s"]'%TRANS_MACHINE).click()
            sleep(0.5)

        # 调用button_click1保存/提交订单
        PurchaseOrder.button_click1(self, type)
        print('仓库验收成功')

    def return_hhtorderno(self):
        return orderno5

class SurgicalLendingSale(PurchaseOrder):
    def data_add_surgicallendingsale(self,jctorder):
        ###打开手术借出转销售###
        wait.until(ec.presence_of_element_located((By.XPATH, '//span[text()="手术借出转销售"]')))
        order_link = chrome.find_element_by_xpath('//span[text()="手术借出转销售"]')
        chrome.execute_script("arguments[0].click();", order_link)
        chrome.switch_to.frame(chrome.find_element_by_xpath('(//iframe[@class="metro-main-frame"])[2]'))
        sleep(0.5)
        # 点击新建按钮
        wait.until(ec.visibility_of_element_located((By.XPATH, '//span[text()="新建"]')))
        sleep(0.5)
        chrome.find_element_by_xpath('//span[text()="新建"]').click()
        sleep(4)
        chrome.switch_to.frame(chrome.find_element_by_xpath('//iframe[contains(@name,"awsui-dialog-iframe")]'))
        sleep(2)

        ###获取订单号###
        global orderno4
        orderno4 = chrome.find_element_by_xpath('//div[text() = "销售订单号 "]/following-sibling::div/span').text
        print('手术借出转销售订单号为:', orderno4)

        # 点击业务员名称并输入查询条件，查询出结果
        chrome.find_element_by_xpath(
            '//div[text()="业务员名称 "]/following-sibling::div/div/div/div/div/div/div/div/span/span/i').click()
        sleep(1)
        chrome.find_element_by_xpath(
            '//input[@placeholder="模糊检索:员工编码,员工名称"]').send_keys(salesman)
        sleep(1)
        chrome.find_element_by_xpath(
            '//input[@placeholder="模糊检索:员工编码,员工名称"]').send_keys(Keys.ENTER)
        sleep(1)
        # 勾选查询出的业务员并点击确定按钮
        btn_div = chrome.find_element_by_xpath(
            '//span/input[@type="radio" and @value="07fa3921bd06ea4d4114a7dfd887433bc"]')
        chrome.execute_script("arguments[0].click();", btn_div)
        sleep(1)
        chrome.find_element_by_xpath('(//span[@class="ensureBtn"]/button[1])').click()
        sleep(1)

        # 点击出库仓库名称，输入仓库名并查询出结果
        chrome.find_element_by_xpath(
            '//div[text()="出库仓库 "]/following-sibling::div/div/div/div/div/div/div/div/span/span/i').click()
        sleep(1)
        chrome.find_element_by_xpath(
            '//input[@placeholder="模糊检索:仓库编码,仓库名称"]').send_keys(lendin)
        chrome.find_element_by_xpath(
            '//input[@placeholder="模糊检索:仓库编码,仓库名称"]').send_keys(Keys.ENTER)
        sleep(1)
        # 勾选查询出的仓库并点击确定按钮
        btn_div = chrome.find_element_by_xpath(
            '//span/input[@type="radio" and @value="0e853ab0be3dae1bdbb65b6699abab0cd"]')
        chrome.execute_script("arguments[0].click();", btn_div)
        sleep(1)
        chrome.find_element_by_xpath('(//button[@class="el-button el-button--primary el-button--default"])[2]').click()
        sleep(1)

        # 输入手术日期
        chrome.find_element_by_xpath('//label[text()="手术日期 "]/following-sibling::div/div').click()
        sleep(0.5)
        chrome.find_element_by_class_name('el-input__inner').send_keys(surgicaldate)
        sleep(1)

        #切换到客户及合同信息页
        chrome.find_element_by_xpath('//div[text()="客户及合同信息"]').click()
        sleep(1)

        # 点击采购合同/协议号并输入信息，查询出结果
        wait.until(ec.visibility_of_element_located((By.XPATH,'//div[text()="合同号 "]/following-sibling::div/div/div/div/div/div/div/div/span/span/i')))
        sleep(0.5)
        chrome.find_element_by_xpath(
            '//div[text()="合同号 "]/following-sibling::div/div/div/div/div/div/div/div/span/span/i').click()
        sleep(1)
        chrome.find_element_by_xpath(
            '//input[@placeholder="模糊检索:合同号,合同协议号,对方编码,项目名称,项目编码,业态编码"]').send_keys(
            contractnumber)
        sleep(1)
        chrome.find_element_by_xpath(
            '//input[@placeholder="模糊检索:合同号,合同协议号,对方编码,项目名称,项目编码,业态编码"]').send_keys(
            Keys.ENTER)
        sleep(1)
        # chrome.find_element_by_xpath(
        #     '//div[@class="multiple-header string_col" and text()="38443"]/ancestor-or-self::td/preceding-sibling::td/div/label/span/span').click()
        # 勾选查询出的合同号并点击确定按钮
        btn_div = chrome.find_element_by_xpath(
            '//span/input[@type="radio" and @value="015f0460ae99d46064e7d15e9a9cc4df2"]')
        chrome.execute_script("arguments[0].click();", btn_div)
        sleep(1)
        chrome.find_element_by_xpath('(//button[@class="el-button el-button--primary el-button--default"])[2]').click()
        sleep(1)

        # 输入客户名称
        chrome.find_element_by_xpath(
            '//div[text()="客户名称 "]/following-sibling::div/div/div/div/div/div/div/div/span/span/i').click()
        sleep(1)
        chrome.find_element_by_xpath('//input[@placeholder="模糊检索:客户编码,客户名称,货币码"]').send_keys(custname)
        sleep(1)
        chrome.find_element_by_xpath('//input[@placeholder="模糊检索:客户编码,客户名称,货币码"]').send_keys(Keys.ENTER)
        sleep(1)
        # chrome.find_element_by_xpath(
        #     '//div[@class="multiple-header string_col" and text()="38443"]/ancestor-or-self::td/preceding-sibling::td/div/label/span/span').click()
        # 勾选查询出的合同号并点击确定按钮
        btn_div = chrome.find_element_by_xpath(
            '//span/input[@type="radio" and @value="054956b6ee3b27c31cb07310caa9b3f77"]')
        chrome.execute_script("arguments[0].click();", btn_div)
        sleep(1)
        chrome.find_element_by_xpath('(//button[@class="el-button el-button--primary el-button--default"])[2]').click()
        sleep(1)

        # 切换到其他信息页
        chrome.find_element_by_xpath('//div[text()="其他信息"]').click()
        sleep(1)

        # 填写配销客户名称
        chrome.find_element_by_xpath(
            '//div[text()="配销客户名称 "]/following-sibling::div/div/div/div/div/div/div/div/span/span/i').click()
        wait.until(ec.visibility_of_element_located((By.XPATH, '//input[@placeholder="模糊检索:客户编码,客商名称"]')))
        sleep(1)
        chrome.find_element_by_xpath('//input[@placeholder="模糊检索:客户编码,客商名称"]').send_keys(custname)
        sleep(1)
        chrome.find_element_by_xpath('//input[@placeholder="模糊检索:客户编码,客商名称"]').send_keys(Keys.ENTER)
        sleep(1)
        btn_div = chrome.find_element_by_xpath(
            '//span/input[@type="radio" and @value="0c4d395678c596b20aa6c2a2fef3483d4"]')
        chrome.execute_script("arguments[0].click();", btn_div)
        chrome.find_element_by_xpath('(//button[@class="el-button el-button--primary el-button--default"])[2]').click()
        sleep(1)

        #保存主表
        chrome.find_element_by_xpath('//span[text()="保存"]').click()
        wait.until(ec.presence_of_element_located((By.XPATH, '//p[text()="保存成功"]')))
        sleep(1)

        ###子表信息录入###
        chrome.find_element_by_xpath('//div[text()="主体信息"]').click()
        sleep(1)
        # 点击添加商品并输入商品编码，查询出结果
        chrome.find_element_by_xpath('//span[text()="添加商品"]').click()
        sleep(1)
        chrome.find_element_by_xpath(
            '//input[@placeholder="模糊检索:借出单号,商品名称,规格型号,批次号,序列号,原始订单类型"]').send_keys(jctorder)
        sleep(0.5)
        chrome.find_element_by_xpath(
            '//input[@placeholder="模糊检索:借出单号,商品名称,规格型号,批次号,序列号,原始订单类型"]').send_keys(Keys.ENTER)
        sleep(2)
        # 勾选查询出的商品并点击确定按钮
        chrome.find_element_by_xpath(
            '//th[@class="el-table_21_column_370 multiple-column el-table-column--selection is-leaf headerCellClassName el-table__cell"]/div/label/span/span').click()
        sleep(0.5)
        chrome.find_element_by_xpath('(//div[@class="el-dialog__body"]/div[2]/span/button[1]/span)[6]').click()
        sleep(3)

        # 提交
        chrome.find_element_by_xpath('//span[text()="提交"]').click()
        # wait.until(ec.visibility_of_element_located((By.XPATH,'(//span[text()="确定"])[22]')))
        # sleep(1)
        # chrome.find_element_by_xpath('(//span[text()="确定"])[22]').click()
        wait.until(ec.presence_of_element_located((By.XPATH,'//p[text()="办理成功"]')))
        PurchaseOrder.closetab(self)
        print('手术借出转销售单提交成功')
    def return_xstorderno(self):
        return orderno4

    def button_click2(self,type=1,msg1='流程结束'):#审批/驳回订单：type=1为审批/其余为驳回订单
        wait.until(ec.visibility_of_element_located((By.XPATH, '//span[text()="审核通过"]')))
        sleep(1)
        if type == 1:#审核流程
            #点击审核通过
            chrome.find_element_by_xpath('//span[text()="审核通过"]').click()
            sleep(1)
            chrome.find_element_by_xpath('(//span[text()="确定"])[1]').click()

            locator = (By.XPATH, '//textarea[@placeholder="意见留言"]')
            wait.until(ec.presence_of_element_located(locator))
            sleep(0.5)
            #填写审核通过信息
            chrome.find_element_by_xpath('//textarea[@placeholder="意见留言"]').send_keys('审核通过')
            sleep(0.5)
            #点击发送按钮
            chrome.find_element_by_xpath('//span[text()="发送"]').click()
            #判断审核成功
            locator = (By.XPATH, '//p[text()="%s"]'%msg1)
            wait.until(ec.presence_of_element_located(locator))
            print('订单审核成功')
        else:#驳回流程
            #点击驳回
            chrome.find_element_by_xpath('//span[text()="审核驳回"]').click()
            locator = (By.XPATH, '//textarea[@placeholder="意见留言"]')
            wait.until(ec.presence_of_element_located(locator))
            sleep(0.5)
            #填写驳回信息
            chrome.find_element_by_xpath('//textarea[@placeholder="意见留言"]').send_keys('审核驳回')
            sleep(0.5)
            #点击发送
            chrome.find_element_by_xpath('//span[text()="发送"]').click()
            #判断驳回成功
            locator = (By.XPATH, '//p[text()="发送成功"]')
            wait.until(ec.presence_of_element_located(locator))
            print('订单驳回成功')
        self.closetab()

if __name__ == '__main__':
    try:
        step1 = LoginSys()
        step2_1 = SurgicalOrder()
        step2_2 = PurchaseOrder()
        step3 = SurgicalDispensing()
        step4 = SurgicalLending()
        step5_1 = Outstore()
        step5_2 = Outstore1()
        step6 = SurgicalReturn()
        step7_1 = Instore1()
        step7_2 = Instore()
        step8 = SurgicalLendingSale()
        step1.loginsys(SIT_URL, usr2, pwd2)
        step2_1.data_add_surgical()
        step2_2.button_click1()
        qltorder = step2_1.return_qltorder()
        step3.dispensing(qltorder)
        step4.lending(qltorder)
        step4.switch_loggin(usr1,pwd1)
        step4.query_click(menu_name='手术借出单', orderno=qltorder,
                                      el='vxe-body--column col_19 col--center col--ellipsis dw-click-cell',
                                      qrcond='请领单号')
        jctorder = step4.return_jctorder()
        step4.button_click2()
        step4.switch_loggin(usr4, pwd4)
        step5_1.deliver_goods(jctorder)  # 仓库发货
        step5_1.picking_goods(jctorder)  # 仓库拣货
        step5_1.switch_loggin(usr5, pwd5)
        step5_2.outbound_review1(jctorder,type=3)  # 出库复核
        step5_1.switch_loggin(usr2, pwd2)
        step6.data_add_surgicalreturn(jctorder)#新增手术还回收货
        hhshtorder = step6.return_hhshtorder()
        step7_1.switch_loggin(usr5,pwd5)
        step7_1.goods_check(hhshtorder,type=3)#仓库验收
        hhtorderno = step7_1.return_hhtorderno()
        step7_1.switch_loggin(usr4,pwd4)
        step7_2.goods_grounding(hhtorderno)#仓库上架
        # step8.data_add_surgicallendingsale(jctorder)#新建销售单
        # xstorderno = step8.return_xstorderno()#返回销售单号
        # step8.switch_loggin(usr3,pwd3)
        # step8.query_click(menu_name='手术借出转销售', orderno=xstorderno,
        #                               el='vxe-body--column col_19 col--center col--ellipsis dw-click-cell',
        #                               qrcond='销售订单号')#进入表单视图
        # step2_2.button_click2(msg1='流程结束')  # 审核订单
    except (Exception,AssertionError) as e:
        step9 =ExceptionHandling()
        traceback.print_exc()
        step9.handle(errmsg6,e)

    finally:
        chrome.quit()