<template>
  <div class="epidemic-form">
    <div class="dialog-h-content scroll-h">
      <el-form
        ref="ref_form1"
        :inline="true"
        :model="formData"
        :rules="dataRule"
        class="form"
      >
        <el-form-item
          label="通知渠道"
          prop="isSelChannel"
          label-width="150px"
          style="display: block"
        >
          <span>小程序通知</span>
          <!-- <el-checkbox v-model="formData.isSelChannel"
                       key="0"
                       label="0">小程序通知</el-checkbox> -->
          <!-- <el-checkbox-group v-model="formData.channel">
            <el-checkbox key="1"
                         label="1">小程序通知</el-checkbox>
            <el-checkbox key="2"
                         label="2">短信通知</el-checkbox>

          </el-checkbox-group> -->
        </el-form-item>

        <el-form-item
          label="通知内容"
          prop="content"
          label-width="150px"
          style="display: block"
        >
          <el-input
            class="item_width_1"
            type="textarea"
            maxlength="500"
            show-word-limit
            :autosize="{ minRows: 10, maxRows: 15 }"
            clearable
            placeholder="请输入通知内容"
            v-model="formData.content"
          ></el-input>
        </el-form-item>
      </el-form>
    </div>

    <div class="form_div_btn">
      <el-button size="small" @click="handleCancle">取 消</el-button>
      <el-button
        size="small"
        type="primary"
        :disabled="btnDisable"
        @click="handleComfirm"
        >确 定</el-button
      >
    </div>
  </div>
</template>

<script>
import { Loading } from "element-ui"; // 引入Loading服务
import { requestPost } from '@/js/dai/request'

let loading; // 加载动画
export default {
  data() {
    return {
      btnDisable: false,
      formData: {
        origin: null,
        isSelChannel: false,
        channel: [],
        content: "",
      },
    };
  },
  props:{
    noticeOrigin:{
      type:String,
      default:null
    }
  },
  components: {},
  mounted() {
    this.formData.origin = this.noticeOrigin
  },
  methods: {
    handleCancle() {
      this.$emit("diaClose");
    },
    async handleComfirm() {
      this.formData.channel = ["0"];

      if (!this.formData.content) {
        this.$message({
          type: "warning",
          message: "请填写通知内容",
        });
        return false;
      }

      this.btnDisable = true;
      setTimeout(() => {
        this.btnDisable = false;
      }, 5000);

      let url = "";

      url = "/epmetuser/icNotice/sendPointNotice";

      const { data, code, msg } = await requestPost(url, this.formData);

      if (code === 0) {
        this.$message({
          type: "success",
          message: "操作成功",
        });
        this.resetData();
        this.btnDisable = false;
        this.handleCancle();
      } else {
        this.btnDisable = false;
        this.$message.error(msg);
      }
    },
    resetData() {
      this.formData = {
        origin: null,
        isSelChannel: false,
        channel: [],
        content: "",
      };
    },

    // 开启加载动画
    startLoading() {
      loading = Loading.service({
        lock: true, // 是否锁定
        text: "正在加载……", // 加载中需要显示的文字
        background: "rgba(0,0,0,.7)", // 背景颜色
      });
    },
    // 结束加载动画
    endLoading() {
      // clearTimeout(timer);
      if (loading) {
        loading.close();
      }
    },
  },
  computed: {
    dataRule() {
      return {
        channel: [
          { required: true, message: "通知渠道不能为空", trigger: "blur" },
        ],
        content: [
          { required: true, message: "通知内容不能为空", trigger: "blur" },
        ],
      };
    },
  },
};
</script>


<style lang="scss" scoped >
@import "@/assets/scss/modules/management/epidemic.scss";
</style>


