<template>
    <a-modal
      :title="defaultMethod=='add'?'新增':'编辑'"
       width="95%"
      :visible="visible"
      :maskClosable="false"
      switchFullscreen
      @cancel="handleCancel"
      @ok='handleOk'
      >
      <a-card :bordered="false" class="top" style="margin-bottom:1%;margin-top:1%" :loading = 'loading'>
        <div class="table-page-search-wrapper">
            <a-form-model layout="inline" @keyup.enter.native="searchQuery" :model="form" :rules="rules"  ref="form">
                <a-row :gutter="24">
                    <a-col :md="4" :sm="24">
                        <a-form-model-item label="生产组织" prop='orgName'>
                            <a-input-search placeholder="请选择" v-model="form.orgName" @search="onSearchPlanOrg" readOnly></a-input-search>
                        </a-form-model-item>
                    </a-col>
                    <a-col  :md="4" :sm="24">
                        <a-form-model-item label="单据号">
                            <a-input placeholder="自动生成" v-model="form.orderCode" disabled></a-input>
                        </a-form-model-item>
                    </a-col>
                    <a-col :md="4" :sm="24">
                        <a-form-model-item label="单据日期" prop='orderDate'>
                            <a-date-picker showTime valueFormat="YYYY-MM-DD" format = "YYYY-MM-DD" v-model="form.orderDate" style="width:100%"/>
                        </a-form-model-item>
                    </a-col>
                   <a-col :md="4" :sm="24">
                        <a-form-model-item label="单据状态">
                            <a-select v-model="form.state"  style='width:100%' disabled>
                                <a-select-option value='开立'> 开立</a-select-option>
                                <a-select-option value='审核'> 审核</a-select-option>
                                <a-select-option value='已运算'> 已运算</a-select-option>
                                <a-select-option value='关闭'> 关闭</a-select-option>
                            </a-select>
                        </a-form-model-item>
                    </a-col>
                    <a-col :md="4" :sm="24">
                        <a-form-model-item label="业务员">
                            <a-input-search placeholder="请选择" v-model="form.salesperson"  @search="onSearchPerson" readOnly></a-input-search>
                        </a-form-model-item>
                    </a-col>
                    <a-col :md="4" :sm="24">
                        <a-form-model-item label="计划部门">
                            <a-input-search placeholder="请选择" v-model="form.planDept" @search="onSearchDept" readOnly></a-input-search>
                        </a-form-model-item>
                    </a-col>
                  
                    <a-col :md="4" :sm="24">
                        <a-form-model-item label="项目名称" prop='projectName'>
                            <a-input-search placeholder="请选择" v-model="form.projectName" @search="onSearchProject" readOnly></a-input-search>
                        </a-form-model-item>
                    </a-col>
                    <a-col :md="4" :sm="24">
                        <a-form-model-item label="项目编码" prop='projectCode'>
                            <a-input placeholder="请选择" v-model="form.projectCode" disabled></a-input>
                        </a-form-model-item>
                    </a-col>
                    <a-col :md="4" :sm="24">
                        <a-form-model-item label="业务类型" prop='type'>
                            <a-select v-model="form.type"  style='width:100%' >
                                <a-select-option value='家装'>家装</a-select-option>
                                <a-select-option value='工装'>工装</a-select-option>
                            </a-select>
                        </a-form-model-item>
                    </a-col>
                    <a-col :md="4" :sm="24">
                        <a-form-model-item label="制单人">
                            <a-input placeholder="自动" v-model="form.createBy" disabled></a-input>
                        </a-form-model-item>
                    </a-col>
                    <a-col :md="4" :sm="24">
                        <a-form-model-item label="审批人">
                            <a-input placeholder="自动" v-model="form.reviewer" disabled></a-input>
                        </a-form-model-item>
                    </a-col>
                    
                    <a-col :md="4" :sm="24">
                        <a-form-model-item label="工单号" prop='workNo'>
                            <a-input placeholder="请输入" v-model="form.workNo"></a-input>
                        </a-form-model-item>
                    </a-col>
                </a-row>
            </a-form-model>
        </div>
     </a-card>
     <a-card :bordered="false" class="three" style="margin-bottom:1%" :loading = 'loading'>
       <div class="table-operator">
            <a-button type="danger" size="small"  @click="addList">增行</a-button>
            <a-button size="small" @click="delectRow">删行</a-button>
       </div>
       <a-form-model ref="formRef" :model="formTable">
        <a-table
          ref="table"
          size="middle"
          bordered
          id='sonList'
          :columns="columns"
           rowKey="rowNo"
          :dataSource="formTable.dataSource"
          :pagination="false"
          :scroll="{ x: 4500, y: 300 }"
          :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
          @change="handleTableChange"
          >
            <span slot="quantityTitle" class="form-table-heard">
                    主数量
            </span>
            <span slot="unQuantityTitle" class="form-table-heard">
                    辅数量
            </span>
            <span slot="inventoryNameTitle" class="form-table-heard">
                    料品名称
            </span>
            <template slot="batch" slot-scope="text, record, index">
                <a-form-model-item prop="batch" class='sonItem'>
                    <a-input placeholder="请输入" v-model="record.batch"></a-input>
                </a-form-model-item>
            </template>
            <template slot="inventoryName" slot-scope="text, record, index">
                <a-form-model-item  :prop="'dataSource.'+index+'.inventoryName'" class='sonItem' :rules="rules1.inventoryName">
                    <a-input-search placeholder="请选择" v-model="record.inventoryName" @search="onSearchInventory(record)" readOnly></a-input-search>
                </a-form-model-item>
            </template> 
            <template slot="inventoryCode" slot-scope="text, record, index">
                <a-form-model-item prop="inventoryCode" class='sonItem'>
                    <a-input placeholder="请输入" v-model="record.inventoryCode"></a-input>
                </a-form-model-item>
            </template>
            <template slot="attribute" slot-scope="text, record, index">
                <a-form-model-item prop="attribute" class='sonItem'>
                    <a-input placeholder="请输入" v-model="record.attribute"></a-input>
                </a-form-model-item>
            </template>
            <template slot="unit" slot-scope="text, record, index">
                <a-form-model-item prop="unit" class='sonItem'>
                    <a-input placeholder="请输入" v-model="record.unit"></a-input>
                </a-form-model-item>
            </template>
            <template slot="auxiliaryUnit" slot-scope="text, record, index">
                <a-form-model-item prop="auxiliaryUnit" class='sonItem'>
                    <a-input placeholder="请输入" v-model="record.auxiliaryUnit"></a-input>
                </a-form-model-item>
            </template>
            <template slot="quantity" slot-scope="text, record, index">
                <a-form-model-item :prop="'dataSource.'+index+'.quantity'" class='sonItem' :rules="rules1.quantity">
                    <a-input placeholder="请输入" v-model="record.quantity" @blur="chengQuantity(record)"></a-input>
                </a-form-model-item>
            </template>
            <template slot="unQuantity" slot-scope="text, record, index">
                <a-form-model-item  :prop="'dataSource.'+index+'.unQuantity'" class='sonItem' :rules="rules1.unQuantity">
                    <a-input placeholder="请输入" v-model="record.unQuantity" @blur="chengQuantity(record)"></a-input>
                </a-form-model-item>
            </template>
            <template slot="rate" slot-scope="text, record, index">
                <a-form-model-item prop="rate" class='sonItem'>
                    <a-input placeholder="请输入" v-model="record.rate"></a-input>
                </a-form-model-item>
            </template>
            <template slot="specs" slot-scope="text, record, index">
                <a-form-model-item prop="specs" class='sonItem'>
                    <a-input placeholder="请输入" v-model="record.specs"></a-input>
                </a-form-model-item>
            </template>
            <template slot="model" slot-scope="text, record, index">
                <a-form-model-item prop="model" class='sonItem'>
                    <a-input placeholder="请输入" v-model="record.model"></a-input>
                </a-form-model-item>
            </template>
            <template slot="color" slot-scope="text, record, index">
                <a-form-model-item prop="color" class='sonItem'>
                    <a-input placeholder="请输入" v-model="record.color"></a-input>
                </a-form-model-item>
            </template>
            <template slot="fixedNum" slot-scope="text, record, index">
                <a-form-model-item prop="fixedNum" class='sonItem'>
                    <a-input placeholder="请输入" v-model="record.fixedNum"></a-input>
                </a-form-model-item>
            </template>
            <template slot="fixedLength" slot-scope="text, record, index">
                <a-form-model-item prop="fixedLength" class='sonItem'>
                    <a-input placeholder="请输入" v-model="record.fixedLength"></a-input>
                </a-form-model-item>
            </template>
            <template slot="widthHeight" slot-scope="text, record, index">
                <a-form-model-item prop="widthHeight" class='sonItem'>
                    <a-input placeholder="请输入" v-model="record.widthHeight"></a-input>
                </a-form-model-item>
            </template>
            <template slot="pieces" slot-scope="text, record, index">
                <a-form-model-item prop="pieces" class='sonItem'>
                    <a-input placeholder="请输入" v-model="record.pieces"></a-input>
                </a-form-model-item>
            </template>
            <template slot="meterWeight" slot-scope="text, record, index">
                <a-form-model-item prop="meterWeight" class='sonItem'>
                    <a-input placeholder="请输入" v-model="record.meterWeight"></a-input>
                </a-form-model-item>
            </template>
            <template slot="decorationLength" slot-scope="text, record, index">
                <a-form-model-item prop="decorationLength" class='sonItem'>
                    <a-input placeholder="请输入" v-model="record.decorationLength"></a-input>
                </a-form-model-item>
            </template>
            <template slot="windowNo" slot-scope="text, record, index">
                <a-form-model-item prop="windowNo" class='sonItem'>
                    <a-input placeholder="请输入" v-model="record.windowNo"></a-input>
                </a-form-model-item>
            </template>
            <template slot="exclusiveZone" slot-scope="text, record, index">
                <a-form-model-item prop="exclusiveZone" class='sonItem'>
                    <a-input placeholder="请输入" v-model="record.exclusiveZone"></a-input>
                </a-form-model-item>
            </template>
            <template slot="widthLength" slot-scope="text, record, index">
                <a-form-model-item prop="widthLength" class='sonItem'>
                    <a-input placeholder="请输入" v-model="record.widthLength"></a-input>
                </a-form-model-item>
            </template>
            <template slot="height" slot-scope="text, record, index">
                <a-form-model-item prop="height" class='sonItem'>
                    <a-input placeholder="请输入" v-model="record.height"></a-input>
                </a-form-model-item>
            </template>
            <template slot="buildingNumber" slot-scope="text, record, index">
                <a-form-model-item prop="buildingNumber" class='sonItem'>
                    <a-input placeholder="请输入" v-model="record.buildingNumber"></a-input>
                </a-form-model-item>
            </template>
            <template slot="framesTang" slot-scope="text, record, index">
                <a-form-model-item prop="framesTang" class='sonItem'>
                    <a-input placeholder="请输入" v-model="record.framesTang"></a-input>
                </a-form-model-item>
            </template>
            <template slot="framesCount" slot-scope="text, record, index">
                <a-form-model-item prop="framesCount" class='sonItem'>
                    <a-input placeholder="请输入" v-model="record.framesCount"></a-input>
                </a-form-model-item>
            </template>
            <template slot="leafCount" slot-scope="text, record, index">
                <a-form-model-item prop="leafCount" class='sonItem'>
                    <a-input placeholder="请输入" v-model="record.leafCount"></a-input>
                </a-form-model-item>
            </template>
            <template slot="semiClass" slot-scope="text, record, index">
                <a-form-model-item prop="semiClass" class='sonItem'>
                    <a-input placeholder="请输入" v-model="record.semiClass"></a-input>
                </a-form-model-item>
            </template>
            <template slot="area" slot-scope="text, record, index">
                <a-form-model-item prop="area" class='sonItem'>
                    <a-input placeholder="请输入" v-model="record.area"></a-input>
                </a-form-model-item>
            </template>
            <template slot="cuttingLength" slot-scope="text, record, index">
                <a-form-model-item prop="cuttingLength" class='sonItem'>
                    <a-input placeholder="请输入" v-model="record.cuttingLength"></a-input>
                </a-form-model-item>
            </template>
            <template slot="cuttingLeftDown" slot-scope="text, record, index">
                <a-form-model-item prop="cuttingLeftDown" class='sonItem'>
                    <a-input placeholder="请输入" v-model="record.cuttingLeftDown"></a-input>
                </a-form-model-item>
            </template>
            <template slot="cuttingRightTop" slot-scope="text, record, index">
                <a-form-model-item prop="cuttingRightTop" class='sonItem'>
                    <a-input placeholder="请输入" v-model="record.cuttingRightTop"></a-input>
                </a-form-model-item>
            </template>
            <template slot="series" slot-scope="text, record, index">
                <a-form-model-item prop="series" class='sonItem'>
                    <a-input placeholder="请输入" v-model="record.series"></a-input>
                </a-form-model-item>
            </template>
            <template slot="glassNumber" slot-scope="text, record, index">
                <a-form-model-item prop="glassNumber" class='sonItem'>
                    <a-input placeholder="请输入" v-model="record.glassNumber"></a-input>
                </a-form-model-item>
            </template>
        </a-table>
       </a-form-model>
    </a-card>
    <projectPopup ref="projectPopup" @okData="okData"></projectPopup>
    <inventoryPopup ref="inventoryPopup" @okData="okDataInvent"></inventoryPopup>
    <deparmentPopup ref="deparmentPopup" @okData="okDataDeparment"></deparmentPopup>
    <OperatorsPopup ref="OperatorsPopup" @okData="okDataOperators"></OperatorsPopup>
    <organizationPopup ref="organizationPopup" @okData="okDataOrganization"></organizationPopup>
    </a-modal>
  </template>
  <script>
  
      import { FormTypes } from '@/utils/JEditableTableUtil'
      import { JEditableTableModelMixin } from '@/mixins/JEditableTableModelMixin'
      import moment from "moment"
      import { httpAction ,getAction,postAction,putAction} from '@/api/manage'
      import projectPopup from '../../Popup/projectPopup'
      import inventoryPopup from '../../Popup/inventoryPopup.vue'
      import deparmentPopup from '../../Popup/deparmentPopup.vue'
      import OperatorsPopup from '../../Popup/OperatorsPopup.vue'
      import organizationPopup from '../../Popup/organizationPopup.vue'
      export default {
        name: 'materialProcurementAdd',
        mixins: [JEditableTableModelMixin],
        components: {
            projectPopup,
            inventoryPopup,
            deparmentPopup,
            OperatorsPopup,
            organizationPopup
        },
        data() {
          return {
            visible:false,
            form:{state:"开立"},
            defaultMethod:'add',
            formTable:{
                dataSource:[],
            },
            rules:{
              orgName: [
                { required: true, trigger: 'change' },
              ],
              orderDate:[
                { required: true, trigger: 'change' },
              ],
              projectName:[
                { required: true, trigger: 'change' },
              ],
              projectCode:[
                { required: true, trigger: 'change' },
              ],
              type:[
                { required: true, trigger: 'change' },
              ],
              workNo:[
                { required: true, trigger: 'change' },
              ],
            },
            rules1:{
                quantity:{required:true,message:"不可为空"},
                unQuantity:{required:true,message:"不可为空"},
                inventoryName:{required:true,message:"不可为空"},
            },
            loading:false,
            // ipagination:{},
            selectedRowKeys:[],
            selectedRows:[],
            columns: [
                {
                    title: '#',
                    dataIndex: '',
                    key: 'rowIndex',
                    width: 60,
                    align: "center",
                    customRender:function (t, r, index) {
                        return parseInt(index)+1;
                    }
                },
                {
                    title: '批次',
                    align:"center",
                    dataIndex: 'batch',
                    ellipsis: true,
                    scopedSlots: { customRender: 'batch' } 
                },
                {
                    title: '项目编码',
                    align:"center",
                    dataIndex: 'projectCode',
                    ellipsis: true,
                },
                {
                    title: '项目名称',
                    align:"center",
                    dataIndex: 'projectName',
                    ellipsis: true,
                },
                {
                    // title: '料品名称',
                    align:"center",
                    dataIndex: 'inventoryName',
                    ellipsis: true,
                    scopedSlots: { customRender: 'inventoryName' } ,
                    slots:{title:'inventoryNameTitle'},
                },
                {
                    title: '料品编码',
                    align:"center",
                    dataIndex: 'inventoryCode',
                    ellipsis: true,
                },
                {
                    title: '料品属性',
                    align:"center",
                    dataIndex: 'attribute',
                    ellipsis: true,
                },
                {
                    title: '计量单位',
                    align:"center",
                    dataIndex: 'unit',
                    ellipsis: true,

                },
                {
                    title: '辅计量单位',
                    align:"center",
                    dataIndex: 'auxiliaryUnit',
                    ellipsis: true,
                },
                {
                    // title: '主数量',
                    align:"center",
                    dataIndex: 'quantity',
                    ellipsis: true,
                    scopedSlots: { customRender: 'quantity' } ,
                    slots:{title:'quantityTitle'},

                },
                {
                    // title: '辅数量',
                    align:"center",
                    dataIndex: 'unQuantity',
                    ellipsis: true,
                    scopedSlots: { customRender: 'unQuantity' } ,
                    slots:{title:'unQuantityTitle'},
                },
                {
                    title: '换算率',
                    align:"center",
                    dataIndex: 'rate',
                    ellipsis: true,
                },
                {
                    title: '规格',
                    align:"center",
                    dataIndex: 'specs',
                    ellipsis: true,
                },
                {
                    title: '型号',
                    align:"center",
                    dataIndex: 'model',
                    ellipsis: true,
                },
                {
                    title: '颜色',
                    align:"center",
                    dataIndex: 'color',
                    ellipsis: true,
                    scopedSlots: { customRender: 'color' } 
                },
                {
                    title: '支数',
                    align:"center",
                    dataIndex: 'fixedNum',
                    ellipsis: true,
                    scopedSlots: { customRender: 'fixedNum' } 
                },
                {
                    title: '定尺',
                    align:"center",
                    dataIndex: 'fixedLength',
                    ellipsis: true,
                    scopedSlots: { customRender: 'fixedLength' } 
                },
                {
                    title: '宽/高',
                    align:"center",
                    dataIndex: 'widthHeight',
                    ellipsis: true,
                    scopedSlots: { customRender: 'widthHeight' } 
                },
                {
                    title: '片数',
                    align:"center",
                    dataIndex: 'pieces',
                    ellipsis: true,
                    scopedSlots: { customRender: 'pieces' } 
                },
                {   
                    title: '米重',
                    align:"center",
                    dataIndex: 'meterWeight',
                    ellipsis: true,
                    scopedSlots: { customRender: 'meterWeight' } 
                },
                {
                    title: '装饰面周长',
                    align:"center",
                    dataIndex: 'decorationLength',
                    ellipsis: true,
                    scopedSlots: { customRender: 'decorationLength' } 
                },
                {
                    title: '窗号',
                    align:"center",
                    dataIndex: 'windowNo',
                    ellipsis: true,
                    scopedSlots: { customRender: 'windowNo' } 

                },
               
                {   
                    title: '专用区',
                    align:"center",
                    dataIndex: 'exclusiveZone',
                    ellipsis: true,
                    scopedSlots: { customRender: 'exclusiveZone' } 
                },
                {
                    title: '宽度/长度',
                    align:"center",
                    dataIndex: 'widthLength',
                    ellipsis: true,
                    scopedSlots: { customRender: 'widthLength' } 
                },
                {
                    title: '高度',
                    align:"center",
                    dataIndex: 'height',
                    ellipsis: true,
                    scopedSlots: { customRender: 'height' } 
                },
                {
                    title: '楼号楼层',
                    align:"center",
                    dataIndex: 'buildingNumber',
                    ellipsis: true,
                    scopedSlots: { customRender: 'buildingNumber' } 
                },
                {
                    title: '樘数',
                    align:"center",
                    dataIndex: 'framesTang',
                    ellipsis: true,
                    scopedSlots: { customRender: 'framesTang' } 
                },
                {
                    title: '框数量',
                    align:"center",
                    dataIndex: 'framesCount',
                    ellipsis: true,
                    scopedSlots: { customRender: 'framesCount' } 
                },
                {
                    title: '扇数量',
                    align:"center",
                    dataIndex: 'leafCount',
                    ellipsis: true,
                    scopedSlots: { customRender: 'leafCount' } 
                 },
                {
                    title: '半成品分类',
                    align:"center",
                    dataIndex: 'semiClass',
                    ellipsis: true,
                    scopedSlots: { customRender: 'semiClass' } 
                },
                {
                    title: '面积',
                    align:"center",
                    dataIndex: 'area',
                    ellipsis: true,
                    scopedSlots: { customRender: 'area' } 
                },
                {
                    title: '切割长度',
                    align:"center",
                    dataIndex: 'cuttingLength',
                    ellipsis: true,
                    scopedSlots: { customRender: 'cuttingLength' } 
                },
                {
                    title: '切割角度左下',
                    align:"center",
                    dataIndex: 'cuttingLeftDown',
                    ellipsis: true,
                    scopedSlots: { customRender: 'cuttingLeftDown' } 
                },
                {
                    title: '切割角度右上',
                    align:"center",
                    dataIndex: 'cuttingRightTop',
                    ellipsis: true,
                    scopedSlots: { customRender: 'cuttingRightTop' } 
                },
                {
                    title: '系列',
                    align:"center",
                    dataIndex: 'series',
                    ellipsis: true,
                    scopedSlots: { customRender: 'series' } 
                },
                {
                    title: '玻璃编号',
                    align:"center",
                    dataIndex: 'glassNumber',
                    ellipsis: true,
                    scopedSlots: { customRender: 'glassNumber' } 
                },
          ],
          }
        },
        created() {
          
        },
        methods: {
            handleCancel(){
                this.visible=false
                this.defaultMethod='add'
                this.formTable.dataSource = [] 
                this.form={}
            },
            handleOk(){
                this.$refs.form.validate(success => {
                    if (success) {
                        this.$refs.formRef.validate(val => {
                            if (val) {
                                var mergedObj = this.form
                                mergedObj.madeMaterialRequisitionDetailList = this.formTable.dataSource
                                if(this.formTable.dataSource.length==0){
                                    this.$message.warning('请添加子表数据！')
                                }else{
                                    this.loading = true
                                    if(this.defaultMethod=='add'){
                                        postAction('/materialRequisition/madeMaterialRequisition/add', mergedObj).then((res) => {
                                            if (res.success) {
                                                this.$message.success('添加成功！');
                                                this.handleCancel()
                                                this.$emit('ok')
                                            } else {
                                                this.$message.error(res.message);
                                            }
                                        }).finally(() => {
                                            this.loading = false
                                        })
                                    }else{
                                        postAction('/materialRequisition/madeMaterialRequisition/edit', mergedObj).then((res) => {
                                            if (res.success) {
                                                this.$message.success('编辑成功！');
                                                this.handleCancel()
                                                this.$emit('ok')
                                            } else {
                                                this.$message.error(res.message);
                                            }
                                        }).finally(() => {
                                            this.loading = false
                                        })
                                    }
                                }
                            }
                        })
                    }
                })                
            },
            onSelectChange(selectedRowKeys, selectionRows) {
                this.selectedRowKeys = selectedRowKeys;
                this.selectedRows = selectionRows;
            },
            handleTableChange(){

            },
            onSearchPlanOrg(){
                this.$refs.organizationPopup.visible = true
                this.$refs.organizationPopup.getData()
            },
            //获取主表信息
            getMainData(id){
                getAction('/materialRequisition/madeMaterialRequisition/queryById',{id:id}).then(res=>{
                    if(res.success){
                       this.form=res.result
                       this.getSonData(this.form.id)
                    }else{
                      this.$message.error(res.message);
                    }
                })
            },
            //获取子表信息
            getSonData(id){
                getAction('/materialRequisition/madeMaterialRequisition/querymadeMaterialRequisitionDetailByMainId',{id:id}).then(res=>{
                    if(res.success){
                       this.formTable.dataSource =res.result
                       this.formTable.dataSource.map((item,index)=>{
                        item.rowNo =index+1
                       })
                       
                    }else{
                      this.$message.error(res.message);
                    }
                })
            },
            addList(){
                this.formTable.dataSource.unshift({rowNo: this.formTable.dataSource.length+1,projectCode:this.form.projectCode,projectName:this.form.projectName,rate:''})
            },
            onSearchProject(){
                if(this.form.orgName&&this.form.orgName!==''){
                    this.$refs.projectPopup.visible = true
                    this.$refs.projectPopup.getData(this.form.planOrg)
                }else{
                    this.$message.warning("请选择组织！")
                }
            },
            onSearchDept(){
                if(this.form.orgName&&this.form.orgName!==''){
                    this.$refs.deparmentPopup.visible = true
                    this.$refs.deparmentPopup.getData(this.form.planOrg)
                }else{
                    this.$message.warning("请选择组织！")
                }
                
            },
            onSearchPerson(){
                if(this.form.orgName&&this.form.orgName!==''){
                    this.$refs.OperatorsPopup.visible = true
                    this.$refs.OperatorsPopup.getData(this.form.planOrg)
                }else{
                    this.$message.warning("请选择组织！")
                }
            },
            onSearchInventory(record){
                if(this.form.orgName&&this.form.orgName!==''){
                    this.$refs.inventoryPopup.visible = true
                    this.$refs.inventoryPopup.getData(this.form.planOrg )
                    this.$refs.inventoryPopup.record=record
                }else{
                    this.$message.warning("请选择组织！")
                }
            },
            okData(data){
                this.$set(this.form,'projectCode',data.Code)
                this.$set(this.form,'projectName',data.Name)
                this.$set(this.form,'project',data.ID)
                this.formTable.dataSource.map(item=>{
                    item.projectCode = data.Code
                    item.projectName = data.Name
                })
                if(this.form.projectName&&this.form.projectName!==''){
                    this.$refs.form.clearValidate(['projectName']);
                }
                if(this.form.projectCode&&this.form.projectCode!==''){
                    this.$refs.form.clearValidate(['projectCode']);
                }
            },
            chengQuantity(record){
                if(record.quantity&&record.quantity!==''&&record.unQuantity&&record.unQuantity!==''){
                    record.rate = ''
                    var num = (Number(record.unQuantity)/Number(record.quantity)).toFixed(2)
                    this.$set(record,'rate',num)
                }else{
                    record.rate = ''
                }
            },
            okDataInvent(data,recoerd){
              this.$set(recoerd,'inventoryCode',data.Code)
              this.$set(recoerd,'inventoryName',data.Name)
              this.$set(recoerd,'specs',data.SPECS)
              this.$set(recoerd,'attribute',data.Code1 )
              this.$set(recoerd,'unit',data.unit )
              this.$set(recoerd,'auxiliaryUnit',data.auxiliaryUnit )
              this.$set(recoerd,'inventory',data.ID )
              this.$refs.formRef.clearValidate(['inventoryName']);
            },
            okDataDeparment(data){
                this.$set(this.form,'planDept',data.Name)
                this.$set(this.form,'planDeptId',data.ID)
            },
            okDataOperators(data){
                this.$set(this.form,'salesperson',data.Name)
                this.$set(this.form,'salespersonId',data.ID)
            },
            okDataOrganization(data){
                this.$set(this.form,'orgName',data.Name)
                this.$set(this.form,'orgCode',data.Code)
                this.$set(this.form,'planOrg',data.ID)
                if(this.form.orgName&&this.form.orgName!==''){
                    this.$refs.form.clearValidate(['orgName']);
                }
            },
            delectRow(){
                if( this.selectedRowKeys.length==0){
                    this.$message.warning('请勾选子表数据！')
                }else{
                    this.selectedRowKeys.map(event=>{
                        this.formTable.dataSource =  this.formTable.dataSource.filter( (x)=> {return x.rowNo !== event});
                    })
                }
            },

        }
      }
  </script>
  
  <style scoped lang="less">
    /* @import '~@assets/less/common.less' */
    /deep/.ant-input{
        height:29px;
    }
    /deep/.ant-select-selection--single {
        height: 29px;
    }
    /deep/.ant-select{
        font-size: 12px;
    }
    /deep/.ant-form label{
        font-size: 12px;
    }
    /deep/.table-page-search-wrapper .ant-form-inline .ant-form-item{
        margin-bottom:9px
    }
    /deep/.moddle>.ant-card-body{
        padding-bottom:0px;
        padding-top: 12px;
    }
    /deep/.top>.ant-card-body{
        padding-bottom:0px;
        padding-top: 12px;
    }
    /deep/.ant-btn{
        height:28px
    }
    /deep/.ant-modal-body{
        padding-bottom: 0px;
        padding-top: 0px;
    }
    // /deep/.ant-modal-body{
    //     background: #f0f2f5;
    // }
    /deep/.ant-modal-content{
        background: #f0f2f5;
    }
    /deep/.ant-card-body .table-operator {
        margin-bottom: 0px;
    }
    /deep/.three>.ant-card-body{
        padding-bottom:12px;
        padding-top: 12px;
    }
    /deep/.bottom>.ant-card-body{
        padding-bottom:0px;
        padding-top: 12px;
    }

    /deep/.ant-calendar-picker{
        min-width: 0px !important;  
    }
    /deep/.sonItem {
        margin-bottom:0px !important
    }
    /deep/#sonList>.ant-spin-nested-loading>.ant-spin-container>.ant-table>.ant-table-content>.ant-table-scroll>.ant-table-body>.ant-table-fixed>.ant-table-tbody > tr > td {
        padding: 0px 8px !important;
    }
     // 表单校验隐藏提示文字
    //  /deep/.ant-form-explain{
    //   display:none
    // }
    .form-table-heard:before {
        content:'*';
        color:red
   }
   /deep/.ant-form-explain, .ant-form-split {
        display: none;
   }
  </style>