/**
 * Created by 1 at 2023-12-19 11:06:39
 * 注册事件类【机构数据填报列表】，参看event.defaultEvent.js
*/
window.$swEvent.setup("mztb.base.partyDataFill.partyDataFillList", {
  setup(page){
    const { $params, $refs, $widgets, $model, $utils, $tabRouter, $api, $lifecycle, $engine, $parent } = page || {};
    const { $$message, $$http, $$sys, $$UtilPub } = $utils || {};

    // 示例
    const demoFunc = () => {

    };

    let task; // 填报月
    let task_text; // 填报月格式化
    let type; // 填报类型(2 年报 1 月报)

    const setValue =(id,data) => {
      task = data.task;
      task_text = data.text;
      type = data.task.includes("99") ? 2 : 1;
    }
    const toPageEdit = async () => {
      if ($model.ds_1.data.form.task === undefined) {
        $$message.notify.warning("请选择任务")
        return false
      }
      // 检查当前机构是否重复推送
      const rt = await $$http.post("mztb/partyDataFill/checkRepetition", {task: $model.ds_1.data.form.task,task_text : $model.ds_1.data.form.task_text})
      $api.closeDialog("tb_dialog")
      $api.toPage("mztb.partyDataFillCard", {
        $fromAction: 'button:add'
        , task: $model.ds_1.data.form.task
        , type: $model.ds_1.data.form.month
        , task_text: $model.ds_1.data.form.task_text
        , outOldData: $model.ds_1.data.form.outOldData
      })
    }

    const selectHide =(data) => {
      if(Number(data) === 1) { //月报
        $refs.year.hide();
        $refs.month1.show();
      }else { // 年报
        $refs.month1.hide();
        $refs.year.show();
      }
      $model.ds_1.data.form.task = undefined
      $model.ds_1.data.form.task_text = ''
    }
    const clearValue = () => {
      $model.ds_1.data.form.task = undefined
      $model.ds_1.data.form.task_text = ''
    }

    const setTypeDef =()=> {
      $model.ds_1.data.form.month = 1
    }

    // 按钮显示隐藏
    const edit_del_affirm_Hide = (data) => { // 编辑 删除 确认
      return Number(data.scope.row.fo_state) === 0
    }
    const  affirm_push_CancelHide= (data) => { // 取消确认 推送
      return Number(data.scope.row.fo_state) === 1
    }

    // 自定义请求 逻辑删除 填报主表
    const logicDel = async (data) => {
      const rt = await $$http.post("mztb/partyDataFill/logicDel", {id: data.row.fo_id})
      if (rt.code === 0) {
        $api.loadList()
        $$message.notify.success("删除完成")
      }
    }
    // 自定义请求 确认
    const affirm = async (data) => {
      const rt =await $$http.post("mztb/partyDataFill/affirm",{id : data.row.fo_id})
      if(rt.code === 0) {
        $api.loadList()
        $$message.notify.success("已确认")
      }
    }
    // 自定义请求 取消确认
    const cancelAffirm =async (data) => {
      const rt = await $$http.post("mztb/partyDataFill/cancelAffirm",{id : data.row.fo_id})
      if(rt.code === 0) {
        $api.loadList()
        $$message.notify.success("已取消确认")
      }
    }
    // 自定义请求推送 数据
    const pushData = (data) => {
      const rt = $$http.post("mztb/partyDataFill/pushData",{id : data.row.fo_id})
      if(rt.code === 0) {
        $api.loadList()
      }
    }

    return {
      demoFunc,setValue,toPageEdit,selectHide,setTypeDef,edit_del_affirm_Hide,affirm_push_CancelHide
      ,logicDel,affirm,cancelAffirm,pushData,clearValue
    }
  }
});
