import { Query, newData, modifyData, moveData } from "@/api/webApi"
export default {
  data () {
    return {
      title: '',
      queryId: '',
      pageIndex: 1,
      pageSize: 9999,
      dataContent: {}
    }
  },
  created () {
    const { title, qid } = this.$route.meta
    this.title = title
    this.queryId = qid
  },
  methods: {
    //查询
    async getQuery (id, type = false, dataContent = {}, pageSize) {
      try {
        // this.loading = true;
        const { code, columnset, returnData } = await Query({
          serviceId: id,
          page: this.pageIndex,
          pageSize: pageSize ?? this.pageSize,
          dataContent,
        })
        if (code == 0) {
          if (type) {
            return columnset
          } else {
            return returnData
          }
        } else {
          return []
        }
      } catch (error) {
        return []
      }
    },
    //增/删/改
    async generalDataReception (id, data, event, type) {
      try {
        const params = {
          serviceId: id,
          dataContent: data,
          event: `${event}`,
        };
        const { code, returnData } =
          event == 1
            ? await newData(params)
            : event == 2
              ? await modifyData(params)
              : await moveData(params);
        if (code == 0) {
          this.$message.success("操作成功");
          if (type) {
            return returnData
          } else {
            return 1
          }
        } else {
          this.$message.error("操作失败");
          return 0
        }
      } catch (error) {
        return 0
      }
    },
  }
}