<template>
  <div>
    <LHeader :text="text"></LHeader>
    <van-form
      @submit="onSubmit"
      :show-error='false'
      :scroll-to-error="true"
      validate-trigger="onSubmit"
    >
      <van-field name="radio" label="隐患复查结果">
        <template #input>
          <van-radio-group
            v-model="radio"
            direction="horizontal"
            @change="selectResult"
          >
            <van-radio name="1">同意</van-radio>
            <van-radio name="0">退回</van-radio>
          </van-radio-group>
        </template>
      </van-field>

      <!-- 同意时的选项 -->
      <div class="agree" v-if="radio == 1">
        <van-field
          v-model="agreeOpinion"
          label="审批意见"
          name="reviewDetails"
          rows="3"
          type="textarea"
          placeholder="请输入"
        />
      </div>

      <!-- 退回是的选项 -->
      <div class="disagree" v-else>
        <van-field
        readonly
        clickable
        name="level"
        :value="thinkLevel"
        label="认为隐患级别"
        placeholder="请选择"
        @click="showThinkLevel = true"
        :rules="[{ required: true, message: '认为隐患级别不能为空' }]"
      />
      <van-popup v-model="showThinkLevel" position="bottom">
        <van-picker
          show-toolbar
          value-key="projectName"
          :columns="columnsThinkLevel"
          @confirm="onConThinkLevel"
          @cancel="showThinkLevel = false"
        />
      </van-popup>

        <van-field
          v-model="disagreeOpinion"
          label="审批意见"
          name="reviewDetails"
          rows="3"
          type="textarea"
          placeholder="请输入"
          :rules="[{ required: true, message: '退回原因不能为空' }]"
        />
      </div>

      <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 { dangerReviewAdd } from "@/service/danger";
export default {
  components: {
    LHeader
  },
  data() {
    return {
      taskId: "",
      radio: "1",
      text: "重大隐患审批",
      agreeOpinion: "",
      disagreeOpinion: "",
      thinkLevel:'', //因为隐患级别
      showThinkLevel: false,
      columnsThinkLevel:["重大隐患","一般隐患A","一般隐患B","一般隐患C",]

    };
  },
   created() {
    this.taskId = this.$route.params.taskId;
  },
  methods: {
    selectResult(val) {
      this.radio = val;
    },

    onSubmit(values) {
      console.log("submit", values);
      this.$toast.loading({
        message: "提交中...",
        forbidClick: true,
        loadingType: "spinner",
        duration: 0
      });
    //   let formdata = new FormData()
    //   formdata.append('reviewResult', this.radio)
    //   formdata.append('reviewDetails', values.reviewDetails)
    //   dangerReviewAdd(`/review/add1/${this.taskId}`,formdata)
    //     .then(res => {
    //       this.$toast.clear();
    //       this.$toast.success({
    //         message: "提交成功",
    //         duration: 2000
    //       });
    //       history.go(-1);
    //     })
    //     .catch(() => {
    //       this.$toast.clear();
    //       this.$toast.fail("提交失败,请稍后再试");
    //     });
    },

    // 所属工程名称
    onConThinkLevel(value) {
      this.thinkLevel = value;
      this.showProjectName = false;
    },



    cancel() {
      this.$router.go(-1);
    }
  }
};
</script>
<style lang="less" scoped>
/* @import url(); 引入css类 */
</style>
