construction_credit.js 7.42 KB
import {
    listCredit,
    getCredit,
    delCredit,
    addCredit,
    updateCredit,
    exportCredit,
    getNames,
    getTypes,
    getPlaces,
    historyCredit
  } from "@/api/business/constructionsites";

  import {
    constructionsitesList,
    getDict,
    getArea,
    updateConstructionsites
  } from "@/api/dict";

import h5Page from '@/views/h5/Pagination';

  export default {
    name: "ConstructionCredit",  
    components: {
    h5Page
    },
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        infoDialog: false,
        // 总条数
        total: 0,
        // 工地表格数据
        creditList: [],
        creditListInfo: [],
        dictNames: [],
        dictTypes: [],
        dictPlaces: [],
        // 弹出层标题
        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: {},
        //建筑垃圾类型集合
        trashTypes: [],
        constructionList: [],
        // 表单校验
        rules: {
          name: [{
            required: true,
            message: '请选择工地',
            trigger: 'change'
          }, ],
          reason: [{
            required: true,
            message: '请填写原因',
            trigger: 'change'
          }, ]
        },
        areas:[],
      };


    },
    created() {

      getArea().then(res => {
          this.areas = res.result;
      });

      getDict({'type': 'CSDisSiteDisposalType'}).then(response => {
        this.trashTypes = response.result;
      });

      this.init();

    },
    methods: {
      init(){
        this.reset();
        this.getList();
        this.getNamesData();
        this.getTypesData();
        this.getPlacesData();

        let query = {
          'page': 1,
          'size': 9999,
          'creditStatus': 0
        };
        constructionsitesList(query).then(response => {
          this.constructionList = response.result.list
        });
      },
      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;
          });
        }
      },
      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(object) {

        this.form.objectId = object.id;

        for(let i in this.areas){
          if(this.areas[i].code == Number(object.areaCode)){
            this.form.place = this.areas[i].name;
            break;
          }
        }
        for(let i in this.trashTypes){
          if(this.trashTypes[i].code == Number(object.cargoId)){
            this.form.type = this.trashTypes[i].name;
            break;
          }
        }
      },
      // 取消按钮
      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 = {
          reason:null,
        };
        this.resetForm("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() {
        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}];

              updateConstructionsites(data).then(response=>{
                  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}];
              updateConstructionsites(data).then(response=>{
                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);
        })
      }
    }
  };