<template>
  <u-sticky class="shadow-default" bgColor="#fff" style="top: 0">
    <u-navbar :titleStyle="{ color: '#000' }" :autoBack="true" :title="pageTitle" :placeholder="true" :safeAreaInsetTop="true" bgColor="#fff">
      <template #left>
        <view class="u-navbar__content__left__item">
          <u-icon name="arrow-left" size="20" color="#000"></u-icon>
        </view>
      </template>
      <template #right>
        <view class="u-navbar__content__right__item">
          <u-icon name="more-dot-fill" size="20" color="#000"></u-icon>
        </view>
      </template>
    </u-navbar>
  </u-sticky>

  <oa-scroll
    customClass="record-container scroll-height"
    :isSticky="false"
    :customStyle="{
      //#ifdef APP-PLUS || MP-WEIXIN
      height: 'calc(100vh - 44px)',
      //#endif
    }"
    :refresherLoad="false"
    :refresherEnabled="false"
    :refresherDefaultStyle="'none'"
    :refresherThreshold="44"
    :lowerThreshold="44"
    :refresherBackground="'#f5f6f7'"
    :data-theme="'theme-' + proxy.$settingStore.themeColor.name"
  >
    <template #default>
      <uni-mall-list
        v-if="userList.length > 0"
        :userList="userList"
        :defaultHeadList="defaultHeadList"
        :activeUserList="activeUserList"
        :activeUserNumber="activeUserNumber"
        @change="handleChange"
        @submit="handleSubmit"
      ></uni-mall-list>
    </template>
  </oa-scroll>
</template>

<script setup>
/*----------------------------------依赖引入-----------------------------------*/
import { onLoad, onShow, onReady, onHide, onLaunch, onUnload, onNavigationBarButtonTap, onPageScroll } from "@dcloudio/uni-app";
import { ref, reactive, computed, getCurrentInstance, toRefs, inject } from "vue";
/*----------------------------------接口引入-----------------------------------*/
import { deptUserTreeSelect } from "@/api/system/user.js";
/*----------------------------------组件引入-----------------------------------*/
import uniMallList from "./components/mall-list.vue";
/*----------------------------------store引入-----------------------------------*/
import { systemStores } from "@/store/modules/index";
/*----------------------------------公共方法引入-----------------------------------*/
/*----------------------------------公共变量-----------------------------------*/
const { proxy } = getCurrentInstance();
const systemStore = systemStores();
/*----------------------------------变量声明-----------------------------------*/
const state = reactive({
  defaultHeadList: { label: "通讯录", id: "18AF75C3-330A-53AC-270E-EAD060BC0E1A" },
  userList: [],
  activeUserList: [],
  activeUserNumber: undefined,
  pageTitle: "",
});
const { defaultHeadList, userList, activeUserList, activeUserNumber,pageTitle } = toRefs(state);

function init() {
  deptUserTreeSelect({ pageNum: "1", pageSize: "10000" }).then((res) => {
    state.userList = JSON.parse(JSON.stringify(res.data).replace(/value/g, "id"))[0].children;
  });
  state.activeUserList = systemStore.mallList.activeUserList;
}

function handleSubmit(event) {
  proxy.$tab.navigateBack(1); //返回到需要执行方法的页面
  uni.$emit("UserMall", event); //将值存储监听器
}

function handleChange() {}

onReady(() => {});

onShow(() => {});

onLoad((options) => {
  if ("number" in options) {
    state.activeUserNumber = parseInt(options.number);
  }
  init();

  if (options.type==1) {
    state.pageTitle = "选择项目负责人";
  } else if (options.type==2) {
    state.pageTitle = "选择项目成员";
  }else{
    state.pageTitle = "选择抄送人"
  }

});

onUnload(() => {});
</script>

<style></style>
