<template>
  <view class="content">
    <view class="card">
      <u-cell-group>
        <view v-for="(item, index) in form" :key="index">
          <u-cell title-style="width: 150px" v-if="item.TYPE === 0" :title="item.ITEM" :value="item.ITEM_VALUE">
            <template #value>
              <view style="word-break: break-all">{{ item.ITEM_VALUE }}</view>
            </template>
          </u-cell>
          <view v-if="item.TYPE === 1">
            <u-cell :title="item.ITEM">
              <template #label>
                <view class="mt-5">
                  <view v-for="(item1, index1) in item.list" :key="index1">
                    <u-image
                        width="400rpx"
                        height="200rpx"
                        :src="$filePath + item1.ITEM_VALUE"
                        mode="widthFix"
                        @click="fnPreviewImage($filePath + item1.ITEM_VALUE)"
                    />
                  </view>
                </view>
              </template>
            </u-cell>
          </view>
          <view v-if="item.TYPE === 3">
            <u-divider text-position="left" :text="item.ITEM" />
          </view>
          <view v-if="item.TYPE === 4">
            <view v-for="(item1, index1) in item.list" :key="index1">
              <view v-for="(item2, index2) in item1.list" :key="index2">
                <u-cell :title="item2.ITEM" :value="item2.ITEM_VALUE" />
              </view>
            </view>
          </view>
          <view v-if="item.TYPE === 5">
            <u-cell :title="item.ITEM">
              <template #label>
                <view class="mt-5">
                  <u-image
                      width="400rpx"
                      height="200rpx"
                      :src="$filePath + item.ITEM_VALUE"
                      mode="widthFix"
                  />
                </view>
              </template>
            </u-cell>
          </view>
        </view>
      </u-cell-group>
      <u-divider text="安全措施" textPosition="left" textColor="#3c9cff" lineColor="#3c9cff"/>
      <u-cell-group>
        <u-cell v-for="(item,index) in questionnaires" :key="index" :title="item.QUESTION">
          <template #title>
            <view style="display: flex;justify-content: space-between">
              <view style="width: 75%;">{{ item.QUESTION }}</view>
              <view>{{ item.TEXT_INFO || item.ANSWER }}</view>
            </view>
          </template>
          <template #label>
            <block v-for="(item1,index1) in item.answers" :key="index1">
              <view>{{ item1.TEXT_INFO }}:{{ item1.ANSWER }}</view>
            </block>
          </template>
        </u-cell>
      </u-cell-group>
      <u-divider text="审批人员" textPosition="left" textColor="#3c9cff" lineColor="#3c9cff"/>
      <u-cell-group>
        <block v-for="(item, index) in jobs" :key="index">
          <u-cell :key="index" :title="item.TYPE_DESCRIBE">
            <template #label>
              <view class="mt-10">
                <view>部门:{{ item.DEPARTMENT_NAME }}</view>
                <view v-if="item.USER_NAME">人员:{{ item.USER_NAME }}</view>
                <view v-if="item.SIGN_PICTURE">
                  <u-image width="400rpx" height="200rpx" :src="$filePath + '/' +item.SIGN_PICTURE" mode="widthFix"/>
                  <view>审批意见:{{ item.APPROVAL_OPINIONS }}</view>
                  <view>审批意见:{{ item.APPROVAL_TIME }}</view>
                </view>
              </view>
            </template>
          </u-cell>
        </block>
      </u-cell-group>
      <view class="mt-10">
        <u-button v-if="isView !== '1'" type="primary" text="下一步" @click="$u.debounce(fnSubmit, 1000,true)"/>
        <u-button v-if="isView === '1'" type="primary" text="返  回" @click="$u.debounce(goBack, 1000,true)"/>
      </view>
    </view>
  </view>
</template>

<script>
import {getTaskInfo} from "@/api";
import {resolveNextOperation} from "@/utils/submitHomeworkProcess";

export default {
  data() {
    return {
      taskId: '',
      type: '',
      jobId: '',
      form: [],
      jobs: [],
      questionnaires: [],
      isView: ''
    }
  },
  onLoad(query) {
    this.taskId = query.taskId
    this.type = query.type
    this.jobId = query.jobId
    if ('1' === query.isView){
      this.isView = '1'
    }
    this.fnGetData(query.taskId)
    uni.setNavigationBarTitle({
      title: query.title + '查看'
    })
  },
  methods: {
    async fnGetData(taskId) {
      let resData = await getTaskInfo({EW_RU_TASK_ID: taskId})
      this.form = resData.list.fromTrans
      this.jobs = resData.list.jobs
      this.questionnaires = resData.list.simpleQues[0]
    },
    async fnSubmit() {
      let CORP_ID = ''
      for (let i = 0; i < this.form.length; i++) {
        if (this.form[i].FK_NAME === 'CORP_ID') {
          CORP_ID = this.form[i].FK_VALUE
          break
        }
      }
      await resolveNextOperation({
        EW_RU_TASK_ID: this.taskId,
        TYPE: this.type,
        CORP_ID,
        EW_RU_JOB_ID: this.jobId,
      })
    },
    goBack(){
      uni.navigateBack()
    },
    fnPreviewImage(src){
      uni.previewImage({
        urls: [src],
        current: src,
      });
    }
  },
}
</script>

<style scoped lang="scss">

</style>