Form.vue 11 KB
<template>
  <el-dialog
    :title="!dataForm.id ? '新建' : isDetail ? '详情' : '编辑'"
    :close-on-click-modal="false"
    :visible.sync="visible"
    class="NCC-dialog NCC-dialog_center"
    lock-scroll
    width="50%"
    v-loading="loading"
  >
    <el-row :gutter="15" class="NCC-dialog-content">
      <el-form
        ref="elForm"
        :model="dataForm"
        size="small"
        label-width="100px"
        label-position="right"
        :disabled="!!isDetail"
        :rules="rules"
      >
        <el-col :span="23" 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="23" v-if="ncc.hasFormP('title') && !dataForm.id">
          <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="23" v-if="ncc.hasFormP('content') && !dataForm.id">
          <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="23" v-if="ncc.hasFormP('annex') && !dataForm.id">
          <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="23" 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 areaOptions"
                :key="index"
                :label="item.id"
                >{{ item.fullName }}</el-checkbox
              >
            </el-checkbox-group>
            <div style="margin-top: 10px">
              <el-button size="mini" @click="selectAreaAll('area')">全选</el-button>
              <el-button size="mini" @click="closeAreaAll('area')">反选</el-button>
            </div>
          </el-form-item>
        </el-col>
        <el-col :span="23" v-if="ncc.hasFormP('communicationOut')">
          <el-form-item label="传达外协" prop="communicationOut">
            <el-checkbox-group v-model="dataForm.communicationOut" :style="{}">
              <el-checkbox
                v-for="(item, index) in communicationOutOptions"
                :key="index"
                :label="item.id"
                >{{ item.fullName }}</el-checkbox
              >
            </el-checkbox-group>
            <div style="margin-top: 10px">
              <el-button size="mini" @click="selectAreaAll">全选</el-button>
              <el-button size="mini" @click="closeAreaAll">反选</el-button>
            </div>
          </el-form-item>
        </el-col>
        <el-col :span="23" v-if="ncc.hasFormP('relationId') && dataForm.id">
          <el-form-item label="填报表单" prop="relationId">
            <el-select v-model="dataForm.relationId" placeholder="请选择专项行动填报表单" style="margin-right: 10px;width: 300px;">
              <el-option v-for="item in BaseList" :key="item.id" :label="item.fullName" :value="item.id">
              </el-option>
            </el-select>
            <el-button size="mini" type="text" @click="dialogVisible = true">没有找到表单?点击设计表单</el-button>
          </el-form-item>
        </el-col>
        <el-col :span="23" v-if="ncc.hasFormP('deadline') && dataForm.id">
          <el-form-item label="截止日期" prop="deadline">
            <el-date-picker
              v-model="dataForm.deadline"
              type="date"
              placeholder="选择截止日期">
            </el-date-picker>
          </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" :loading="btnLoading">确 定</el-button>
    </span>
    <el-dialog class="zxDialog" title="专项行动表单设计" :visible.sync="dialogVisible" fullscreen @close="handleClose" :modal="false">
      <iframe 
        :src="nestedPageUrl" 
        width="100%" 
        :height="viewportHeight - 58 + 'px'" 
        frameborder="0" 
        allowfullscreen>
      </iframe>
    </el-dialog>
  </el-dialog>
</template>
<script>
import request from "@/utils/request";
import { getDictionaryDataSelector } from "@/api/systemData/dictionary";
import { previewDataInterface } from "@/api/systemData/dataInterface";
export default {
  components: {},
  props: [],
  data() {
    return {
      loading: false,
      visible: false,
      isDetail: false,
      dataForm: {
        id: "",
        id: undefined,
        specialActionType: undefined,
        title: undefined,
        content: undefined,
        releaseTime: undefined,
        annex: [],
        communicationArea: [],
        communicationOut: [],
        state: undefined,
        creatorUserId: undefined,
        creatorTime: undefined,
        lastModifyUserId: undefined,
        lastModifyTime: undefined,
        deadline: undefined,
        relationId: undefined,
      },
      rules: {
        specialActionType: [
          {
            required: true,
            message: "请输入类型",
            trigger: "change",
          },
        ],
        title: [
          {
            required: true,
            message: "请输入标题",
            trigger: "blur",
          },
        ],
        deadline: [
          {
            required: true,
            message: "请输入截止日期",
            trigger: "change",
          }
        ],
        relationId: [
          {
            required: true,
            message: "请选择关联表单",
            trigger: "change",
          }
        ]
      },
      areaOptions: [],
      communicationOutOptions: [],
      BaseList:[],
      viewportHeight: 0,
      nestedPageUrl:"http://8.130.38.56:8043/old/#/onlineDev/webDesign/indexNew",
      dialogVisible: false,
      btnLoading: false
    };
  },
  computed: {},
  watch: {},
  created() {
    this.initAreaTypeList();
    this.initCommunicationOutOptions();
    this.updateViewportHeight();
    this.getDataForm();
      // 监听窗口大小变化事件
      window.addEventListener('resize', this.updateViewportHeight);
  },
  mounted() {},
  beforeDestroy() {
    // 移除窗口大小变化事件监听器
    window.removeEventListener('resize', this.updateViewportHeight);
  },
  methods: {
    updateViewportHeight() {
      // 获取页面显示高度
      this.viewportHeight = window.innerHeight || document.documentElement.clientHeight;
    },
    handleClose() {
      // 这里是对话框关闭后需要执行的代码
      this.getDataForm();
      // 例如,你可以在这里添加任何其他的逻辑
    },
     //查询表单
     getDataForm() {
      request({
        url: "/visualdev/Base?type=1",
        method: "get",
      }).then((res) => {
        this.BaseList = res.data.list[0].children;
        console.log(this.BaseList)
      });
    },
    async initAreaTypeList() {
      let list = this.$store.state.meta.area;
      !list && (list = await this.$store.dispatch("getTypeListByCode", "area"));
      this.areaOptions = list;
    },
    async initCommunicationOutOptions() {
      let list = this.$store.state.meta.externalAssistanceList;
      !list && (list = await this.$store.dispatch("getTypeListByCode", "externalAssistance"));
      this.communicationOutOptions = list;
    },
    // 全选
    selectAreaAll(type) {
      if(type == 'area') {
        this.dataForm.communicationArea = this.areaOptions.map(
          (option) => option.id
        );
      } else {
        this.dataForm.communicationOut = this.communicationOutOptions.map(
          (option) => option.id
        );
      }
    },
    // 反选
    closeAreaAll(type) {
      if(type == 'area') {
        this.dataForm.communicationArea = this.areaOptions
          .filter(
            (option) => !this.dataForm.communicationArea.includes(option.id)
          )
          .map((option) => option.id);
      } else {
        this.dataForm.communicationOut = this.communicationOutOptions
          .filter(
            (option) => !this.dataForm.communicationOut.includes(option.id)
          )
          .map((option) => option.id);
      }
    },
   
    goBack() {
      this.$emit("refresh");
    },
    init(row, isDetail) {
      this.dataForm.id = row.id || 0;
      this.visible = true;
      this.isDetail = isDetail || false;
      this.$nextTick(() => {
        this.$refs["elForm"].resetFields();
        if(this.dataForm.id) {
          console.log(row, 'row');
          this.dataForm.communicationArea = JSON.parse(row.communicationArea);
          this.dataForm.communicationOut = JSON.parse(row.communicationOut);
        }
      });
    },
    dataFormSubmit() {
      this.$refs["elForm"].validate((valid) => {
        if (valid) {
          this.btnLoading = true;
          if (!this.dataForm.id) {
            let {title, content, annex, communicationArea, communicationOut} = this.dataForm;
            // 新增
            request({
              url: `/Extend/BaseSpecialAction`,
              method: "post",
              data: { title, content, annex, communicationArea, communicationOut },
            }).then((res) => {
              this.$message({
                message: res.msg,
                type: "success",
                duration: 1000,
                onClose: () => {
                  this.btnLoading = false;
                  (this.visible = false), this.$emit("refresh", true);
                },
              });
            }).catch(() => this.btnLoading = false);
          } else {
            // 发布任务
            request({
              url: "/Extend/BaseSpecialAction/Release",
              method: "PUT",
              data: this.dataForm,
            }).then((res) => {
              this.$message({
                message: res.msg,
                type: "success",
                duration: 1000,
                onClose: () => {
                  this.btnLoading = false;
                  this.visible = false;
                  this.$emit("refresh", true);
                },
              });
            }).catch(() => this.btnLoading = false);
          }
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
</style>