<template>
  <view class="generate-report">
    <view class="form">
      <uv-form
        labelPosition="left"
        :model="form"
        ref="formRef"
        labelWidth="120"
        :labelStyle="labelStyle"
      >
        <uv-form-item label="执行包名称" prop="score_package_name" borderBottom required>
          <uv-input v-model="form.score_package_name" border="none" placeholder="请输入" readonly />
        </uv-form-item>
        <uv-form-item label="报告ID" prop="report_id" borderBottom required>
          <uv-input v-model="form.report_id" border="none" placeholder="请输入" readonly />
        </uv-form-item>
        <uv-form-item label="完成积分值" prop="score" borderBottom required>
          <uv-input v-model="form.score" border="none" placeholder="请输入" readonly />
        </uv-form-item>
        <uv-form-item label="合计服务数" prop="score_count" borderBottom required>
          <uv-input v-model="form.score_count" border="none" placeholder="请输入" readonly />
        </uv-form-item>
        <uv-form-item label="结算企业" prop="description" borderBottom required>
          <uv-input v-model="form.description" border="none" placeholder="请输入" readonly />
        </uv-form-item>
      </uv-form>
    </view>
    <view class="btn">
      <view @click="generateApprovalFn">生成报告并审批</view>
    </view>
  </view>
</template>

<script setup lang="ts">
import { onLoad } from '@dcloudio/uni-app'
import { ref, reactive } from 'vue'

import { selectReportApi, saveAndUpdateWmReportApi } from '@/service/modules/taskManagement'

const currentId = ref()

onLoad((e: any) => {
  currentId.value = e?.scorePackageId
  selectReportFn()
})
const labelStyle = {
  fontWeight: 400,
  fontSize: '30rpx',
  color: '#000'
}
const form = ref({
  score_package_name: '',
  report_id: '',
  score: '',
  score_count: '',
  description: ''
})

const selectReportFn = async () => {
  const obj = {
    scorePackageId: currentId.value
  }

  const res = await selectReportApi(obj)
  if (res.data == 0) {
    uni.showToast({
      icon: 'none',
      title: '没有可生成报告的服务'
    })
    setTimeout(() => {
      uni.navigateBack()
    }, 1000)
  } else {
    form.value = res.data
  }
}

const generateApprovalFn = async () => {
  const obj = {
    scorePackageId: currentId.value,
    taskStatus: 3
  }
  const res = await saveAndUpdateWmReportApi(obj)
  if (res.code === 0) {
    uni.showToast({
      title: '提交成功',
      icon: 'none'
    })
    setTimeout(() => {
      uni.navigateBack()
    }, 1000)
  }
}
</script>

<style lang="scss" scoped>
.generate-report {
  min-height: 100vh;
  background-color: #f2f2f2;
  padding: 24rpx;
  .form {
    background: #fff;
    padding: 30rpx;
    border-radius: 12rpx;
  }
}
:deep(.uv-form-item__body__left) {
  padding-left: 18rpx;
}

.btn {
  width: 700rpx;
  background-color: #fff;
  height: 160rpx;
  box-sizing: border-box;
  border-radius: 12rpx;
  position: fixed;
  bottom: 40rpx;
  left: 24rpx;
  padding: 34rpx 46rpx 54rpx;
  view {
    background-color: #6eb657;
    border-radius: 8rpx;
    text-align: center;
    line-height: 72rpx;
    font-weight: 400;
    color: #fff;
    font-size: 32rpx;
  }
}
</style>
