export default {
  name: "user_cards_list",
  data() {
    return {
      page: 1,
      total: 0,
      status: 0,
      type: "0",
      keywords:"",
      workfileData: [],
      loading:false,
      outerVisible: false,
      addDialog:false,
      editDialog:false,
      add_form: {
        parent_id: 0,
        category_id: 0,
        name: '',
        f_name: '',
        order: '1',
        type:1,
      },
      count: {
        total: 0,
        type1: 0,
        type2: 0,
        status0: 0,
        status1: 0,
        status2: 0,
      },
      tableData: [],
    }
  },
  mounted() {
    this.getAuditList();
    this.getTableData();
  },
  methods: {
    addDialogEvent(row) {
      this.add_form.parent_id = row.category_id;
      this.addDialog = true;
    },
    addFirstCate(){
      this.addDialog = true;
    },
    formAdd() {
      this.$post("/api/admin/common/addCategory", this.add_form).then(res => {
        if (res && res.status === 1) {
          this.getTableData();
          this.$message.success('操作成功')
          this.addDialog = false;
          this.add_form.parent_id =0;
          this.add_form.category_id =0;
          this.add_form.name ='';
          this.add_form.f_name ='';
          this.add_form.order =0;
          this.editDialog = false;
        }
      });

    },
    form(){

    },
    async onChange(id, type) {
      this.loading = true;
      let res = await this.$post("/api/admin/UserWorks/changeWorkFile", {id: id, type: type});
      if (res && res.status === 1) {
        this.$message({
          type: 'success',
          message: '操作成功!'
        });
        this.getAuditList();
        this.loading = false;
      }
    },
    editDialogEvent(row) {
      let form = this.add_form;
      form.parent_id = row.parent_id;
      form.category_id = row.category_id;
      form.name = row.name;
      form.f_name = row.f_name;
      form.order = row.order;
      this.editDialog = true;
    },
    //筛选类型
    async typechange(val) {
      this.page=1;
      this.type=val;
      this.keywords="";
      this.getAuditList();
    },
    //删选状态
    async statuschange(val) {
      this.page=1;
      this.status=val;
      this.keywords="";
      this.getAuditList();
    },
    //搜索删选
    async searchkeywords() {
      this.page=1;
      this.keywords=this.keywords;
      this.getAuditList();
    },
    //获取分类列表
    async getTableData() {

      let id = 1;
      let arr = [];
      let where={type:1};
      let res = await this.$post("/api/admin/common/getCategoryMap",where);
      let list = res.data;
      for (const i of list) {
        let row = {
          id: id,
          type:1,
          category_id: i.category_id,
          name: i.name,
          f_name: i.f_name,
          parent_id: i.parent_id,
          order: i.order,
          children: []
        }
        id++;
        if (i.child) {
          for (const j of i.child) {
            row.children.push({
              id:id,
              type:1,
              category_id: j.category_id,
              parent_id: i.parent_id,
              name: j.name,
              f_name: j.f_name,
              order: j.order
            });
            id++;
          }
        }
        arr.push(row);
      }
      this.tableData = arr;
    },
    async getAuditList() {
      const data = {
        page:this.page,
        status:this.status,
        type:this.type,
        keywords:this.keywords,
      };
      let res = await this.$post("/api/admin/UserWorks/getWorkFileList", data);
      if (res && res.status === 1) {
        this.workfileData = res.data.list || [];
        this.total = res.data.total * 1;
        this.count = res.data.count;
      }
    },
    async deleteWorkFile(id) {
      let res = await this.$post("/api/admin/UserWorks/deleteWorkFile", {id: id});
      if (res && res.status === 1) {
        this.$message({
          type: 'success',
          message: '删除成功!'
        });
        this.getAuditList();
        this.loading = false;
      }
    },
    handleCurrentChange(val) {
      this.page = val;
      this.getAuditList();
    },
  }

}
