company_credit.js 6.44 KB
  import {
    listCredit,
    getCredit,
    delCredit,
    addCredit,
    updateCredit,
    exportCredit,
    getNames,
    getPlaces,
    historyCredit
  } from "@/api/business/company";

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

  import {
    companyList,
    updateCompany,
  } from "@/api/dict";


  export default {
    name: "Credit",
    components: {
    h5Page
    },
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        infoDialog :false,
        // 总条数
        total: 0,
        // 工地表格数据
        creditList: [],
        creditListInfo: [],
        companyList:[],
        dictNames:[],
        dictPlaces:[],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        isEdit:false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          name: 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' },
          ],
        },
        rules2: {
          reason: [
            { required: true, message: '请填写原因', trigger: 'change' },
          ],
        },
      };
    },
    created() {
      this.init();
    },
    methods: {
      init(){
          this.getList();
          getNames(this.queryParams).then(response => {
            this.dictNames = response;
          });
          getPlaces(this.queryParams).then(response => {
            this.dictPlaces = response;
          });

          let query = {
            'page':1,
            'size':9999,
            'creditStatus':0
          }
          companyList(query).then(response => {

            this.companyList = response.result.list;
          });
      },
      getDataInfo(row){
        let param ={"objectId":row.objectId}

        listCredit(param).then(response => {
          this.creditListInfo = response.rows;
          this.infoDialog = true;
        });

      },
      getData(stauts){
        this.queryParams.status=0;
        this.queryParams.lostCredit=stauts;
        this.resetQuery();
        this.getList();
      },
      getHistoryData(){
        this.queryParams.status=1;
        this.resetQuery();
        this.getList();
      },
      colStyle(obj){
        if(obj.column.property == "id"){
          return {background:"#f8f8f9"}
        }
      },
      getObjId(a){
        this.form.objectId = a.id;
        this.form.place = a.areaName;
      },
      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,
          time: null,
          place: null,
          reason: null,
          lostCredit: null,
          objectId: null,
        };
        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.isEdit){
          this.$refs["updateForm"].validate(valid => {
            if (valid) {
              this.loading = true;
                this.form.lostCredit = 0;
                this.updateForm.id = this.form.id;
                let data = [{id:this.form.objectId,dishonestState:this.form.lostCredit}];
                updateCompany(data).then(res=>{
                  updateCredit(this.updateForm).then(response => {
                    this.msgSuccess("撤销成功");
                    this.isEdit = false;
                    this.updateForm = {};
                    this.init();
                  });
                });
            }
          });
        }else{
          this.$refs["form"].validate(valid => {
            if (valid) {
              this.loading = true;
                this.form.lostCredit = 1;
                let data = [{id:this.form.objectId,dishonestState:this.form.lostCredit}];
                updateCompany(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);
        })
      }
    }
  };