<!--
  @description:采购寻源-选择采购方式--产品未使用
  @Modifier：gmy
  @date：  2020-7-2- 11:39:19
-->
<template>
  <el-dialog
    v-dialogDrag
    :visible.sync="dialogData.dialog"
    :lock-scroll="false"
    title="选择采购方式"
    width="760px"
    class="el-dialog_table"
  >
    <div class="p8">
      <el-form
        ref="formData"
        :model="formData"
        :rules="rules"
        :inline-message="true"
      >
        <table class="from_table">
          <tr>
            <td><el-form-item label="选择采购方式" prop="tendermethod" /></td>
            <td>
              <el-radio-group v-model="formData.tendermethod">
                <el-radio
                  v-for="(item) in tender_methodList"
                  :key="item.typecode"
                  :label="item.typecode"
                >
                  {{ item.typename }}
                </el-radio>
              </el-radio-group>
            </td>
          </tr>
        </table>
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button :loading="confirmLoading" type="primary" @click="okdialog('formData')">确认</el-button>
      <el-button :loading="confirmLoading" @click="close">取消</el-button>
    </span>
  </el-dialog>
</template>

<script>
/* api*/
import { generatePurchaseOrder } from '@/api/procurement/purchasplan'
/*  公共方法 */
import { procurementPlanGrounpMixins } from '../mixins/procurementPlanGroupMixins'
import { restoreInitialValue } from '@/assets/js/utils' // 清空数据
export default {
  name: 'OfferReviewaddDialogVue',
  mixins: [procurementPlanGrounpMixins],
  props: {
    // 选择评审方式弹框
    dialogData: {
      type: Object,
      default: function() {
        return
      }
    },
    // 选择采购方式确认后的回调
    selectTenderMethoder: {
      type: Function,
      default: function(tendermethodData) {}
    }
  },
  data() {
    return {
      confirmLoading: false, // loading
      formData: {
        tendermethod: '' // 选择的采购方式
      },
      tendermethodData: {
        tenderNo: '', // 项目编号
        dialog: '' // 弹框关闭情况
      },
      rules: {
        tendermethod: [{ required: true, message: '请选择', trigger: 'blur' }] // 交货时间
      }
    }
  },
  watch: {
    'dialogData.dialog'(val) {
      if (val) {
        // 清空数据
        restoreInitialValue(this.tendermethodData)
      }
    }
  },
  created() {
    // 查询项目字典方法
    // this.initWebTypeGroup()
  },
  methods: {
    // 确认
    okdialog(formName) {
      this.$refs[formName].validate((valid, field) => {
        if (valid) { // 校验通过
          this.confirmLoading = true
          const data = {
            planDetailIds: this.dialogData.implementPurchaseList, // 选择采购计划的项目id集合
            purchaseMethod: this.formData.tendermethod // 选择的采购方式
          }
          // 调用执行选择方法
          this.selectPlanMeth(data)
        } else {
          this.confirmLoading = false
          return false
        }
      })
    },
    // 封装执行选择确定方法
    selectPlanMeth(data) {
      generatePurchaseOrder(data)
        .then(res => {
          const { tenderNo } = res.data
          this.tendermethodData.tenderNo = tenderNo // 获取采购方式
          this.tendermethodData.dialog = false // 声明关闭弹框 dialog 为false
          this.selectTenderMethoder(this.tendermethodData) // 调用选择采购方式后的回调
        })
        .catch(() => {
          this.confirmLoading = false
        })
    },
    // 取消
    close() {
      this.formData.tendermethod = '' // 清空数据
      this.dialogData.dialog = false // 关闭弹框
    }
  }

}
</script>

<style scoped>

</style>
