//资源管理运力
<template>
  <div class="steel_inbound">
    <div class="sache">
      <el-input placeholder="请输入内容" v-model="textInput" clearable>
      </el-input>
      <el-button
        type="primary"
        class="btn"
        @click="onclick"
        :loading="selectLoading"
      >
        <i class="el-icon-search"></i>查询
      </el-button>
      <el-button type="primary" class="btn" @click="toInsert">
        <i class="el-icon-plus"></i>新增
      </el-button>
      <el-button type="primary" class="btn" @click="toInsert1">
        <i class="el-icon-plus"></i>新增特殊车牌
      </el-button>
      <el-button type="primary" @click="exportAllExcel()"
        ><i class="el-icon-download"></i>导出(Excel)</el-button>
    </div>
    <div class="table">
      <dilTable
        ref="excelDom"
        v-bind.sync="options"
        :loading="tableloading"
        @func="func"
        :isKuang="isKuang"
      >
        <el-table-column fixed="right" label="操作" width="100">
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              @click="updateCapacity(scope.row.capacityCarrierId)"
            >
              修改
            </el-button>
            <el-button
              type="text"
              size="small"
              @click="deleteCapacity(scope.row)"
              v-if="show == true"
            >
              删除
            </el-button>
            <el-button
              type="text"
              size="small"
              @click="showCapacity(scope.row.capacityId)"
              v-if="show == false"
            >
              查看详情
            </el-button>
          </template>
        </el-table-column>
      </dilTable>
    </div>
  </div>
</template>
<script>
import { getCookie } from "@/utils/util.js";
export default {
  data() {
    return {
      selectLoading: false,
      isKuang: false,
      tableloading: false,
      show: false,
      name: "homeworkPath",
      textInput: "",
      restaurants: [],
      ssoId: null,
      options: {
        // first请求数据的地址
        requestUrl: ""
      },
      noSettleDetailsColumn: [],
      exportAllList:[]
    };
  },
  created() {
    if (
      getCookie("orgCode") == "wuliuchuyunzhongxin" ||
      getCookie("orgCode") == "dagangadmin" ||
      getCookie("orgCode") == "zidonghuabu" ||
      getCookie("orgCode") == "chengyunshang"
    ) {
      this.show = true;
    }
    if (getCookie("orgCode") == "chengyunshang") {
      this.options.requestUrl =
        "/api/v1/rms/getCapacityList?apiId=397&carrierSSOId=" +
        getCookie("userId");
    } else if (getCookie("orgCode") == "baohua") {
      this.options.requestUrl =
        "/api/v1/rms/getCapacityList?apiId=397&carrierSSOId=" +
        getCookie("userId");
    } else {
      this.options.requestUrl =
        "/api/v1/rms/getCapacityList?apiId=397&carrierSSOId=" + null;
    }
  },
  methods: {
    func(res) {
      if (this.tableloading) {
        this.tableloading = false;
      }
      if (this.isKuang) {
        this.isKuang = false;
      }
      if (this.selectLoading) {
        this.selectLoading = false;
      }
    },
    exportAllExcel() {
      this.isKuang = true;
      this.tableloading = true;
      this.selectLoading = true;
      if (this.textInput) {
        if (getCookie("orgCode") == "chengyunshang") {
          this.axios.post("/api/v1/rms/getCapacityList?apiId=397&carrierSSOId=" +
            getCookie("userId") +
            "&con=" +
            this.textInput +
            "&i=" +
            new Date())
            .then(res => {
            console.log(res.data.data)
            this.exportAllList = res.data.data.list
            this.noSettleDetailsColumn=res.data.data.columnData
            this.exportAllReportToExcel(
              this.tableTitle,
              this.exportAllList,
              this.noSettleDetailsColumn
            )
          })
        } else if (getCookie("orgCode") == "baohua") {
          this.axios.post("/api/v1/rms/getCapacityList?apiId=397&carrierSSOId=" +
            getCookie("userId") +
            this.textInput +
            "&i=" +
            new Date())
            .then(res => {
            console.log(res.data.data)
            this.exportAllList = res.data.data.list
            this.noSettleDetailsColumn=res.data.data.columnData
            this.exportAllReportToExcel(
              this.tableTitle,
              this.exportAllList,
              this.noSettleDetailsColumn
            )
          })
        } else {
          this.axios.post("/api/v1/rms/getCapacityList?apiId=397&carrierSSOId=" +
            null +
            "&con=" +
            this.textInput +
            "&i=" +
            new Date())
            .then(res => {
            console.log(res.data.data)
            this.exportAllList = res.data.data.list
            this.noSettleDetailsColumn=res.data.data.columnData
            this.exportAllReportToExcel(
              this.tableTitle,
              this.exportAllList,
              this.noSettleDetailsColumn
            )
          })
        }
      } else {
        if (getCookie("orgCode") == "chengyunshang") {
          this.axios.post("/api/v1/rms/getCapacityList?apiId=397&carrierSSOId=" +
            getCookie("userId") +
            "&i=" +
            new Date())
            .then(res => {
            console.log(res.data.data)
            this.exportAllList = res.data.data.list
            this.noSettleDetailsColumn=res.data.data.columnData
            this.exportAllReportToExcel(
              this.tableTitle,
              this.exportAllList,
              this.noSettleDetailsColumn
            )
          })
        } else if (getCookie("orgCode") == "baohua") {
          this.axios.post("/api/v1/rms/getCapacityList?apiId=397&carrierSSOId=" +
            getCookie("userId") +
            "&i=" +
            new Date())
            .then(res => {
            console.log(res.data.data)
            this.exportAllList = res.data.data.list
            this.noSettleDetailsColumn=res.data.data.columnData
            this.exportAllReportToExcel(
              this.tableTitle,
              this.exportAllList,
              this.noSettleDetailsColumn
            )
          })
        } else {
          this.axios.post("/api/v1/rms/getCapacityList?apiId=397&carrierSSOId=" +
            null +
            "&i=" +
            new Date())
            .then(res => {
            console.log(res.data.data)
            this.exportAllList = res.data.data.list
            this.noSettleDetailsColumn=res.data.data.columnData
            this.exportAllReportToExcel(
              this.tableTitle,
              this.exportAllList,
              this.noSettleDetailsColumn
            )
          })
        }
      }
    },
    //导出excel
    exportAllReportToExcel(tableTitle, dataArr, columnData) {
      var title = tableTitle
      let tHeader = []
      let filterVal = []
      columnData.forEach(e1 => {
        if (tHeader.indexOf(e1.label) === -1) {
          tHeader.push(e1.label)
        }
        if (filterVal.indexOf(e1.prop) === -1) {
          filterVal.push(e1.prop)
        }
      })
      //导出为excel
      this.downloadLoading = true
      require.ensure([], () => {
        const {
          export_json_to_excel
        } = require('@/assets/excel/Export2Excel.js') //这里必须使用绝对路径，使用@/+存放export2Excel的路径
        // let list = this.$refs.excelDom.dataTabel;
        let data = dataArr.map(v => filterVal.map(j => v[j])) //3.formatJson格式转换
        export_json_to_excel(tHeader, data, title) // (title)导出的表格名称
      })
      this.tableloading=false
      this.selectLoading=false   
    },
    onclick() {
      this.isKuang = true;
      this.tableloading = true;
      this.selectLoading = true;
      if (this.textInput) {
        if (getCookie("orgCode") == "chengyunshang") {
          this.options.requestUrl =
            "/api/v1/rms/getCapacityList?apiId=397&carrierSSOId=" +
            getCookie("userId") +
            "&con=" +
            this.textInput +
            "&i=" +
            new Date();
        } else if (getCookie("orgCode") == "baohua") {
          this.options.requestUrl =
            "/api/v1/rms/getCapacityList?apiId=397&carrierSSOId=" +
            getCookie("userId") +
            this.textInput +
            "&i=" +
            new Date();
        } else {
          this.options.requestUrl =
            "/api/v1/rms/getCapacityList?apiId=397&carrierSSOId=" +
            null +
            "&con=" +
            this.textInput +
            "&i=" +
            new Date();
        }
      } else {
        if (getCookie("orgCode") == "chengyunshang") {
          this.options.requestUrl =
            "/api/v1/rms/getCapacityList?apiId=397&carrierSSOId=" +
            getCookie("userId") +
            "&i=" +
            new Date();
        } else if (getCookie("orgCode") == "baohua") {
          this.options.requestUrl =
            "/api/v1/rms/getCapacityList?apiId=397&carrierSSOId=" +
            getCookie("userId") +
            "&i=" +
            new Date();
        } else {
          this.options.requestUrl =
            "/api/v1/rms/getCapacityList?apiId=397&carrierSSOId=" +
            null +
            "&i=" +
            new Date();
        }
      }
    },
    toInsert() {
      this.$router.push("/addCapacity");
    },
    toInsert1() {
      this.$router.push("/addOtherCapacity");
    },
    updateCapacity(capacityCarrierId) {
      // console.log("capacityCarrierId" +capacityCarrierId);
      this.$router.push("/editCapacity/" + capacityCarrierId);
    },
    showCapacity(capacityId) {
      this.$router.push("/showCapacity/" + capacityId);
    },
    deleteUser(userId) {
      this.axios.delete("pass/v1/sysusers/" + userId).then(res => {});
    },

    deleteCapacity(row) {
      console.log("row", row);
      console.log(row);
      let map = {
        capacityCarrierId: row.capacityCarrierId,
        carrierSSOId: getCookie("userId"),
        capacityId: row.capacityId
      };
      if (
        getCookie("orgCode") == "wuliuchuyunzhongxin" ||
        getCookie("orgCode") == "dagangadmin" ||
        getCookie("orgCode") == "zidonghuabu" ||
        getCookie("orgCode") == "chengyunshang"
      ) {
        this.$confirm(
          "是否删除与车牌号(" + row.capacityNumber + ")的绑定关系?",
          "提示",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }
        )
          .then(() => {
            this.axios
              .post("/api/v1/rms/deleteCapacityCarrier", map)
              .then(res => {
                if (res.data.code == "0") {
                  this.$message.success("删除成功!");
                  if (getCookie("orgCode") == "chengyunshang") {
                    this.options.requestUrl =
                      "/api/v1/rms/getCapacityList?apiId=397&carrierSSOId=" +
                      getCookie("userId") +
                      "&i=" +
                      new Date();
                  } else if (getCookie("orgCode") == "baohua") {
                    this.options.requestUrl =
                      "/api/v1/rms/getCapacityList?apiId=397&carrierSSOId=" +
                      getCookie("userId") +
                      "&i=" +
                      new Date();
                  } else {
                    this.options.requestUrl =
                      "/api/v1/rms/getCapacityList?apiId=397&carrierSSOId=" +
                      null +
                      "&i=" +
                      new Date();
                  }
                }
              });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消删除"
            });
          });
      } else {
        this.$message.error("权限不足，请联系管理员!");
      }
    }
  }
};
</script>
<style lang="scss" scode>
.steel_inbound {
  .sache {
    padding: 1.25rem 0.375rem;
    .el-input {
      width: 20%;
      margin-right: 1.25rem;
    }
  }
}
</style>
