<template>
  <div class="dialog" v-if="dialogForm">
    <div class="head_box">
      <span class="title">转为指令</span>
      <div>
        <el-button type="primary" size="small" :loading="loading" @click="submit" >保存</el-button>
        <el-button size="small" @click="close">关闭</el-button>
      </div>
    </div>
    <div class="form_cnt">
      <FormMessage v-model="listQuery" :formList="formData" ref="elform" :rules="rules"></FormMessage>
    </div>
  </div>
</template>

<script setup>
import FormMessage from '@/components/aboutTable/FormMessage.vue'
import { qcckGet, qcckPost, qcckPut } from "@/api/qcckApi.js";
import { useRouter } from "vue-router";
import { ref, defineExpose, reactive, onMounted, defineEmits, getCurrentInstance, nextTick } from "vue";
const emit = defineEmits(["updateDate"]);
const props = defineProps({
  dic: Object
});
const router = useRouter();
const { proxy } = getCurrentInstance();
const dialogForm = ref(false); //弹窗
const rules = reactive({
  zlbt: [{ required: true, message: "请输入指令标题", trigger: "blur" }],
  zllx: [{ required: true, message: "请选择指令类型", trigger: "change" }],
  zldj: [{ required: true, message: "请选择指令等级", trigger: "change" }],
  jssj: [{ required: true, message: "请选择反馈结束时间", trigger: "change" }],
  zllxr: [{ required: true, message: "请输入联系人", trigger: "blur" }],
  zllxdh: [{ required: true, message: "请输入联系电话", trigger: "blur" }],
  zsdw: [{ required: true, message: "请选择主送单位", trigger: "change" }],
  csdw: [{ required: true, message: "请选择抄送单位", trigger: "change" }],
  zlnr: [{ required: true, message: "请输入指令内容", trigger: "blur" }],
});
const formData = ref([
  { label: "线索名称", prop: "glxs", type: "input", disabled:true },
  { label: "指令标题", prop: "zlbt", type: "input", },
  { label: "指令类型", prop: "zllx",  type: "select", options: props.dic.D_GS_XS_ZLLX  },
  { label: "指令等级", prop: "zldj",  type: "select", options: props.dic.D_GS_ZDQT_FXDJ },
  { label: "反馈结束时间", prop: "jssj",  type: "datetime"  },
  { label: "联系人", prop: "zllxr",  type: "input"  },
  { label: "联系电话", prop: "zllxdh",  type: "input"  },
  { label: "主送单位", prop: "zsdw",  type: "department"  },
  { label: "抄送单位", prop: "csdw",  type: "department"  },
  { label: "指令内容", prop: "zlnr",  type: "textarea",width: '100%' },
  { label: "附件", prop: "fjzd",  type: "upload",width: '100%' },
]);
const listQuery = ref({}); //表单
const loading = ref(false);
const elform = ref();

onMounted(() => {});
// 初始化数据
const init = (row) => {
  listQuery.value.fjzd = null
  dialogForm.value = true;
  listQuery.value.glxs = row.xsMc;
  listQuery.value.glxsid = row.id;
};
;

// 提交
const submit = () => {
  elform.value.submit((data)=>{
    let params = { ...data }
    params.fjzd = params.fjzd ? params.fjzd.join(','):''
    loading.value = true;
    qcckPost(params, '/mosty-gsxt/zlxx/add').then((res) => {
      loading.value = false;
      proxy.$message({ type: "success", message: "转发成功" });
      router.push('/InstructionInformation')
    }).catch(() => {loading.value = false;});
  });
};

// 关闭
const close = () => {
  listQuery.value = {};
  dialogForm.value = false;
  loading.value = false;
};
defineExpose({ init });
</script>

<style lang="scss" scoped>
@import "~@/assets/css/layout.scss";
@import "~@/assets/css/element-plus.scss";
</style>
