﻿<template>
  <div class="item-box common-info-box">
    <div class="item-title">安排部署</div>
    <div class="item-body">
      <div style="
          background-color: #fff;
          width: 100%;
          height: 100%;
          padding: 15px;
        ">
        <el-row :gutter="15" class="">
          <el-form ref="elForm" :model="dataForm" size="small" label-width="100px" label-position="right"
            :disabled="!!isDetail" :rules="rules">
            <el-col :span="24" v-if="false">
              <el-form-item label="主键" prop="id">
                <el-input v-model="dataForm.id" placeholder="请输入" clearable :style="{ width: '100%' }">
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24" v-if="ncc.hasFormP('specialActionType')">
              <el-form-item label="类型" prop="specialActionType">
                <el-select v-model="dataForm.specialActionType" placeholder="请选择" clearable required
                  :style="{ width: '100%' }">
                  <el-option v-for="(item, index) in specialActionTypeOptions" :key="index" :label="item.fullName"
                    :value="item.id"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="24" v-if="ncc.hasFormP('title')">
              <el-form-item label="标题" prop="title">
                <el-input v-model="dataForm.title" placeholder="请输入" clearable required :style="{ width: '100%' }">
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24" v-if="ncc.hasFormP('content')">
              <el-form-item label="内容" prop="content">
                <el-input v-model="dataForm.content" placeholder="请输入" show-word-limit :style="{ width: '100%' }"
                  type="textarea" :autosize="{ minRows: 4, maxRows: 4 }">
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="发布时间" prop="releaseTime">
                <el-date-picker v-model="dataForm.releaseTime" placeholder="请选择" clearable :style="{ width: '100%' }"
                  type="datetime">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="发布次数" prop="releaseCount">
                <el-input-number v-model="dataForm.releaseCount" :min="1" :max="100"></el-input-number>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="发布周期" prop="releaseCount">
                <el-select v-model="dataForm.releaseCycle" placeholder="请选择">
                  <el-option v-for="item in CycleOptions" :key="item.value" :label="item.label" :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="自动发布" prop="isOpenRelease">
                <el-radio-group v-model="dataForm.isOpenRelease">
                  <el-radio :label="true">是</el-radio>
                  <el-radio :label="false">否</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="24" v-if="ncc.hasFormP('annex')">
              <el-form-item label="附件" prop="annex">
                <NCC-UploadFz v-model="dataForm.annex" :fileSize="5" sizeUnit="MB" :limit="9" buttonText="点击上传">
                </NCC-UploadFz>
              </el-form-item>
            </el-col>
            <el-col :span="24" v-if="ncc.hasFormP('communicationArea')">
              <el-form-item label="传达区域" prop="communicationArea">
                <el-checkbox-group v-model="dataForm.communicationArea" :style="{}">
                  <el-checkbox v-for="(item, index) in communicationAreaOptions" :key="index" :label="item.id">{{
                    item.fullName }}</el-checkbox>
                </el-checkbox-group>
                <div style="margin-top: 10px;">
                  <el-button size="mini" @click="selectAll">全选</el-button>
                  <el-button size="mini" @click="invertSelection">反选</el-button>
                </div>
              </el-form-item>
            </el-col>
            <el-col :span="24" v-if="ncc.hasFormP('communicationArea')">
              <el-form-item label="填报表单" prop="communicationArea">
                <el-button size="mini" @click="dialogVisible = true">设计表单</el-button>
              </el-form-item>
            </el-col>
            <el-col :span="24" v-if="false">
              <el-form-item label="状态" prop="state">
                <el-input v-model="dataForm.state" placeholder="请输入" clearable :style="{ width: '100%' }">
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24" v-if="false">
              <el-form-item label="创建用户" prop="creatorUserId">
                <el-input v-model="dataForm.creatorUserId" placeholder="系统自动生成" readonly>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24" v-if="false">
              <el-form-item label="创建时间" prop="creatorTime">
                <el-input v-model="dataForm.creatorTime" placeholder="系统自动生成" readonly>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24" v-if="false">
              <el-form-item label="修改用户" prop="lastModifyUserId">
                <el-input v-model="dataForm.lastModifyUserId" placeholder="系统自动生成" readonly>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24" v-if="false">
              <el-form-item label="修改时间" prop="lastModifyTime">
                <el-input v-model="dataForm.lastModifyTime" placeholder="系统自动生成" readonly>
                </el-input>
              </el-form-item>
            </el-col>
          </el-form>
        </el-row>
        <span slot="footer" class="dialog-footer">
          <el-button @click="visible = false">取 消</el-button>
          <el-button type="primary" @click="dataFormSubmit()" v-if="!isDetail">确 定</el-button>
        </span>
      </div>
    </div>
    <el-dialog title="专项行动表单设计" :visible.sync="dialogVisible" fullscreen >
      <!-- <webDesignForm ref="webDesignForm"></webDesignForm> -->
      <iframe 
        :src="nestedPageUrl" 
        width="100%" 
        :height="viewportHeight - 110 + 'px'" 
        frameborder="0" 
        allowfullscreen>
      </iframe>
    </el-dialog>
  </div>
</template>
<script>
import request from "@/utils/request";
import { getDictionaryDataSelector } from "@/api/systemData/dictionary";
import { previewDataInterface } from "@/api/systemData/dataInterface";
import webDesignForm from './webDesign/Form.vue';

export default {
  components: { webDesignForm },
  props: [],
  data() {
    return {
      loading: false,
      visible: false,
      isDetail: false,
      dialogVisible: false,
      viewportHeight: 0,
      nestedPageUrl:"http://8.130.38.56:8043/old/#/onlineDev/webDesign/indexNew",
      dataForm: {
        id: undefined,
        specialActionType: undefined,
        title: undefined,
        content: undefined,
        releaseTime: null,
        annex: [],
        communicationArea: [],
        state: undefined,
        creatorUserId: undefined,
        creatorTime: undefined,
        lastModifyUserId: undefined,
        lastModifyTime: undefined,
        isOpenRelease: false,
      },
      rules: {
        specialActionType: [
          {
            required: true,
            message: "请输入类型",
            trigger: "change",
          },
        ],
        title: [
          {
            required: true,
            message: "请输入标题",
            trigger: "blur",
          },
        ],
      },
      CycleOptions: [
        {
          value: '天',
          label: '天'
        }, {
          value: '月',
          label: '月'
        },
        {
          value: '季',
          label: '季'
        },
        {
          value: '年',
          label: '年'
        },
      ],
      specialActionTypeOptions: [],
      communicationAreaOptions: [],
    };
  },
  computed: {},
  watch: {},
  created() {
    this.getspecialActionTypeOptions();
    this.getcommunicationAreaOptions();
    this.updateViewportHeight();
    // 监听窗口大小变化事件
    window.addEventListener('resize', this.updateViewportHeight);
  },
  mounted() { },
  beforeDestroy() {
    // 移除窗口大小变化事件监听器
    window.removeEventListener('resize', this.updateViewportHeight);
  },
  methods: {

    //查询所有区县
    getcommunicationAreaOptions() {
      request({
        url: "/extend/systeminformation/GetRegionList",
        method: "get",
      }).then((res) => {
        this.communicationAreaOptions = res.data;
      });
    },
    updateViewportHeight() {
      // 获取页面显示高度
      this.viewportHeight = window.innerHeight || document.documentElement.clientHeight;
    },
    getspecialActionTypeOptions() {
      getDictionaryDataSelector("576310654982423813").then((res) => {
        this.specialActionTypeOptions = res.data.list;
      });
    },
    selectAll() {
      this.dataForm.communicationArea = this.communicationAreaOptions.map(option => option.id);
    },
    invertSelection() {
      this.dataForm.communicationArea = this.communicationAreaOptions
        .filter(option => !this.dataForm.communicationArea.includes(option.id))
        .map(option => option.id);
    },
    goBack() {
      this.$emit("refresh");
    },
    init(id, isDetail) {
      this.dataForm.id = id || 0;
      this.visible = true;
      this.isDetail = isDetail || false;
      this.$nextTick(() => {
        this.$refs["elForm"].resetFields();
        if (this.dataForm.id) {
          request({
            url: "/Extend/BaseSpecialAction/" + this.dataForm.id,
            method: "get",
          }).then((res) => {
            this.dataForm = res.data;
            if (!this.dataForm.annex) this.dataForm.annex = [];
            if (!this.dataForm.communicationArea)
              this.dataForm.communicationArea = [];
          });
        }
      });
    },
    dataFormSubmit() {
      this.$refs["elForm"].validate((valid) => {
        if (valid) {
          if (!this.dataForm.id) {
            request({
              url: `/Extend/BaseSpecialAction`,
              method: "post",
              data: this.dataForm,
            }).then((res) => {
              this.$message({
                message: res.msg,
                type: "success",
                duration: 1000,
                onClose: () => {
                  (this.visible = false), this.$emit("refresh", true);
                },
              });
            });
          } else {
            request({
              url: "/Extend/BaseSpecialAction/" + this.dataForm.id,
              method: "PUT",
              data: this.dataForm,
            }).then((res) => {
              this.$message({
                message: res.msg,
                type: "success",
                duration: 1000,
                onClose: () => {
                  this.visible = false;
                  this.$emit("refresh", true);
                },
              });
            });
          }
        }
      });
    },
  },
};
</script>
<style>
.el-dialog__body{padding: 0px !important;}
</style>
