"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
;/* empty css                                               */
;/* empty css                                                  */
;/* empty css                                               */
const Vue = require("vue");
const dataSourceUtil = require("../../../utils/dataSourceUtil.js");
const index = require("../../../../node_modules/vant/es/list/index.js");
const _sfc_main = {
  __name: "List",
  props: {
    modelValue: {
      type: Array,
      default: []
    },
    disabledLoad: {
      type: Boolean,
      default: false
    },
    offset: {
      type: String,
      default: "0"
    },
    direction: {
      type: String,
      default: "down"
    },
    dataSource: {
      type: String,
      default: ""
    },
    params: {
      type: Object,
      default: {}
    },
    pageSize: {
      type: String,
      default: "10"
    }
  },
  emits: ["update:modelValue"],
  setup(__props, { emit: __emit }) {
    const props = __props;
    const listRef = Vue.ref();
    let isDesigner = false;
    Vue.onMounted(() => {
      var _a, _b;
      try {
        const uid = (_b = (_a = listRef.value) == null ? void 0 : _a.$el) == null ? void 0 : _b.getAttribute("data-uid");
        if (uid) {
          isDesigner = true;
        }
      } catch (error2) {
      }
    });
    const emit = __emit;
    const tableData = Vue.computed({
      get: () => {
        return props.modelValue;
      },
      set: (val) => {
        emit("update:modelValue", val);
      }
    });
    const finished = Vue.ref(false);
    const error = Vue.ref(false);
    const loading = Vue.ref(false);
    let pageNo = 1;
    const dataSource = dataSourceUtil.useDataSource(props.dataSource);
    if (dataSource && !isDesigner) {
      if (props.disabledLoad) {
        tableData.value = [];
        call();
      } else {
        pageNo = 0;
      }
    } else {
      loading.value = false;
    }
    function onLoad() {
      if (dataSource && !isDesigner) {
        loading.value = true;
        pageNo++;
        call();
      } else {
        loading.value = false;
      }
    }
    Vue.watch(
      () => props.params,
      () => {
        tableData.value = [];
        pageNo = 1;
        finished.value = false;
        loading.value = true;
        call();
      },
      {
        deep: true
      }
    );
    function call() {
      error.value = false;
      dataSource == null ? void 0 : dataSource.load({ ...props.params, pageNo, pageSize: props.pageSize }).then((res) => {
        var _a;
        const data = ((_a = res == null ? void 0 : res.data) == null ? void 0 : _a.records) || (res == null ? void 0 : res.data) || res || [];
        tableData.value.push(...data);
        if (data.length < props.pageSize) {
          finished.value = true;
        }
        loading.value = false;
      }).catch((err) => {
        console.error(err);
        error.value = true;
        loading.value = false;
      });
    }
    return (_ctx, _cache) => {
      const _component_van_list = index.List;
      return Vue.openBlock(), Vue.createBlock(_component_van_list, {
        ref_key: "listRef",
        ref: listRef,
        loading: Vue.unref(loading),
        "onUpdate:loading": _cache[0] || (_cache[0] = ($event) => Vue.isRef(loading) ? loading.value = $event : null),
        error: Vue.unref(error),
        "onUpdate:error": _cache[1] || (_cache[1] = ($event) => Vue.isRef(error) ? error.value = $event : null),
        finished: Vue.unref(finished),
        disabled: __props.disabledLoad,
        offset: __props.offset,
        "finished-text": "没有更多了",
        "error-text": "请求失败，点击重新加载",
        onLoad
      }, {
        default: Vue.withCtx(() => [
          Vue.renderSlot(_ctx.$slots, "default")
        ]),
        _: 3
      }, 8, ["loading", "error", "finished", "disabled", "offset"]);
    };
  }
};
exports.default = _sfc_main;
