<template>
  <view class="content">
    <view class="title"> 审核列表 </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>

    <search-drawer title="查询项目" ref="searchDrawer" @onOk="search">
      <uni-forms :modelValue="projectFilter" label-position="top" class="form">
        <uni-forms-item label="项目名称">
          <uni-easyinput
            type="text"
            class="input"
            v-model="projectFilter.project_name"
          />
        </uni-forms-item>
        <uni-forms-item label="项目编号">
          <uni-easyinput
            type="text"
            class="input"
            v-model="projectFilter.project_code"
          />
        </uni-forms-item>
        <uni-forms-item label="状态">
          <picker
            @change="selectChangeStatus"
            :range="statusList"
            :range-key="'label'"
          >
            <view class="select">
              {{
                projectFilter.project_status != null
                  ? statusList[projectFilter.project_status + 1].label
                  : "全部"
              }}
            </view>
          </picker>
        </uni-forms-item>
      </uni-forms>
    </search-drawer>
  </view>
</template>

<script>
import { queryAuth } from "@/services/project";
import { mapState } from "vuex";
import mixin from "@/utils/listMixin";
const statusList = [
  { value: null, label: "全部" },
  { value: 0, label: "售前" },
  { value: 1, label: "转执行" },
  { value: 2, label: "转运营" },
  { value: 3, label: "转质保" },
];
export default {
  mixins: [mixin],
  computed: {
    ...mapState(["currentProject"]),
  },
  data() {
    return {
      projectList: [],
      projectFilter: {
        project_name: "",
        project_code: "",
        project_status: null,
      },
      statusList,
    };
  },
  onShow() {
    this.initData();
  },
  onNavigationBarButtonTap() {
    uni.reLaunch({
      url: "/pages/index/index",
    });
  },
  methods: {
    async getProject(params) {
      let res = {};
      res = await queryAuth(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}&auth=${true}`,
      });
    },
    selectChangeStatus(e) {
      const item = this.statusList[e.target.value];
      this.projectFilter.project_status = item.value;
    },
    async search() {
      this.projectFilter.project_code =
        this.projectFilter.project_code.toUpperCase();
      this.pagination.currentPage = 1;
      await this.initData();
      this.$refs.searchDrawer.closeDrawer();
    },
  },
};
</script>

<style lang="less" scoped>
.content {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
}

.title {
  width: 100%;
  padding: 0 20px 20px 20px;
  position: fixed;
  background: #f8f8f8;
  font: 24px bold;
}
.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;
}
.form {
  margin: 0 20px;
}
</style>
