6.16 7

export default {
  data() {
    return {
      currentDisplayCount: 2,
      searchItems: [
        {field: 'name', label: '政策名称', value: '', logicalOperator: 'AND', matchType: '精确'},
        {field: 'type', label: '政策分类', value: '', logicalOperator: 'AND', matchType: '精确'},
        {field: 'category', label: '分类', value: '', logicalOperator: 'AND', matchType: '精确'},
        {field: 'range', label: '施行范围', value: '', logicalOperator: 'AND', matchType: '精确'},
        {field: 'document', label: '发文字号', value: '', logicalOperator: 'AND', matchType: '精确'},
        {field: 'form', label: '颁布形式', value: '', logicalOperator: 'AND', matchType: '精确'},
        {field: 'organ', label: '制定机关', value: '', logicalOperator: 'AND', matchType: '精确'},
        {field: 'text', label: '全文', value: '', logicalOperator: 'AND', matchType: '精确'},
      ],
      searchForm: {
        name: '', // 政策名称
        type: '', // 政策分类
        category: '', // 分类
        range: '', // 施行范围
        form: '', // 颁布形式
        document: '', // 发文字号
        organ: '', // 发文机构
        text: '', // 全文检索
      },
      tableData: [], // 统一使用一个tableData,根据是否有搜索条件决定显示数据
      currentPage4: 1, // 初始化 currentPage4
      pageSize: 10, // 分页大小
      total: 0, // 总记录数
      SList:[]
    };
  },
  computed: {
    limitedSearchItems() {
      return this.searchItems.slice(0,this.currentDisplayCount); // 只取前两项
    },
  },
  async created() {
    await this.fetchPolicies();
  },
  methods: {
    async search1() {
      let isEmpty = true;
      for (let item of this.searchItems) {
        if (item.value) {
          isEmpty = false;
          break;
        }
      }

      if (isEmpty) {
        alert("至少需要填写第一个搜索框");
        return;
      }

      let isAnyLineIncomplete = false;
      for (let item of this.searchItems) {
        if (!item.logicalOperator || !item.matchType) {
          isAnyLineIncomplete = true;
          break;
        }
      }

      if (isAnyLineIncomplete) {
        alert("请确保每一行的‘AND/OR’、输入框、精确/模糊都得到填写");
        return;
      }
      let queryParts = [];
      for (let item of this.searchItems) {

        if (item.value) {
          let conditionPart = `${item.field}=${item.value}matchType=${item.matchType}`;
          if (queryParts.length >= 0) {
            conditionPart = `${encodeURIComponent(item.logicalOperator)}${conditionPart}`;
          }
          queryParts.push(conditionPart);
        }
      }
      let dp = queryParts.join('&');
      console.log(dp);
      try {
        const response = await axios.get(`http://localhost:9090/policy/selectDP?dp=${queryParts}`);
        this.tableData = response.data;
      } catch (error) {
        console.error('Search failed:', error);
      }

    },

    addSearchItem() {
      // 如果显示的检索项数量未达到最大值,则增加显示一项
      if (this.currentDisplayCount < 8) {
        this.currentDisplayCount++;
      } else {
        alert("已达最大检索项数量!");
      }
    },

    removeSearchItem(index) {
      // 只允许从第三项开始删除,并确保至少保留两项
      if (index > 1 && this.currentDisplayCount > 2) {
        this.currentDisplayCount--;
      }
    },

 

posted @ 2024-06-17 23:16  七安。  阅读(13)  评论(0)    收藏  举报