<template>
  <view >
    <cu-custom bgColor="bg-gradual-blueness" :isBack="true">
      <block slot="backText">返回</block>
      <block slot="content">隐患登记</block>
    </cu-custom>
    <hiddenAdd hidden_source="2" :check_content="CHECK_CONTENT"/>
  </view>
</template>

<script>
import {
   formatDate, loginSession
} from '@/common/tool.js';
import hiddenAdd from '@/components/hidden_add/index.vue';

export default {
  components: {
    hiddenAdd
  },
  data() {
    return {
      CHECK_CONTENT:"",
      msg:"",
      HIDDEN_ID:"",
      riskId:"",
      itemId:"",
      LISTMANAGER_ID:"",
      RISK_UNIT_ID:"",
      RISK_UNIT_NAME:"",
      index:"",
    }
  },
  onLoad(event) {
    let now = new Date();
    var tomorrow = now.setDate(now.getDate() + 1);
    tomorrow = new Date(tomorrow);
    this.rectifyPlanCompletionStartTime = formatDate(tomorrow, 'yyyy-MM-dd');
    this.HIDDEN_ID = event.HIDDEN_ID;
    if (this.HIDDEN_ID) {
      this.msg = "riskListCheckEdit";
      // this.getData();
    } else {
      this.CHECK_CONTENT = JSON.parse(decodeURIComponent(event.checkContent));
      this.riskId = JSON.parse(decodeURIComponent(event.riskId));
      this.itemId = JSON.parse(decodeURIComponent(event.itemId));
      this.LISTMANAGER_ID = JSON.parse(decodeURIComponent(event.LISTMANAGER_ID));
      this.RISK_UNIT_ID = JSON.parse(decodeURIComponent(event.RISK_UNIT_ID));
      this.RISK_UNIT_NAME = JSON.parse(decodeURIComponent(event.RISK_UNIT_NAME));
      this.index = event.index;
    }
    loginSession();
  },
  beforeDestroy() {
    uni.$off('submitByHiddenSource')
  },
  mounted() {
    uni.$on('submitByHiddenSource', (data) => {
      this.submitByHiddenSource(data)
    })
  },

  methods: {
    submitByHiddenSource(data) {
      if (data.info == 'success') {
        uni.showToast({
          icon: 'none',
          title: '提交成功',
          duration: 1500
        });
        setTimeout(() => {
          var pages = getCurrentPages();	// 获取当前页面栈
          var prePage = pages[pages.length - 1];	// 上一个页面
          // var task = prePage.$vm.list[_this.index];
          prePage.$vm.initflag = data.initflag;    // A 页面 init方法 为true
          uni.navigateBack({});
          uni.hideLoading();
        }, 1500)

      }
    }
  }
}
</script>

<style>
.prevent {
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  overflow: hidden;
}

.cu-form-title {
  padding: 20upx 0;
}

.cu-form-textarea {
  background-color: #ffffff;
  padding: 1upx 30upx 20upx;
  min-height: 100upx;
}

.cu-form-textarea textarea {
  height: 4.6em;
  width: 100%;
  line-height: 1.2em;
  flex: 1;
  font-size: 28upx;
  padding: 0;
}

.selected {
  display: flex;
  align-items: center;
  height: 100upx;
}

.selected .radio {
  transform: scale(0.8);
  margin-right: 10upx;
}

.group {
  display: flex;
  align-items: center;
}

.cu-form-group .title {
  font-size: 28upx;
  font-weight: bold;
  color: #000;
}

.cu-bar .action:first-child {
  font-size: 28upx;
}

.cu-form-group .picker {
  color: #808080;
}

.picker-tree {
  color: #808080;
}

.ai_btn {
  width: 100%;
  box-sizing: border-box;
  background: #FFFFFF;
  margin-bottom: 10px;
  padding: 10px;
}

.ai_btn .ai_btn_con {
  width: 45%;
  background: #dfeaff;
  border-radius: 20px;
  display: flex;
  align-items: center;
  height: 40px;
  padding: 0 10px;
}
</style>
