earthsites_credit.js 6.18 KB

import {
  listCredit,
  getCredit,
  delCredit,
  addCredit,
  updateCredit,
  exportCredit,
  getNames,
  getTypes,
  getPlaces,
  historyCredit
} from "@/api/business/earthsites";

import {
  earthsitesList,
  updateEarthsites
} from "@/api/dict";
import h5Page from '@/views/h5/Pagination';
import requestRemote from '@/utils/requestRemote'

export default {
  name: "EarthSitesCredit",
  components: {
  h5Page
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      infoDialog :false,
      // 总条数
      total: 0,
      // 工地表格数据
      creditList: [],
      creditListInfo: [],
      earthsitesList:[],
      dictNames:[],
      dictTypes:[],
      dictPlaces:[],
      names:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      isEdit:false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        type: null,
        time: null,
        place: null,
        reason: null,
        status: 0,
        lostCredit: 1
      },
      // 表单参数
      form: {},
      updateForm:{},
      // 表单校验
      rules: {name: [
          { required: true, message: '请选择处理场所', trigger: 'change' },
        ],reason: [
          { required: true, message: '请填写原因', trigger: 'change' },
        ]}
    };
  },
  created() {
    this.init();
  },
  methods: {
    init(){
      this.reset();
      this.getList();
      this.getNamesData();
      this.getTypesData();
      this.getPlacesData();

      let query = {
        'page': 1,
        'size': 9999,
        'creditStatus': 0
      };
      earthsitesList(query).then(response => {
        this.earthsitesList = response.result.list
      });
    },
    getDataInfo(row){
      let param ={"objectId":row.objectId}
      listCredit(param).then(response => {
        this.creditListInfo = response.rows;
        this.infoDialog = true;
      });

    },
    getNamesData(){
      getNames(this.queryParams).then(response => {
        this.dictNames = response;
      });
    },
    getTypesData() {
       getTypes(this.queryParams).then(response => {
        this.dictTypes = response;
      });
    },
    getPlacesData() {
      getPlaces(this.queryParams).then(response => {
        this.dictPlaces = response;
      });
    },
    getData(stauts){
      this.queryParams.status=0;
      this.queryParams.lostCredit=stauts;
        this.resetQuery();
      this.init();
    },
    getHistoryData(){
      this.queryParams.status=1;
        this.resetQuery();
      this.init();
    },
    colStyle(obj){
      if(obj.column.property == "id"){
        return {background:"#f8f8f9"}
      }
    },
    getObjId(a){
      this.form.objectId = a.id;
      this.form.place = a.areaName;
      this.form.type = a.typeName;
    },
    getList() {
      this.loading = true;
      if(this.queryParams.status==0){
        listCredit(this.queryParams).then(response => {
          this.creditList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      }
      if(this.queryParams.status==1){
        historyCredit(this.queryParams).then(response => {
          this.creditList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      }

    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.isEdit = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        type: null,
        time: null,
        place: null,
        reason: null,
        lostCredit: null,
        objectId: null,
      };
      this.updateForm = {};
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      console.log(this.queryParams);
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加处理场所";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getCredit(id).then(response => {
        this.form = response.data;
        this.isEdit = true;
      });
    },
    /** 提交按钮 */
    submitForm() {
        if(this.open){
          this.updateForm.reason = "1";
        }

      this.$refs["form"].validate(valid => {
        if (valid) {
        this.loading = true;
          if (this.form.id != null) {
            this.form.lostCredit = 0;
            let data = [{creditStatus:this.form.lostCredit,objectId:this.form.objectId}];
            updateEarthsites(data).then(res=>{
              this.updateForm.id = this.form.id;
              updateCredit(this.updateForm).then(response => {
                this.msgSuccess("撤销成功");
                this.isEdit = false;

                this.init();
              });
            });
          } else {
            this.form.lostCredit = 1;
            let data = [{creditStatus:this.form.lostCredit,objectId:this.form.objectId}];
            updateEarthsites(data).then(res=>{
              addCredit(this.form).then(response => {
                this.msgSuccess("新增成功");
                this.open = false;

                this.init();
              });
            });

          }
        }
      });
    },
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有处理场所数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return exportCredit(queryParams);
      }).then(response => {
        this.download(response.message);
      })
    }
  }
};