<!--
  @description: 采购计划-计划结果执行确认-重新执行采购弹框
  @author: lxl
  @date： 2020-10-30 10:32
-->
<template>
  <el-dialog
    :visible.sync="dialogAnewData.AnewVisible"
    :before-close="handleClose"
    title="重新执行采购"
    width="700px"
  >
    <section>
      <el-table
        :data="tableData"
      >
        <el-table-column align="center" type="index" label="序号" />
        <el-table-column prop="purchaseNo" align="center" label="行项目编号" />
        <el-table-column prop="purchaseCode" align="center" label="物资编码" />
        <el-table-column prop="purchaseName" align="center" label="物资信息" />
      </el-table>
      <pagination :pagination-data="paginationData" />
    </section>

    <el-form
      ref="formData"
      label-position="left"
      :inline-message="true"
      :rules="rules"
      :model="formData"
    >
      <table class="from_table" style="margin:10px 0px">
        <tr>
          <td>
            <el-form-item
              label="重新执行采购原因:"
              prop="bizReason"
            />
          </td>
          <td>
            <gx-input
              v-model.trim="formData.bizReason"
              gx-maxlength="varchar100"
            />
          </td>
        </tr>
      </table>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="ensure('formData')">
        确 定
      </el-button>
      <el-button @click="handleClose()">
        取 消
      </el-button>
    </div>
  </el-dialog>
</template>
<script>
/* api*/
import { purchasePlanDetailApplyPackOnResultAffirm } from '@/api/procurement/purchasplan'
/* 公共*/
import { ListMixin } from '@/mixins/ListMixin' // 分页
import pagination from '@comp/common/pagination/pagination' // 分页组件
import { paging } from '@/assets/js/utils/index.js' // 前端分页
import { characters1_50 } from '@/assets/js/validate'// 校验输入内容
export default {
  name: 'AnewBaleDialog',
  components: {
    pagination
  },
  mixins: [ListMixin],
  props: {
    dialogAnewData: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      loading: false,
      tableData: [],
      formData: {
        bizReason: '' // 重新采购原因
      },
      rules: {
        bizReason: [{ required: true, validator: characters1_50, trigger: 'blur' }]
      }
    }
  },
  watch: {
    'dialogAnewData.AnewVisible'(val) {
      if (val) {
        this.tableData = paging({}, this.dialogAnewData.paramsData, this.paginationData)
      }
    }
  },
  created() {
  },
  methods: {
    resultAffirm() {
      // bizTypeCode:业务类型编号 00-集采转自采;01-退回计划;02-采购方式变更;03-业务部退回计划;04-【结果执行确认】重新打包采购
      const data = this.tableData.map((item) => {
        return {
          purchaseNo: item.purchaseNo,
          planDetailId: item.planDetailId,
          purchaseCode: item.purchaseCode
        }
      })
      const params = {
        bizReason: this.formData.bizReason,
        bizTypeCode: '04',
        packList: data
      }
      purchasePlanDetailApplyPackOnResultAffirm(params).then(response => {
        this.$message.success(response.header.msg)
        this.handleClose()
      })
        .catch((error) => {
          this.$message.warning(error)
        })
    },
    ensure(formName) {
      this.$refs[formName].validate((valid, field) => {
        if (valid) { // 校验通过
          this.resultAffirm()
        } else {
          this.$message.warning('请注意页面提示信息')
          return false
        }
      })
    },
    handleClose() {
      this.$emit('close')
      this.dialogAnewData.AnewVisible = false
    }
  }
}
</script>
<style scoped>
</style>
