var A = Object.defineProperty;
var M = (e, s, t) => s in e ? A(e, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[s] = t;
var l = (e, s, t) => (M(e, typeof s != "symbol" ? s + "" : s, t), t);
import { PluginStaticResource as j, ViewMode as D } from "@ibiz-template/runtime";
import { CustomPortletController as B, ViewPortletController as N, SpanEditorController as R, AppPortalViewNerve as F, AppPortalViewController as G } from "@ibiz-template/controller";
import m from "dayjs";
import { PortletPartModel as q, ListModel as E, ViewPortletModel as Y } from "@ibiz-template/model";
import { defineComponent as w, reactive as z, watch as k, h as a, getCurrentInstance as C, ref as P, computed as _ } from "vue";
import { useNamespace as p, useTabExpViewController as U, useRouter as $, useRoute as V, getViewName as K, getSpanProps as W, useListController as L, useViewController as H } from "@ibiz-template/vue-util";
const J = new j(import.meta.url);
class Q {
  constructor() {
    l(this, "component", "IndexView");
  }
}
class O extends B {
  constructor() {
    super(...arguments);
    l(this, "items", [
      {
        text: "近一年",
        value: 12
      },
      {
        text: "近半年",
        value: 6
      },
      {
        text: "近三月",
        value: 3
      }
    ]);
    l(this, "data", {
      selectDate: [],
      itemValue: 12
    });
    l(this, "onItemValueChange", (t) => {
      const r = m();
      this.data.selectDate = [
        r.subtract(t, "month").add(1, "day").toDate(),
        r.toDate()
      ];
    });
  }
  async onInit() {
    await super.onInit(), this.onItemValueChange(this.data.itemValue), this.changeViewParams();
  }
  changeViewParams() {
    const [t, r] = this.data.selectDate;
    if (t && r) {
      const o = m(t).format("YYYY-MM-DD"), i = m(r).format("YYYY-MM-DD");
      this.dashboard.nerve.self.evt.asyncEmit(
        "contextOrParamsChange",
        { ...this.context },
        {
          ...this.params,
          starttime: o,
          endtime: i,
          kssj: o,
          jssj: i,
          tjkssj: o,
          tjjssj: i
        },
        !0
      );
    }
  }
}
class T extends N {
  constructor() {
    super(...arguments);
    /**
     * 实体服务
     *
     * @author zhanghengfeng
     * @date 2023-11-16 15:11:57
     * @type {EntityService}
     */
    l(this, "entityService");
    /**
     * 请求结果
     *
     * @author zhanghengfeng
     * @date 2023-11-16 15:11:41
     * @type {{ data: IData }}
     */
    l(this, "result", { data: {} });
  }
  async onInit() {
    await super.onInit(), this.entityService = await ibiz.entityService.getService(
      "GwxnFwzl",
      this.context
    ), this.dashboard.nerve.self.evt.on("mounted", () => {
      this.load();
    });
  }
  calcViewParams() {
    super.calcViewParams(), this.dashboard.complete && this.load();
  }
  /**
   * 加载数据
   *
   * @author zhanghengfeng
   * @date 2023-11-16 15:11:28
   * @return {*}  {Promise<void>}
   */
  async load() {
    if (!this.entityService)
      return;
    const t = await this.entityService.exec(
      "Getfwzldata",
      this.context,
      this.params
    );
    t.ok && t.data ? this.result.data = t.data : this.result.data = {};
  }
}
class X {
  constructor() {
    l(this, "component", "PortalDatePicker");
  }
  async createController(s, t, r) {
    const o = new O(
      s,
      t,
      r
    );
    return await o.init(), o;
  }
}
class Z {
  constructor() {
    l(this, "component", "CustomTabExpView");
  }
}
class tt {
  constructor(s) {
    l(this, "formEditor", "GrowthRateSpan");
    l(this, "gridEditor", "IBizGridSpan");
    s === "SPAN_LINK" && (this.formEditor = "IBizSpanLink", this.gridEditor = "IBizSpanLink");
  }
  async createController(s, t) {
    const r = new R(s, t);
    return await r.init(), r;
  }
}
class et {
  constructor() {
    l(this, "component", "BwsdCustomList");
  }
}
class st {
  constructor() {
    l(this, "component", "FwzlPortal");
  }
  async createController(s, t, r) {
    const o = new T(s, t, r);
    return await o.init(), o;
  }
}
class at {
  constructor() {
    l(this, "component", "FwzlCustomList");
  }
}
class rt {
  constructor() {
    l(this, "component", "GwxnAppPortalView");
  }
}
const ot = w({
  name: "PortalDatePicker",
  props: {
    modelData: {
      type: q,
      required: !0
    },
    controller: {
      type: O,
      required: !0
    }
  },
  setup(e) {
    const s = p("portal-date-picker"), t = e.controller;
    Object.assign(t, {
      data: z(t.data)
    });
    const r = m("2017-01-01"), o = m(), i = {
      disabledDate: (d) => {
        const u = m(d);
        return u.isBefore(r, "day") || o.isBefore(u, "day");
      }
    }, c = (d) => {
      if (Array.isArray(d) && d.length === 2) {
        const [u, h] = d.map((x) => m(x));
        if (u.clone().add(1, "year").subtract(1, "day").isBefore(h, "day")) {
          t.data.selectDate = [...t.data.selectDate], ibiz.message.error("统计期间不能超过一年");
          return;
        }
        t.data.selectDate = [u.toDate(), h.toDate()], t.data.itemValue = 0;
      }
    };
    return k(() => t.data.selectDate, (d, u) => {
      const [h, y] = d.map((n) => m(n).format("YYYY-MM-DD")), [x, S] = u.map((n) => m(n).format("YYYY-MM-DD"));
      h === x && y === S || t.changeViewParams();
    }), {
      ns: s,
      options: i,
      onSelectDateChange: c
    };
  },
  render() {
    const {
      model: e
    } = this.controller, s = [this.ns.b(), this.ns.m(this.modelData.modelClass)];
    return a("portlet-layout", {
      attrs: {
        controller: this.controller
      },
      class: s
    }, [a("div", {
      class: this.ns.b("content")
    }, [a("div", {
      class: this.ns.e("text")
    }, [e.title || ""]), a("i-date-picker", {
      class: this.ns.e("picker"),
      attrs: {
        type: "daterange",
        placeholder: "请选择日期",
        separator: "  至  ",
        clearable: !1,
        editable: !1,
        "split-panels": !0,
        value: this.controller.data.selectDate,
        options: this.options
      },
      on: {
        "on-change": this.onSelectDateChange
      }
    }), a("i-radio-group", {
      class: this.ns.e("radio-group"),
      attrs: {
        type: "button"
      },
      on: {
        "on-change": this.controller.onItemValueChange
      },
      model: {
        value: this.controller.data.itemValue,
        callback: (t) => {
          this.$set(this.controller.data, "itemValue", t);
        }
      }
    }, [this.controller.items.map((t) => a("i-radio", {
      class: this.ns.e("radio"),
      attrs: {
        label: t.value
      }
    }, [t.text]))])])]);
  }
});
const it = w({
  props: {
    context: Object,
    params: {
      type: Object
    },
    modelPath: {
      type: String,
      required: !0
    },
    modal: {
      type: Object
    },
    noLoadDefault: {
      type: Boolean,
      required: !1
    }
  },
  setup(e) {
    const {
      proxy: s
    } = C(), t = p("custom-tab-exp-view"), r = p("view"), o = U(s, e.modelPath), i = P([]), c = P(""), d = P(!1), u = $(s), h = {}, y = async (n) => {
      const f = V(s).fullPath;
      h[c.value] = f;
      const b = o.model.tabExpPanel.tabExpPages.find((v) => v.name === n);
      if ((b == null ? void 0 : b.embedView.initialized) === !1 && await b.embedView.init(), o.context.isRouter) {
        if (d.value = !0, h[n])
          u.push(h[n]);
        else {
          const v = Object.assign(o.context.clone(), {
            toRouteLevel: o.modal.level + 1
          });
          ibiz.openView.root(b.embedView.source, v, o.params);
        }
        setTimeout(() => {
          d.value = !1, c.value = n;
        }, 0);
      } else
        i.value.includes(n) || (i.value.push(n), c.value = n);
    };
    o.nerve.self.evt.on("created", () => {
      const n = V(s), {
        tabExpPages: g
      } = o.model.tabExpPanel;
      if (o.context.isRouter) {
        const f = e.modal.level + 1, b = n.params[`view${f}`];
        if (b) {
          const v = g.find((I) => K(I.embedView.source) === b);
          v && (c.value = v.name);
        }
      }
      if (g.length && !c.value) {
        const f = g[0].name;
        y(f);
      }
    });
    const x = _(() => Object.values(o.tabExpPages).map((n) => n.key)), S = {
      mode: D.EMBED
    };
    return {
      c: o,
      ns: t,
      ns2: r,
      onTabClick: y,
      lazyList: i,
      deactivateAll: d,
      activeTab: c,
      keyHistory: x,
      embedViewModal: S
    };
  },
  render() {
    const e = this.c, s = this.c.context.isRouter === !0;
    return a("view-base", {
      class: [this.ns.b(), s ? this.ns.m("route") : ""],
      attrs: {
        controller: this.c
      },
      scopedSlots: {
        caption: () => a("div", {
          class: this.ns2.b("caption")
        }, [e.complete && e.model.source.getPSSysImage() ? [a("app-icon", {
          class: this.ns2.be("caption", "icon"),
          attrs: {
            icon: e.model.source.getPSSysImage()
          }
        }), a("span", {
          class: this.ns2.be("caption", "text"),
          attrs: {
            title: e.caption
          }
        }, [e.caption])] : a("span", {
          class: this.ns2.be("caption", "text"),
          attrs: {
            title: e.caption
          }
        }, [e.caption]), e.complete && a("i-radio-group", {
          class: this.ns.e("radio-group"),
          attrs: {
            type: "button"
          },
          on: {
            "on-change": this.onTabClick
          },
          model: {
            value: this.activeTab,
            callback: (t) => {
              this.activeTab = t;
            }
          }
        }, [this.c.model.tabExpPanel.tabExpPages.map((t) => {
          if (this.c.tabExpPages[t.name])
            return a("i-radio", {
              class: this.ns.e("radio"),
              attrs: {
                label: t.name
              }
            }, [t.source.caption]);
        })])])
      }
    }, [this.c.complete && [a("i-tabs", {
      class: this.ns.e("tab"),
      attrs: {
        name: this.c.model.codeName
      },
      on: {
        "on-click": this.onTabClick
      },
      model: {
        value: this.activeTab,
        callback: (t) => {
          this.activeTab = t;
        }
      }
    }, [this.c.model.tabExpPanel.tabExpPages.map((t) => {
      const r = this.c.tabExpPages[t.name];
      if (r)
        return a("i-tab-pane", {
          class: this.ns.e("tab-item"),
          attrs: {
            tab: this.c.model.codeName,
            label: t.source.caption,
            name: t.name
          }
        }, [this.lazyList.includes(t.name) && a("ViewShell", {
          attrs: {
            context: this.c.context,
            params: this.c.params,
            modal: this.embedViewModal,
            modelPath: t.embedView.source.modelPath
          },
          on: {
            neuronInit: this.c.nerve.onNeuronInit(t.name)
          },
          key: r.key
        })]);
    })]), s && this.activeTab && a("div", {
      class: this.ns.e("route-content")
    }, [a("router-view", {
      key: this.c.tabExpPages[this.activeTab].key,
      on: {
        "neuron-init": this.c.nerve.onNeuronInit(this.activeTab)
      }
    }, [({
      Component: t
    }) => t && a("appKeepAlive", {
      attrs: {
        keyList: this.keyHistory
      }
    }, [a(t)])])])]]);
  }
}), nt = w({
  name: "GrowthRateSpan",
  props: W(),
  setup() {
    return {
      ns: p("growth-rate-span")
    };
  },
  render() {
    return a("div", {
      class: [this.ns.b()]
    }, [a("rate-span", {
      attrs: {
        value: this.value
      }
    })]);
  }
});
const lt = w({
  name: "BwsdCustomList",
  props: {
    modelData: {
      type: E,
      required: !0
    },
    context: {
      type: Object,
      required: !0
    },
    params: {
      type: Object,
      default: () => ({})
    },
    /**
     * 行数据默认激活模式
     * - 0 不激活
     * - 1 单击激活
     * - 2 双击激活(默认值)
     *
     * @type {(number | 0 | 1 | 2)}
     */
    mdCtrlActiveMode: {
      type: Number,
      default: 2
    },
    /**
     * 是否默认选中第一条数据
     *
     * @type boolean
     */
    isSelectFirstDefault: {
      type: Boolean,
      required: !1
    },
    /**
     * 默认选中的数据
     *
     * @type Array
     */
    defaultSelectKeys: {
      type: Array,
      required: !1
    },
    /**
     * 是否包含在导航视图内
     *
     * @type boolean
     */
    isExpView: {
      type: Boolean,
      required: !1
    }
  },
  setup(e) {
    const {
      proxy: s
    } = C(), t = p("bwsd-custom-list"), r = L(s, e.modelData, e.context, e.params);
    r.size = r.model.size;
    let o = "";
    const {
      defaultSortField: i,
      defaultSortDir: c
    } = r.model;
    return i && c && (o = `${i},${c}`), r.nerve.self.evt.on("beforeLoad", () => !r.model.source.noSort && o ? {
      sort: o
    } : {}), {
      c: r,
      ns: t
    };
  },
  render() {
    return a("control-layout", {
      attrs: {
        modelData: this.c.model
      }
    }, [a("div", {
      class: this.ns.b()
    }, [this.c.items.length ? null : a("div", {
      class: this.ns.b("item")
    }, ["暂无数据"]), this.c.items.map((e, s) => a("div", {
      class: this.ns.b("item")
    }, [a("div", {
      class: this.ns.be("item", "index")
    }, [`${s + 1}.`]), a("div", {
      class: this.ns.be("item", "key")
    }, [e.key || ""]), a("div", {
      class: this.ns.be("item", "value")
    }, [e.value || ""])]))])]);
  }
});
const ct = w({
  name: "FwzlPortal",
  props: {
    modelData: {
      type: Y,
      required: !0
    },
    controller: {
      type: T,
      required: !0
    }
  },
  setup(e) {
    const s = p("view-portlet"), t = (o) => {
      e.controller.setViewNeuron(o);
    };
    Object.assign(e.controller, {
      result: z(e.controller.result)
    });
    const r = p("fwzl-portal");
    return {
      ns: s,
      ns2: r,
      onNeuronInit: t
    };
  },
  render() {
    const e = this.controller, s = [this.ns.b(), this.ns.m(this.modelData.modelClass), this.ns2.b()], t = () => a("div", {
      class: [this.ns2.b("content")]
    }, [a("div", {
      class: this.ns2.e("text")
    }, ["总计退文"]), a("div", {
      class: this.ns2.e("value")
    }, [e.result.data.ztws || 0]), a("div", {
      class: this.ns2.e("text")
    }, ["件"]), a("div", {
      class: this.ns2.e("rate")
    }, [a("rate-span", {
      attrs: {
        value: e.result.data.tqztwszf
      }
    })])]);
    return a("portlet-layout", {
      attrs: {
        controller: this.controller
      },
      class: s
    }, [t(), a("ViewShell", {
      attrs: {
        context: e.viewContext,
        params: e.params,
        modal: {
          mode: D.EMBED
        },
        modelPath: e.model.embedView.source.modelPath
      },
      on: {
        neuronInit: this.onNeuronInit
      },
      key: e.model.embedView.codeName
    })]);
  }
});
const dt = w({
  name: "FwzlCustomList",
  props: {
    modelData: {
      type: E,
      required: !0
    },
    context: {
      type: Object,
      required: !0
    },
    params: {
      type: Object,
      default: () => ({})
    },
    /**
     * 行数据默认激活模式
     * - 0 不激活
     * - 1 单击激活
     * - 2 双击激活(默认值)
     *
     * @type {(number | 0 | 1 | 2)}
     */
    mdCtrlActiveMode: {
      type: Number,
      default: 2
    },
    /**
     * 是否默认选中第一条数据
     *
     * @type boolean
     */
    isSelectFirstDefault: {
      type: Boolean,
      required: !1
    },
    /**
     * 默认选中的数据
     *
     * @type Array
     */
    defaultSelectKeys: {
      type: Array,
      required: !1
    },
    /**
     * 是否包含在导航视图内
     *
     * @type boolean
     */
    isExpView: {
      type: Boolean,
      required: !1
    }
  },
  setup(e) {
    var c;
    const {
      proxy: s
    } = C(), t = L(s, e.modelData, e.context, e.params), r = p("fwzl-custom-list"), o = P([]), i = (c = t.model.source.getPSControlParam()) == null ? void 0 : c.ctrlParams;
    return i && i.COLOR && (o.value = JSON.parse(i.COLOR)), {
      c: t,
      ns: r,
      colorList: o
    };
  },
  render() {
    const e = () => this.c.items.length ? a("div", {
      class: this.ns.b()
    }, [a("div", {
      class: this.ns.b("item-icon")
    }, [this.c.items.map((s, t) => a("div", {
      class: this.ns.b("item")
    }, [a("div", {
      class: this.ns.be("item", "icon"),
      style: {
        "--background": `${this.colorList[t] || "#5190ff"}`
      }
    })]))]), a("div", {
      class: this.ns.b("item-text")
    }, [this.c.items.map((s) => a("div", {
      class: this.ns.b("item")
    }, [s.text && a("div", {
      class: this.ns.be("item", "text")
    }, [s.text])]))]), a("div", {
      class: this.ns.b("item-value")
    }, [this.c.items.map((s) => a("div", {
      class: this.ns.b("item")
    }, [s.value != null && a("div", {
      class: this.ns.be("item", "value")
    }, [s.value])]))]), a("div", {
      class: this.ns.b("item-percentage")
    }, [this.c.items.map((s) => a("div", {
      class: this.ns.b("item")
    }, [s.percentage && a("div", {
      class: this.ns.be("item", "percentage")
    }, [s.percentage])]))]), a("div", {
      class: this.ns.b("item-rate")
    }, [this.c.items.map((s) => a("div", {
      class: this.ns.b("item")
    }, [a("div", {
      class: this.ns.be("item", "rate")
    }, [a("rate-span", {
      attrs: {
        value: s.rate
      }
    })])]))])]) : a("div", {
      class: [this.ns.b(), this.ns.m("empty")]
    }, ["未有被退文部门"]);
    return a("control-layout", {
      attrs: {
        modelData: this.c.model
      }
    }, [this.c.complete && e()]);
  }
});
const ut = w({
  name: "RateSpan",
  props: {
    value: {
      type: String
    }
  },
  setup(e) {
    const s = p("rate-span"), t = P(""), r = P();
    return k(() => e.value, (o) => {
      if (!o || !parseInt(o, 10)) {
        t.value = "";
        return;
      }
      if (o.startsWith("-")) {
        t.value = o.slice(1), r.value = "decrease";
        return;
      }
      t.value = o, r.value = "increase";
    }, {
      immediate: !0
    }), {
      ns: s,
      text: t,
      type: r
    };
  },
  render() {
    if (!(!this.text || !this.type))
      return a("div", {
        class: [this.ns.b(), this.ns.m(this.type)]
      }, [this.text]);
  }
});
class mt extends F {
  connect(s, t) {
    var r;
    super.connect(s, t), s === "dashboard" && ((r = this.dashboard) == null || r.evt.on(
      "contextOrParamsChange",
      this.controller.setContextOrParams.bind(this.controller)
    ));
  }
}
class pt extends G {
  createNerve() {
    return new mt(this);
  }
}
function ht(e, s) {
  return H(
    e,
    (t, r) => new pt(s, t, r)
  );
}
const bt = w({
  name: "GwxnAppPortalView",
  props: {
    context: Object,
    params: {
      type: Object
    },
    modelPath: {
      type: String,
      required: !0
    },
    modal: {
      type: Object
    },
    noLoadDefault: {
      type: Boolean,
      required: !1
    }
  },
  setup(e) {
    const {
      proxy: s
    } = C();
    return {
      c: ht(s, e.modelPath)
    };
  },
  render(e) {
    let s = null;
    if (this.c.complete) {
      const {
        dashboard: t
      } = this.c.model;
      this.c.providers[t.name] && (s = e(this.c.providers[t.name].component, {
        props: {
          modelData: t,
          context: this.c.context,
          params: this.c.params
        },
        on: {
          neuronInit: this.c.nerve.onNeuronInit(t.name)
        }
      }));
    }
    return e("view-base", {
      attrs: {
        controller: this.c
      }
    }, [s]);
  }
}), Ct = {
  mateUrl: import.meta.url,
  install(e) {
    J.loadStyle(["/style.css"]), ibiz.register.view.register(
      "VIEW_CUSTOM_GwxnIndexCSS",
      new Q()
    ), e.component("RateSpan", ut), e.component("GwxnAppPortalView", bt), ibiz.register.view.register(
      "VIEW_CUSTOM_GwxnAppPortalView",
      new rt()
    ), e.component("PortalDatePicker", ot), ibiz.register.portletPart.register(
      "PORTLET_CUSTOM_PortalDatePicker",
      new X()
    ), e.component("CustomTabExpView", it), ibiz.register.view.register(
      "VIEW_CUSTOM_CustomTabExpView",
      new Z()
    ), e.component("GrowthRateSpan", nt), ibiz.register.editor.register(
      "SPAN_GrowthRateSpan",
      new tt()
    ), e.component("BwsdCustomList", lt), ibiz.register.control.register(
      "CUSTOM_BwsdCustomList",
      new et()
    ), e.component("FwzlPortal", ct), ibiz.register.portletPart.register(
      "PORTLET_CUSTOM_FwzlPortal",
      new st()
    ), e.component("FwzlCustomList", dt), ibiz.register.control.register(
      "CUSTOM_FwzlCustomList",
      new at()
    );
  }
};
export {
  Ct as default
};
