<!-- 延时监火的任务转发 -->
<template>
  <view class="content">
    <view class="card">
      <u-form labelPosition="left" :model="form" :rules="rules" ref="formRef" labelWidth="140px">
        <u-form-item label="接班监火人部门:" prop="PYROMANCER" borderBottom required @click="fnSelect">
          <u-input v-model="form.DEPARTMENT_NAME" border="none" readonly />
          <u-icon name="arrow-right"></u-icon>
        </u-form-item>
      </u-form>
    </view>
    <view style="margin-top: 30upx;">
      <u-button class="bg-green" style="max-width: 50%;"
                @click="$u.debounce(goSubmit, 1000, true)">确认</u-button>
    </view>
  </view>
</template>

<script>
import {setTaskSign} from "../../../../api";

export default {
  data() {
    return {
      form: {
        DEPARTMENT_NAME: '',
        DEPARTMENT_ID: ''
      },
      rules: {
        DEPARTMENT_NAME: [{ type: 'string', required: true, message: '请输入监火人', trigger: ['blur', 'change'] }]
      },
      EW_RU_TASK_ID: '',
      EW_RU_JOB_ID: '',
      CORP_ID: '',
      TYPE: ''

    }
  },
  onLoad(event) {
    this.STATE = event.state;
    this.EW_RU_TASK_ID = event.taskId
    this.EW_RU_JOB_ID = event.EW_RU_JOB_ID
    this.CORP_ID = event.CORP_ID
    this.TYPE = event.TYPE
  },
  methods: {
    fnSelect() {
      uni.navigateTo({
        url: `/pages/eight_assignments/select_department?CORP_ID=${this.CORP_ID}`,
        events: {
          confirm: (event) => {
            console.log(event)
            this.form.DEPARTMENT_NAME = event.DEPARTMENT_NAME
            this.form.DEPARTMENT_ID = event.DEPARTMENT_ID
          }
        },
      })
    },
    async goSubmit(){
      const JOB_DTO = {
        DEPARTMENT_ID: this.form.DEPARTMENT_ID,
            DEPARTMENT_NAME: this.form.DEPARTMENT_NAME,
            CORP_ID: this.$store.getters.getUserInfo.CORPINFO_ID,
            CORP_NAME: this.$store.getters.getUserInfo.CORP_NAME
      }
      try {
        await this.$refs.formRef.validate()
        try {
          await setTaskSign({
            EW_RU_JOB_ID: this.EW_RU_JOB_ID,
            EW_RU_TASK_ID: this.EW_RU_TASK_ID,
            SIGN_FLAG: 1,
            JOB_DTO: JSON.stringify(JOB_DTO)
          })
          uni.$u.toast('保存成功')
          setTimeout(() => {
            uni.switchTab({
              url: '/pages/index/index'
            })
          }, 2000)
        } catch {
        }
      } catch {
        uni.$u.toast('请补全必填项')
      }
    }
  }
}
</script>

<style scoped lang="scss">
  .bg-green {
    background-color: #39b54a;
    color: #fff;
    border-radius: 16upx;
  }
</style>
