import { defineComponent, useSlots, ref, computed, watchEffect, openBlock, createBlock, unref, createSlots, withCtx, renderSlot, createElementVNode, markRaw, defineAsyncComponent, createElementBlock, withModifiers, normalizeStyle, toDisplayString, createVNode, Fragment, renderList, createCommentVNode, Suspense, normalizeClass, render, onMounted, nextTick, isRef } from "vue";
import { _ as _sfc_main$4, s as select_plat_icon, a as arrow_trg_icon, r as removeEmptyField } from "./index4.js";
import { Popover } from "vant";
import { S as Store } from "./index2.js";
import { _ as _sfc_main$5 } from "./index9.js";
import { t as typeDetection } from "./utils.js";
import "@wltech/svg";
import "dayjs";
const __default__$2 = {
  name: "WlPopover"
};
const _sfc_main$3 = /* @__PURE__ */ defineComponent({
  ...__default__$2,
  props: {
    actions: { default: null },
    modelValue: { type: Boolean, default: false }
  },
  emits: ["update:modelValue", "onSelect"],
  setup(__props, { emit }) {
    const props = __props;
    const slots = useSlots();
    const hasDefault = ref(slots.default !== void 0);
    const slotName = computed(() => hasDefault.value ? "default" : "content");
    const popoverVisible = ref(false);
    const onTogglePopover = (bool) => {
      popoverVisible.value = bool;
      emit("update:modelValue", bool);
    };
    const onSelect = (val) => {
      emit("onSelect", val);
      onTogglePopover(false);
    };
    watchEffect(() => {
      popoverVisible.value = props.modelValue;
    });
    return (_ctx, _cache) => {
      return openBlock(), createBlock(unref(Popover), {
        show: popoverVisible.value,
        "onUpdate:show": _cache[1] || (_cache[1] = ($event) => popoverVisible.value = $event),
        actions: __props.actions,
        onSelect
      }, createSlots({
        reference: withCtx(() => [
          renderSlot(_ctx.$slots, "reference")
        ]),
        _: 2
      }, [
        hasDefault.value ? {
          name: unref(slotName),
          fn: withCtx(() => [
            createElementVNode("div", {
              onClick: _cache[0] || (_cache[0] = ($event) => popoverVisible.value = false)
            }, [
              renderSlot(_ctx.$slots, "default")
            ])
          ])
        } : void 0
      ]), 1032, ["show", "actions"]);
    };
  }
});
var index_vue_vue_type_style_index_0_lang$2 = "";
const _hoisted_1$2 = { class: "list-item" };
const _hoisted_2$1 = ["onClick"];
const _hoisted_3 = {
  key: 0,
  class: "arrow"
};
const _hoisted_4 = { class: "icon" };
const __default__$1 = {
  name: "BCBusinessStagePopup"
};
const _sfc_main$2 = /* @__PURE__ */ defineComponent({
  ...__default__$1,
  props: {
    modelValue: { default: null },
    businessOppDetail: { default: null },
    isEdit: { type: Boolean, default: true },
    stageList: { default: null },
    stageFailList: { default: null },
    maxWidth: { default: null }
  },
  emits: ["onClickItem", "onFail", "onSuccess", "update:modelValue"],
  setup(__props, { emit }) {
    const props = __props;
    const FailPopup = markRaw(
      defineAsyncComponent(() => import("./index14.js"))
    );
    const SucessPopup = markRaw(
      defineAsyncComponent(() => import("./index15.js"))
    );
    const default_color = "#6236FF";
    const default_background_color = "#F6F0FF";
    const stage_base_setting = {
      "4": {
        color: "rgba(98, 54, 255, 1)",
        backgroundColor: "rgba(246, 240, 255, 1)"
      },
      "2": {
        color: "rgba(98, 54, 255, 1)",
        backgroundColor: "rgba(246, 240, 255, 1)"
      },
      "100": {
        color: "rgba(255, 69, 69, 1)",
        type: "success",
        backgroundColor: "rgba(255, 242, 240, 1)"
      },
      "99": {
        color: "rgba(137, 138, 141, 1)",
        type: "fail",
        backgroundColor: "rgba(242, 242, 242, 1)"
      }
    };
    const successPopupVisibe = ref(false);
    const failPopupVisible = ref(false);
    const actionVisible = ref(false);
    const stageData = ref(null);
    const filterData = (list, key) => {
      let data = null;
      for (let i = 0; i < 2; i++) {
        const stage = list[i];
        const len = stage.length;
        for (let i2 = 0; i2 < len; i2++) {
          const ele = stage[i2];
          if (ele.key == key) {
            data = ele;
          }
        }
      }
      return data;
    };
    const item_style = computed(() => {
      return function(item) {
        const { key = "" } = props.modelValue;
        const { key: itemKey } = item;
        const is_select = key === itemKey;
        return {
          "--color": is_select ? item.color : "rgba(0, 0, 0, 1)",
          "--backgroundColor": is_select ? item.backgroundColor : "transparent"
        };
      };
    });
    const info_style = computed(() => {
      const { value = "", key = "" } = props.modelValue;
      if (value) {
        const setting = stage_base_setting[key + ""];
        const {
          color = default_color,
          backgroundColor = default_background_color
        } = setting || {};
        return {
          "--color": color,
          "--backgroundColor": backgroundColor
        };
      } else if (key) {
        const data = filterData(business_opportunity_stage_list.value, key);
        const {
          color = default_color,
          backgroundColor = default_background_color
        } = data || {};
        return {
          "--color": color,
          "--backgroundColor": backgroundColor
        };
      }
      return {};
    });
    const info_text = computed(() => {
      const { value = "", key = "" } = props.modelValue;
      if (value) {
        return value;
      } else if (key) {
        const data = filterData(business_opportunity_stage_list.value, key) || {};
        return data.value;
      }
      return "";
    });
    const business_opportunity_stage_list = computed(() => {
      var _a;
      const fail_list2 = props.stageFailList || [];
      const list_len = (_a = props.stageList) == null ? void 0 : _a.length;
      let list = [];
      let last_list = [];
      for (let i = 0; i < list_len; i++) {
        const ele = props.stageList[i];
        const { key = "" } = ele;
        if (key + "" === "99") {
          last_list.push({
            ...ele,
            fail_list: fail_list2,
            ...stage_base_setting[key]
          });
        } else {
          const setting = stage_base_setting[key] || {
            color: default_color,
            backgroundColor: default_background_color
          };
          list.push({
            fail_list: fail_list2,
            ...ele,
            ...setting
          });
        }
      }
      return [list, last_list];
    });
    const fail_list = computed(() => {
      var _a;
      const fail_list2 = ((_a = props.stageFailList) != null ? _a : []).map((ele) => {
        return {
          ...ele,
          name: ele.value,
          type: ele.key + "" === "99" ? "ipt" : ""
        };
      });
      return fail_list2;
    });
    const popover_style = computed(() => {
      if (!props.maxWidth)
        return {};
      if (typeof props.maxWidth === "number") {
        return {
          "max-width": props.maxWidth + "px"
        };
      }
      return {
        "max-width": props.maxWidth
      };
    });
    const onClickItem = (item) => {
      const { type = "" } = item;
      stageData.value = item;
      emit("onClickItem", { stage: item });
      actionVisible.value = false;
      if (type === "success") {
        successPopupVisibe.value = true;
        failPopupVisible.value = false;
      } else if (type === "fail") {
        successPopupVisibe.value = false;
        failPopupVisible.value = true;
      } else {
        emit("update:modelValue", item);
        failPopupVisible.value = false;
        successPopupVisibe.value = false;
      }
    };
    const onFailConfirm = (data) => {
      emit("onFail", { ...data, stage: stageData.value });
      successPopupVisibe.value = false;
      failPopupVisible.value = false;
      emit("update:modelValue", stageData.value);
    };
    const onPopupSuccess = (data) => {
      emit("onSuccess", { stage_value: data, stage: stageData.value });
      successPopupVisibe.value = false;
      failPopupVisible.value = false;
      emit("update:modelValue", stageData.value);
    };
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", {
        onClick: _cache[3] || (_cache[3] = withModifiers(() => {
        }, ["stop"])),
        class: "bo-stage",
        "data-weiling-mobile-ui-bc-business-stage-popup": ""
      }, [
        __props.isEdit ? (openBlock(), createBlock(_sfc_main$3, {
          key: 0,
          modelValue: actionVisible.value,
          "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => actionVisible.value = $event),
          trigger: "click",
          placement: "bottom-start"
        }, {
          reference: withCtx(() => [
            createElementVNode("div", {
              class: "info",
              style: normalizeStyle(unref(info_style))
            }, [
              createElementVNode("p", null, toDisplayString(unref(info_text)), 1),
              createElementVNode("div", _hoisted_4, [
                createVNode(_sfc_main$4, { src: unref(select_plat_icon) }, null, 8, ["src"])
              ])
            ], 4)
          ]),
          default: withCtx(() => [
            createElementVNode("div", {
              class: "business-opportunity-status-popover",
              "data-weiling-mobile-ui-bc-business-stage-popup-content": "",
              style: normalizeStyle(unref(popover_style))
            }, [
              (openBlock(true), createElementBlock(Fragment, null, renderList(unref(business_opportunity_stage_list), (parent, index) => {
                return openBlock(), createElementBlock("div", {
                  key: index,
                  class: "list"
                }, [
                  createElementVNode("div", _hoisted_1$2, [
                    (openBlock(true), createElementBlock(Fragment, null, renderList(parent, (item, index2) => {
                      return openBlock(), createElementBlock("div", {
                        class: "item-wrap",
                        key: item.key,
                        onClick: withModifiers(($event) => onClickItem(item), ["stop"])
                      }, [
                        createElementVNode("div", {
                          class: "item",
                          style: normalizeStyle(unref(item_style)(item))
                        }, toDisplayString(item.value), 5),
                        index2 !== parent.length - 1 ? (openBlock(), createElementBlock("div", _hoisted_3, [
                          createVNode(_sfc_main$4, { src: unref(arrow_trg_icon) }, null, 8, ["src"])
                        ])) : createCommentVNode("", true)
                      ], 8, _hoisted_2$1);
                    }), 128))
                  ])
                ]);
              }), 128))
            ], 4)
          ]),
          _: 1
        }, 8, ["modelValue"])) : (openBlock(), createElementBlock("div", {
          key: 1,
          class: "info",
          style: normalizeStyle(unref(info_style))
        }, [
          createElementVNode("p", null, toDisplayString(unref(info_text)), 1)
        ], 4)),
        failPopupVisible.value ? (openBlock(), createBlock(Suspense, { key: 2 }, {
          default: withCtx(() => [
            createVNode(unref(FailPopup), {
              modelValue: failPopupVisible.value,
              "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => failPopupVisible.value = $event),
              list: unref(fail_list),
              onOnConfirmField: onFailConfirm,
              onOnConfirm: onFailConfirm
            }, null, 8, ["modelValue", "list"])
          ]),
          _: 1
        })) : createCommentVNode("", true),
        successPopupVisibe.value ? (openBlock(), createBlock(Suspense, { key: 3 }, {
          default: withCtx(() => [
            createVNode(unref(SucessPopup), {
              modelValue: successPopupVisibe.value,
              "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => successPopupVisibe.value = $event),
              data: __props.businessOppDetail,
              onOnSubmit: onPopupSuccess
            }, null, 8, ["modelValue", "data"])
          ]),
          _: 1
        })) : createCommentVNode("", true)
      ]);
    };
  }
});
const proxy_api = {
  dev_uat: "/uat_api",
  dev_stg: "/stg_api",
  dev_prd: "/prd_api",
  dev_cos_api: "/cos_api",
  dev_uat_xsf: "/xsf_api",
  dev: "/uat_api",
  uat: "",
  stg: "",
  prd: "",
  gray: "",
  production: "",
  uat_xsf: "https://test.xsfapi.weiling.cn",
  stg_xsf: "https://pre-xsfapi.weiling.cn",
  prd_xsf: "https://xsfapi.weiling.cn",
  gray_xsf: "https://xsfapi.weiling.cn"
};
const token_key = {
  dev_uat: "auth-token-mp-test",
  dev_stg: "auth-token-mp",
  dev_prd: "auth-token-mp",
  dev_uat_xsf: "auth-token-se-test",
  dev_stg_xsf: "auth-token-se",
  dev_gray_xsf: "auth-token-se",
  dev_prd_xsf: "auth-token-se",
  uat: "auth-token-mp-test",
  stg: "auth-token-mp",
  prd: "auth-token-mp",
  gray: "auth-token-mp",
  uat_xsf: "auth-token-se-test",
  stg_xsf: "auth-token-se",
  prd_xsf: "auth-token-se",
  gray_xsf: "auth-token-se"
};
var index_vue_vue_type_style_index_0_lang$1 = "";
const _hoisted_1$1 = { class: "icon" };
const _hoisted_2 = { class: "text" };
const __default__ = {
  name: "WlNotice"
};
const _sfc_main$1 = /* @__PURE__ */ defineComponent({
  ...__default__,
  props: {
    show_toast: { type: Boolean, default: true },
    message: { default: "" },
    type: { default: "success" },
    duration: { default: 1500 }
  },
  setup(__props) {
    return (_ctx, _cache) => {
      return __props.show_toast ? (openBlock(), createElementBlock("div", {
        key: 0,
        class: normalizeClass(`notice ${__props.type}`),
        "data-weiling-mobile-ui-wl-notice": ""
      }, [
        createElementVNode("div", _hoisted_1$1, [
          __props.type === "success" ? (openBlock(), createBlock(_sfc_main$5, {
            key: 0,
            type: "successFill",
            width: "24",
            height: "24",
            color: "#45ce03"
          })) : __props.type === "warning" ? (openBlock(), createBlock(_sfc_main$5, {
            key: 1,
            type: "warningFill",
            width: "24",
            height: "24",
            color: "#f3a401"
          })) : __props.type === "alert" ? (openBlock(), createBlock(_sfc_main$5, {
            key: 2,
            type: "tipsFill",
            width: "24",
            height: "24",
            color: "#1b9fff"
          })) : __props.type === "error" ? (openBlock(), createBlock(_sfc_main$5, {
            key: 3,
            type: "closeFill",
            width: "24",
            height: "24",
            color: "#ff2a2d"
          })) : createCommentVNode("", true)
        ]),
        createElementVNode("p", _hoisted_2, toDisplayString(__props.message), 1)
      ], 2)) : createCommentVNode("", true);
    };
  }
});
let mountNode = null;
var WlNotice = (options) => {
  const duration = options.duration | 2e3;
  if (mountNode) {
    document.body.removeChild(mountNode);
    mountNode = null;
  }
  const app = createVNode(_sfc_main$1, {
    ...options,
    duration,
    show_toast: true
  });
  let timer = setTimeout(() => {
    if (mountNode) {
      document.body.removeChild(mountNode);
      mountNode = null;
    }
    clearTimeout(timer);
  }, duration);
  mountNode = document.createElement("div");
  render(app, mountNode);
  document.body.appendChild(mountNode);
};
function obj2String(obj, arr = [], idx = 0) {
  for (let item in obj) {
    arr[idx++] = [item, obj[item]];
  }
  return new URLSearchParams(arr).toString();
}
function getOptions(options) {
  var _a;
  const { sid = "", corp_id = "", card_resource = "" } = (_a = Store) != null ? _a : {};
  const params = {
    sid,
    corp_id,
    card_resource,
    ...options
  };
  return obj2String(params);
}
const onHandleUrl = (url) => {
  const { node_env } = Store;
  const isPersonMiniApp = node_env.includes("xsf");
  if (isPersonMiniApp) {
    return setPersonMiniAppUrl(url);
  }
  return url;
};
const setPersonMiniAppUrl = (url) => {
  let filterUrl = url;
  if (filterUrl.includes("/api/user/share/path")) {
    filterUrl = filterUrl.replace("/api/user/share/path", "/apise/material/share/path");
  } else if (filterUrl.includes("/interact/")) {
    filterUrl = filterUrl.replace("/interact/", "/apise/");
  } else if (filterUrl.includes("/api/")) {
    filterUrl = filterUrl.replace("/api/", "/apise/");
  } else if (filterUrl.includes("/wx/track")) {
    filterUrl = filterUrl.replace("/wx/track", "/apise/track/wx/track");
  }
  return filterUrl;
};
function request(url, options, method = "GET") {
  const staticOption = {
    sid: Store.sid,
    corp_id: Store.corp_id,
    tab_change: 0
  };
  const data = {
    ...staticOption,
    ...options
  };
  const searchStr = getOptions(removeEmptyField(data));
  const staticSearchStr = getOptions(removeEmptyField(staticOption));
  let initObj = {};
  let params = "";
  if (method === "GET") {
    initObj = {
      method,
      credentials: "include",
      headers: new Headers({
        [token_key[Store.node_env]]: Store.token
      })
    };
    params = searchStr;
  } else if (method === "FormPOST") {
    initObj = {
      method: "POST",
      credentials: "include",
      headers: new Headers({
        [token_key[Store.node_env]]: Store.token
      }),
      body: options
    };
    params = staticSearchStr;
  } else {
    initObj = {
      method,
      credentials: "include",
      headers: new Headers({
        Accept: "application/json, text/plain, */*",
        "Content-Type": "application/json",
        [token_key[Store.node_env]]: Store.token
      }),
      body: JSON.stringify(data)
    };
    params = staticSearchStr;
  }
  const filterUrl = onHandleUrl(url) + "?" + params;
  return fetch(filterUrl, initObj).then((res) => {
    const isArea = url.includes("region.json");
    return res.json().then((result) => {
      var _a;
      if (result.code === 200 || isArea) {
        return result;
      } else {
        WlNotice({ message: (_a = result.msg) != null ? _a : "\u670D\u52A1\u5668\u5185\u90E8\u9519\u8BEF", type: "error", duration: 3e3 });
        throw Error(result);
      }
    });
  }).then((res) => {
    return res;
  });
}
const GET = (url, options) => {
  return request(url, options, "GET");
};
var Api = {
  getBusinessDetail(params) {
    return GET(
      `${proxy_api[Store.node_env]}/crm_v2/web/business_opp/detail`,
      params
    );
  }
};
var index_vue_vue_type_style_index_0_lang = "";
const _hoisted_1 = {
  key: 0,
  class: "uno-ml-6"
};
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "index",
  props: {
    data: { default: () => {
      return {};
    } },
    listItem: { default: () => {
      return {
        isEdit: false
      };
    } },
    fieldConfig: { default: () => {
      return {};
    } },
    tenantConfig: { default: () => {
      return {};
    } }
  },
  emits: ["onClickItem", "onFail", "onSuccess"],
  setup(__props, { emit }) {
    const props = __props;
    let stageValue = ref();
    const dataIsArray = computed(() => {
      return typeDetection(props.data) === "array";
    });
    watchEffect(() => {
      var _a;
      if (props.data) {
        if (dataIsArray.value) {
          stageValue.value = { key: (_a = props.data[0]) == null ? void 0 : _a.stage.toString() };
          return;
        }
        stageValue.value = { key: props.data.toString() };
      }
    });
    const stageList = computed(() => {
      return props.tenantConfig["business_stage"];
    });
    const stageFailList = computed(() => {
      return props.tenantConfig["business_fail_reason"];
    });
    const businessOppDetail = ref({});
    const onClickItem = async (params) => {
      var _a, _b;
      if (!params.stage.type) {
        emit("onClickItem", params);
        (_a = props.listItem.on) == null ? void 0 : _a.onClickItem(params);
      } else if (params.stage.type == "success") {
        const { data } = await Api.getBusinessDetail({
          business_id: (_b = props.listItem) == null ? void 0 : _b.businessId
        });
        businessOppDetail.value = data;
      }
    };
    const onFail = (params) => {
      var _a;
      emit("onFail", params);
      (_a = props.listItem.on) == null ? void 0 : _a.onFail(params);
    };
    const onSuccess = (params) => {
      var _a;
      emit("onSuccess", params);
      (_a = props.listItem.on) == null ? void 0 : _a.onSuccess(params);
    };
    const stageRef = ref(null);
    const maxWidth = ref();
    onMounted(() => {
      nextTick(() => {
        maxWidth.value = stageRef.value.scrollWidth;
      });
    });
    return (_ctx, _cache) => {
      var _a;
      return openBlock(), createElementBlock("div", {
        class: "bo-stage-popup a-row",
        ref_key: "stageRef",
        ref: stageRef,
        onClick: _cache[1] || (_cache[1] = withModifiers(() => {
        }, ["stop"]))
      }, [
        createVNode(_sfc_main$2, {
          modelValue: unref(stageValue),
          "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => isRef(stageValue) ? stageValue.value = $event : stageValue = $event),
          isEdit: ((_a = __props.listItem) == null ? void 0 : _a.isEdit) || false,
          stageList: unref(stageList),
          stageFailList: unref(stageFailList),
          businessOppDetail: businessOppDetail.value,
          maxWidth: maxWidth.value,
          onOnClickItem: onClickItem,
          onOnFail: onFail,
          onOnSuccess: onSuccess
        }, null, 8, ["modelValue", "isEdit", "stageList", "stageFailList", "businessOppDetail", "maxWidth"]),
        unref(dataIsArray) && __props.data.length > 1 ? (openBlock(), createElementBlock("span", _hoisted_1, toDisplayString(`\u5171${__props.data.length}\u4E2A`), 1)) : createCommentVNode("", true)
      ], 512);
    };
  }
});
export { _sfc_main as default };
