<template>
  <div>
    <LHeader :text="text"></LHeader>
    <van-cell-group
        inset
        v-for="(item, index) in messageList"
        :key="index"
        @click="goDetail(item.pid)"
      >
        <van-row gutter="">
          <van-col span="7">隐患编号：</van-col>
          <van-col span="17">{{ item.pid }}</van-col>
        </van-row>
        <van-row gutter="">
          <van-col span="7">隐患项目名称：</van-col>
          <van-col span="17">{{ item.projectName }}</van-col>
        </van-row>
        <van-row gutter="">
          <van-col span="7">隐患级别：</van-col>
          <van-col span="17">{{ item.hdLev | dangerText }}</van-col>
        </van-row>
        <!-- <van-row gutter="">
          <van-col span="7">隐患发现时间：</van-col>
          <van-col span="17">{{ item.createTime }}</van-col>
        </van-row> -->
        <!-- *接口对接4 END -->
        <!-- 详情 -->
      <div class="detail">详情</div>
      </van-cell-group>

    <van-form
      @submit="onSubmit"
      :show-error='false'
      :scroll-to-error="true"
      validate-trigger="onSubmit"
    >
        <van-field
          v-model="opinion"
          label="批示内容"
          name="superviseAdd"
          rows="3"
          type="textarea"
          placeholder="请输入"
        />
      <div style="margin: 16px;">
        <van-button round block type="info" native-type="submit"
          >保存</van-button
        >
      </div>
    </van-form>
    <div style="margin:10px 16px 0px;padding-bottom:16px">
      <van-button round block type="warning" @click.native="cancel"
        >取消</van-button
      >
    </div>
  </div>
</template>

<script>
import LHeader from "@/components/header.vue";
import {getFun,postFun} from "@/service/table.js";
import { superviseAdd } from "@/service/danger";
export default {
  name:"super-survey",
  components: {
    LHeader
  },
  data() {
    return {
      taskId: "",
      text: "隐患督办批示",
      messageList: [],
      opinion: "",
    

    };
  },
    beforeRouteEnter(to, from, next) {
    next(vm => {
      if (from.name === "supervise-danger") {
        vm.messageList = [];
        let paramsData = to.params.data;
        vm.taskId = paramsData.taskId;
        vm.messageList.push(paramsData);
        vm.opinion = "";
      }
    });
  },
  created() {},
  methods: {
    onSubmit(values) {
      this.$toast.loading({
        message: "提交中...",
        forbidClick: true,
        loadingType: "spinner",
        duration: 0
      });
      let formdata = new FormData()
      formdata.append('instructionsContent', values.instructionsContent)
      superviseAdd(`/instructions/add`,formdata)
        .then(res => {
          this.$toast.clear();
          this.$toast.success({
            message: "提交成功",
            duration: 2000
          });
          history.go(-1);
        })
        .catch(() => {
          this.$toast.clear();
          this.$toast.fail("提交失败,请稍后再试");
        });
    },
     // 详情
    goDetail(pid) {
      this.$router.push({
        name: "normal-detail",
        params: {
          id: pid
        }
      });
    },

    cancel() {
      this.$router.go(-1);
    }
  }
};
</script>
<style lang="less" scoped>
/* @import url(); 引入css类 */
.van-cell-group--inset {
  margin: 0;
  margin-bottom: 10px;
  padding: 10px;
  font-size: 13px;
  position: relative;
  .van-row {
    margin-bottom: 0.133333rem;
    line-height: 0.64rem;
  }
  .van-overlay {
    position: absolute;
    .wrapper {
      display: flex;
      align-items: center;
      justify-content: space-evenly;
      height: 100%;
    }
  }
}
.detail {
  position: absolute;
  bottom: 0.32rem;
  right: 15px;
  color: #2a80f7;
  font-weight: none;
  z-index: 99;
}
</style>
