export default {
  name: "user_cards_list",
  data() {
    return {
      catetype:2,////分类这里改
      page: 1,
      total: 0,
      status: -1,
      type: "0",
      keywords:"",
      workfileData: [],
      loading:false,
      outerVisible: false,
      addDialog:false,
      editDialog:false,
      infoDialog:false,
      add_form: {
        parent_id: 0,
        category_id: 0,
        name: '',
        f_name: '',
        order: '1',
        type:2,////分类这里改
      },
      count: {
        total: 0,
        type1: 0,
        type2: 0,
        status0: 0,
        status1: 0,
        status2: 0,
      },
      info:{

      },
      tableData: [],
      logList:[],
    }
  },
  mounted() {
    this.getAuditList();
  },
  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.getCategoryMap();
          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(){

    },
    infoDialogFunc(info){
      this.getContent(info)
    },
    async changeStatus(id,status,content)
    {
      let res = await this.$post("/api/admin/sale/changeStatus", {id: id, status: status,content:content});
      if (res && res.status === 1) {
        this.$message({
          type: 'success',
          message: '操作成功!'
        });
        this.info.status=status;
        this.logListFunc(id);
        this.getAuditList();
        this.loading = false;
      }
    },
    async onChange(id, status) {
      this.loading = true;
      if(status==3)
      {
        this.$prompt('请输入拒绝理由', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
        }).then(({ value }) => {
          this.changeStatus(id,status,value);
        }).catch(() => {
          this.loading = false;
          this.$message({
            type: 'info',
            message: '取消输入'
          });
        });
      }
      else
      {
        this.changeStatus(id,status,"");
      }
    },
    async getContent(info) {
      this.loading = true;
      this.logListFunc(info.id);
      let res = await this.$post("/api/admin/sale/content", {id: info.id});
      if (res && res.status === 1) {
        info.content=res.data.content;
        this.infoDialog=true;
        this.info={};
        this.info=info;
        this.loading = false;
      }
      else
      {
        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) {
      let form = this.add_form;
      this.page=1;
      this.type=val;
      this.keywords="";
      if(val==1)
      {
        this.catetype=2;
        form.type=2;
        this.add_form=form;
      }
      else if(val==2)
      {
        this.catetype=3;
        form.type=3;
        this.add_form=form;
      }
      else
      {
        this.catetype=0;
        form.type=0;
        this.add_form=form;
      }
      this.getAuditList();
      this.getCategoryMap();
    },
    //删选状态
    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 getCategoryMap() {
      let id = 1;
      let arr = [];
      let where={type:this.catetype};
      let res = await this.$post("/api/admin/common/getCategoryMap",where);
      let list = res.data;
      for (const i of list) {
        let row = {
          id: id,
          type:this.catetype,
          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:this.catetype,
              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 logListFunc(sale_id) {
      let where={sale_id:sale_id};
      let res = await this.$post("/api/admin/sale/logList",where);
      this.logList=res.data;
    },
    async getAuditList() {
      const data = {
        page:this.page,
        status:this.status,
        type:this.type,
        keywords:this.keywords,
      };
      let res = await this.$post("/api/admin/sale/list", data);
      if (res && res.status === 1) {
        this.workfileData = res.data.list || [];
        this.total = res.data.total * 1;
        this.count = res.data.count;
      }
    },
    handleCurrentChange(val) {
      this.page = val;
      this.getAuditList();
    },
  }

}
