<template>
  <div class="project-cost-ledger-container">
    <div class="project-cost-ledger-inner" v-if="!isupload">
      <div class="title_wrap">
        <div class="enterprise_title">
          项目成本台账
        </div>
      </div>
      <div class="content-project">
        <el-form :model="formdata" label-width="82px" label-position="right"  :inline="true" >
          <el-row>
            <el-form-item label="工程名称">
              <el-input v-model="formdata.customerName" placeholder="请输入工程名称" clearable></el-input>
            </el-form-item>
            <el-form-item label="IPM项目编码" label-width="100px">
              <el-input v-model="formdata.customerName" placeholder="请输入IPM项目编码" clearable></el-input>
            </el-form-item>
            <el-form-item label="成本阶段">
              <el-select v-model="formdata.customerClass" multiple placeholder="请选择" :collapse-tags="true" clearable>
                  <el-option v-for="(item,index) in cbStagelist" :label="item.dictLabel" :value="item.dictValue" :key="index"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="项目状态">
              <el-select v-model="formdata.customerClass" multiple placeholder="请选择" :collapse-tags="true" clearable>
                  <el-option v-for="(item,index) in ztStagelist" :label="item.dictLabel" :value="item.dictValue" :key="index"></el-option>
              </el-select>
            </el-form-item>
          </el-row>
          <el-divider></el-divider>
          <el-form-item label="  ">
            <el-button type="primary" size="small" @click="getSearch">查询</el-button>
            <el-button size="small" @click="clears">重置</el-button>
          </el-form-item>
        </el-form>
      </div>

      <div class="table-project">
        <div class="table-item-jf1" v-if="total == 0 && !isSkeleton">
          <img class="item-jf-img" src="@/assets/images/kong.png" alt="">
          <div class="item-jf-titel">暂无数据，点击按钮导入项目成本数据</div>
          <el-button type="primary" class="jf-btn" size="small" @click="addPro">新增项目</el-button>
        </div>
        <skeleton v-if="isSkeleton"></skeleton>
        <div style='padding: 16px' v-if="!isSkeleton&&total>0">
          <div class="total-title">
            <div class="totals">共{{total}}条</div>
            <div class="btns">
              <div class="btn btn_primary h32" @click="addPro">导入项目</div>
              <div class="btn btn_default h32" @click="getcgx">草稿箱 ({{cgxtotal}})</div>
            </div>
          </div>
          <div class="table-item-jf table-item">
            <el-table :data="tableData" :header-cell-style="{ background:'#f0f3fa',color: 'rgba(35,35,35,0.8)'}"
                      v-sticky-header.always="{offsetTop : '-16px',offsetBottom : '10px'}" class="table-item1 fixed-table" border highlight-current-row
                      :header-row-class-name="setHeaderRow" :cell-class-name="setCellClass" :row-class-name="setRowClass" :header-cell-class-name="setCellClass"
                      ref="theOwnerListTable" :row-key="'customerKey'">

              <el-table-column type="index" label="序号" width="60" :resizable="false">
                <template slot-scope="scope">
                  <span>{{(formdata.pageNum - 1) *formdata.pageSize + scope.$index + 1}}</span>
                </template>
              </el-table-column>

              <el-table-column label="工程名称" width="416" :resizable="false">
                <template slot-scope="scope">
                  <div style="display:flex;align-items:center">
                    <el-tooltip placement="top" v-if="scope.row.customerText.length>20">
                      <div slot="content">{{scope.row.customerText}}</div>
                      <div class="renling">
                        <router-link v-if="scope.row.companyId" :to="`/enterprise/${encodeStr(scope.row.companyId)}?path=cooperationRecord&companyName=${scope.row.customerName}`" tag="a"
                                     class="wordprimary" v-html="scope.row.customerName"></router-link>
                        <span v-else v-html="scope.row.customerName"></span>
                      </div>
                    </el-tooltip>
                    <div class="renling" v-else>
                      <router-link v-if="scope.row.companyId" :to="`/enterprise/${encodeStr(scope.row.companyId)}?path=cooperationRecord&companyName=${scope.row.customerName}`" tag="a"
                                   class="wordprimary" v-html="scope.row.customerName"></router-link>
                      <span v-else v-html="scope.row.customerName"></span>
                    </div>
                  </div>

                </template>

              </el-table-column>
              <el-table-column label="项目状态" prop="customerCode"  width="90" :resizable="false">
              </el-table-column>

              <el-table-column label="IPM项目编码" min-width="136">
                <template slot-scope="scope">
                  {{scope.row.recommendOrg||"--"}}
                </template>
              </el-table-column>
              <el-table-column label="文件名称" min-width="286" :resizable="false">
                <template slot-scope="scope">
                  {{scope.row.registerRegion||"--"}}
                </template>
              </el-table-column>
              <el-table-column label="成本阶段" prop="customerCode"  width="90" :resizable="false">
              </el-table-column>
              <el-table-column label="上传人" prop="customerCode"  width="90" :resizable="false">
              </el-table-column>

              <el-table-column label="上传时间" min-width="180" :resizable="false">
                <template slot-scope="scope">
                  {{scope.row.approveDate2||"--"}}
                </template>
              </el-table-column>
              <el-table-column label="操作" min-width="256" :resizable="false" fixed="right">
                <template slot-scope="scope">
                  <span class="wordprimary tabs" @click="goAccess(scope.row)">修改项目信息</span>
                  <span class="wordprimary tabs" @click="goAssessment(scope.row)">查看导入进度</span>
                  <span class="worddel tabs" @click="goDisposal(scope.row)">删除</span>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
        <div class="pagination clearfix" v-show="total>formdata.pageSize">
          <el-pagination background :page-size="formdata.pageSize" :current-page.sync="formdata.pageNum" @current-change="handleCurrentChange" layout="prev, pager, next"
                         :total="total">
          </el-pagination>
        </div>
      </div>
      <el-dialog
        class="pro-news"
        :visible.sync="dialogVisible"
        width="480px">
        <div class="poptitle">
          <span>{{protitle}}</span>
        </div>
        <el-form class="popform" label-width="97px" :model="queryParam" :rules="rules" ref="ruleForm">
          <el-form-item label="项目名称" class="row">
            <el-input type="text" v-model="queryParam.projectName" placeholder="请输入完整的项目名称"></el-input>
          </el-form-item>
          <el-form-item label="IPM项目编码" class="row">
            <el-input type="text" placeholder="请输入IPM项目编码" v-model="queryParam.ipmProjectNo">
              <template slot="append"><div class="pro-getbtn" @click="getipmProjectNo">获取数据</div></template>
            </el-input>
          </el-form-item>
          <el-form-item label="文件名称" class="row">
            <el-input type="text" placeholder="请输入文件名称" v-model="queryParam.projectFileName"></el-input>
          </el-form-item>
          <el-form-item label="成本阶段" class="row" prop="cbStage">
            <el-select placeholder="请选择成本阶段" v-model="queryParam.cbStage">
              <el-option v-for="(item,index) in cbStagelist" :label="item.dictLabel" :value="item.dictValue" :key="index"></el-option>
            </el-select>
          </el-form-item>
        </el-form >
        <div class="popbot">
          <div class="btn btn_cancel h32" @click="dialogVisible = false">取消</div>
          <div class="btn btn_primary h32" @click="insertPro" :class="{'btn_disabled':!queryParam.cbStage}" :disabled="!queryParam.cbStage">下一步，导入数据</div>
        </div>
      </el-dialog>

    </div>
    <proupload v-if="isupload" :uploadData=uploadData></proupload>

    <el-dialog title="草稿箱" :visible.sync="cgxVisible" width="960px" custom-class='dialog-supplier'>
      <el-divider></el-divider>
      <div style="padding: 24px 20px;">
        <skeleton v-if="cgxSkeleton"></skeleton>
        <div class="table-item-jf table-item" v-if="!cgxSkeleton">
          <el-table :data="cgxlist" :header-cell-style="{ background:'#f0f3fa',color: 'rgba(35,35,35,0.8)'}"
                    v-sticky-header.always="{offsetTop : '-16px',offsetBottom : '10px'}" class="table-item1 fixed-table"
                    border highlight-current-row>

            <!--<el-table-column type="index" label="序号" width="60" :resizable="false">-->
              <!--<template slot-scope="scope">-->
                <!--<span>{{scope.$index + 1}}</span>-->
              <!--</template>-->
            <!--</el-table-column>-->
            <el-table-column label="项目名称" width="451px" >
              <template slot-scope="scope">
                <span>{{scope.row.projectName||'--'}}</span>
              </template>
            </el-table-column>
            <el-table-column label="成本阶段" width="105px">
              <template slot-scope="scope">
                <div v-for="item in cbStagelist">
                  <span v-if="scope.row.cbStage == item.dictValue">{{item.dictLabel}}</span>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="更新时间" width="205px" :resizable="false">
              <template slot-scope="scope">
                <span>{{scope.row.updateTime||'--'}}</span>
              </template>
            </el-table-column>
            <el-table-column label="操作">
              <template slot-scope="scope">
                <span class="wordprimary" @click="jxbj(scope.row)">继续编辑</span>
                <span class="worddel">删除</span>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="pagination clearfix" v-show="total>formdata.pageSize">
          <el-pagination background :page-size="formdata.pageSize" :current-page.sync="formdata.pageNum"
                         @current-change="handleCurrentChange" layout="prev, pager, next"
                         :total="cgxtotal">
          </el-pagination>
        </div>
      </div>
    </el-dialog>
  </div>
</template>
<script>
  import '@/assets/styles/public.scss'
  import { checkProjectCodeExist,addProject,getDraftDialogList } from '@/api/projectCostLedger/index'
  import { getDicts } from '@/api/system/dict/data'
  import proupload from '@/views/projectCostLedger/upload/index'
  import skeleton from '@/views/project/projectList/component/skeleton'

  export default {
  name: "projectCostLedger",
    components:{proupload,skeleton},
  data() {
    return {
      formdata:{},
      isSkeleton:false,
      total:10,
      protitle:'',
      dialogVisible:false,
      cbStagelist:[],
      ztStagelist:[],
      //新建项目参数
      queryParam:{
        projectName:'',//项目名称
        ipmProjectNo:'',//	IPM项目编码
        isGetProjectDetail:0,//	是否获取项目详情 0:否、1:是)
        projectFileName:'',//	文件名称
        cbStage:'',//成本阶段
      },
      rules:{
        cbStage:[{ required: true, message: '请选择成本阶段！', trigger: 'blur' },],
      },
      isupload:false,
      tableData:[],
      cgxVisible:false,
      cgxSkeleton:false,
      cgxtotal:0,
      cgxlist:[],
      uploadData:{},//新增项目返回的数据
    };
  },
  //可访问data属性
  created() {
    // this.isupload = true
    //成本阶段
    getDicts('pro_cbstage').then(res=>{
      this.cbStagelist = res.data
    })
    //项目文件状态
    getDicts('pro_ztstage').then(res=>{
      this.ztStagelist = res.data
    })
    //获取草稿箱
    this.getCGXlist()
  },
  //计算集
  computed: {

  },
  //方法集
  methods: {
    addPro(){
      this.dialogVisible = true
      this.queryParam = {
        projectName: '',//项目名称
        ipmProjectNo: '',//	IPM项目编码
        isGetProjectDetail: 0,//	是否获取项目详情 0:否、1:是)
        projectFileName: '',//	文件名称
        cbStage: ''//成本阶段
      }
      this.protitle = '新增项目'
    },
    getSearch(){
      this.formdata.pageNum = 1
      // this.customerAll()
    },
    getipmProjectNo(){
      //点击且校验了当前编码有数据才获取
      checkProjectCodeExist(this.queryParam.ipmProjectNo).then(res=>{
        if(res.code == 200 && res.data == true){
          this.queryParam.isGetProjectDetail = 1
        }else{
          this.queryParam.isGetProjectDetail = 0
        }
      })
    },
    clears(){
      this.formdata={
        customerName: '',
        customerClass:[],
        areas:[],
        province:[],
        city:[],
        customerState:[],
        creditLevel:[],
        credential:[],
        approveDateBegion:null,
        approveDateEnd:null,
        times:[],
        pageSize:50,
        pageNum:1,
      }
      // this.customerAll()
    },
    //添加项目
    insertPro(){
      addProject(JSON.stringify(this.queryParam)).then(res=>{
        if(res.code == 200){
          this.uploadData = res.data
          this.isupload = true
        }
      })
    },
    //继续编辑
    jxbj(data){
      console.log(this.cgxlist)
      console.log(data)
      this.uploadData = data
      this.isupload = true
      this.cgxVisible = false
    },
    handleCurrentChange(val){
      this.formdata.pageNum = val
      this.customerAll()
    },
    setHeaderRow() {
      return "owner-table-list-header";
    },
    setCellClass({ row, column, rowIndex, columnIndex }) {
      if (columnIndex == 1) {
        return "enterprise-name-column";
      }
    },
    setRowClass({ row, rowIndex }) {
      return "enterprise-name-row";
    },
    getcgx(){
      this.getCGXlist()
      this.cgxVisible = true
    },
    getCGXlist(){

      this.cgxSkeleton = true
      getDraftDialogList().then(res=>{
        this.cgxtotal = res.data.length
        this.cgxlist = res.data
        this.cgxSkeleton = false
      })
    }
  },
}
</script>
<style lang="scss" scoped>
  .project-cost-ledger-container {
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    padding: 16px 24px;
    overflow: auto;
    .project-cost-ledger-inner {
      width: 100%;
      /*height: 100%;*/
    }

    .content-project {
      background: #fff;
      padding-top: 14px;

      .el-form-item {
        margin-bottom: 16px;
      }

      .el-divider {
        margin-bottom: 16px;
      }
    }

    .table-project {
      background: #fff;
      margin-top: 16px;
      height: calc(100vh - 296px);
      padding-top: 1px;
      min-height: 350px;

      .table-item-jf1 {
        margin-top: calc(27vh - 90px);

        .item-jf-img {
          margin-bottom: 16px;
        }
      }

      .item-jf-titel {
        font-size: 14px;
        color: #232323;
        line-height: 22px;
        margin-bottom: 16px;
      }

      .jf-btn {
        display: block;
        background: #0081ff;
        margin: auto;
      }
      .btn{
        width: auto;
        padding: 0 12px;
      }
      .btn + .btn{
       margin-left: 16px;
      }
    }

    ::v-deep .pro-news {
      .el-dialog__body {
        padding: 24px 0 0;
      }

      .el-dialog__headerbtn {
        top: 20px;
        right: 20px;
        z-index: 3;
      }

      .poptitle {
        line-height: 56px;
        border-bottom: 1px solid #eee;
        height: 56px;
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;

        > span {
          padding-left: 20px;
          font-weight: bold;
          font-size: 16px;
          color: #232323;
          font-family: Microsoft YaHei-Bold, Microsoft YaHei;
          width: 385px;
          display: block;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
        }
      }

      .popform {
        padding: 24px 20px 0;

        .row {
          margin-bottom: 16px;
          position: relative;

          .el-form-item__label {
            font-weight: 400;
            opacity: 0.8;
            padding: 0;
            font-size: 14px;
            color: #232323;
            padding-right: 16px;
          }

          .el-input,
          .el-textarea,
          .el-select {
            display: inline-block;
            width: 343px;

            .el-input__inner,
            .el-textarea__inner {
              width: 100%;
              height: 32px;
              border-radius: 0px;

              &:hover {
                border-color: #0081ff;
              }
            }

            .el-textarea__inner {
              height: 90px;
              font-family: inherit;
              color: #000;
            }

            .el-input__suffix {
              height: 32px;
            }

            .el-input__icon {
              line-height: 32px;
            }
          }

          .el-form-item__error {
            padding-top: 2px;
          }
        }
        .el-input-group--append{
          position: relative;
          .el-input-group__append{
            position: absolute;
            right: 0;
            width: 76px;
            top: 0;
            border: 0;
            background: none;
            &:hover{
              background: none !important;
            }
            .pro-getbtn{
              border-left: 1px solid #DCDFE6;
              height: 32px;
              color: #0081FF;
              line-height: 32px;
              text-align: center;
            }
          }
        }
      }

      .popbot {
        border-top: 1px solid #EEEEEE;
        text-align: right;
        margin-top: 24px;
        padding: 16px 20px;

        .btn {
          border-radius: 2px;
          margin-left: 12px;
          padding: 0 24px;
          &.btn_disabled{
            background: #8BD1FF;
          }
        }
      }
    }

    .total-title{
      height: 32px;
      line-height: 32px;
      .totals{
        padding-left: 6px;
        position: relative;
        font-size: 12px;
        color: #3D3D3D;
        display: inline-block;
        &::before{
          content: ' ';
          position: absolute;
          width: 2px;
          height: 2px;
          background: rgba(35,35,35,0.4);
          border-radius: 50%;
          left: 0;
          top: 12px;
        }
      }
      margin-bottom: 16px;
      .btns{
        float: right;
        display: inline-block;
        width: 30%;
        text-align: right;
      }
    }
  }
  ::v-deep .dialog-supplier{
    .el-dialog__body{
      padding: 0;
    }
  }
.worddel{
  color: #FA5351;
  padding-left: 12px;
}
</style>
