<template>
  <div class="app-container">
    <!-- Start 列表页面 -->
    <div v-show="viewState == 1">
      <button-bar view-title="待核对单车返利列表" ref="btnbar" :btndisabled="btndisabled" @btnhandle="btnHandle"/>
      <div class="main-content">
        <div class="switch_btn">
          <el-button :class="{btn_style:viewState === 1}">待核对</el-button>
          <el-button class="" @click="handleClick">核对审核申请</el-button>
        </div>
        <div class="searchcon">
          <el-button size="small" class="searchbtn" @click="clicksearchShow">{{ searchxianshitit }}</el-button>
          <div v-show="isSearchShow" class="search">
            <el-form ref="listQueryform" :inline="true" :model="listQuery" label-width="100px" class="tab-header">
              <el-form-item label="品牌">
                <el-select v-model="listQuery.params.brandSid" placeholder="请选择" filterable clearable>
                  <el-option v-for="item in brand_list" :key="item.sid" :label="item.brandName" :value="item.sid"/>
                </el-select>
              </el-form-item>
              <el-form-item label="车架号">
                <el-input v-model="listQuery.params.vinNo" placeholder="" clearable/>
              </el-form-item>
              <el-form-item label="创建日期">
                <el-date-picker v-model="listQuery.params.createStartTime" type="date" clearable value-format="yyyy-MM-dd" placeholder="选择日期"/>
                <span style="padding: 0 8px">至</span>
                <el-date-picker v-model="listQuery.params.createEndTime" type="date" clearable value-format="yyyy-MM-dd" placeholder="选择日期"/>
              </el-form-item>
              <el-form-item label="返利类型">
                <el-select v-model="listQuery.params.rebateTypeKey" placeholder="请选择" filterable clearable>
                  <el-option v-for="item in rebateType_list" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey"/>
                </el-select>
              </el-form-item>
              <el-form-item label="返利名称">
                <el-input v-model="listQuery.params.rebateName" placeholder="" clearable/>
              </el-form-item>
              <el-form-item label="调整状态">
                <el-select v-model="listQuery.params.adjustmentState" placeholder="请选择" filterable clearable>
                  <el-option v-for="item in state_list" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey"/>
                </el-select>
              </el-form-item>
            </el-form>
            <div class="btn" style="text-align: center;">
              <el-button type="primary" icon="el-icon-search" @click="handleFilter" size="small">查询</el-button>
              <el-button type="primary" icon="el-icon-refresh" @click="handleReset" size="small">重置</el-button>
            </div>
          </div>
        </div>
        <div class="listtop">
          <div class="tit">单车返利待核对列表</div>
          <div>
            <el-button size="mini" type="success" @click="exportByFirst">一次导出</el-button>
            <el-button size="mini" type="success" @click="importByFirst">一次导入</el-button>
            <el-button size="mini" type="success" @click="exportBySecond">二次导出</el-button>
            <el-button size="mini" type="success" @click="importBySecond">二次导入</el-button>
          </div>
        </div>
        <div class="">
          <el-table :key="tableKey" v-loading="listLoading" :data="list" border style="width: 100%;" @selection-change="handleSelectionChange">
            <el-table-column fixed type="selection" align="center" width="50px"/>
            <el-table-column fixed label="序号" type="index" :index="indexMethod" align="center" width="80px"/>
            <el-table-column label="上传状态" align="center" width="120">
              <template slot-scope="scope">
                <span>{{ scope.row.uploadState == '0' ? '未上传' : scope.row.uploadState == '1' ? '已上传' : ''}}</span>
              </template>
            </el-table-column>
            <el-table-column label="一次核对状态" align="center" width="120">
              <template slot-scope="scope">
                <span>{{ scope.row.onceCheckState == '0' ? '否' : scope.row.onceCheckState == '1' ? '是' : scope.row.onceCheckState == '2' ? '一次核对中' : '' }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="brandName" label="品牌" align="center" width="120" />
            <el-table-column prop="vehModelName" label="车型" align="center" min-width="200" />
            <el-table-column prop="vinNo" label="车架号" align="center" width="150" />
            <el-table-column prop="manufactorSettlementPrice" label="厂家结算价" align="center" width="140" />
            <el-table-column prop="freight" label="其中运费" align="center" width="120" />
            <el-table-column prop="createTime" label="创建日期" align="center" width="120" />
            <el-table-column prop="rebateName" label="返利名称" align="center" min-width="150" />
            <el-table-column prop="rebateTypeValue" label="返利类型" align="center" width="120" />
            <el-table-column prop="estimateRebate" label="预计返利" align="center" width="120" />
            <el-table-column prop="withholdCost" label="其中预提费用" align="center" width="140" />
            <el-table-column prop="palceGenDate" label="所属年月" align="center" width="120" />
            <el-table-column prop="uploadDate" label="上传日期" align="center" width="120" />
            <el-table-column prop="uploadMoney" label="上传金额" align="center" width="120" />
            <el-table-column prop="secondaryUploadDate" label="二次上传日期" align="center" width="140" />
            <el-table-column prop="secondaryUploadMoney" label="二次上传金额" align="center" width="140" />
            <el-table-column prop="stayDetermineMoney" label="待确定金额" align="center" width="130" />
            <el-table-column prop="money" label="费用" align="center" width="120" />
            <el-table-column prop="diffAmount" label="差异金额" align="center" width="120" />
            <el-table-column prop="isAdjustment" label="是否调整" align="center" width="120" />
            <el-table-column prop="adjustmentMoney" label="调整金额" align="center" width="120" />
            <el-table-column prop="adjustmentRemarks" label="调整说明" align="center" min-width="300" />
            <el-table-column label="操作" align="center" width="180px">
              <template slot-scope="scope">
                <el-button type="primary" v-if="scope.row.onceCheckState == '0'" size="mini" @click="toSave(scope.row)">修改</el-button>
                <el-button type="primary" v-else size="mini" @click="toAdjust(scope.row)">调整</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="pages">
          <!-- 翻页 -->
          <pagination v-show="list.length > 0" :total="listQuery.total" :page.sync="listQuery.current" :limit.sync="listQuery.size" class="pagination" @pagination="getList"/>
        </div>
      </div>
    </div>
    <!-- 核对审核申请分页列表 -->
    <bicyclerebatecheck v-show="viewState == 2" ref="divCheck" @doback="resetState" />
    <!-- 新增核对审核申请 -->
    <bicyclerebatecheckAdd v-show="viewState == 3" ref="divCheckAdd" @doback="resetState" @reloadlist="getList" />
    <!-- 新增核对审核申请 -->
    <bicyclerebatetobecheckedByUpdate v-show="viewState == 4" ref="divCheckEdit" @doback="resetState" @reloadlist="getList" />
    <!-- 二次调整页面 -->
    <el-dialog center :visible.sync="dialogVisible" width="80%">
      <div class="app-container">
        <div class="tab-header webtop">
          <!--标题-->
          <div>{{ viewTitle }}</div>
          <!--start 添加修改按钮-->
          <div>
            <el-button type="primary" size="small" :disabled="submitdisabled" @click="handleSave()">确定</el-button>
            <el-button type="info" size="small" @click="handleReturn()">关闭</el-button>
          </div>
        </div>
        <el-form title="返利调整" ref="form_obj" :model="formobj" :rules="rules" class="formaddcopy02">
          <div class="title">待确定金额分配</div>
          <el-row style="border-top: 1px solid #E0E3EB">
            <el-col :span="24">
              <div class="span-sty">待确定金额</div>
              <el-form-item><span class="addinputInfo">{{ formobj.stayDetermineMoneyNew }}</span></el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <div class="span-sty">其中待支付费用</div>
              <el-form-item><el-input class="addinputInfo addinputw" v-model="formobj.onceTreatCost" @keyup.native="formobj.onceTreatCost = getNumber(formobj.onceTreatCost, 2)" @input="firstCostInput" clearable placeholder=""/></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">其中抵顶费用</div>
              <el-form-item><el-input class="addinputInfo addinputw" v-model="formobj.onceSuppCost" @keyup.native="formobj.onceSuppCost = getNumber(formobj.onceSuppCost, 2)" @input="firstCostInput" clearable placeholder=""/></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">其中含返利</div>
              <el-form-item><span class="addinputInfo">{{ formobj.firstRebate }}</span></el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <div class="span-sty">抵顶费用说明</div>
              <el-form-item><el-input class="addinputInfo addinputw" v-model="formobj.onceSuppRemark" clearable placeholder=""/></el-form-item>
            </el-col>
          </el-row>
          <div class="title">
            <el-checkbox disabled v-model="checked"><span style="color: #FFFFFF">返利二次上传</span></el-checkbox>
          </div>
          <el-row>
            <el-col :span="8">
              <div class="span-sty">二次上传日期</div>
              <el-form-item><el-date-picker class="addinputInfo addinputw" v-model="formobj.secondaryUploadDate" type="date" clearable value-format="yyyy-MM-dd" placeholder="选择日期" /></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">二次上传金额</div>
              <el-form-item><el-input class="addinputInfo addinputw" v-model="formobj.secondaryUploadMoney" @keyup.native="formobj.secondaryUploadMoney = getNumber(formobj.secondaryUploadMoney, 2)" @input="secondCostInput" clearable placeholder=""/></el-form-item>
            </el-col>
            <el-col :span="8">
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <div class="span-sty">其中待支付费用</div>
              <el-form-item><el-input class="addinputInfo addinputw" v-model="formobj.secondTreatCost" @keyup.native="formobj.secondTreatCost = getNumber(formobj.secondTreatCost, 2)" @input="secondCostInput" clearable placeholder=""/></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">其中抵顶费用</div>
              <el-form-item><el-input class="addinputInfo addinputw" v-model="formobj.secondSuppCost" @keyup.native="formobj.secondSuppCost = getNumber(formobj.secondSuppCost, 2)" @input="secondCostInput" clearable placeholder=""/></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">其中含返利</div>
              <el-form-item><span class="addinputInfo">{{ formobj.secondRebate }}</span></el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <div class="span-sty">抵顶费用说明</div>
              <el-form-item><el-input class="addinputInfo addinputw" v-model="formobj.secondSuppRemark" clearable placeholder=""/></el-form-item>
            </el-col>
          </el-row>
          <div class="title">调整说明</div>
          <el-row>
            <el-col :span="8">
              <div class="span-sty">剩余预计返利</div>
              <el-form-item><span class="addinputInfo">{{ formobj.surplusRebate }}</span></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">调整金额合计</div>
              <el-form-item><span class="addinputInfo">{{ formobj.adjustmentMoney }}</span></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">调整说明</div>
              <el-form-item><el-input class="addinputInfo addinputw" v-model="formobj.adjustmentRemarks" clearable placeholder="" /></el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
    </el-dialog>
    <!-- 导入、导出 -->
    <el-dialog :visible.sync="dialogFileVisible" width="70%" :show-close="false">
      <el-card class="box-card">
        <div>
          <el-upload
            ref="upload"
            class="upload-demo"
            accept=".xls"
            name="file"
            :action="updateAction"
            :on-success="handleSuccess"
            :on-remove="handleRemove"
            :file-list="fileList"
            :auto-upload="false"
            :multiple="false"
            :limit="1"
            :data="uploadData"
            :headers="headers"
          >
            <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
            <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上传</el-button>
          </el-upload>
        </div>
        <div>
          <h3>文件上传结果</h3>
          <el-card class="box-card">
            <div>{{ uploadResultMesssage }}</div>
          </el-card>
        </div>
      </el-card>
      <div slot="footer" class="dialog-footer" style="text-align: center">
        <el-button type="primary" size="small" @click="handleConfirm">确定</el-button>
        <el-button size="small" @click="dialogFileVisible = false">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import req from '@/api/bikerebate/bicyclerebatecheck'
import bicyclerebatemanagement from '@/api/bikerebate/bicyclerebatemanagement'
import Pagination from '@/components/pagination'
import ButtonBar from '@/components/ButtonBar'
import bicyclerebatecheck from './bicyclerebatecheck'
import bicyclerebatecheckAdd from './bicyclerebatecheckAdd'
import bicyclerebatetobecheckedByUpdate from './bicyclerebatetobecheckedByUpdate'
import { brandDown, getOrgSidByPath, typeValues } from '@/api/cheliang/dictcommons'

export default {
  name: 'BicycleRebateToBeChecked',
  components: {
    Pagination,
    ButtonBar,
    bicyclerebatecheck,
    bicyclerebatecheckAdd,
    bicyclerebatetobecheckedByUpdate
  },
  data() {
    return {
      btndisabled: false,
      dialogVisible: false,
      btnList: [
        {
          type: 'primary',
          size: 'small',
          icon: '',
          btnKey: 'toAdd',
          btnLabel: '核对审核申请'
        },
        {
          type: 'info',
          size: 'small',
          icon: 'cross',
          btnKey: 'doClose',
          btnLabel: '关闭'
        }
      ],
      isSearchShow: false,
      searchxianshitit: '显示查询条件',
      viewState: 1,
      // 查询条件 -----------
      tableKey: 0,
      list: [],
      sids: [],
      FormLoading: false,
      brand_list: [],
      rebateType_list: [],
      state_list: [
        {
          dictKey: '0',
          dictValue: '否'
        },
        {
          dictKey: '1',
          dictValue: '是'
        }
      ],
      listLoading: false,
      listQuery: {
        params: {
          brandSid: '',
          createOrgSid: '',
          vinNo: '',
          rebateTypeKey: '',
          rebateName: '',
          state: '',
          createEndTime: '',
          createStartTime: '',
          orgPath: '',
          userSid: '',
          menuUrl: ''
        },
        current: 1,
        size: 5,
        total: 0
      },
      rules: {},
      viewTitle: '返利调整',
      submitdisabled: false,
      checked: true,
      formobj: {
        sid: '',
        stayDetermineMoneyNew: '',
        onceTreatCost: '',
        onceSuppCost: '',
        firstRebate: '',
        onceSuppRemark: '',
        surplusRebate: '',
        secondaryUploadDate: '',
        secondaryUploadMoney: '',
        secondTreatCost: '',
        secondSuppCost: '',
        secondRebate: '',
        secondSuppRemark: '',
        adjustmentMoney: '',
        adjustmentRemarks: ''
      },
      dialogFileVisible: false,
      updateAction: '',
      fileList: [],
      uploadResultMesssage: '',
      uploadData: {
        sid: '',
        userSid: '',
        orgPath: ''
      },
      headers: {
        token: window.sessionStorage.getItem('token')
      }
    }
  },
  created() {
    // 加载列表
    this.init()
  },
  mounted() {
    this.$refs['btnbar'].setButtonList(this.btnList)
  },
  methods: {
    init() {
      typeValues({ type: 'rebateType' }).then((res) => {
        if (res.success) {
          this.rebateType_list = res.data
        }
      })
      getOrgSidByPath({ orgPath: window.sessionStorage.getItem('defaultOrgPath') }).then((resp) => {
        if (resp.success) {
          this.listQuery.params.createOrgSid = resp.data
          brandDown({ useOrg: this.listQuery.params.createOrgSid }).then((res) => {
            if (res.success) {
              this.brand_list = res.data
            }
          })
          this.getList()
        }
      })
    },
    // 搜索条件效果
    clicksearchShow() {
      this.isSearchShow = !this.isSearchShow
      if (this.isSearchShow) {
        this.searchxianshitit = '隐藏查询条件'
      } else {
        this.searchxianshitit = '显示查询条件'
      }
    },
    btnHandle(btnKey) {
      console.log('XXXXXXXXXXXXXXX    ' + btnKey)
      switch (btnKey) {
        case 'toAdd':
          this.toAdd()
          break
        case 'doClose':
          this.doClose()
          break
        default:
          break
      }
    },
    // 序号
    indexMethod(index) {
      var pagestart = (this.listQuery.current - 1) * this.listQuery.size
      var pageindex = index + 1 + pagestart
      return pageindex
    },
    handleSelectionChange(row) {
      const aa = []
      row.forEach((element) => {
        aa.push(element.sid)
      })
      this.sids = aa
      console.log('sids', this.sids)
    },
    // 查询列表信息
    getList() {
      this.listLoading = true
      this.listQuery.params.userSid = window.sessionStorage.getItem('userSid')
      this.listQuery.params.orgPath = window.sessionStorage.getItem('defaultOrgPath')
      this.listQuery.params.menuUrl = this.$route.path
      req.listPage(this.listQuery).then((response) => {
        console.log('列表查询结果：', response)
        this.listLoading = false
        if (response.success) {
          this.list = response.data.records
          this.listQuery.total = response.data.total
        } else {
          this.list = []
          this.listQuery.total = 0
        }
      })
    },
    // 查询按钮
    handleFilter() {
      this.listQuery.current = 1
      this.getList()
    },
    handleReset() {
      this.listQuery = {
        params: {
          brandSid: '',
          createOrgSid: '',
          vinNo: '',
          rebateTypeKey: '',
          rebateName: '',
          state: '',
          createEndTime: '',
          createStartTime: '',
          orgPath: '',
          userSid: '',
          menuUrl: ''
        },
        current: 1,
        size: 5,
        total: 0
      }
      this.getList()
    },
    getNumber(val, limit) {
      val = val.replace(/[^0-9.]/g, '') // 保留数字
      val = val.replace(/^00/, '0.') // 开头不能有两个0
      val = val.replace(/^\./g, '0.') // 开头为小数点转换为0.
      val = val.replace(/\.{2,}/g, '.') // 两个以上的小数点转换成一个
      val = val.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.'); // 只保留一个小数点
      /^0\d+/.test(val) ? val = val.slice(1) : '' // 两位以上数字开头不能为0
      const str = '^(\\d+)\\.(\\d{' + limit + '}).*$'
      const reg = new RegExp(str)
      if (limit === 0) {
        // 不需要小数点
        val = val.replace(reg, '$1')
      } else {
        // 通过正则保留小数点后指定的位数
        val = val.replace(reg, '$1.$2')
      }
      return val
    },
    handleClick() {
      this.viewState = 2
      this.$refs['divCheck'].init()
    },
    // 新增核对审核申请
    toAdd() {
      this.viewState = 3
      this.$refs['divCheckAdd'].showAdd(this.listQuery.params.createOrgSid)
    },
    // 保存
    toSave(row) {
      this.viewState = 4
      this.$refs['divCheckEdit'].showInfo(row)
    },
    // 二次调整
    toAdjust(row) {
      bicyclerebatemanagement.fetchBySid(row.sid).then((resp) => {
        if (resp.success) {
          this.dialogVisible = true
          this.formobj = resp.data
          this.firstCostInput()
          this.secondCostInput()
          this.adjustmentMoneyAdd()
        }
      })
    },
    // 二次调整页面--待确定金额模块
    firstCostInput() {
      // 其中含返利 = 待确定金额 - 其中待支付费用 - 其中抵顶费用
      this.formobj.firstRebate = Math.round((parseFloat(this.formobj.stayDetermineMoneyNew !== '' ? this.formobj.stayDetermineMoneyNew : 0) - parseFloat(this.formobj.onceTreatCost !== '' ? this.formobj.onceTreatCost : 0) - parseFloat(this.formobj.onceSuppCost !== '' ? this.formobj.onceSuppCost : 0)) * 100) / 100
      this.adjustmentMoneyAdd()
    },
    // 二次调整页面--返利二次上传模块
    secondCostInput() {
      // 二次上传金额 > 0 时，返利二次上传为勾选状态
      if (parseFloat(this.formobj.secondaryUploadMoney) > 0) {
        this.checked = true
      } else {
        this.checked = false
      }
      // 其中含返利 = 二次上传金额 - 其中待支付费用 - 其中抵顶费用
      this.formobj.secondRebate = Math.round((parseFloat(this.formobj.secondaryUploadMoney !== '' ? this.formobj.secondaryUploadMoney : 0) - parseFloat(this.formobj.secondTreatCost !== '' ? this.formobj.secondTreatCost : 0) - parseFloat(this.formobj.secondSuppCost !== '' ? this.formobj.secondSuppCost : 0)) * 100) / 100
      this.adjustmentMoneyAdd()
    },
    // 二次调整页面--调整说明模块
    adjustmentMoneyAdd() {
      // 剩余预计返利 = 列表预提返利-其中预提费用-一次上传返利金额(列表一次上传金额-一次费用-待确定）
      this.formobj.surplusRebate = Math.round((parseFloat(this.formobj.estimateRebate !== '' ? this.formobj.estimateRebate : 0) - parseFloat(this.formobj.withholdCost !== '' ? this.formobj.withholdCost : 0) - (parseFloat(this.formobj.uploadMoney !== '' ? this.formobj.uploadMoney : 0) - parseFloat(this.formobj.onceTreatCost !== '' ? this.formobj.onceTreatCost : 0) - parseFloat(this.formobj.onceSuppCost !== '' ? this.formobj.onceSuppCost : 0) - parseFloat(this.formobj.stayDetermineMoneyNew !== '' ? this.formobj.stayDetermineMoneyNew : 0))) * 100) / 100
      // 调整金额合计 = 其中含返利之和 - 剩余预提返利
      this.formobj.adjustmentMoney = Math.round((parseFloat(this.formobj.firstRebate !== '' ? this.formobj.firstRebate : 0) + parseFloat(this.formobj.secondRebate !== '' ? this.formobj.secondRebate : 0) - parseFloat(this.formobj.surplusRebate !== '' ? this.formobj.surplusRebate : 0)) * 100) / 100
    },
    handleSave() {
      if (parseFloat(this.formobj.firstRebate) < 0) {
        this.$message({ showClose: true, type: 'error', message: '待确定金额分配模块其中含返利为负数，请检查所填写相关费用是否正确' })
        return
      }
      if (parseFloat(this.formobj.secondRebate) < 0) {
        this.$message({ showClose: true, type: 'error', message: '返利二次上传模块其中含返利为负数，请检查所填写相关费用是否正确' })
        return
      }
      req.adjustment(this.formobj).then((resp) => {
        if (resp.success) {
          this.$message({ showClose: true, type: 'success', message: '保存成功' })
          this.getList()
          this.handleReturn()
        }
      })
    },
    handleReturn() {
      this.dialogVisible = false
      this.formobj = {
        sid: '',
        stayDetermineMoneyNew: '',
        onceTreatCost: '',
        onceSuppCost: '',
        firstRebate: '',
        onceSuppRemark: '',
        surplusRebate: '',
        secondaryUploadDate: '',
        secondaryUploadMoney: '',
        secondTreatCost: '',
        secondSuppCost: '',
        secondRebate: '',
        secondSuppRemark: '',
        adjustmentMoney: '',
        adjustmentRemarks: ''
      }
      this.checked = true
    },
    resetState() {
      this.viewState = 1
    },
    doClose() {
      this.$store.dispatch('tagsView/delView', this.$route)
      this.$router.go(-1)
    },
    exportByFirst() {
      const loading = this.$loading({
        lock: true,
        text: 'Loading',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })
      req.excelListOne(this.listQuery.params).then((resp) => {
        loading.close()
        const blob = new Blob([resp], {
          type: 'application/vnd.ms-excel'
        })
        const fileName = '一次导入模版' + '.xls'
        const elink = document.createElement('a')
        elink.download = fileName
        elink.style.display = 'nonde'
        elink.href = URL.createObjectURL(blob)
        document.body.appendChild(elink)
        elink.click()
        URL.revokeObjectURL(elink.href)
        document.body.removeChild(elink)
      }).catch(() => {
        loading.close()
      })
    },
    importByFirst() {
      this.dialogFileVisible = true
      this.updateAction = process.env.VUE_APP_BASE_API + '/scm/v1/scmvehrebate/getExcelOneInfo'
      this.fileList = []
      this.uploadResultMesssage = ''
    },
    exportBySecond() {
      const loading = this.$loading({
        lock: true,
        text: 'Loading',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })
      req.excelListTwo(this.listQuery.params).then((resp) => {
        loading.close()
        const blob = new Blob([resp], {
          type: 'application/vnd.ms-excel'
        })
        const fileName = '二次导入模版' + '.xls'
        const elink = document.createElement('a')
        elink.download = fileName
        elink.style.display = 'nonde'
        elink.href = URL.createObjectURL(blob)
        document.body.appendChild(elink)
        elink.click()
        URL.revokeObjectURL(elink.href)
        document.body.removeChild(elink)
      }).catch(() => {
        loading.close()
      })
    },
    importBySecond() {
      this.dialogFileVisible = true
      this.updateAction = process.env.VUE_APP_BASE_API + '/scm/v1/scmvehrebate/getExcelTwoInfo'
      this.fileList = []
      this.uploadResultMesssage = ''
    },
    handleRemove() {
      this.uploadResultMesssage = ''
    },
    submitUpload() {
      this.uploadData.userSid = window.sessionStorage.getItem('userSid')
      this.uploadData.orgPath = window.sessionStorage.getItem('defaultOrgPath')
      this.$refs.upload.submit()
    },
    handleSuccess(resp, file, fileList) {
      const _this = this
      if (resp.success) {
        _this.uploadResultMesssage = resp.msg
      } else {
        _this.uploadResultMesssage = resp.msg
      }
    },
    handleConfirm() {
      if (this.uploadResultMesssage === '') {
        this.$message({ showClose: true, type: 'error', message: '请先上传单车返利模版' })
        return
      } else {
        this.dialogFileVisible = false
        this.updateAction = ''
        this.uploadData.userSid = ''
        this.uploadData.orgPath = ''
        this.getList()
      }
    }
  }
}
</script>
<style scoped>
.switch_btn {
  padding: 15px 0 10px 0;
}
.btn_style {
  background-color: #018ad2;
  color: white;
  font-weight: 600;
}
.span-sty {
  width: 130px !important;
}
.addinputInfo {
  margin-left: 120px !important;
}
.formaddcopy02 .el-row .el-col /deep/ .el-form-item .addinputw {
  margin-left: 120px !important;
  width: calc(100% - 115px);
}
</style>
