import ProcessRequest from '../../common/util/request/ProcessRequest'
import OperationItem from '../../viewmodel/OperationItem'
import ProcessInfo from '../../viewmodel/process/ProcessInfo'
import ProcessMaterial from '../../viewmodel/process/ProcessMaterial'
import RequestParamModel from '../../viewmodel/RequestParamModel'
import WorkOrderInfo from '../../viewmodel/WorkOrderInfo'
import promptAction from '@ohos.promptAction'
import { ModifyMaterialNumDialog } from '../ModifyMaterialNumDialog'
import PageInfo from '../../viewmodel/PageInfo'
import OperationComponent from '../../viewmodel/process/OperationComponent'
import RecordItem from '../../viewmodel/process/RecordItem'
import { RecordItemDialog } from '../RecordItemDialog'

// 补充缺失的UI相关导入（根据实际项目调整）


// 物料采集工序
@Component
export struct RecordItemsView {
  @Link recordItems:RecordItem[]
  @State isEditRecord:boolean = false
  @State selectRecordItem:RecordItem={}
  @State selectDefectIndex :number = -1
  @Link opComponents: OperationComponent[]
  @Link index:number
  aboutToAppear() {

  }


  build() {
    Column() {
      Row() {
        Text('记录项')
          .fontSize($r('app.float.fontSize_24'))
          .fontWeight(FontWeight.Medium)
          .fontColor($r('app.color.FFFFFF'))
      }
      .height('10%')
      .width('96%')
      // 不良类型记录列表
      List({space: 6}) {
        ForEach(this.recordItems, (item: RecordItem, index: number) => {
          ListItem() {
            Column() {
              Text('标题:'+(item.title ? item.title!: ''))
                .fontColor($r('app.color.FFFFFF'))
                .fontSize($r('app.float.fontSize_16'))
                .fontWeight(FontWeight.Bold)
                .height($r('app.float.virtualSize_48'))
              Text('内容：' + (item.content ? item.content : ''))
                .fontColor($r('app.color.FFFFFF'))
                .fontSize($r('app.float.fontSize_16'))
                .fontWeight(FontWeight.Lighter)
                .padding({bottom: 10})
            }
            .width('92%')
            .alignItems(HorizontalAlign.Start)
          }
          .backgroundColor($r('app.color.20FFFFFF'))
          .borderRadius($r('app.float.fontSize_16'))
          .width('100%')
          .onClick(()=>{
            this.selectDefectIndex = index;
            this.selectRecordItem = item;
            this.isEditRecord = true;
            this.recordController.open()

          })
        })
      }
      .width('90%')
      .height('80%')
      .alignListItem(ListItemAlign.Center)
      .margin({top: 10})

      Row(){

        Row() {
          Image($r('app.media.general_add'))
            .width($r('app.float.virtualSize_32'))
            .height($r('app.float.virtualSize_32'))
            .fillColor($r('app.color.0A84FF'))
        }
        .height('100%')
        .width('40%')
        .margin({left:'30%'})
        .borderRadius($r('app.float.virtualSize_16'))
        .backgroundColor($r('app.color.20FFFFFF'))
        .justifyContent(FlexAlign.Center)
        .onClick(()=>{
          this.isEditRecord = false;
          this.recordController.open()

        })
        Row({space: 4}) {
          Image($r("app.media.next_step"))
            .width($r('app.float.virtualSize_24'))
            .height($r('app.float.virtualSize_24'))
            .fillColor($r('app.color.0A84FF'))
          Text('下一步')
            .fontColor($r('app.color.0A84FF'))
            .fontSize($r('app.float.fontSize_24'))
            .fontWeight(FontWeight.Medium)
        }
        .width('10%')
        .height('100%')
        .justifyContent(FlexAlign.Center)
        .margin({left:'10%'})
        .backgroundColor($r('app.color.20FFFFFF'))
        .borderRadius($r('app.float.fontSize_16'))
        .onClick(()=>{
          this.opComponents[this.index].isComplete=true
          this.index++

        })
      } .height('7.1%')
      .width('100%')
    }
    .width('100%')
    .height('100%')
  }


  recordController: CustomDialogController = new CustomDialogController({
    builder: RecordItemDialog({
      isEdit: this.isEditRecord,
      recordItems:this.recordItems,
      recordItem:this.isEditRecord ? this.selectRecordItem : {},
      RecordIndex:this.selectDefectIndex,
    }),
    autoCancel: true, // 点击遮罩关闭
    customStyle: true,
    alignment:DialogAlignment.Center,
    maskColor: 'rgba(0,0,0,0.8)',  // 黑色遮罩
  })
}