<template>
    <!-- 归属地变更申请结果处理 -->
    <el-dialog
      title="归属地变更申请结果处理"
      :close-on-click-modal="false"
      :visible.sync="visible"
      class="NCC-dialog NCC-dialog_center"
      lock-scroll
      width="70%"
    >
        <div class="NCC-dialog-content">
          <el-form
        :model="dataForm"
        :rules="rules"
        ref="elForm"
        size="small"
        label-width="100px"
        v-loading="loading"
      >
        <!-- <el-form-item label="市属" prop="city">
          <el-input
            v-model="dataForm.city"
            placeholder="请输入市属"
            maxlength="20"
          ></el-input>
        </el-form-item> -->
        <el-form-item label="转入归属地" prop="toChangeIntoId">
          <el-radio-group
            v-model="dataForm.toChangeIntoId"
            placeholder="请选择所属区县"
            style="line-height: 22px"
          >
            <el-radio v-for="v in areaOptions" :key="v.id" :label="v.id" :disabled="!!dataForm.id">{{ v.fullName }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="内容描述" prop="applnycontent">
          <el-input
            type="textarea"
            v-model="dataForm.applnycontent"
            placeholder="请输入内容描述"
            maxlength="300"
            :disabled="!!dataForm.id"
          ></el-input>
        </el-form-item>
        <el-form-item label="处理结果" prop="processingresults">
          <el-radio-group v-model="dataForm.processingresults">
            <el-radio label="同意">同意</el-radio>
            <el-radio label="不同意">不同意</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="处理意见" prop="opinion">
          <el-input
            type="textarea"
            v-model="dataForm.opinion"
            placeholder="请输入处理意见"
            maxlength="300"
          ></el-input>
        </el-form-item>
          </el-form>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="visible = false">取 消</el-button>
          <el-button type="primary" @click="dataFormSubmit" :loading="btnLoading">确 定</el-button>
        </span>
    </el-dialog>
  </template>
  <script>
  import request from "@/utils/request";
  export default {
    components: {},
    props: [],
    data() {
      return {
        loading: false,
        visible: false,
        isDetail: false,
        dataForm: {
          id: "",
          applnycontent: '',
          toChangeIntoId: '',
          processingresults: '',
          opinion: '',
        },
        rules: {
            areaId: [
                { required: true, message: '请选择转入归属地', trigger: 'change' },
            ],
            processingresults: [
                { required: true, message: '请选择处理意见', trigger: 'change' },
            ],
        },
        areaOptions: [],
        btnLoading: false,
      };
    },
    computed: {},
    watch: {},
    created() {
        this.initAreaTypeList();
    },
    mounted() {},
    methods: {
      async initAreaTypeList() {
        let list = this.$store.state.meta.area;
            !list && (list = await this.$store.dispatch('getTypeListByCode', 'area'));
            this.areaOptions = list;
      },
     
      goBack() {
        this.$emit("refresh");
      },
      init(id, isDetail) {
        this.dataForm.id = id || '';
        this.visible = true;
        this.isDetail = isDetail || false;
        this.$nextTick(async () => {
          this.$refs["elForm"].resetFields();
          if(!this.dataForm.id) return
          this.loading = true;
          request({
              url: `/Extend/BaseChangeTerritory/${this.dataForm.id}`,
              method: "GET",
          }).then((res) => {
              this.dataForm.toChangeIntoId = res.data.toChangeIntoId;
              this.dataForm.id = res.data.id;
              this.dataForm.applnycontent = res.data.applnycontent;
              this.loading = false;
          })
        });
      },
      dataFormSubmit() {
        this.$refs["elForm"].validate(async (valid) => {
          if (valid) {
            this.btnLoading = true;
            request({
              url: `/Extend/BaseChangeTerritory/DisposeOf`,
              method: "POST",
              data: this.dataForm,
            }).then((res) => {
                this.btnLoading = false;
                this.visible = false;
                this.$message({
                  message: res.msg,
                  type: 'success'
                });
                this.$emit("refresh", true);
            }).catch(() => {
                this.btnLoading = false;
            });
          
          }
        });
      },
    },
  };
  </script>
  