<template>
  <view class="container">
    <view class="list">
      <view>
        <u-search :show-action="true" v-model="data.nickName" action-text="搜索" input-align="left" height="65" border-color="#ff9900" @search="getList" @custom="getList"></u-search>
      </view>
      <scroll-view scroll-y="true" class="scroll-Y" style="height: calc(100vh - 80rpx)">
        <u-checkbox-group class="item" @change="checkChange">
          <u-checkbox class="dec" v-model="item.checked" v-for="(item, index) in list" :key="index" :name="item">{{ item.personName }}</u-checkbox>
        </u-checkbox-group>
      </scroll-view>
      <u-button form-type="button" style="color:#ffffff;backgroundColor:#3C9CFF;position: fixed;bottom: 0px;width: 100%" @click="onSubmit">确认选择</u-button>

<!--      <view class="item" v-for="(item, index) in list" :key="index" @click="openDetail(item)">-->
<!--        <view class="dec">-->
<!--          <view>{{ item.workerName }}</view>-->
<!--          <view>1</view>-->
<!--        </view>-->
<!--      </view>-->
    </view>
  </view>
  <u-alert-tips type="error" :title="系统提示" close-text="close" :description="请选择人员" :close-able="true" :show="show"></u-alert-tips>
</template>

<script setup lang="ts">
/* 初始化 */
import { onLoad, onShow } from "@dcloudio/uni-app"
import { getCurrentInstance, ref } from "vue"
/* 引入API */
import tags from "@components/tags/index.vue"
import * as workSchedulingApi from "@/api/mes/workScheduling"
import * as workSchedulingListApi from "@/api/mes/workScheduling"
import { _toast } from "@/utils/common"

const { proxy } = getCurrentInstance()

tags.data = ref([
  {
    text: "1",
    value: "2"
  }
])
const data = ref({
  planDayCode: '',
  processCode: '',
  nickName: ''
})
let show = false
let checked: string | any[] = []
/* 是否显示"没有更多了" */
const status = ref('loadmore')
/* 列表数据集 */
const list = ref([])

/* 列表调用API方法 */
async function getList() {
  if (status.value === 'nomore') return
  status.value = 'loading'
  proxy.$modal.loading('加载中')
  // "{"status":"1","remark":null,"planMasterCode":"PO20240429-0015","schedulingCode":"9bb4ab0cfcc14e3284833506b5041571","productCode":"015.886-117","productName":null,"workroomCode":"work1","lineCode":"work1-line1","prouteCode":"015.886-117","planCount":25,"finishCount":0,"qualifiedCount":null,"unqualifiedCount":null,"flagDo":"0","planSubCode":null,"workingNode":"QD_HJ_01","workingTaskSort":1,"formType":"BATCH","workSort":0,"currentWorkstation":null,"planStartTime":null,"planEndTime":1714388234000,"realStartTime":null,"realFinishedTime":null,"qualityFormNo":null,"reason":null,"planNoDay":null,"batchCode":"M015.886-117-001","id":61,"createTime":1714370517000,"creator":"1"}"
  await workSchedulingApi.getConfigProcessWorker(data.value).then((res) => {
    uni.setStorageSync("isLeader", res.data.leader)
    if (res.data.leader) {
      list.value = res.data.list
    } else {
      uni.setStorageSync("processReportList", res.data.list)
      uni.redirectTo({
        url: "./processReportForm"
      })
    }
  })
  proxy.$modal.closeLoading()
}
function checkChange(checkedArray: any[]) {
  checked = checkedArray
}
/* 打开详情页 */
function openDetail(item: any) {
  console.log(item)
  // proxy.$tab.navigateTo(`/pages/mes/orderDapPlan/detail?obj=${item}`)
}

/* 通用方法 */
onShow(() => {
  list.value = []
  getList()
})
function onSubmit() {
  if (checked.length == 0){
    _toast("请选择人员")
    return
  }
  uni.setStorageSync("processReportList", checked)
  uni.redirectTo({
    url: "./processReportForm"
  })
}
onLoad((option) => {
  data.value.planDayCode = uni.getStorageSync("processReportListParams").planMasterCode
  data.value.processCode = uni.getStorageSync("processReportListParams").workingNode
})
</script>

<style lang="scss" scoped>
.container {
  background: #f5f5f5;
  min-height: 100vh;
}

.list {
  background: #f5f5f5;
  margin-top: 20rpx;

  .item {
    padding: 30rpx 30rpx 0px 30rpx;
    margin-top: 20rpx;
    background: white;
    position: relative;

    .title {
      display: flex;
      align-items: center;
      padding-bottom: 20rpx;

      .title-txt {
        color: #409eff;
        font-weight: bold;
        font-size: 36rpx;
        width: 0px;
        flex: 1;
        word-wrap: break-word;
      }

      .time {
        color: #919191;
      }
    }

    .dec {
      padding-bottom: 20rpx;
      display: flex;
      align-items: center;

      view {
        &:nth-child(1) {
          width: 160rpx;
        }

        &:nth-child(2) {
          color: #999999;
          flex: 1;
          width: 0px;
          word-wrap: break-word;
        }
      }
    }

    .last {
      padding-bottom: 30rpx;
    }

    .bottom {
      display: flex;
      justify-content: space-between;
      align-items: center;
      border-top: 1px solid #e4e4e4;
      padding: 20rpx 0px;
      height: 90rpx;
    }
  }
}
::v-deep .u-checkbox-group {
  display: grid !important;
}
</style>
