﻿delete from "LOWCODE_FRAME"."LOWCODE_DBFORM_ENHANCE_JS" where dbform_id in (select id from "LOWCODE_FRAME"."LOWCODE_DBFORM"  where TABLE_NAME in ('lc_fire_operation'));
insert into "LOWCODE_FRAME"."LOWCODE_DBFORM_ENHANCE_JS"("ID", "TENANT_ID", "CREATE_USER", "CREATE_TIME", "CREATE_DEPT", "UPDATE_USER", "UPDATE_TIME", "IS_DELETED", "DBFORM_ID", "JS_TYPE", "JS_JSON") values(1968941306648506371, 1, 1, '2025-09-19 15:32:43', 100, 1, '2025-11-20 17:51:36', 0, 1963872316314165250, 'js', '// 初始化全局数据
let assigneeData = {}
let processDefinitionId = ''''
let dbFormId = undefined
let dataId = undefined
let rowId = undefined

//初始化控件
useFun.controlInit(''ControlView'', ''taskSelectView'', {
  controlName: ''BpmTaskSelectAssigneeForm'', //控件名称（全局注册的控件使用，例：el-transfer ）
  controlPath: ''components/BpmTaskAssign/TaskSelectAssigneeForm.vue'', //控件相对路径（未全局注册的控件使用，例：components/IFrame/src/IFrame.vue）
  controlParams: {
    name: ''BpmTaskSelectAssigneeForm'',
    updateModelValue: (newVal) => {
      assigneeData = newVal
    },
    modelValue: assigneeData
  }, //控件配置
  showType: ''dialog'', //弹窗类型 dialog | drawer
  popOption: { //弹窗配置
    title: ''发起人选择审批人'', //标题
    width: '''', //弹窗宽度
    fullscreen: false, //是否全屏
    footerBtn: [ //底部按钮配置
      {
        params: { "type": "primary" }, //el-button 其他参数
        name: ''确定'', //按钮名称
        display: true, //是否显示
        loading: true, //点击时是否有loading
        icon: '''', //图标
        clickFun: (loading) => {
          // 这里需要先验证表单
          componentRef.value.taskSelectView.controlRef.validateAssignee(() => {
            // 利用事件完成了双向绑定，拿到了数据
            console.log(JSON.stringify(assigneeData))
            let assignee = {}
            Object.keys(assigneeData).forEach(key => {
              assignee[key] = assigneeData[key].split('','')
            })
            console.log(JSON.stringify(assignee))
            useFun.requestApi(''post'', ''/bpm/process-instance/listCreate'', {
              data: { ''processDefinitionId'': processDefinitionId, ''dbFormId'': dbFormId, ''dataId'': dataId, ''assignee'': assignee }
            }).then(res2 => {
              if (res2.length > 0) {
                message.success(''流程发起成功'')
                useFun.refreshChange()
              } else {
                message.error(res2.message)
              }
              // 最后关闭这个
              if (loading) loading()
              taskSelectView.value.show = false
            })
          }, () => {
            // 操作失败触发事件
            if (loading) loading()
          })
        }
      }
    ],
    headerBtn: [], //顶部按钮配置（配置同上）
    dialogParams: {}, //弹窗其他配置
    handleClose: (done) => { //关闭弹窗前的回调
      done()
    }
  }
})



//初始化控件
useFun.controlInit(''FormView'', ''formView_253058'', {
  formId: ''1991395199198253058'', //表单设计id
  formType: ''edit'', //表单类型 add | edit | view
  handleType: '''', //处理类型 default | returnData
  showType: ''dialog'', //弹窗类型 dialog | drawer
  showButton: true, //是否显示底部默认操作按钮
  dataOption: { //数据配置 

  },
  defaultData: {}, //默认表单数据
  enhanceData: {}, //传递给表单js增强内部调用配置
  popOption: { //弹窗配置
    title: ''选择流程表单'', //标题
    width: '''', //弹窗宽度
    heigth: ''800px'',
    fullscreen: false, //是否全屏
    footerBtn: [ //底部按钮配置
      // {
      //   params: {}, //el-button 其他参数
      //   name: ''测试按钮'', //按钮名称
      //   display: true, //是否显示
      //   loading: true, //点击时是否有loading
      //   icon: '''', //图标
      //   clickFun: (loading) => {
      //     //点击事件
      //     if (loading) loading() //关闭loading
      //   }
      // }
    ],
    headerBtn: [], //顶部按钮配置（配置同上）
    dialogParams: {} //弹窗其他配置
  },
  beforeClose: (type, done, formData, loading) => {
    // type:关闭类型  submit:提交后触发  close:直接关闭弹窗触发
    // done:关闭弹窗方法 formData:表单数据  loading:关闭loading方法
    if (type == ''submit'') {
      debugger
      formData.detail.forEach((item) => {
        if (item.selected == "1") {
          processDefinitionId = item.id
        }
      })
      useFun.requestApi(''get'', ''/bpm/task-assign-rule/list?processDefinitionId='' + processDefinitionId)
        .then(taskAssignRules => {
          let userSelectRules = taskAssignRules?.filter(rule => rule.type === 35)
          if (userSelectRules?.length > 0) {
            taskSelectView.value.params.controlParams.taskAssignRules = userSelectRules
            taskSelectView.value.show = true
          } else {
            // 直接发起流程
            useFun.requestApi(''post'', ''/bpm/process-instance/listCreate'', {
              data: { ''processDefinitionId'': processDefinitionId, ''dbFormId'': props.tableId, ''dataId'': rowId }
            }).then(res2 => {
              if (res2.length > 0) {
                message.success(''流程发起成功'')
                useFun.refreshChange()
              } else {
                message.error(res2.message)
              }
            })
          }
        }).catch(err => {
          message.error(err.message)
        })
    }
    done()
  }
})

const { taskSelectView } = Vue.toRefs(rendControlData.value)
const { formView_253058 } = Vue.toRefs(rendControlData.value)

return {
  btnViewApprove(row) {
    if (row.processInstanceId) {
      useFun.urlPush(''/process-instance/detail'', { id: row.processInstanceId });
    } else {
      message.warning(''当前单据无流程记录'')
    }
  },
  btnSubmitApprove(row) {
    loading.value = true
    dbFormId = props.tableId
    dataId = row.id
    if (row.approveStatus !== 1 && row.approveStatus !== 2) {
      useFun.requestApi(''get'', ''/bpm/process-definition/dbformlist?dbFormId='' + props.tableId, {
        data: { ''dbFormId'': props.tableId }
      }).then(res => {
        rowId = row.id
        if (res?.length > 0) {
          formView_253058.value.show = true
          const controlData = formView_253058.value.params //FormView的配置
          controlData.defaultData.detail = res
        } else {
          message.error(res.message)
        }

      })
    }

    loading.value = false
  }
}');

DELETE from "LOWCODE_FRAME"."LOWCODE_DESFORM" where id ='1991395199198253058';

insert into "LOWCODE_FRAME"."LOWCODE_DESFORM"("ID", "TENANT_ID", "CREATE_USER", "CREATE_TIME", "CREATE_DEPT", "UPDATE_USER", "UPDATE_TIME", "IS_DELETED", "DESFORM_NAME", "DESFORM_JSON", "GROUP_DESFORM_ID", "IS_OPEN", "IS_TEMPLATE", "IS_HIDE", "I18N_DATA") values(1991395199198253058, 1, 1, '2025-11-20 14:36:28', 100, 1, '2025-11-20 17:20:09', 0, '流程选择表单', '{"jsEnhance":"return {\r\n  beforeSubmit(submitData) { //表单提交前执行\r\n    var hasSelect = false\r\n    formData.value.detail.forEach((item) => {\r\n      if (item.selected == \"1\") {\r\n        hasSelect = true\r\n      }\r\n    })\r\n    if (!hasSelect) {\r\n      message.warning(''请选择要使用的流程表单！'')\r\n      resolve(false)\r\n    }else{\r\n      return new Promise((resolve, reject) => {\r\n      resolve(submitData)\r\n    })\r\n    }\r\n  },\r\n}","scssEnhance":".low-form__1991395199198253058 {\n\n  //样式请写在当前位置内\n  .readonly {\n    pointer-events: none;\n    border: none;\n  }\n}","labelPosition":"right","labelSuffix":" ","labelWidth":120,"gutter":20,"menuBtn":true,"submitBtn":true,"submitText":"提交","emptyBtn":false,"emptyText":"清空","externalTitle":"","menuPosition":"center","size":"default","isSubmitTable":true,"column":{"detail":{"type":"layoutTable","controlType":"layout","label":"表格布局","dataType":"array","tableType":"cellEdit","btnData":{"menu":[],"header":[]},"tableEnhanceStr":"return {\r\n  //表格配置初始化\r\n  initTable() {\r\n    if (formData.value.detail.length == 1) {\r\n      formData.value.detail[0].$selected = \"1\"\r\n      formData.value.detail[0].selected = \"1\"\r\n    }\r\n  },\r\n  //表格数据格式化\r\n  setTableData(data, { type, index, id }) {\r\n\r\n    return data\r\n  },\r\n  //底部统计配置\r\n  // summaryMethod(columns, tableData) {\r\n  //   const sums = [];\r\n  //   if (columns.length > 0) {\r\n  //     columns.forEach((column, index) => {\r\n  //       let prop = column.property;\r\n  //       sums[index] = ''-'';\r\n  //     });\r\n  //   }\r\n  //   return sums;\r\n  // }, \r\n  // rowStyle({ row, rowIndex }) { }, //行样式\r\n  // cellStyle({ row, column, rowIndex, columnIndex }) { }, //列样式\r\n  rowClick(row, column, event) {\r\n    if (column.columnKey == ''selected'') {\r\n      formData.value.detail.forEach((item) => {\r\n        if (item.id !== row.id) {\r\n          item.$selected = \"0\"\r\n          item.selected = \"0\"\r\n        }\r\n      })\r\n    }\r\n  }, //行单击\r\n}\r\n","params":{"headerAlign":"center","align":"center","addBtn":false,"delBtn":false,"editBtn":true,"selection":false,"border":true,"menuWidth":120},"column":{"id":{"type":"input","controlType":"input","label":"文本输入框","readonly":true,"clearable":true,"display":false,"span":12,"disabled":false,"required":false,"hideLabel":false,"i18nCode":"fields_3318245"},"name":{"type":"input","controlType":"input","label":"流程名称","readonly":true,"clearable":true,"display":true,"span":12,"disabled":true,"required":false,"hideLabel":false,"i18nCode":"fields_1700720","className":"readonly","placeholder":""},"description":{"type":"input","controlType":"input","label":"流程描述","readonly":true,"clearable":true,"display":true,"span":24,"disabled":true,"required":false,"hideLabel":false,"i18nCode":"fields_2096109","className":"readonly","placeholder":" "},"selected":{"type":"switch","controlType":"select","label":"使用当前流程","value":"0","dicData":[{"lable":"","value":"0"},{"lable":"","value":"1"}],"display":true,"span":12,"disabled":false,"hideLabel":false,"i18nCode":"fields_9855417","moreOptionStr":"return {\n\n}"}},"display":true,"span":24,"hideLabel":true,"i18nCode":"fields_1081934"}},"group":[]}', 1820725650445041666, 'N', 'N', 'N', '{"fields_3318245":"return {\n  //简体中文\n  ''zh-CN'': ''文本输入框'',\n  //English\n  ''en'': '''',\n}","fields_1700720":"return {\n  //简体中文\n  ''zh-CN'': ''流程名称'',\n  //English\n  ''en'': '''',\n}","fields_2096109":"return {\n  //简体中文\n  ''zh-CN'': ''流程描述'',\n  //English\n  ''en'': '''',\n}","fields_9855417":"return {\n  //简体中文\n  ''zh-CN'': ''使用当前流程'',\n  //English\n  ''en'': '''',\n}","config_submitBtn":"return {\n  //简体中文\n  ''zh-CN'': ''提交'',\n  //English\n  ''en'': '''',\n}","config_emptyBtn":"return {\n  //简体中文\n  ''zh-CN'': ''清空'',\n  //English\n  ''en'': '''',\n}","config_externalTitle":"return {\n  //简体中文\n  ''zh-CN'': '''',\n  //English\n  ''en'': '''',\n}"}');