name: instance_query
amis_schema: |-
  {
    "type": "service",
    "body": [
        {
        "type": "button",
        "label": "查找",
        "id": "u:instance_query",
        "level": "default",
        "className": "instance-query-btn",
        "onEvent": {
            "click": {
            "actions": [
                {
                "actionType": "dialog",
                "dialog": {
                    "type": "dialog",
                    "title": "高级搜索",
                    "body": [
                    {
                        "type": "form",
                        "title": "表单",
                        "persistData": "instanceSearchFormData",
                        "body": [
                        {
                            "label": "流程",
                            "type": "steedos-select-flow",
                            "name": "flow",
                            "id": "u:36f73975bd24",
                            "mode": "tree-select",
                            "searchable": true,
                            "className": "!mb-6"
                        },
                        {
                            "type": "radios",
                            "label": "申请单状态",
                            "name": "state",
                            "options": [
                            {
                                "label": "流转中",
                                "value": "pending"
                            },
                            {
                                "label": "已结束",
                                "value": "completed"
                            }
                            ],
                            "id": "u:565121a7b6ac"
                        },
                        {
                            "type": "select",
                            "label": "归档",
                            "name": "archive",
                            "options": [
                            {
                                "label": "未归档",
                                "value": false
                            },
                            {
                                "label": "已归档",
                                "value": true
                            }
                            ],
                            "id": "u:052da4105733",
                            "multiple": false,
                            "clearable": true
                        },
                        {
                            "type": "input-text",
                            "label": "文件标题",
                            "name": "name",
                            "id": "u:eefd91d3e001"
                        },
                        {
                            "type": "input-text",
                            "label": "提交人姓名",
                            "name": "applicant_name",
                            "id": "u:873b9ef9bc4b"
                        },
                        {
                            "type": "input-text",
                            "label": "提交人所属部门名称",
                            "name": "applicant_organization_name",
                            "id": "u:646b6efbbfcc"
                        },
                        {
                            "type": "input-date-range",
                            "label": "提交日期",
                            "name": "submit_date",
                            "embed": false,
                            "inputFormat": "YYYY-MM-DD",
                            "format": "YYYY-MM-DDT00:00:00.000[Z]",
                            "joinValues": false
                        }
                        ],
                        "id": "u:742f9c0dc8a1",
                        "mode": "normal"
                    }
                    ],
                    "id": "u:d6a6647ba65a",
                    "actions": [
                    {
                        "type": "button",
                        "label": "确定",
                        "onEvent": {
                        "click": {
                            "actions": [
                            {
                                "componentId": "",
                                "args": {
                                },
                                "actionType": "custom",
                                "script": "\n\nconst selector = {};\n\nconst isSearchInstanceTasks = ['inbox', 'outboux'].includes(Session.get('box'));\n\nconst { flow, state, name, archive, applicant_name, applicant_organization_name, submit_date } = event.data;\n\nconst and = [];\n\n\nif (flow) {\n  Session.set(\"flowId\", flow);\n  selector['flow'] = flow;\n} else {\n  Session.set(\"flowId\", null);\n}\n\n\nif (state) {\n  selector[isSearchInstanceTasks ? 'instance_state' : 'state'] = state\n  Session.set(\"instance-search-state\", state)\n}\n\nif (name) {\n  var name_key_words = name.split(\" \");\n  _.each(name_key_words, function (k) {\n    and.push({\n      [isSearchInstanceTasks ? 'instance_name' : 'name']: {\n        $regex: Steedos.convertSpecialCharacter(k)\n      }\n    });\n  })\n  Session.set(\"instance-search-name\", name)\n}\n\nif (and.length > 0) {\n  selector.$and = and;\n}\n\nif (applicant_name) {\n  selector.applicant_name = {\n    $regex: Steedos.convertSpecialCharacter(applicant_name)\n  };\n  Session.set(\"instance-search-appplicant-name\", applicant_name)\n}\n\nif (applicant_organization_name) {\n  selector.applicant_organization_name = {\n    $regex: Steedos.convertSpecialCharacter(applicant_organization_name)\n  };\n  Session.set(\"instance-search-applicant-organization-name\", applicant_organization_name)\n}\n\nif (submit_date && submit_date.length === 2) {\n  var submit_date_start = submit_date[0];\n  Session.set(\"submit-date-start\", submit_date_start);\n  var submit_date_end = submit_date[1];\n  Session.set(\"submit-date-end\", submit_date_end);\n  if (submit_date_start && submit_date_end) {\n    selector.submit_date = {\n      $gte: new Date(submit_date_start),\n      $lte: new Date(submit_date_end)\n    };\n  } else if (submit_date_start && !submit_date_end) {\n    selector.submit_date = {\n      $gte: new Date(submit_date_start),\n      $lte: new Date()\n    };\n  } else if (!submit_date_start && submit_date_end) {\n    selector.submit_date = {\n      $gte: new Date(null),\n      $lte: new Date(submit_date_end)\n    };\n  }\n}\n\n\nvar ins_is_archived = archive;\n\nSession.set(\"instance-earch-is-archived\", ins_is_archived);\n\nif (ins_is_archived) {\n  if (ins_is_archived) {\n    selector[\"values.record_need\"] = \"true\";\n    selector.is_archived = true;\n  } else {\n    selector[\"values.record_need\"] = \"true\";\n    selector.is_archived = {\n      $ne: true\n    };\n  }\n}\n\nSession.set('instance_more_search_selector', selector);"
                            },
                            {
                                "componentId": "",
                                "args": {
                                },
                                "actionType": "closeDialog"
                            }
                            ]
                        }
                        },
                        "id": "u:d34523242f59",
                        "level": "primary"
                    },
                    {
                        "type": "button",
                        "label": "取消",
                        "onEvent": {
                        "click": {
                            "actions": [
                            {
                                "componentId": "",
                                "args": {
                                },
                                "actionType": "closeDialog"
                            }
                            ]
                        }
                        },
                        "id": "u:41efdab9a0c4"
                    }
                    ],
                    "closeOnEsc": false,
                    "closeOnOutside": false,
                    "showCloseButton": true,
                    "size": "md"
                }
                }
            ],
            "weight": 0
            }
        }
        }
    ],
    "regions": [
        "body"
    ],
    "data": {
        "context": {
        "rootUrl": "http://127.0.0.1:5300",
        "tenantId": "osjAHnCr7nampKZ9Z",
        "userId": "63044e7529b3b23f86e0c95a",
        "authToken": "5cf8ab7088dc78270cd6ade9d01c51fba791b0c34430fb293bd8e5d20d7cb40e8a1478019f05b61ddeb57a"
        },
        "app_id": "",
        "tab_id": "",
        "object_name": "",
        "dataComponentId": "",
        "record_id": "",
        "record": {
        },
        "permissions": {
        }
    },
    "bodyClassName": "p-0",
    "id": "u:8ea24306e6b2"
    }
is_enable: true
label: 查找
'on': list
type: amis_button
visible: true
