//钢材统计报表
<template>
  <div class="purchasFuelNewMonitor">
    <div class="tableTop">
      <el-form :inline="true" style="margin-top :5px">
        <el-form-item>
          <el-select
            v-model="screen"
            placeholder="请选择需筛选的内容"
            clearable
            @change="changeScreen"
            style="width:100px"
          >
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
          <el-input
            style="width:170px"
            v-model="input"
            placeholder="请输入查询条件"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-select
            v-model="screen1"
            placeholder="请选择需筛选的内容"
            clearable
            style="width:100px"
          >
            <el-option
              v-for="item in options1"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
          <el-input
            style="width:170px"
            v-model="input1"
            placeholder="请输入查询条件"
            clearable
          ></el-input>
          <el-button type="primary" class="btn" @click="onclick">
            <i class="el-icon-search"></i>
          </el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="exportAllReportToExcel"
            >下载Excel</el-button
          >
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="addSaleOrder1"
            >重新生成计划</el-button
          >
        </el-form-item>
        <el-form-item>
          <el-upload
            class="upload-excel"
            action=""
            :on-change="exportEasEntry"
            :show-file-list="false"
            accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"
            :auto-upload="false"
          >
            <el-button type="primary" icon="el-icon-upload"
              >导入金蝶分录查询</el-button
            >
          </el-upload>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="refresh">
            <i class="el-icon-refresh"></i>
          </el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="updateSaleOrderRemark">
            重置上传限制
          </el-button>
        </el-form-item>
        <el-form-item>
          <span style="margin-left: 1rem;font-size:16px">车数/件数：</span>
          <span style="font-size:16px"
            >{{ totalCapacity }}/{{ totalNumber }}</span
          >
        </el-form-item>
      </el-form>
    </div>
    <div class="table">
      <el-table
        :data="tableData"
        :span-method="objectSpanMethod"
        ref="tableRef"
        border
        style="width: 100%; margin-top: 20px"
        :max-height="maxHeight"
        :height="maxHeight"
        @filter-change="filterChange"
        @selection-change="handleSelectionChange"
        :lazy="true"
      >
        <el-table-column
          type="selection"
          width="50"
          align="center"
          fixed="left"
        >
        </el-table-column>
        <el-table-column
          width="50"
          label="序号"
          align="center"
          :resizable="false"
        >
          <template slot-scope="scope">{{ scope.row.group + 1 }}</template>
        </el-table-column>
        <el-table-column
          prop="orderTime"
          label="订单日期"
          width="110px"
          align="center"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          prop="saleOrderStatus"
          label="销售订单状态"
          width="100px"
          align="center"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          prop="consigneeName"
          label="客户"
          width="160px"
          align="center"
          column-key="consigneeName"
          :filters="filterConsigneeList"
          sortable
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          prop="areaName"
          label="销售片区"
          width="150px"
          align="center"
          column-key="saleAreaList"
          :filters="filterSaleAreaList"
        >
        </el-table-column>
        <el-table-column
          prop="closeEntryId"
          label="金蝶分录ID"
          width="150px"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="entryStatus"
          label="分录状态"
          width="100px"
          show-overflow-tooltip
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="saleRemark"
          label="摘要"
          width="150px"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="carrierName"
          label="承运商"
          align="center"
          width="80px"
          column-key="carrierList"
          sortable
          show-overflow-tooltip
          :filters="filterCarrierList"
        >
        </el-table-column>
        <el-table-column
          prop="capacityNo"
          column-key="capacityNo"
          label="车牌号"
          align="center"
          width="90px"
          sortable
          show-overflow-tooltip
          :filters="filterCapacityList"
        >
        </el-table-column>
        <el-table-column
          prop="materialName"
          column-key="materialNameList"
          label="物资名称"
          align="center"
          width="150px"
          sortable
          :filters="filtermaterialNameList"
        >
        </el-table-column>
        <el-table-column
          prop="materialSpe"
          label="物资规格"
          align="center"
          sortable
          width="120px"
        >
        </el-table-column>
        <el-table-column
          prop="materialNum"
          label="物资件数"
          align="center"
          width="50px"
        >
        </el-table-column>
        <el-table-column
          prop="addressPlace"
          label="收货地址"
          width="250px"
          sortable
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          prop="orderStatus"
          label="运单状态"
          align="center"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          prop="entryGateTime"
          label="进厂时间"
          width="130px"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          prop="tareWeightTime"
          label="皮重时间"
          width="130px"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column prop="tareWeight" label="皮重" show-overflow-tooltip>
        </el-table-column>
        <el-table-column
          prop="loadTime"
          label="装货时间"
          width="130px"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          prop="grossWeightTime"
          label="毛重时间"
          width="130px"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column prop="grossWeight" label="毛重" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="netWeight" label="净重" show-overflow-tooltip>
        </el-table-column>
        <el-table-column
          prop="orderNo"
          label="运输订单号"
          width="180px"
          align="center"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          prop="capacityTel"
          label="司机电话"
          width="120px"
          align="center"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          prop="saler"
          label="业务员"
          align="center"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          prop="shipperName"
          label="发货单位"
          width="170px"
          align="center"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          prop="consigneeTel"
          label="收货客户电话"
          width="120px"
          align="center"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column prop="isSelfMention" label="是否自提" align="center">
        </el-table-column>
        <el-table-column
          prop="saleOrderNo"
          label="销售订单号"
          width="200px"
          align="center"
          show-overflow-tooltip
        >
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import { sjTime } from '@/utils/sharedJsFile'
import { getCookie } from '@/utils/util.js'

export default {
  data() {
    return {
      input: null,
      screen: '',
      screen1: '',
      options: [
        {
          value: '客户',
          lable: '客户'
        },
        {
          value: '承运商',
          lable: '承运商'
        },
        {
          value: '车牌号',
          lable: '车牌号'
        },
        {
          value: '分录ID',
          lable: '分录ID'
        }
      ],
      options1: [
        {
          value: '客户',
          lable: '客户'
        },
        {
          value: '承运商',
          lable: '承运商'
        },
        {
          value: '车牌号',
          lable: '车牌号'
        }
      ],
      //合计净重
      totalNumber: 0,
      //合计车数
      totalCapacity: 0,
      tableTitle: '销售统计报表',
      tableData: [],
      //筛选条件1（客户）
      filters1: [],
      spanArr: [],
      pos: 0,
      //需要合并列的名称
      mergeList: [
        '序号',
        '整车操作',
        '销售订单状态',
        '销售订单号',
        '发货单位',
        '司机电话',
        '运输订单号',
        '签收地址',
        '签收时间',
        '抵达地址',
        '抵达时间',
        '出厂时间',
        '进厂时间',
        '运单状态',
        '车牌号',
        '承运商',
        '客户',
        '收货地址',
        '业务员',
        '送货单打印',
        '收货客户电话',
        '是否自提',
        '订单日期',
        '短信发送',
        '销售片区',
        '抵达时间',
        '签收时间',
        '净重',
        '皮重时间',
        '皮重',
        '毛重时间',
        '毛重',
      ],
      //钢材多拼车辆线路ID
      //索引从1-10为1-10拼路线ID
      tableTitle: '销售钢材未装货统计报表',
      //所有省
      provinceList: [],
      //选中的省
      province: '',
      //所有市
      cityList: [],
      //选中的市
      city: '',
      //所有的县(区)
      countyList: [],
      //选中的县
      county: '',
      //地址输入框的值
      addresText: '',
      //已选中省市县
      address: null,
      //具体地址
      place: null,
      //暂存具体地址
      place1: null,
      //省市县Id
      addressId: null,
      addressRow: {},
      input1: '',
      maxHeight: window.innerHeight - 140,
      tableRowIndex: '',
      isRowClick: 0,
      orgCodeList: [
        'wuliuyunshubu',
        'dagangadmin',
        'shichangxinxibu',
        'xiaoshouyewuyuan',
        'zidonghuabu'
      ],
      filterConsigneeList: [],
      filterCarrierList: [],
      filterCapacityList: [],
      filtermaterialNameList: [],
      filterSaleAreaList: [],
      filterMap: {},
      //销售订单主表数据
      saleOrderList: [
        'receiveId',
        'receiveName',
        'isSelfMention',
        'saleRemark',
        'saleOrderReceiveCustomer',
        'salerName',
        'salerId',
        'saleOrderNo',
        'saleArea',
        'saleOrderId'
      ],
      saleOrderMapList: [
        'orderNo',
        'truckNo',
        'province',
        'district',
        'town',
        'truckRemark',
        'shipperAddressId',
        'placeId',
        'place',
        'saleOrderConsigneeTel',
        'saleDateOfReceipt',
        'materialId',
        'materialName',
        'materialSpecification',
        'materialModel',
        'materialNumber',
        'steelMeters',
        'isPoundSale',
        'carrierId'
      ],
      saleDateOfReceipt: null,
      remarkDateNew: null,
      remarkDateOld: null,
      entryIdList: []
    }
  },
  created() {
    let loadTime1 = new Date(
      new Date(new Date().toLocaleDateString()).getTime() +
        (3600 * 1000 * 8 - 1)
    ) // 当天8点前
    let loadTime2 = new Date(
      new Date(new Date().toLocaleDateString()).getTime() +
        (3600 * 1000 * 32 - 1)
    ) // 次天8点前
    if (new Date().getTime() - loadTime1 > 0) {
      this.saleDateOfReceipt = loadTime2
    } else {
      this.saleDateOfReceipt = loadTime1
    }
    this.remarkDateNew = this.getRemarkDate()
    this.remarkDateOld = this.getRemarkDateOld()
    this.addSaleOrder1 = this.debounce(() => {
      this.addSaleOrder()
    }, 1000)
    this.getSteelReport()
  },
  watch: {
    tableData: {
      handler(oldVal, newVal) {
        this.filterListChange()
      },
      deep: true,
      immediate: true
    }
  },
  computed: {},
  mounted() {
    this.$nextTick(() => {
      window.onresize = () => {
        return (() => {
          this.maxHeight = window.innerHeight - 150
        })()
      }
    })
  },
  activated() {
    this.maxHeight = window.innerHeight - 150
  },
  computed: {},
  methods: {
    getSaleDateOfReceipt() {
      let loadTime1 = new Date(
        new Date(new Date().toLocaleDateString()).getTime() +
          (3600 * 1000 * 8 - 1)
      ) // 当天8点前
      let loadTime2 = new Date(
        new Date(new Date().toLocaleDateString()).getTime() +
          (3600 * 1000 * 32 - 1)
      ) // 次天8点前
      if (new Date().getTime() - loadTime1 > 0) {
        this.saleDateOfReceipt = loadTime2
      } else {
        this.saleDateOfReceipt = loadTime1
      }
    },
    //防抖函数--防止用户重复点击
    debounce(func, delay) {
      let timer = null
      return function(...args) {
        if (timer !== null) {
          clearTimeout(timer)
        }
        timer = setTimeout(function() {
          func.apply(this, args)
        }, delay)
      }
    },
    handleSelectionChange() {},
    //记录每一行的合并数
    getSpanArr(data) {
      //每次调用方法初始化
      this.spanArr = []
      for (var i = 0; i < data.length; i++) {
        if (i === 0) {
          this.spanArr.push(1)
          data[i].group = i
          this.pos = 0
        } else {
          // 判断当前元素与上一个元素是否相同
          if (data[i].saleOrderMaterialId === data[i - 1].saleOrderMaterialId || ( data[i].weightBatchId && data[i].weightBatchId ===data[i - 1].weightBatchId)) {
            this.spanArr[this.pos] += 1
            data[i].group = data[i - 1].group
            this.spanArr.push(0)
          } else {
            this.spanArr.push(1)
            this.pos = i
            data[i].group = data[i - 1].group + 1
          }
        }
        this.totalCapacity = data[data.length - 1].group + 1
        this.totalNumber = data.reduce(function(prev, item) {
          return prev + item.materialNum
        }, 0)
      }
    },
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      if (this.mergeList.indexOf(column.label) != -1) {
        const _row = this.spanArr[rowIndex]
        const _col = _row > 0 ? 1 : 0
        return {
          rowspan: _row,
          colspan: _col
        }
      }
    },
    exportEasEntry(file) {
      let that = this
      that.entryIdList = []
      if (!file) {
        that.$message({
          message: '文件错误!',
          type: 'warning'
        })
        return
      }
      this.entryIdList = []
      var reader = new FileReader()
      var data = null
      var workbook = null
      //设置读取操作
      reader.onload = function(e) {
        data = e.target.result
        workbook = XLSX.read(data, {
          type: 'binary'
        })
        let rows = XLSX.utils.sheet_to_json(
          workbook.Sheets[workbook.SheetNames[0]]
        ) //只取第一页
        let arr = []
        Array.from(rows).forEach(e => {
          let map = {}
          Object.keys(e).forEach(e1 => {
            if (e1.includes('分录ID')) {
              map.entryId = e[e1]
              arr.push(map)
            }
          })
        })
        that.entryIdList = Array.from(
          new Set(
            arr.map(e => {
              return e.entryId
            })
          )
        )
        if (that.entryIdList.length > 0) {
          let obj = {}
          obj.entryIdList = that.entryIdList
          that.onclick(obj)
        }
      }
      reader.readAsBinaryString(file.raw) //以二进制方式读取
    },
    addSaleOrder() {
      this.getSaleDateOfReceipt()
      this.$confirm(
        `确定将所选${this.$refs.tableRef.selection.length}条分录重新上传金蝶?`,
        '提示',
        {
          cancelButtonText: '取消',
          confirmButtonText: '确定',
          center: true
        }
      )
        .then(() => {
          const loading = this.$loading({
            lock: true,
            text: '正在快马加鞭为您生成上传销售订单,请勿退出该界面',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.7)'
          })
          let closeEntryList = []
          this.$refs.tableRef.selection.forEach(e => {
            let map = {}
            if (
              typeof e.saleRemark.split(this.remarkDateOld)[1] === 'undefined'
            ) {
              e.saleRemark = `${this.remarkDateNew}${e.areaName},直发${e.addressDistrict}`
            } else {
              e.saleRemark =
                this.remarkDateNew + e.saleRemark.split(this.remarkDateOld)[1]
            }

            map.saleMaterialId = e.saleMaterialId
            map.closeEntryId = e.closeEntryId
            map.number = e.saleOrderNo
            closeEntryList.push(map)
          })
          const map1 = this.$refs.tableRef.selection.reduce((result, item) => {
            result[item.saleOrderNo] = result[item.saleOrderNo] || []
            result[item.saleOrderNo].push(item)
            return result
          }, {})
          let result = Object.values(map1)
          //遍历数组
          let saleOrderListMap = []
          result.forEach((saleOrderList, index) => {
            let map = {}
            let arr = []
            saleOrderList.forEach(e => {
              let mapMaterial = {}
              Object.keys(e).forEach(e1 => {
                if (this.saleOrderList.includes(e1)) {
                  map[e1] = e[e1]
                }
                if (this.saleOrderMapList.includes(e1)) {
                  mapMaterial[e1] = e[e1]
                }
              })
              mapMaterial.saleDateOfReceipt = sjTime(this.saleDateOfReceipt)
              arr.push(mapMaterial)
            })
            map.shipperId = 1
            map.mapList = arr
            map.isUploadEas = 1
            map.operator = getCookie('loginName')
            saleOrderListMap.push(map)
          })
          if (Promise.all && this.PromiseAllSettled) {
            const promiseAllSettled = this.PromiseAllSettled([
              this.axios.post(
                '/api/v1/ams/addUnloadSteelSaleOrderList',
                saleOrderListMap,
                {
                  timeout: 6 * 60 * 1000
                }
              ),
              this.axios.post('/api/v1/ams/closingEntries', closeEntryList, {
                timeout: 3 * 60 * 1000
              })
            ])
            const _this = this
            promiseAllSettled.then(function(res) {
              console.log(res, 'res')
              _this.getSteelReport()
              loading.close()
              if (
                res[0].status == 'fulfilled' &&
                res[1].status == 'fulfilled'
              ) {
                _this.$message({
                  type: 'success',
                  offset: '250',
                  message: '生成订单成功,关闭分录成功',
                  duration: 2000
                })
              } else if (
                res[0].status == 'rejected' &&
                res[1].status == 'fulfilled'
              ) {
                _this.$message({
                  type: 'error',
                  offset: '250',
                  message: '生成订单失败,关闭分录成功,请重新上传!',
                  duration: 2000
                })
              } else if (
                res[1].status == 'rejected' &&
                res[0].status == 'fulfilled'
              ) {
                _this.$message({
                  type: 'success',
                  offset: '250',
                  message: '生成订单成功,分录关闭失败',
                  duration: 2000
                })
              } else {
                _this.$message({
                  type: 'success',
                  offset: '250',
                  message: '生成订单失败,分录关闭失败',
                  duration: 2000
                })
              }
            })
          } else {
            this.axios
              .post(
                '/api/v1/ams/addUnloadSteelSaleOrderList',
                saleOrderListMap,
                {
                  timeout: 5 * 60 * 1000
                }
              )
              .then(res => {
                if (res.data.code == '200') {
                  this.axios
                    .post('/api/v1/ams/closingEntries', closeEntryList, {
                      timeout: 3 * 60 * 1000
                    })
                    .then(res => {
                      if (res.data.code == '200') {
                        this.getSteelReport()
                        loading.close()
                        this.$message({
                          type: 'success',
                          offset: '250',
                          message: '生成订单成功,关闭分录成功',
                          duration: 2000
                        })
                      }
                    })
                    .catch(e => {
                      loading.close()
                    })
                }
              })
              .catch(e => {
                loading.close()
              })
          }
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '取消操作',
            offset: '200'
          })
        })
    },
    PromiseAllSettled(promises = [], onlyResult) {
      return Promise.all(
        promises.map(
          onlyResult
            ? item => (item instanceof Promise ? item.catch(e => e) : item)
            : item =>
                item instanceof Promise
                  ? item
                      .then(value => ({ status: 'fulfilled', value }))
                      .catch(reason => ({ status: 'rejected', reason }))
                  : { status: 'fulfilled', value: item }
        )
      )
    },
    getRemarkDate() {
      let day = new Date().getDate()
      let month = new Date().getMonth() + 1
      console.log(day)
      if (day < 10) {
        day = '0' + day
      }
      return `${month}.${day}`
    },
    getRemarkDateOld() {
      let day = new Date(new Date().getTime() - 86400000).getDate()
      let month = new Date(new Date().getTime() - 86400000).getMonth() + 1
      if (day < 10) {
        day = '0' + day
      }
      return `${month}.${day}`
    },
    //继续装
    //筛选
    filterChange(obj) {
      if (typeof obj.carrierList != 'undefined' && obj.carrierList.length > 0) {
        this.filterMap.carrierList = obj.carrierList
      }
      if (
        typeof obj.carrierList != 'undefined' &&
        obj.carrierList.length == 0
      ) {
        delete this.filterMap.carrierList
      }
      if (
        typeof obj.materialNameList != 'undefined' &&
        obj.materialNameList.length > 0
      ) {
        this.filterMap.materialNameList = obj.materialNameList
      }
      if (
        typeof obj.materialNameList != 'undefined' &&
        obj.materialNameList.length == 0
      ) {
        delete this.filterMap.materialNameList
      }
      if (typeof obj.capacityNo != 'undefined' && obj.capacityNo.length > 0) {
        this.filterMap.capacityList = obj.capacityNo
      }
      if (typeof obj.capacityNo != 'undefined' && obj.capacityNo.length == 0) {
        delete this.filterMap.capacityList
      }
      if (
        typeof obj.consigneeName != 'undefined' &&
        obj.consigneeName.length > 0
      ) {
        this.filterMap.consigneeNameList = obj.consigneeName
      }
      if (
        typeof obj.consigneeName != 'undefined' &&
        obj.consigneeName.length == 0
      ) {
        delete this.filterMap.consigneeNameList
      }
      if (
        typeof obj.saleAreaList != 'undefined' &&
        obj.saleAreaList.length > 0
      ) {
        this.filterMap.saleAreaList = obj.saleAreaList
      }
      if (
        typeof obj.saleAreaList != 'undefined' &&
        obj.saleAreaList.length == 0
      ) {
        delete this.filterMap.saleAreaList
      }
      // if (obj)
      this.onclick(this.filterMap)
    },
    //控制筛选数组变化
    filterListChange() {
      let consigneeNameList = this.tableData.map(e => {
        return e.consigneeName
      })
      let carrierNameList = this.tableData.map(e => {
        return e.carrierName
      })
      let capacityList = this.tableData.map(e => {
        return e.capacityNo
      })
      let materialNameList = this.tableData
        .map(e => {
          return e.materialName
        })
        .filter(e => {
          return e != null
        })
      let saleAreaList = this.tableData
        .map(e => {
          return e.areaName
        })
        .filter(e => {
          return e != null
        })
      this.filterConsigneeList = []
      this.filterCarrierList = []
      this.filterCapacityList = []
      this.filtermaterialNameList = []
      this.filterSaleAreaList = []
      Array.from(new Set(consigneeNameList)).forEach(e => {
        let map = {}
        map.text = e
        map.value = e
        this.filterConsigneeList.push(map)
      })
      Array.from(new Set(carrierNameList)).forEach(e => {
        let map = {}
        map.text = e
        map.value = e
        this.filterCarrierList.push(map)
      })
      Array.from(new Set(capacityList)).forEach(e => {
        let map = {}
        map.text = e
        map.value = e
        this.filterCapacityList.push(map)
      })
      Array.from(new Set(materialNameList)).forEach(e => {
        let map = {}
        map.text = e
        map.value = e
        this.filtermaterialNameList.push(map)
      })
      Array.from(new Set(saleAreaList)).forEach(e => {
        let map = {}
        map.text = e
        map.value = e
        this.filterSaleAreaList.push(map)
      })
    },
    //筛选
    //筛选客户
    //点击操作弹出框
    //销售钢材报表导出excel
    exportAllReportToExcel() {
      const loading = this.$loading({
        lock: true,
        text: '正在导出Excel',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })
      var title = this.tableTitle
      let tHeader = []
      let filterVal = []
      this.$refs.tableRef.$children.forEach(item => {
        if (item.label != undefined && item.prop != undefined) {
          if (tHeader.indexOf(item.label) === -1) {
            tHeader.push(item.label)
          }
          if (filterVal.indexOf(item.prop) === -1) {
            filterVal.push(item.prop)
          }
        }
      })
      this.downloadLoading = true
      require.ensure([], () => {
        const {
          export_json_to_excel
        } = require('@/assets/excel/Export2Excel.js') //这里必须使用绝对路径，使用@/+存放export2Excel的路径
        let data = this.tableData.map(v => filterVal.map(j => v[j])) //3.formatJson格式转换
        export_json_to_excel(tHeader, data, title) // (title)导出的表格名称
      })
      loading.close()
    },
    changeScreen() {},
    //承运商弹出层
    //查询，输入查询条件
    onclick(obj) {
      this.isRowClick = 0
      const loading = this.$loading({
        lock: true,
        text: '正在获取数据',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })
      let startTime = null
      let endTime = null
      let carrierSsoId = null
      let carrierName = null
      let consigneeName = null
      let capacityNo = null
      let remark = null
      let saler = null
      let easPrimaryId = null
      if (this.startTime && this.endTime) {
        startTime = sjTime(this.startTime)
        endTime = sjTime(this.endTime)
      }
      if (getCookie('orgCode') == 'chengyunshang') {
        carrierSsoId = getCookie('userId')
      }
      if (getCookie('orgCode') == 'xiaoshouyewuyuan') {
        saler = getCookie('loginName')
      }
      if (this.screen == '客户') {
        consigneeName = this.input
      } else if (this.screen == '承运商') {
        carrierName = this.input
      } else if (this.screen == '车牌号') {
        capacityNo = this.input
      } else if (this.screen == '分录ID') {
        easPrimaryId = this.input
      } else {
        remark = this.input
      }
      if (this.screen1 == '客户') {
        consigneeName = this.input1
      } else if (this.screen1 == '承运商') {
        carrierName = this.input1
      } else if (this.screen1 == '车牌号') {
        capacityNo = this.input1
      } else {
        remark = this.input1
      }
      this.axios
        .post(
          '/api/v1/tms/loadingSaleSteelReport?startTime=' +
            startTime +
            '&endTime=' +
            endTime +
            '&carrierSsoId=' +
            carrierSsoId +
            '&i=' +
            new Date() +
            '&remark=' +
            remark +
            '&consigneeName=' +
            consigneeName +
            '&carrierName=' +
            carrierName +
            '&capacityNo=' +
            capacityNo +
            '&saler=' +
            saler +
            '&easPrimaryId=' +
            easPrimaryId,
          obj
        )
        .then(res => {
          this.tableData = res.data.data
          this.$nextTick(() => {
            this.$refs.tableRef.toggleAllSelection()
          })
          this.getSpanArr(res.data.data)
          loading.close()
        })
    },
    //重新获取表格数据
    refresh() {
      this.getSteelReport()
    },
    //获取钢材统计报表
    getSteelReport() {
      this.isRowClick = 0
      let startTime = null
      let endTime = null
      let carrierSsoId = null
      let carrierName = null
      let consigneeName = null
      let capacityNo = null
      let remark = null
      let saler = null
      if (this.startTime && this.endTime) {
        startTime = sjTime(this.startTime)
        endTime = sjTime(this.endTime)
      }
      if (getCookie('orgCode') == 'chengyunshang') {
        carrierSsoId = getCookie('userId')
      }
      if (getCookie('orgCode') == 'xiaoshouyewuyuan') {
        saler = getCookie('loginName')
      }
      if (this.screen == '客户') {
        consigneeName = this.input
      } else if (this.screen == '承运商') {
        carrierName = this.input
      } else if (this.screen == '车牌号') {
        capacityNo = this.input
      } else {
        remark = this.input
      }
      if (this.screen1 == '下单客户') {
        consigneeName = this.input1
      } else if (this.screen1 == '承运商') {
        carrierName = this.input1
      } else if (this.screen1 == '车牌号') {
        capacityNo = this.input1
      } else {
        remark = this.input1
      }
      if (getCookie('orgCode') == 'chengyunshang') {
        carrierSsoId = getCookie('userId')
      }
      if (getCookie('orgCode') == 'xiaoshouyewuyuan') {
        saler = getCookie('loginName')
      }
      this.axios
        .post(
          '/api/v1/tms/loadingSaleSteelReport?startTime=' +
            startTime +
            '&endTime=' +
            endTime +
            '&carrierSsoId=' +
            carrierSsoId +
            '&saler=' +
            saler +
            '&i=' +
            new Date() +
            '&remark=' +
            remark +
            '&consigneeName=' +
            consigneeName +
            '&carrierName=' +
            carrierName +
            '&capacityNo=' +
            capacityNo
        )
        .then(res => {
          this.tableData = res.data.data
          this.$nextTick(() => {
            this.$refs.tableRef.toggleAllSelection()
          })
          this.getSpanArr(res.data.data)
        })
    },
    updateSaleOrderRemark() {
      this.$confirm(
        `确定将所选${this.$refs.tableRef.selection.length}条分录重置上传限制?`,
        '提示',
        {
          cancelButtonText: '取消',
          confirmButtonText: '确定',
          center: true
        }
      )
        .then(() => {
          const loading = this.$loading({
            lock: true,
            text: '正在快马加鞭为您重置上传限制,请稍候',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.7)'
          })
          let map = {
            list: this.$refs.tableRef.selection
          }
          this.axios
            .post('/api/v1/ams/updateSaleOrderRemark', map, {
              timeout: 5 * 60 * 1000
            })
            .then(res => {
              if (res.data.code == '200') {
                this.$message({
                  type: 'success',
                  message: '重置成功',
                  offset: '200',
                  duration: 2000
                })
                loading.close()
              }
            })
            .catch(e => {
              loading.close()
            })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '取消操作',
            offset: '200'
          })
        })
    }
  }
}
</script>

<style lang="scss" scoped>
.purchasFuelNewMonitor {
  .tableTop {
    margin-left: 20px;
    margin-top: 20px;
  }
  .table {
    margin-left: 20px;
    margin-top: 20px;
    .el-tooltip {
      width: auto !important;
    }
    ::-webkit-scrollbar {
      // width: 20px;
      height: 20px;
      background-color: transparent;
    }
  }
  .dialog {
    .steelMapClass {
      .steelMapClass1 {
        display: flex;
        flex-direction: row;
        justify-content: flex-start;
        align-items: flex-start;
        font-size: 16px;
        .steelMapClass12 {
          margin-left: 50px;
          margin-right: 10px;
        }
      }
      .steelMapClass2 {
        margin-top: 20px;
        display: flex;
        flex-direction: row;
        justify-content: flex-start;
        align-items: flex-start;
        font-size: 16px;
        .steelMapClass22 {
          margin-left: 50px;
          margin-right: 10px;
          .el-select {
            .el-input .el-input--suffix {
              .el-input__inner {
                border: 0px solid !important;
              }
            }
          }
        }
      }
      .steelMapClass3 {
        margin-top: 20px;
        display: flex;
        flex-direction: row;
        justify-content: flex-start;
        align-items: flex-start;
        font-size: 16px;
        .steelMapClass32 {
          margin-left: 50px;
          // margin-right: 10px;
        }
        .steelMapClass33 {
          margin-left: 20px;
          // margin-right: 10px;
        }
      }
      .steelMapClass4 {
        margin-top: 20px;
        display: flex;
        flex-direction: row;
        justify-content: flex-start;
        align-items: flex-start;
        font-size: 16px;

        .steelMapClass42 {
          margin-left: 50px;
          margin-right: 10px;
        }
        .steelMapClass43 {
          margin-left: 50px;
          margin-right: 10px;
        }
        .steelMapClass44 {
          margin-left: 50px;
          margin-right: 10px;
        }
      }
      .steelMapClass5 {
        margin-top: 20px;
        display: flex;
        flex-direction: row;
        justify-content: flex-start;
        align-items: flex-start;
        font-size: 16px;

        .steelMapClass52 {
          margin-left: 50px;
          margin-right: 10px;
          .steelMapClass521 {
            margin-left: 20px;
          }
        }
      }
      .steelMapClass6 {
        margin-top: 20px;
        display: flex;
        flex-direction: row;
        justify-content: flex-start;
        align-items: flex-start;
        font-size: 16px;
        .steelMapClass62 {
          margin-left: 50px;
          margin-right: 10px;
        }
      }
    }
  }
  .address {
    .button-box {
      display: flex;
      justify-content: center;
      align-items: center;
    }
  }
}
</style>
