﻿<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">
      <el-form
        ref="elForm"
        :model="dataForm"
        size="small"
        label-width="110px"
        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 />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="系统名称" prop="systemName">
			      <el-select
 			        v-model="dataForm.systemName"
 			        filterable
 			        remote
 			        reserve-keyword
 			        placeholder="请输入关键词"
 			        :remote-method="getSystemSelect"
               @change="systemChange"
 			        :loading="system_loading">
 			        <el-option
 			          v-for="item in systemOption"
 			          :key="item.value"
 			          :label="item.systemName"
 			          :value="item.id">
 			        </el-option>
 			      </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="注册主体" prop="registeredEntity">
            <el-input v-model="dataForm.registeredEntity" placeholder="选择系统自动带出" clearable disabled/>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="系统类别" prop="category">
            <el-input v-model="dataForm.category" placeholder="选择系统自动带出" clearable disabled/>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="备案号" prop="recordNumber">
            <el-input v-model="dataForm.recordNumber" placeholder="选择系统自动带出" clearable disabled/>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="所属区县" prop="districtCounty">
              <el-radio-group
                v-model="dataForm.districtCounty"
                placeholder="请选择所属区县"
                style="line-height: 22px"
              >
                <el-radio v-for="v in areaOptions" :key="v.id" :label="v.id">{{
                  v.fullName
                }}</el-radio>
              </el-radio-group>
            </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="违法原因" prop="illegalReasons">
            <el-input type="textarea" v-model="dataForm.illegalReasons" placeholder="请输入违法原因" clearable maxlength="200"/>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="处罚要求" prop="punishmentRequirements">
            <el-input type="textarea" v-model="dataForm.punishmentRequirements" placeholder="请输入处罚要求" clearable maxlength="200"/>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="处罚内容" prop="punishmentContent">
            <el-input type="textarea" v-model="dataForm.punishmentContent" placeholder="请输入处罚内容" clearable maxlength="200"/>
          </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" v-if="!isDetail" @click="submit(1)">{{isSHILevel ? '下 发' : '上 报'}}</el-button>
      <el-button type="info" v-if="!isDetail" @click="submit(0)">保 存</el-button>
    </span>
  </el-dialog>
</template>
<script>
import infoMixin from "@/mixins/info";
import request from "@/utils/request";
import { getSystemDetail } from "@/api/baseData/info";
import { dynamicTextUP } from "@/filters/index";

export default {
  mixins: [infoMixin],
  data() {
    return {
      visible: false,
      loading: false,
      isDetail: false,
      dataForm: {
		    id: undefined,
		    registrationTime: undefined,
		    systemName: undefined,
		    registeredEntity: undefined,
		    category: undefined,
		    recordNumber: undefined,
		    districtCounty: undefined,
		    illegalReasons: undefined,
		    punishmentRequirements: undefined,
		    punishmentContent: undefined,
		    state: undefined,
		    record: undefined,
		    caseHandlingOpinions: undefined,
		    enforcementRecords: undefined,
		    noticeLetter: undefined,
		    punishmentDecision: undefined,
		    closingReport: undefined,
	    },
      rules: {
        systemName: [
          { required: true, message: "请选择系统名称", trigger: "change" }
        ],
        districtCounty: [
          { required: true, message: "请选择所属区域", trigger: "change" }
        ],
      },
      systemOption: [],
      system_loading: false,
      areaOptions: [],
    };
  },
  computed: {
    isSHILevel() {
      // 判断角色是否为‘市级办公室’
      return this.$store.state.user.islader;
    },
  },
  watch: {},
  created() {
    this.getSystemSelect();
    this.initSystemTypeList();
    this.initAreaTypeList();
  },
  mounted() {},
  methods: {
    // 获取系统列表
    getSystemSelect(val) {
      let query = {
        SystemName: val || "",
      };
      this.system_loading = true;
      request({
        url: "/Extend/basesysteminfo/GetNoPagingList",
        method: "get",
        params: query,
      }).then(({data}) => {
        this.systemOption = data;
        this.system_loading = false;
      })
    },
    // 系统名称改变
    systemChange(val) {
      getSystemDetail(val).then(({data}) => {
        this.dataForm.registeredEntity = data.companyId;
        this.dataForm.category = dynamicTextUP(data.systemType, this.systemTypeOptions);
        this.dataForm.recordNumber = data.specialRecordNumber || '--';
        this.dataForm.districtCounty = data.areaId;
      })
    },
    goBack() {
      this.$emit("refresh");
    },
    init(id, isDetail) {
      this.dataForm.id = id || 0;
      this.isDetail = isDetail || false;
      //   this.loading = true;
      this.visible = true;
      this.$nextTick(() => {
        this.$refs["elForm"].resetFields();
        if (this.dataForm.id) {
          request({
            url: `/Extend/BaseCaseHandling/${this.dataForm.id}`,
            method: "GET",
          }).then((res) => {
            this.dataForm = res.data;
            // this.loading = false;
          });
        }
      });
    },
    // 提交
    submit(type) {
      // type: 1 上报 0 保存
      let obj = {
        ...this.dataForm,
        isReport: type,
      }
			this.$refs['elForm'].validate((valid) => {
        if(!type || valid) {
          request({
            url: `/Extend/BaseCaseHandling`,
            method: "POST",
            data: obj,
          }).then((res) => {
            this.$message({
              type: "success",
              message: res.msg,
              onClose: () => {
                this.visible = false;
                this.$emit("refresh", true);
              },
            });
          });
        }
      })
    }
  },
};
</script>
