<!--
  @description: 招标计划信息-招标计划基本信息
  @Modifier: haofengxian
  @routerPath:
  @date: 2020-6-11-10:05
-->
<template>
  <div>
    <el-form ref="ruleForm" :model="formData" :rules="rules" :inline-message="true">
      <table class="from_table">
        <tr>
          <td>
            <el-form-item label="招标计划编号" />
          </td>
          <td>
            <el-input v-model="formData.schemeNo" placeholder="招标计划编号自动生成" disabled />
          </td>
          <td>
            <el-form-item label="招标计划名称" prop="schemeName" />
          </td>
          <td>
            <el-input v-model.trim="formData.schemeName" placeholder="招标计划名称" />
          </td>
        </tr>
        <tr>
          <td>
            <el-form-item label="工程项目编号" />
          </td>
          <td>
            <el-input v-model.trim="formData.projectNo" placeholder="工程项目编号" />
          </td>
          <td>
            <el-form-item label="工程项目名称" />
          </td>
          <td>
            <el-input v-model.trim="formData.projectName" placeholder="工程项目名称" />
          </td>
        </tr>
        <tr>
          <td>
            <el-form-item label="招标组织单位编号" prop="schemeDeptno" />
          </td>
          <td>
            <el-input v-model="formData.schemeDeptno" placeholder="招标组织单位编号" disabled style="width: calc(100% - 180px)" />
            <el-button type="primary" @click="subsidiaryOrganDialog.dialog=true">
              选择
            </el-button>
            <el-button @click="clearDept">
              清空
            </el-button>
          </td>
          <td>
            <el-form-item label="招标组织单位名称" />
          </td>
          <td>
            <el-input v-model.trim="formData.schemeDeptname" placeholder="招标组织单位名称" disabled />
          </td>
        </tr>
        <tr>
          <td>
            <el-form-item label="采购级别" prop="purchasLevel" />
          </td>
          <td>
            <el-select v-model="formData.purchasLevel" placeholder="请选择" style="width: 100%">
              <el-option
                v-for="item in purchaseSchemeLevelList"
                :key="item.typecode"
                :label="item.typename"
                :value="item.typecode"
              />
            </el-select>
          </td>
          <td>
            <el-form-item label="招标组织形式" prop="biddingOrganizationForm" />
          </td>
          <td>
            <el-radio-group v-model="formData.biddingOrganizationForm">
              <el-radio
                v-for="item in purchasesSchemeBidOrgFormList"
                :key="item.typecode"
                :label="item.typecode"
              >
                {{ item.typename }}
              </el-radio>
            </el-radio-group>
          </td>
        </tr>
        <tr>
          <td>
            <el-form-item label="所属二级公司" prop="secondaryLevelCompanyName" />
          </td>
          <td>
            <el-input v-model="formData.secondaryLevelCompanyName" placeholder="所属二级公司" disabled style="width: calc(100% - 180px)" />
            <el-button type="primary" @click="handelSecondaryLevelCompanyName('00')">
              选择
            </el-button>
            <el-button @click="handelSecondaryLevelCompanyName('01')">
              清空
            </el-button>
          </td>
          <td>
            <el-form-item label="基层公司" prop="grassRootsCompaniesName" />
          </td>
          <td>
            <el-input v-model="formData.grassRootsCompaniesName" placeholder="基层公司" disabled style="width: calc(100% - 180px)" />
            <el-button type="primary" @click="handleGrassRootsCompaniesName('00')">
              选择
            </el-button>
            <el-button @click="handleGrassRootsCompaniesName('00')">
              清空
            </el-button>
          </td>
        </tr>
        <tr>
          <td>
            <el-form-item label="招标代理机构" prop="biddingAgencyName" required />
          </td>
          <td>
            <el-input v-model="formData.biddingAgencyName" placeholder="招标代理机构" disabled />
          </td>
          <td>
            <el-form-item label="项目性质" prop="schemeNature" />
          </td>
          <td>
            <el-select v-model="formData.schemeNature" style="width: 100%;" placeholder="请选择">
              <el-option
                v-for="item in purchaseSchemeProjectNatureList"
                :key="item.typecode"
                :label="item.typename"
                :value="item.typecode"
              />
            </el-select>
          </td>
        </tr>
        <tr>
          <td>
            <el-form-item label="招标项目类型" prop="biddingSchemeType" />
          </td>
          <td>
            <el-select
              v-model="formData.biddingSchemeType"
              style="width: 100%;"
              @change="projectIndustryChange"
            >
              <el-option
                v-for="item in purchaseSchemeProjectTypeList"
                :key="item.typecode"
                :label="item.typename"
                :value="item.typecode"
              />
            </el-select>
          </td>
          <td>
            <el-form-item label="招标类别二级分类" prop="biddingClassSecondLevel" />
          </td>
          <td>
            <el-select
              v-for="item in purchaseSchemeProjectTypeList"
              v-if="formData.biddingSchemeType===item.typecode"
              ref="biddingClassSecondLevel"
              :key="item.typecode"
              v-model="formData.biddingClassSecondLevel"
              style="width: 100%;"
              @change="projectIndustryChange(item.typecode,item.child)"
            >
              <el-option
                v-for="(child,childIndex) in item.child"
                :key="childIndex"
                :label="child.typename"
                :value="child.typecode"
              />
            </el-select>
            <!--<el-select v-if="selectIsShow" v-model="formData.biddingClassSecondLevel" style="width: 100%;" placeholder="请选择"/>-->
          </td>
        </tr>
        <tr>
          <td>
            <el-form-item label="工程分类" prop="schemeClass" />
          </td>
          <td>
            <el-select v-model="formData.schemeClass" style="width: 100%;" placeholder="请选择">
              <el-option
                v-for="item in purchaseSchemeEngineeringTypeList"
                :key="item.typecode"
                :label="item.typename"
                :value="item.typecode"
              />
            </el-select>
          </td>
          <td>
            <el-form-item label="采购类型" prop="purchasType" />
          </td>
          <td>
            <el-select v-model="formData.purchasType" style="width: 100%;">
              <el-option
                v-for="item in purchaseSchemeTypeList"
                :key="item.typecode"
                :label="item.typename"
                :value="item.typecode"
              />
            </el-select>
          </td>
        </tr>
        <tr>
          <td>
            <el-form-item label="概算金额（元）">
              <el-popover
                placement="top-start"
                popper-class="hint"
                offset="5"
                trigger="hover"
                style="margin-left:5px;"
                content="由物料组概算总价自动求和而得"
              >
                <el-button slot="reference" type="info" class="prompt">
                  <i class="iconfont icon-qm" />
                </el-button>
              </el-popover>
            </el-form-item>
          </td>
          <td colspan="3">
            <money :money-value="formData" :thousands="true" name="schemeBudget" disabled />
          </td>
        </tr>
        <tr>
          <td>
            <el-form-item label="招标范围" />
          </td>
          <td colspan="3">
            <el-input
              v-model="formData.biddingArea"
              :autosize="{ minRows: 4, maxRows: 4 }"
              type="textarea"
              style="width: 96%"
            />
          </td>
        </tr>
      </table>
    </el-form>
    <!-- 所属机构选择弹框 -->
    <subsidiaryOrganDialog :dialog-data="subsidiaryOrganDialog" @buyersInfo="subsidiaryOrganInfo" />
    <!--所属二级公司-->
    <secondLevelOrganTree ref="secondLevelOrganTree" @secondaryLevelCheckedNodes="checkedNodes" />
    <!--获取基层公司-->
    <organTreeDialog ref="organTree" @call-back="callBackOrganTree" />
  </div>
</template>

<script>
/* 组件*/
import subsidiaryOrganDialog from './subsidiaryOrgan-dialog'
import secondLevelOrganTree from '@views/common/user/organizationTree/secondLevelOrganTree-dialog'
import organTreeDialog from '@views/common/user/organizationTree/organTree-dialog'
import money from '@comp/common/money/money'
/* mixins混入公共方法*/
import { tenderPlan } from '../../mixins/tenderPlan'
/* 常用公共方法*/
import { checkMoney, validateInput, characters1_auto } from '@/assets/js/validate'
export default {
  name: 'BiddingPlanInfoForm',
  components: {
    subsidiaryOrganDialog, // 所属机构选择弹框
    money, // 金额组件
    secondLevelOrganTree, // 所属二级公司
    organTreeDialog // 基层公司
  },
  mixins: [tenderPlan],
  props: {
    formData: {
      type: Object,
      default: function() {
        return {}
      }
    }
  },
  data() {
    return {
      selectIsShow: true, // 招标类别二级分类下拉选择框控制显示隐藏
      //  委托人选择弹框
      subsidiaryOrganDialog: {
        dialog: false
      },
      rules: {
        schemeName: [{ required: true, validator: validateInput, trigger: 'blur' }], // 招标计划名称
        biddingSchemeType: [{ required: true, validator: characters1_auto, trigger: 'blur' }], // 招标项目类型
        biddingAgencyName: [{ required: true, validator: characters1_auto, trigger: 'blur' }], // 招标代理机构
        purchasLevel: [{ required: true, validator: characters1_auto, trigger: 'blur' }], // 采购级别
        schemeDeptno: [{ required: true, validator: characters1_auto, trigger: 'blur' }], // 招标组织单位编号
        schemeBudget: [{ required: true, validator: checkMoney, trigger: 'blur' }], // 概算金额
        biddingOrganizationForm: [{ required: true, validator: characters1_auto, trigger: 'blur' }], // 招标组织形式
        schemeNature: [{ required: true, validator: characters1_auto, trigger: 'blur' }], // 项目性质
        biddingClassSecondLevel: [{ required: true, validator: characters1_auto, trigger: 'blur' }], // 招标二级分类
        purchasType: [{ required: true, validator: characters1_auto, trigger: 'blur' }] // 采购类型
      }
    }
  },
  created() {
    // 招标计划-字典信息
    this.initPurchaseSchemeWebTypeGroup()
  },
  mounted() {
    const id = this.formData.id ? this.formData.id : ''
    if (id) {
      this.selectIsShow = false // 如果有id,回显数据,需要把招标分类二级分类下拉框隐藏
    }
  },
  methods: {
    // 项目分类选择
    projectIndustryChange(val, child) {
      this.selectIsShow = false
      if (!child) {
        // 当改变父级状态时将子级数据清空
        this.formData.biddingClassSecondLevel = ''
      }
      // 数据强制刷新
      this.$forceUpdate()
    },
    // 招标组织单位编号 && 名称
    subsidiaryOrganInfo(data) {
      this.formData.schemeDeptname = data.departName
      this.formData.schemeDeptno = data.orgCode
    },
    // 清空 招标组织单位编号 && 名称
    clearDept() {
      this.formData.schemeDeptname = ''
      this.formData.schemeDeptno = ''
    },
    // 提交校验
    vaildate() {
      return this.$refs['ruleForm'].validate()
    },
    // 选择/清空所属公司 00选择 01清空
    handelSecondaryLevelCompanyName(type) {
      if (type === '00') {
        this.$refs.secondLevelOrganTree.openDialog()
      } else {
        this.formData.secondaryLevelCompanyName = ''
        this.formData.secondaryLevelCompanyId = ''
      }
    },
    // 子组件返回已选所属公司
    checkedNodes(CheckedNodes) {
      this.formData.secondaryLevelCompanyName = CheckedNodes.companyName // 所属二级公司名称
      this.formData.secondaryLevelCompanyId = CheckedNodes.companyId // 所属二级公司id
    },
    // 选择/清空基层公司 00选择 01清空
    handleGrassRootsCompaniesName(type) {
      if (type === '00') {
        if (this.formData.secondaryLevelCompanyId) {
          this.$refs.organTree.open({
            title: '选择基层公司', // 弹框标题
            dialog: true, // 弹窗状态
            onlyOneSelected: true, // 是否只能选最后一级且是单选
            companyId: this.formData.secondaryLevelCompanyId
          })
        } else {
          this.$message.warning('请先选择所属二级公司')
        }
      } else {
        this.formData.grassRootsCompaniesName = '' // 基层公司名称
        this.formData.grassRootsCompaniesId = '' // 基层公司id
      }
    },
    // 子组件返回已选基层公司
    callBackOrganTree(data) {
      this.formData.grassRootsCompaniesName = data.labels //  基层公司名称
      this.formData.grassRootsCompaniesId = data.keys // 基层公司id
    }
  }
}
</script>

<style scoped>

</style>
