<!--
  @description: 采购计划-退回计划管理-重新上报弹框
  @author: lxl
  @date： 2020-11-02 13:52
-->
<template>
  <div>
    <el-dialog
      :visible.sync="dialogReportedData.dialogRreVisible"
      :before-close="handleClose"
      title="重新上报"
      width="700px"
      custom-class="el-dialog__body-p0 el-dialog__body-p8 el-dialog_table"
    >
      <section class="p0-16">
        <el-table
          v-loading="loading"
          :data="tableData"
        >
          <el-table-column align="center" width="60" type="index" label="序号" />
          <el-table-column prop="purchaseNo" min-width="150" align="center" label="行项目编码" />
          <el-table-column prop="purchaseCode" header-align="center" min-width="180" align="left" label="物资编码" />
          <el-table-column prop="purchaseName" header-align="center" min-width="220" align="left" label="物资信息" />
          <el-table-column prop="purchaseDepartName" header-align="center" min-width="220" align="left" label="上报单位" />
          <el-table-column prop="purchaseSpecification" header-align="center" min-width="220" align="left" label="物资规格" />
        </el-table>
        <page-nation :pagination-data="paginationData" @change="loadData" />
      </section>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="ensure()">
          确 定
        </el-button>
        <el-button @click="handleClose">
          取 消
        </el-button>
        <div />
      </div>
    </el-dialog>
  </div>
</template>
<script>
/* api*/
import {
  modifyProtPurchaseTenderMethodPage, // 初始化数据
  purchasePlanDetailsRestartReport // 提交
} from '@/api/procurement/purchasplan'
import { ListMixin } from '@/mixins/ListMixin' // 分页
import { paging } from '@/assets/js/utils/index.js' // 前端分页
import pagination from '@comp/common/pagination/pagination' // 分页组件
export default {
  name: 'BackReportedDialog',
  components: {
    'page-nation': pagination
  },
  mixins: [ListMixin],
  props: {
    dialogReportedData: { // 弹框状态
      type: Object,
      default: () => {}
    },
    paramsId: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      tableData: [], // 表格数据
      loading: false
    }
  },
  watch: {
    'dialogReportedData.dialogRreVisible'(val) {
      if (val) {
        this.loadData()
      }
    }
  },
  created() {
  },
  methods: {
    // 数据请求方法
    loadData() {
      const params = { planDetailIds: this.paramsId }
      modifyProtPurchaseTenderMethodPage(params)
        .then(response => {
          this.loading = false
          this.tableData = paging({}, response.data.list, this.paginationData)
        })
        .catch(() => {
          this.loading = false
        })
    },
    purPlanRet() {
      const data = { planDetailIds: this.paramsId }
      purchasePlanDetailsRestartReport(data).then(response => {
        this.$message.success(response.header.msg)
        this.handleClose()
      }).catch((error) => {
        this.$message.warning(error)
      })
    },
    ensure() {
      this.$confirm('是否确定提交？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        this.purPlanRet()
      }).catch(() => {
      })
    },
    handleClose() {
      this.$emit('close')
      this.dialogReportedData.dialogRreVisible = false
    }
  }
}
</script>
<style scoped>
</style>
