//专检
import ProcessRequest from '../common/util/request/ProcessRequest';
import { BindTaskSeqVO } from '../viewmodel/process/BindTaskSeq';
import TaskSeqVO from '../viewmodel/process/TaskSeqInfo';
import RequestParamModel from '../viewmodel/RequestParamModel';
import { Font } from '@ohos.arkui.UIContext';
import { UserInfo } from '../viewmodel/UserInfo';

@CustomDialog
export struct SpecialInspectionDialog{
  controller: CustomDialogController
  onConfirm: ()=> void = () => {}
  onDelete:()=> void = () => {}

  //扫描工牌号
  @State scanCardValue:string= ''
  //是否合格(-1 不合格，0：初始，1：合格)
  @State isQualified:number  = 0
  //合格按钮缩放
  @State qualifiedClick:number  = 1
  //不合格按钮缩放
  @State unQualifiedClick:number  = 1
  //当前检验员
  @State currentInspector:UserInfo={}

  queryWorkCard=async()=>{
    this.currentInspector = await ProcessRequest.post('/api/v1/sys/user/get', {
      id:this.scanCardValue,
    } as RequestParamModel) as UserInfo;
  }

  build() {
    Column(){
      Column() {
        Text('专检')
          .fontColor($r('app.color.FFFFFF'))
          .fontSize($r('app.float.fontSize_30'))
      }
      .height('16%')
      .width('100%')
      .justifyContent(FlexAlign.Center)
      Column(){
        Text('专检人员')
          .fontSize($r('app.float.fontSize_16'))
          .fontColor($r('app.color.FFFFFF'))
        Row() {
          // 左侧二维码图标
          Image($r('app.media.material_qr_code'))
            .width($r('app.float.virtualSize_20'))
            .height($r('app.float.virtualSize_20'))
            .fillColor($r('app.color.FFFFFF'))
            .margin({ left: '2%'})
          // 扫码输入框
          TextInput({text:this.scanCardValue, placeholder: '请录入工牌或检验人员专码' })
            .type(InputType.Normal)
            .placeholderFont({ size: $r('app.float.fontSize_16') })
            .placeholderColor($r('app.color.30FFFFFF'))
            .fontSize($r('app.float.fontSize_16'))
            .fontColor($r('app.color.FFFFFF'))
            .enableKeyboardOnFocus(false)
            .onSubmit(async () => {
              this.queryWorkCard()
            })
            .onChange((value: string) => {
              this.scanCardValue = value;
            })
        }
        .height('10%')
        .width('100%')
        .borderRadius($r('app.float.virtualSize_16'))
        .backgroundColor($r('app.color.000000'))
        .margin({top:'3%',bottom:'3%'})

        Column(){
          if(this.currentInspector.id){
            Row(){
              Text(`检验员`)
                .fontColor($r('app.color.FFFFFF'))
                .fontSize($r('app.float.fontSize_16'))
                .fontWeight(FontWeight.Lighter)
              Text(`${this.currentInspector.userName}`)
                .fontColor($r('app.color.FFFFFF'))
                .fontSize($r('app.float.fontSize_16'))
                .fontWeight(FontWeight.Bold)
            }
            .margin({left:'4%',top:'4%'})
            Row(){
              Text(`部门`)
                .fontColor($r('app.color.FFFFFF'))
                .fontSize($r('app.float.fontSize_16'))
                .fontWeight(FontWeight.Lighter)
              Text(`${this.currentInspector?.depts?.[0]?.deptName ?? ''}`)
                .fontColor($r('app.color.FFFFFF'))
                .fontSize($r('app.float.fontSize_16'))
                .fontWeight(FontWeight.Bold)
            }
            .margin({left:'4%',top:'2%'})
            Text(`电子签章`)
              .fontColor($r('app.color.FFFFFF'))
              .fontSize($r('app.float.fontSize_16'))
              .fontWeight(FontWeight.Lighter)
              .margin({left:'4%',top:'5%'})
            Row(){

            }
            .height('48%')
            .width('92%')
            .margin({left:'4%',right:'4%',top:'2%'})
            .backgroundColor($r('app.color.FFFFFF'))
          }else{
            Image($r('app.media.process_user_name'))
              .height('80%')
              .width('50%')
              .margin({left:'25%',right:'25%',top:'10%',bottom:'10%'})
              .fillColor($r('app.color.15FFFFFF'))
              .objectFit(ImageFit.Fill)

          }
        }
        .height('55%')
        .width('100%')
        .border({width:1,color:$r('app.color.15FFFFFF')})
        .borderRadius($r('app.float.virtualSize_16'))
        .alignItems(HorizontalAlign.Start)
        Row(){
          Row(){
            Image($r('app.media.unqualified_special_inspection'))
              .height($r('app.float.virtualSize_24'))
              .width($r('app.float.virtualSize_24'))
              .fillColor(this.isQualified === -1?$r('app.color.FFFFFF'):$r('app.color.FF453A'))
            Text('不合格')
              .fontSize($r('app.float.fontSize_24'))
              .fontColor(this.isQualified === -1?$r('app.color.FFFFFF'):$r('app.color.FF453A'))
              .margin({left:'5%'})
          }
          .justifyContent(FlexAlign.Center)
          .backgroundColor(this.isQualified === -1?$r('app.color.FF453A'):$r('app.color.20FFFFFF'))
          .borderRadius($r('app.float.virtualSize_16'))
          .width('45%')
          .height('100%')
          .scale({ x: this.unQualifiedClick, y: this.unQualifiedClick })
          .animation({
            duration: 200,
            curve: Curve.Linear
          })
          .onClick(() => {
            this.unQualifiedClick = 0.9;
            setTimeout(() => {
              this.isQualified = -1
              this.unQualifiedClick = 1;
            }, 200);
          })
          Row(){
            Image($r('app.media.device_normal'))
              .height($r('app.float.virtualSize_24'))
              .width($r('app.float.virtualSize_24'))
              .fillColor(this.isQualified === 1?$r('app.color.FFFFFF'):$r('app.color.30D158'))
            Text('合格')
              .fontSize($r('app.float.fontSize_24'))
              .fontColor(this.isQualified === 1?$r('app.color.FFFFFF'):$r('app.color.30D158'))
              .margin({left:'5%'})
          }
          .width('45%')
          .height('100%')
          .margin({left:'10%'})
          .justifyContent(FlexAlign.Center)
          .backgroundColor(this.isQualified === 1?$r('app.color.30D158'):$r('app.color.20FFFFFF'))
          .borderRadius($r('app.float.virtualSize_16'))
          .scale({ x: this.qualifiedClick, y: this.qualifiedClick })
          .animation({
            duration: 200,
            curve: Curve.Linear
          })
          .onClick(() => {
            this.qualifiedClick = 0.9;
            setTimeout(() => {
              this.isQualified = 1
              this.qualifiedClick = 1;
            }, 200);
          })
        }
        .height('15%')
        .width('100%')
        .margin({top:'5%'})
      }
      .width('70%')
      .height('74%')
      .margin({left:'15%',right:'15%'})
      .alignItems(HorizontalAlign.Start)
      Column() {
          Divider()
            .vertical(false)
            .strokeWidth(1)
            .color($r('app.color.15FFFFFF'))
          Row() {
            Row() {
              Text('取消')
                .fontColor($r('app.color.60FFFFFF'))
                .fontSize($r('app.float.fontSize_30'))
            }
            .justifyContent(FlexAlign.Center)
            .width('50%')
            .onClick(() => this.controller.close())
            Divider()
              .vertical(true)
              .strokeWidth(1)
              .color($r('app.color.15FFFFFF'))
            Row() {
              Text('确定')
                .fontColor($r('app.color.007AFF'))
                .fontSize($r('app.float.fontSize_30'))
            }
            .justifyContent(FlexAlign.Center)
            .width('50%')
            .onClick(() => {
            })
          }
        }
        .width('100%')
        .height('10%')
    }
    .height('55%')
    .width('30%')
    .backgroundColor($r('app.color.2A2A2A'))
    .justifyContent(FlexAlign.End)
    .alignItems(HorizontalAlign.Start)
    .borderColor($r('app.color.000000'))
    .borderWidth(1)
    .borderRadius($r('app.float.virtualSize_16'))
  }
}