<template>
  <view class="content">
    <view class="head">
      <span class="title">项目列表</span>
      <span class="self">
        <uni-data-checkbox
          multiple
          v-model="checkself"
          :localdata="self"
          @change="checkSelf()"
        ></uni-data-checkbox>
      </span>
    </view>
    <view class="list">
      <view
        class="project"
        v-for="project in projectList"
        :key="project.id"
        @click="onClickProject(project)"
      >
        {{ `${project.project_name}(${project.project_full_code})` }}
      </view>
      <view class="loadmore">{{ loadMoreText }}</view>
    </view>

    <uni-fab
      :horizontal="'right'"
      :popMenu="false"
      @fabClick="onClickAdd()"
    ></uni-fab>
  </view>
</template>

<script>
import { queryProject } from "@/services/project";
import { mapState } from "vuex";
import mixin from "@/utils/listMixin";
export default {
  mixins: [mixin],
  computed: {
    ...mapState(["currentProject"]),
  },
  data() {
    return {
      checkself: [],
      projectList: [],
      self: [{ text: "只看自己", value: 0 }],
    };
  },
  onShow() {
    this.initData();
  },
  methods: {
    async getProject(params) {
      let res = {};
      res = await queryProject(params);
      this.pagination.currentPage == 1
        ? (this.projectList = res.data.list)
        : (this.projectList = this.projectList.concat(res.data.list));
      return res.data;
    },
    async onClickProject(project) {
      await this.$store.commit("setCurrentProject", project);
      uni.navigateTo({
        url: `./detail?id=${project.id}`,
      });
    },
    checkSelf() {
      this.projectFilter = {
        ...this.projectFilter,
        filter_type: this.checkself.length,
      };
      this.initData();
    },
    onClickAdd() {
      uni.navigateTo({
        url: "./add",
      });
    },
  },
};
</script>

<style lang="less" scoped>
.content {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
}
.head {
  width: 100%;
  padding: 0 20px 20px 20px;
  position: fixed;
  background: #f8f8f8;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .title {
    font: 24px bold;
  }
  .self {
    font: 16px;
  }
}
.list {
  width: 90%;
  margin-top: 60px;
  border-top: 2px solid gray;
}
.project {
  border-bottom: 2px solid gray;
  padding: 20px 0px;
  font-size: 18px;
}
.loadmore {
  padding: 20px 0px;
  font-size: 18px;
  color: gray;
  text-align: center;
}
</style>
