<template>
  <view class="content">
    <view v-if="isView !== '1'" class="flex-end padding">
      <u-button type="primary" text="添加" size="mini" class="bth-mini" @click="goToAdd"/>
      <u-button type="primary" text="任务转发" size="mini" class="bth-mini ml-10" @click="goToTaskForword"/>
    </view>
    <view>
      <view class="form" v-if="list.length > 0">
        <view class="wui-form-list" v-for="(item, index) in list" :key="index">
          <view class="cu-form-group">
            <view class="title">监火人：</view>
            {{ item.USER_NAME }}
          </view>
          <view class="cu-form-group">
            <view class="title">时间：</view>
            {{ item.TIME }}
          </view>
          <view class="cu-form-group">
            <view class="title">照片：</view>
            <view><u-button size="mini" type="primary" text="查看图片" @click="ViewImage1(item.FILE_PATH)" /></view>
          </view>
        </view>
        <view style="margin-top: 30upx;" v-show="list.length !== 0 && isView !== '1'">
          <u-button class="bg-green" style="max-width: 50%;" @click="$u.debounce(goSubmit, 1000, true)">完成延时监火</u-button>
        </view>
      </view>
      <empty v-else></empty>
    </view>
    <app-fab-button v-if="isView !== '1'" type="plus" @click="fnScan" />
    <app-fab-up-button v-if="isView !== '1'" type="edit" @click="fnUpScan" />
  </view>
</template>

<script>
import { getHotWorkRecord, setTaskSign} from "../../../../api";
import AppFabButton from "@/components/fab_button/index.vue";
import AppFabUpButton from "@/components/fab_button/up_index.vue";

export default {
  components: {
    AppFabButton,AppFabUpButton
  },
  data() {
    return {
      list: [],
      STATE: '',
      EW_RU_TASK_ID: '',
      EW_RU_JOB_ID: '',
      TYPE: '',
      CORP_ID: '',
      isView: '1'
    }
  },
  onLoad(event) {
    this.STATE = event.state;
    this.EW_RU_TASK_ID = event.taskId
    this.EW_RU_JOB_ID = event.EW_RU_JOB_ID
    this.TYPE = event.TYPE
    this.CORP_ID = event.CORP_ID
    this.isView = event.isView
  },
  onShow() {
    this.resetList()
  },
  methods: {
    async getData() {
      let resData = await getHotWorkRecord({
        EW_RU_TASK_ID: this.EW_RU_TASK_ID
      });
      this.list = [...this.list, ...resData.list];
    },
    resetList() {
      this.list = []
      this.getData()
    },
    /**
     * 跳转到延时监火的添加页面
     */
    goToAdd() {
      uni.$u.route({
        url: '/pages/eight_assignments/hot_work/delay_fire_monitoring/add',
        params: {taskId: this.EW_RU_TASK_ID, EW_RU_JOB_ID:this.EW_RU_JOB_ID,TYPE:this.TYPE}
      });
    },
    /**
     * 跳转到延时监火的任务转发页面
     */
    goToTaskForword() {
      uni.$u.route({
        url: '/pages/eight_assignments/hot_work/delay_fire_monitoring/task_forward',
        params: {taskId: this.EW_RU_TASK_ID, EW_RU_JOB_ID: this.EW_RU_JOB_ID, TYPE: this.TYPE, CORP_ID: this.CORP_ID}
      });
    },
    /**
     * 图片预览
     */
    ViewImage1(urls) {
      uni.previewImage({
        urls: [this.$filePath + urls]
      });
    },
    /**
     * 完成延时监火的确认按钮事件
     */
    async goSubmit() {
      await setTaskSign({
        EW_RU_JOB_ID: this.EW_RU_JOB_ID,
        EW_RU_TASK_ID: this.EW_RU_TASK_ID,
      })
      uni.$u.toast('保存成功')
      setTimeout(() => {
        uni.switchTab({
          url: '/pages/index/index'
        })
      }, 2000)
     },
    fnScan() {
      uni.$u.route({
        url: '/pages/eight_assignments/hot_work/delay_fire_monitoring/add',
        params: {taskId: this.EW_RU_TASK_ID, EW_RU_JOB_ID:this.EW_RU_JOB_ID,TYPE:this.TYPE}
      });
    },
    fnUpScan(){
      uni.$u.route({
        url: '/pages/eight_assignments/hot_work/delay_fire_monitoring/task_forward',
        params: {taskId: this.EW_RU_TASK_ID, EW_RU_JOB_ID:this.EW_RU_JOB_ID,TYPE:this.TYPE}
      });
    }
  }
}
</script>

<style scoped lang="scss">
.content {
  .padding {
    padding: 20upx;
  }

  .wui-form-list {
    background-color: #FFFFFF;
    border-radius: 10upx;
    margin: 20upx;
  }

  .wui-form-list .cu-form-group {
    color: #808080;
    font-size: 28upx;
    padding: 30upx;
    display: flex;
    justify-content: space-between;
  }

  .wui-form-list .cu-form-group .title {
    min-width: 200upx;
    width: max-content;
    font-weight: bold;
    color: #000000;
    font-size: 28upx;
    /* white-space: nowrap; */
  }

  .cu-form-group+.cu-form-group {
    border-top: 1px solid #eee;
  }

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