<template>
  <el-dialog
      :modal="true"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      destroy-on-close
      title="其他部门惩戒清单"
      :model-value="dialogVisible"

      :before-close="handleClose"
  >
    <diy-el-form ref="formDialogRef" class="form" :forms="formConfig" v-model:model-form="form">

    </diy-el-form>
    <template  v-if="dialogOperationType != 'detail'" #footer>
      <el-button :icon="SuccessFilled" @click="conform">确定</el-button>
      <el-button @click="handleClose" :icon="Close">取消</el-button>
    </template>
  </el-dialog>
</template>

<script>
import {Close, Delete, Edit, Plus, SuccessFilled} from "@element-plus/icons-vue";
import DiyElForm from "@/components/common/DiyElForm.vue";
import {computed, onBeforeMount, ref} from "vue";
import {handleMes} from "@/units/element-ui/tip";
import {rewardsAndPunishmentsMeasureManageDetail} from "@/data/all-form";
import {
  proInsertXyxxJccs, proUpdateXyxxJccs
} from "@/service/combined-rewards-and-punishments/rewards-and-punishments-measure-manage/rewards-and-punishments-measure-manage";
import {InsertSyslog} from "@/units/use-method/user-log";
export default {
  name: "RewardsAndPunishmentsMeasureManageSettingDialog",
  components:{DiyElForm},
  computed: {
    Delete() {
      return Delete
    },
    Edit() {
      return Edit
    },
    Plus() {
      return Plus
    },
    SuccessFilled() {
      return SuccessFilled
    },
    Close() {
      return Close
    }
  },
  props:{
    dialogVisible:{  //是否可见

    },
    dialogOperationType:{   //操作类型

    },
    currentDialogObj:{   //当前选中信息

    },
  },
  setup(props,{emit}){
    const form = ref({});  //表单内容-值
    const formConfig = ref({...rewardsAndPunishmentsMeasureManageDetail});
    const formDialogRef =ref(null);  //表单ref
    function conform(){
      formDialogRef.value.refEl.validate(commit);
    }
    function commit(){
      debugger
      if(form.value.CSID){  //修改
        proUpdateXyxxJccs({
          CODE: form.value.CSID,
          bwlmc: form.value.BWLMC,
          csjb: form.value.CSJB,
          jclxmc: form.value.JCLXMC,
          jyzrbm: form.value.ZRBM,
          time: form.value.TIME,
          csmc: form.value.CSMC,
          bwlid: form.value.BWLID,
          jclx: form.value.JCLX,
          tgdw: form.value.TGDW
        }).then(res =>{
          handleMes(res,() => {
            InsertSyslog(localStorage.getItem("xyxx_usercode"),localStorage.getItem("xyxx_unitcode"), "信息修改", "奖惩措施管理修改成功", "奖惩措施管理", "")
            handleClose();
            emit('getTableData')
          })
        })
      }else{  //新增
        proInsertXyxxJccs({
          bwlmc: form.value.BWLMC,
          csjb: form.value.CSJB,
          jclxmc: form.value.JCLXMC,
          jyzrbm: form.value.ZRBM,
          time: form.value.TIME,
          csmc: form.value.CSMC,
          bwlid: form.value.BWLID,
          jclx: form.value.JCLX,
          tgdw: form.value.TGDW
        }).then(res =>{
          handleMes(res,() => {
            InsertSyslog(localStorage.getItem("xyxx_usercode"),localStorage.getItem("xyxx_unitcode"), "信息新增", "奖惩措施管理新增成功", "奖惩措施管理", "")
            handleClose();
            emit('getTableData')
          })
        })
      }
    }
    function handleClose(){
      emit('update:dialogVisible',false);
    }
    onBeforeMount(()=>{
      formConfig.value.formAttrs.disabled=props.dialogOperationType === 'detail';
      form.value = {
        ...props.currentDialogObj
      }
    })
    return {
      form,
      formDialogRef,
      formConfig,
      conform,
      handleClose,
    }
  }
}
</script>

<style scoped>

</style>