<!--
 * @Author: ysh
 * @Date: 2025-01-08 15:53:45
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2025-01-09 13:58:07
-->
<template>
  <div>
    <el-upload ref="uploadSettleRef" :action="uploadFileUrl" class="upload-demo" drag :limit="1" :headers="headers"
      :auto-upload="false" :on-success="handleSuccess">
      <i class="el-icon-upload"></i>
      <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
      <div class="el-upload__tip" slot="tip">
        <div class="el-upload__tip text-center">
          <span>批量导入项目完成工作量，若无模板，请先</span>
          <el-link style="font-size:12px;;vertical-align: baseline;" type="primary" @click="downTemplate">下载模板</el-link>
        </div>
      </div>
    </el-upload>
    <div class="text-center mt20">
      <el-button type="primary" @click="submitUpload">确 定</el-button>
      <el-button @click="$emit('cancel')">取 消</el-button>
    </div>
  </div>
</template>

<script>
import { uploadSettleSheet } from "@/api/oa/settle/settle"
import { getPrice, getPriceRemarkByWorkType } from "@/api/oa/price/price";
import { getToken } from "@/utils/auth";

export default {
  data() {
    return {
      baseUrl: process.env.VUE_APP_BASE_API,
      uploadFileUrl: process.env.VUE_APP_BASE_API + "/oa/settle/uploadSheet", // 上传文件服务器地址
      headers: {
        Authorization: "Bearer " + getToken(),
      },
    }
  },
  methods: {
    async handleSuccess(response) {
      if (response.code == 200) {
        let list = response.data
        const traList = list.map(item => ({
          ...item,
          coefficient: Number(item.coefficient),
          groundType: item.groundType == '一般地类' ? '0' : '1',
          priceId: Number(item.priceId),
          workload: Number(item.workload),
        }));
        for (let i of traList) {
          let res = await getPrice(i.priceId);
          i.scale = res.data.scaleGrade;
          i.unit = res.data.unit;
          i.price = i.groundType == '1' ? res.data.commonPrice : res.data.complexPrice;
          
        }
        this.$emit('getDataList', traList)
      }
    },
    submitUpload() {
      this.$refs['uploadSettleRef'].submit();
    },
    downTemplate(){
      window.location.href = `${this.baseUrl}${'/profile/upload/项目结算/cmc项目结算导入模板.xlsx'}`
    }
  },
}
</script>

<style lang="scss" scoped></style>