import { defineComponent, ref, reactive, computed, onMounted, resolveComponent, openBlock, createBlock, isRef, unref, withCtx, createVNode, createElementVNode, toDisplayString, withKeys, createTextVNode, createCommentVNode } from 'vue';
import '../../../api/index.mjs';
import { useBaseApi } from '../../../api/base/index.mjs';

const _hoisted_1 = { style: { "color": "#fff" } };
const _hoisted_2 = { style: { "padding": "8px 16px", "background-color": "var(--el-color-primary-light-9)", "border-left": "5px solid var(--el-color-primary)", "margin-bottom": "5px" } };
const _hoisted_3 = { style: { "padding": "8px 16px", "background-color": "var(--el-color-primary-light-9)", "border-left": "5px solid var(--el-color-primary)", "margin-bottom": "5px" } };
const _hoisted_4 = { style: { "margin-top": "10px" } };
const _hoisted_5 = { class: "dialog-footer" };
var _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "userSelectDialog",
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    title: {
      type: String,
      default: ""
    },
    data: {
      type: Array,
      default: () => []
    },
    orgService: {
      type: String,
      default: "autoRes"
    },
    orgAction: {
      type: String,
      default: "userOrgList"
    },
    orgPost: {
      type: Boolean,
      default: true
    },
    orgparas: {
      type: Object,
      default: null
    },
    userService: {
      type: String,
      default: "autoRes"
    },
    userAction: {
      type: String,
      default: "UserTable"
    },
    userParams: {
      type: Object,
      default: () => {
      }
    }
  },
  emits: ["update:visible", "change"],
  setup(__props, { emit: __emit }) {
    let emits = __emit;
    const props = __props;
    const userList = ref([]);
    let checkedUsersList = ref([]);
    const state = reactive({
      total: 0,
      queryParams: {
        orgId: -1,
        page: 1,
        pageSize: 50
      }
    });
    let visibleDialog = computed({
      get() {
        return props.visible;
      },
      set() {
        closeDialog();
      }
    });
    onMounted(async () => {
      await getUserList();
    });
    const resetQuery = () => {
      state.queryParams = {};
      handleQuery();
    };
    const handleNodeChange = async (node) => {
      var _a, _b, _c;
      state.queryParams.orgId = node.id;
      state.queryParams.cmpId = (_a = node.cmpId) != null ? _a : 0;
      state.queryParams.deptId = (_b = node.deptId) != null ? _b : 0;
      state.queryParams.groupId = (_c = node.groupId) != null ? _c : 0;
      await handleQuery();
    };
    const getUserList = async () => {
      var _a, _b, _c, _d;
      let res = await useBaseApi(props.userService).post({ ...state.queryParams, ...props.userParams }, props.userAction);
      userList.value = (_b = (_a = res.data.result) == null ? void 0 : _a.items) != null ? _b : [];
      state.queryParams.total = (_d = (_c = res.data.result) == null ? void 0 : _c.total) != null ? _d : 0;
    };
    async function handleQuery() {
      state.queryParams.pageNum = 1;
      await getUserList();
    }
    function handleSelectUser(row) {
      if (!row || row.id == "") return;
      emits("change", { id: row.id, name: row.realName, data: row });
    }
    const handledbclick = (row) => {
      handleSelectUser(row);
    };
    const handleSizeChange = (val) => {
      state.queryParams.pageSize = val;
      handleQuery();
    };
    const handleCurrentChange = (val) => {
      state.queryParams.page = val;
      handleQuery();
    };
    const closeDialog = () => {
      checkedUsersList.value = [];
      emits("update:visible", false);
    };
    return (_ctx, _cache) => {
      const _component_ele_Edit = resolveComponent("ele-Edit");
      const _component_el_icon = resolveComponent("el-icon");
      const _component_FmTree = resolveComponent("FmTree");
      const _component_el_col = resolveComponent("el-col");
      const _component_el_input = resolveComponent("el-input");
      const _component_el_form_item = resolveComponent("el-form-item");
      const _component_el_button = resolveComponent("el-button");
      const _component_el_button_group = resolveComponent("el-button-group");
      const _component_el_form = resolveComponent("el-form");
      const _component_ele_Plus = resolveComponent("ele-Plus");
      const _component_el_table_column = resolveComponent("el-table-column");
      const _component_el_table = resolveComponent("el-table");
      const _component_el_pagination = resolveComponent("el-pagination");
      const _component_el_card = resolveComponent("el-card");
      const _component_el_row = resolveComponent("el-row");
      const _component_el_dialog = resolveComponent("el-dialog");
      return openBlock(), createBlock(_component_el_dialog, {
        modelValue: unref(visibleDialog),
        "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => isRef(visibleDialog) ? visibleDialog.value = $event : visibleDialog = $event),
        style: { "width": "70vw" },
        "append-to-body": "",
        draggable: "",
        "close-on-click-modal": false
      }, {
        header: withCtx(() => [
          createElementVNode("div", _hoisted_1, [
            createVNode(_component_el_icon, {
              size: "16",
              style: { "margin-right": "3px", "display": "inline", "vertical-align": "middle" }
            }, {
              default: withCtx(() => [
                createVNode(_component_ele_Edit)
              ]),
              _: 1
              /* STABLE */
            }),
            createElementVNode(
              "span",
              null,
              toDisplayString(_ctx.$t("\u9009\u62E9")) + toDisplayString(_ctx.$t(__props.title)),
              1
              /* TEXT */
            )
          ])
        ]),
        footer: withCtx(() => [
          createElementVNode("div", _hoisted_5, [
            createVNode(_component_el_button, {
              icon: "ele-CircleCloseFilled",
              onClick: closeDialog
            }, {
              default: withCtx(() => [
                createTextVNode(
                  toDisplayString(_ctx.$t("\u53D6\u6D88")),
                  1
                  /* TEXT */
                )
              ]),
              _: 1
              /* STABLE */
            }),
            createCommentVNode(' <el-button type="primary" icon="ele-CircleCheckFilled" @click="saveDialog">\u786E\u5B9A</el-button> ')
          ])
        ]),
        default: withCtx(() => [
          createVNode(_component_el_row, { gutter: 10 }, {
            default: withCtx(() => [
              createVNode(_component_el_col, { span: 6 }, {
                default: withCtx(() => [
                  createElementVNode(
                    "p",
                    _hoisted_2,
                    toDisplayString(_ctx.$t("\u673A\u6784")),
                    1
                    /* TEXT */
                  ),
                  createVNode(_component_FmTree, {
                    ref: "orgTreeRef",
                    apiService: __props.orgService,
                    apiAction: __props.orgAction,
                    isPost: __props.orgPost,
                    paras: __props.orgparas,
                    onNodeClick: handleNodeChange,
                    style: { "height": "calc(100% - 40px)", "overflow-y": "scroll", "overflow-x": "hidden" }
                  }, null, 8, ["apiService", "apiAction", "isPost", "paras"])
                ]),
                _: 1
                /* STABLE */
              }),
              createVNode(_component_el_col, { span: 18 }, {
                default: withCtx(() => [
                  createElementVNode(
                    "p",
                    _hoisted_3,
                    toDisplayString(_ctx.$t(__props.title)) + toDisplayString(_ctx.$t("\u5217\u8868")),
                    1
                    /* TEXT */
                  ),
                  createElementVNode("div", _hoisted_4, [
                    createVNode(_component_el_form, {
                      model: state.queryParams,
                      ref: "queryRef",
                      inline: true
                    }, {
                      default: withCtx(() => [
                        createVNode(_component_el_form_item, {
                          label: _ctx.$t("\u5173\u952E\u5B57")
                        }, {
                          default: withCtx(() => [
                            createVNode(_component_el_input, {
                              modelValue: state.queryParams.keyword,
                              "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => state.queryParams.keyword = $event),
                              clearable: "",
                              style: { "width": "150px" },
                              onKeyup: withKeys(handleQuery, ["enter"])
                            }, null, 8, ["modelValue"])
                          ]),
                          _: 1
                          /* STABLE */
                        }, 8, ["label"]),
                        createVNode(_component_el_form_item, null, {
                          default: withCtx(() => [
                            createVNode(_component_el_button_group, null, {
                              default: withCtx(() => [
                                createVNode(_component_el_button, {
                                  type: "primary",
                                  icon: "ele-Search",
                                  onClick: handleQuery
                                }, {
                                  default: withCtx(() => [
                                    createTextVNode(
                                      toDisplayString(_ctx.$t("\u67E5\u8BE2")),
                                      1
                                      /* TEXT */
                                    )
                                  ]),
                                  _: 1
                                  /* STABLE */
                                }),
                                createVNode(_component_el_button, {
                                  icon: "ele-Refresh",
                                  onClick: resetQuery
                                }, {
                                  default: withCtx(() => [
                                    createTextVNode(
                                      toDisplayString(_ctx.$t("\u91CD\u7F6E")),
                                      1
                                      /* TEXT */
                                    )
                                  ]),
                                  _: 1
                                  /* STABLE */
                                })
                              ]),
                              _: 1
                              /* STABLE */
                            }),
                            createCommentVNode(' <el-button type="primary" icon="ele-DArrowRight" plain style="margin-left: 10px" @click="handleSelectAllUser"> \u5168\u9009 </el-button> ')
                          ]),
                          _: 1
                          /* STABLE */
                        })
                      ]),
                      _: 1
                      /* STABLE */
                    }, 8, ["model"]),
                    createVNode(_component_el_card, {
                      class: "full-table",
                      shadow: "hover"
                    }, {
                      default: withCtx(() => [
                        createVNode(_component_el_table, {
                          ref: "refTable",
                          data: userList.value,
                          style: { "height": "calc(70vh - 96px)" },
                          onRowDblclick: handledbclick
                        }, {
                          default: withCtx(() => [
                            createVNode(_component_el_table_column, {
                              label: "\u64CD\u4F5C",
                              width: "60",
                              align: "center"
                            }, {
                              default: withCtx((scope) => [
                                createVNode(_component_el_button, {
                                  link: "",
                                  type: "primary",
                                  onClick: ($event) => handleSelectUser(scope.row)
                                }, {
                                  default: withCtx(() => [
                                    createVNode(_component_el_icon, null, {
                                      default: withCtx(() => [
                                        createVNode(_component_ele_Plus)
                                      ]),
                                      _: 1
                                      /* STABLE */
                                    })
                                  ]),
                                  _: 1
                                  /* STABLE */
                                }, 8, ["onClick"])
                              ]),
                              _: 1
                              /* STABLE */
                            }),
                            createVNode(_component_el_table_column, {
                              label: _ctx.$t("\u8D26\u53F7\u540D\u79F0"),
                              prop: "account",
                              align: "center",
                              "show-overflow-tooltip": true
                            }, null, 8, ["label"]),
                            createVNode(_component_el_table_column, {
                              label: _ctx.$t("\u771F\u5B9E\u59D3\u540D"),
                              prop: "realName",
                              align: "center",
                              "show-overflow-tooltip": true
                            }, null, 8, ["label"]),
                            createVNode(_component_el_table_column, {
                              label: _ctx.$t("\u8054\u7CFB\u65B9\u5F0F"),
                              prop: "phone",
                              align: "center",
                              "show-overflow-tooltip": true
                            }, null, 8, ["label"]),
                            createVNode(_component_el_table_column, {
                              label: _ctx.$t("\u5C97\u4F4D"),
                              prop: "posName",
                              align: "center",
                              "show-overflow-tooltip": true
                            }, null, 8, ["label"]),
                            createVNode(_component_el_table_column, {
                              label: _ctx.$t("\u5DE5\u53F7"),
                              prop: "jobNum",
                              align: "center",
                              "show-overflow-tooltip": true
                            }, null, 8, ["label"]),
                            createVNode(_component_el_table_column, {
                              label: _ctx.$t("\u6240\u5C5E\u673A\u6784"),
                              prop: "orgName",
                              align: "center",
                              "show-overflow-tooltip": true
                            }, null, 8, ["label"])
                          ]),
                          _: 1
                          /* STABLE */
                        }, 8, ["data"]),
                        createVNode(_component_el_pagination, {
                          currentPage: state.queryParams.page,
                          "page-size": state.queryParams.pageSize,
                          total: state.queryParams.total,
                          "page-sizes": [10, 20, 50, 100],
                          background: "",
                          onSizeChange: handleSizeChange,
                          onCurrentChange: handleCurrentChange,
                          layout: "total, sizes, prev, pager, next, jumper",
                          style: { "padding-bottom": "8px" }
                        }, null, 8, ["currentPage", "page-size", "total"])
                      ]),
                      _: 1
                      /* STABLE */
                    })
                  ])
                ]),
                _: 1
                /* STABLE */
              })
            ]),
            _: 1
            /* STABLE */
          })
        ]),
        _: 1
        /* STABLE */
      }, 8, ["modelValue"]);
    };
  }
});

export { _sfc_main as default };
