<!--
  @description:财务状况
  @Modifier:qk
  @routerPath:supplierDeclaration/supplier/financialSituation
  @date:2020/2/17-17:27
-->
<template>
  <div>
    <div>
      <section>
        <div style="margin-bottom:10px;">
          <el-button type="primary" @click="addFinancialCondition('')">
            添加财务审计报告
          </el-button>
        </div>
        <div>
          <el-table
            ref="smallTable"
            v-loading="loading"
            :data="tableData"
          >
            <el-table-column
              type="index"
              label="序号"
              width="60px"
              align="center"
            />
            <el-table-column
              prop="year"
              align="center"
              label="年度"
              width="80"
            />
            <el-table-column
              header-align="center"
              align="right"
              prop="totalAssets"
              label="资产总计(万元)"
              min-width="110"
            />
            <el-table-column
              header-align="center"
              align="right"
              prop="totalLiabilities"
              label="负债总计(万元)"
              min-width="110"
            />
            <el-table-column
              header-align="center"
              align="right"
              label="利润总额(万元)"
              prop="totalProfit"
              min-width="110"
            />
            <el-table-column
              label="净利润(万元)"
              prop="netProfit"
              header-align="center"
              align="right"
              min-width="100"
            />
            <el-table-column
              label="资产负债率(%)"
              prop="assetLiabilityRatio"
              header-align="center"
              align="right"
              min-width="110"
            />
            <el-table-column
              label="流动比率(%)"
              prop="flowRate"
              header-align="center"
              align="right"
              min-width="100"
            />
            <el-table-column
              header-align="center"
              label="财务审计报告扫描件"
              prop="auditReportAttr"
              align="left"
              min-width="160"
            >
              <template slot-scope="scope">
                <downloadFile :data="scope.row.financialAuditingReportData" />
              </template>
            </el-table-column>
            <el-table-column
              header-align="center"
              label="操作"
              align="center"
              width="160px"
            >
              <template slot-scope="scope">
                <el-link
                  type="primary"
                  @click.stop="addFinancialCondition(scope.row.id,scope.row.oldId)"
                >
                  [编辑]
                </el-link>
                <el-link
                  type="primary"
                  @click.stop="seeFinancialCondition(scope.row)"
                >
                  [查看]
                </el-link>
                <el-link
                  type="primary"
                  @click.stop="deleteFinancialCondition(scope.row)"
                >
                  [删除]
                </el-link>
              </template>
            </el-table-column>
          </el-table>
          <!--分页组件-->
          <pagination :pagination-data="paginationData" @change="loadData" />
        </div>
        <!-- 审核意见 -->
        <inforaMtionAudit />
        <!-- 添加/编辑 -->
        <financialSituation v-if="dialogData.dialog" :dialog-data="dialogData" @consignContractInfo="consignContractInfo" />
        <!-- 查看 -->
        <financialSituationDetail v-if="dialogDetailData.dialog" :data="dialogDetailData" />
      </section>
    </div>
    <div class="but_footer">
      <div class="but_footer-h">
        <div class="but_footer-but">
          <!-- 编辑申报材料 -->
          <template v-if="pageType==='declarationFirst'">
            <el-button @click="prevStep">
              上一步
            </el-button>
            <el-button :loading="confirmLoading" type="primary" @click="submit('form')">
              提交
            </el-button>
          </template>
          <!-- 申报材料变更 -->
          <template v-if="pageType==='declarationChange'">
            <el-button :loading="confirmLoading" type="primary" @click="submitChange()">
              提交
            </el-button>
          </template>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
/* 接口*/
import { submitDepartInfo } from '@/api/supplier/supplierBaseInfo'
import { listFinancialSituationPages, removeFinancialSituation } from '@/api/supplier/supplierFinancialSituation'
import { changeSupplierInfoSubmit } from '@/api/supplier/supplierChange'// 基本信息变更提交
// import { listChangeableFinancialSituationPages } from '@/api/supplier/supplierChange'
// import { changeSupplierInfoSubmit } from '@/api/supplier/supplierChange.js'// 财务状态，供货记录，和资质证书变更提交
/* 公用方法*/
import { filterObj } from '@/assets/js/utils'// 常用方法
/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin'// 分页
import { declareHegSupperMixins } from '@/views/supplier/editorDeclaration/mixins/declareHegSupperMixins'// 供应商-公用方法参数
/* 组件*/
import downloadFile from '@comp/common/updownload/downloadFile'// 附件
import inforaMtionAudit from '../inforaMtionAudit/inforaMtionAudit-detail'// 审核信息
import pagination from '@comp/common/pagination/pagination'// 分页
import financialSituation from './financialSituation-dialog' // 添加/编辑
import financialSituationDetail from './financialSituationDetail-dialog' // 查看供货
export default {
  name: 'ProjectManagerTenderList',
  components: {
    downloadFile, // 附件
    pagination, // 分页
    financialSituation, // 添加/编辑
    financialSituationDetail, // 查看
    inforaMtionAudit
  },
  mixins: [ListMixin, declareHegSupperMixins],
  data() {
    return {
      pageType: this.$route.meta.type, // 当前页面所处状态 declarationFirst 编辑申报材料查看 declarationChange 申报材料变更时
      searchForm: {
        departId: this.$route.query.departId// 机构Id
      },
      loading: true, // 列表loding
      confirmLoading: false, // Loding
      // 添加/编辑财务状况-弹框
      dialogData: {
        dialog: false, // 展示状态
        id: '', // 编辑时才会有财务状况id
        oldId: '' // 修改时用的Id
      },
      // 查看财务状况-弹框
      dialogDetailData: {
        dialog: false, // 展示状态
        id: '', // 编辑时才会有财务状况id
        oldId: '' // 修改时用的Id
      },
      tableData: []// 列表信息
    }
  },
  created() {
    this.loadData()
  },
  methods: {
    // 添加财务状况回调函数
    consignContractInfo() {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      this.loadData()// 获取数据
    },
    // 获取数据
    loadData() {
      const params = this.getQueryParams()// 查询条件
      listFinancialSituationPages(params).then(response => {
        this.loading = false
        this.tableData = response.data.records
        this.paginationData.total = response.data.total
        this.tableData.forEach((item, index) => {
          // 证书扫描
          item.financialAuditingReportData = {
            ...this.financialAuditingReportData,
            bizId: item.id
          }
        })
      }).catch(() => {

      })
    },
    // 查询条件
    getQueryParams() {
      const param = Object.assign({}, this.searchForm)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      return filterObj(param)
    },
    prevStep() {
      // route携带参数
      const pathData = {
        ...this.$route.query
      }
      this.$emit('stepPage', 'prev', pathData)// 步骤条切换方法 prev 上一步
    },
    // 添加/编辑
    addFinancialCondition(id, oldId) {
      this.dialogData = {
        dialog: true,
        id: id,
        oldId: oldId // 修改时用的Id
      }
    },
    // 查看
    seeFinancialCondition(row) {
      this.dialogDetailData = {
        dialog: true,
        id: row.id, // 主键Id
        oldId: row.oldId // 修改时用的Id
      }
    },
    // 删除
    deleteFinancialCondition(row) {
      this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        const data = [{
          id: row.id, // 项目id
          oldId: row.oldId
        }]
        removeFinancialSituation(data).then(res => {
          this.$message({
            message: '删除成功',
            type: 'success'
          })
          // 获取列表信息
          this.loadData()
        })
      }).catch(() => {
      })
    },
    // 提交
    submitDepartInfo() {
      const data = {
        departId: this.$route.query.departId, // 供应商主键
        financeId: '', // 供应商财务信息主键
        id: this.$route.query.id, // 供应商departInfo主键
        status: '01'// (00:保存,01:提交)
      }
      submitDepartInfo(data).then(res => {
        if (this.pageType === 'declarationChange') {
          this.$nextTick(() => {
            this.$emit('showStatuschage')// 传给父集组件参数-审核状态-审核图片展示
          })
        } else {
          this.$router.push('/supplierDeclaration/supplier')
        }
        this.confirmLoading = false// Loading
      }).catch(() => {
        this.confirmLoading = false// Loading
      })
    },
    // 提交-检查申报条件
    submit() {
      this.$confirm('确认提交?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        this.confirmLoading = true// Loading
        this.judgeSubmitDepartInfo().then(res => {
          if (!res) {
            this.submitDepartInfo()// 提交
          } else {
            this.confirmLoading = false// Loading
          }
        }).catch(() => {
          this.confirmLoading = false// Loading
        })
      })
    },
    // 申报材料变更-提交
    submitChange() {
      this.$confirm('确认提交审核吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const data = this.searchForm
        changeSupplierInfoSubmit(data).then((response) => {
          if (response.header.ret === '0') {
            // 修改状态
            this.$nextTick(() => {
              this.$emit('showStatuschage')// 传给父集组件参数-审核状态-审核图片展示
            })
            this.saveData('save')
            this.$message({
              type: 'success',
              message: '提交成功'
            })
          } else {
            this.$message({
              type: 'warning',
              message: '提交失败'
            })
          }
        })
      }).catch(() => {
      })
    }
  }
}
</script>
<style lang="less" scoped>

</style>
