<!--
  @description: 采购计划-集采计划打包-重新打包
  @author: lxl
  @date： 2020-11-03 11:32
-->
<template>
  <div>
    <el-dialog
      v-dialogDrag
      :visible.sync="dialogAnewBaleData.dialogVisibleAnew"
      :before-close="handleClose"
      title="重新打包"
      width="700px"
    >
      <section class="main mb10">
        <el-table v-loading :data="tableData">
          <el-table-column
            width="60"
            align="center"
            type="index"
            label="序号"
          />
          <el-table-column
            min-width="150"
            prop="purchaseNo"
            align="center"
            label="行项目编码"
          />
          <el-table-column
            min-width="150"
            prop="purchaseCode"
            align="center"
            label="物资编码"
          />
          <el-table-column
            min-width="300"
            prop="purchaseName"
            align="left"
            header-align="center"
            label="物资信息"
          />
        </el-table>
        <pagination :pagination-data="paginationData" @change="loadData" />
      </section>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" :loading="confirmLoading" @click="ensure">
          确 定
        </el-button>
        <el-button @click="handleClose">
          取 消
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
/* api*/
import { purchasePlanDetailsWaitPackAudit, modifyProtPurchaseTenderMethodPage, purchasePlanDetailsReadyRepack } from '@/api/procurement/purchasplan'
/* 公用方法*/
// import { procurementPlanGrounpMixins } from '@views/procurement/procurementPlan/mixins/procurementPlanGroupMixins' // 字典信息
// import { filterDictText } from '@/assets/js/utils' // 字典方法
import { ListMixin } from '@/mixins/ListMixin' // 分页
import pagination from '@comp/common/pagination/pagination' // 分页组件
import { paging } from '@/assets/js/utils/index.js' // 前端分页
export default {
  name: 'AnewBaleDialog',
  components: {
    pagination
  },
  mixins: [ListMixin],
  props: {
    dialogAnewBaleData: {
      type: Object,
      default: () => {}
    },
    paramsId: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      tableData: [],
      confirmLoading: false,
      loading: true
    }
  },
  watch: {
    'dialogAnewBaleData.dialogVisibleAnew'(val) {
      if (val) {
        this.loadData()
      }
    }
  },
  created() {
  },
  methods: {
    // filterDictText,
    // 初始化接口方法
    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
        })
    },
    // 退回点击确定接口方法
    purchasePlanDetail() {
      // predictPackType 00 预打包的重新打包 01 业务退回的重新打包
      if (this.dialogAnewBaleData.predictPackType === '00') {
        // 预打包-重新打包保存方法
        this.savePredictPack()
      } else if (this.dialogAnewBaleData.predictPackType === '01') {
        // 业务退回的重新打包保存方法
        this.saveSendBackPack()
      }
    },
    /*
    * 预打包-重新打包保存方法
    * @params {planDetailIds: 选择的行项目id集合}
    * 重新对行项目进行打包 返回代打包处
    */
    savePredictPack() {
      const data = {
        planDetailIds: this.dialogAnewBaleData.planDetailIds
      }
      this.confirmLoading = true
      purchasePlanDetailsReadyRepack(data).then(response => {
        this.loading = false
        this.confirmLoading = false
        this.handleClose()
      })
        .catch(() => {
          this.confirmLoading = false
          this.loading = false
        })
    },
    // 业务退回的重新打包保存方法
    saveSendBackPack() {
      const params = {
        bizTypeCode: '05', // 业务退回计划重新打包code值 05
        packList: this.tableData
      }
      this.confirmLoading = true
      purchasePlanDetailsWaitPackAudit(params).then(response => {
        this.loading = false
        this.confirmLoading = false
        this.handleClose()
      })
        .catch(() => {
          this.confirmLoading = false
          this.loading = false
        })
    },
    // 确定
    ensure() {
      this.purchasePlanDetail()
    },
    // 关闭
    handleClose() {
      this.$emit('close')
      this.dialogAnewBaleData.dialogVisibleAnew = false
    }
  }
}
</script>
<style scoped>
</style>
