<template>
  <a-modal 
    :visible="visible" 
    :mask-closable="false" 
    :title="modalTitle" 
    :width="1308"
    :footer="null" 
    destroyOnClose
    @cancel="closeTheModal">

    <a-row :gutter="8" style="height: 780px;">
      <a-col :span="8" id="col1" style="overflow-y: auto;height: 100%;">
        <a-card title="总体数据" :bodyStyle="{padding:'8px'}">
          <a-table :columns="populationColumn" :dataSource="populationList" :pagination="false" :scroll="{x:true}" bordered>
            <template slot="serial" slot-scope="text, record, index0">
              {{ index0 + 1 }}
            </template>
            <template slot="valuetype" slot-scope="text, record, index0">
              <!-- 公共ID展示 -->
              <template v-if="record.translate == '#DBID'">
                {{ record.value }}
              </template>
              <template v-if="record.translate == '仿真模型'">
                <a-button type="link" @click="dataModelVisible = true">编辑</a-button>
              </template>
              <!-- 三维立体模型 -->
              <template v-if="record.translate == '三维模型'">
                <template v-if="opType == 1">
                  <input
                    name="upive"
                    id="upload_ive"
                    type="file"
                    data-options="buttonText:'选择',prompt:'请选择文件...'"
                    @change="uploadIVE">
                </template>
                <template v-if="opType == 2">
                  <input
                    name="upive"
                    id="upload_ive"
                    type="file"
                    data-options="buttonText:'选择',prompt:'请选择文件...'"
                    @change="uploadIVE">
                </template>
                <template v-if="opType == 3">
                  <input
                    name="upive"
                    id="upload_ive"
                    type="file"
                    data-options="buttonText:'选择',prompt:'请选择文件...'"
                    @change="uploadIVE">
                </template>
                <template v-if="opType == 4">
                  
                </template>
              </template>
              <!-- 判断展示类型为：详情 -->
              <template v-if="opType == 4">
                {{ record.value }}
                <!-- <template v-if="text == 'combobox'">
                  <template v-if="record.fieldname == 'Type'">
                    {{ record.value }}
                  </template>
                  <template v-if="record.fieldname == 'Category'">
                    {{ record.value }}
                  </template>
                </template>
                <template v-else-if="text == 'combotree'">
                  <span v-for="(item1,index1) in treeData" :key="index1">
                    <span v-if="item1.key == record.value">
                      {{ item1.title }}
                    </span>
                    <span v-for="(item2,index2) in item1.children" :key="index2">
                      <span v-if="item2.key == record.value">
                        {{ item2.title }}
                      </span>
                      <span v-for="(item3,index3) in item2.children" :key="index3">
                        <span v-if="item3.key == record.value">
                          {{ item3.title }}
                        </span>
                      </span>
                    </span>
                  </span>
                </template>
                <template v-else-if="text == 'checkbox'">
                  <span v-if="record.value == 1">是</span>
                  <span v-if="record.value == 0">否</span>
                </template>
                <template v-else>
                  <template v-if="record.translate != '#DBID'">
                    {{ record.value }}
                  </template>
                </template> -->
              </template>
              <!-- 判断展示类型为：除 详情 以外的其它类型 -->
              <template v-else>
                <template v-if="text == 'text'">
                  <a-input size="small" style="width: 187px !important;" v-model="record.value" />
                </template>
                <template v-if="text == 'passwordbox'">
                  <a-input type="password" size="small" style="width: 187px !important;" v-model="record.value" />
                </template>
                <template v-if="text == 'combobox'">
                  <a-select 
                    size="small" 
                    style="width: 187px !important;" 
                    showSearch 
                    option-filter-prop="children" 
                    :filter-option="filterOption"
                    v-model="record.value">
                    <template v-if="record.translate.indexOf('国') != -1">
                      <a-select-option v-for="(item,index) in dicData.operatorcountry" :key="index" :value="item.id.toString()" :title="item.description">{{ item.description }}</a-select-option>
                    </template>
                    <template v-if="record.translate.indexOf('军种') != -1">
                      <a-select-option v-for="(item,index) in dicData.operatorservice" :key="index" :value="item.id.toString()" :title="item.description">{{ item.description }}</a-select-option>
                    </template>
                    <template v-if="record.translate.indexOf('属性') != -1">
                      <a-select-option v-for="(item,index) in dicData.aircraftcode" :key="index" :value="item.id.toString()" :title="item.description">{{ item.description }}</a-select-option>
                    </template>
                    <template v-if="record.translate.indexOf('有效目标') != -1">
                      <a-select-option v-for="(item,index) in dicData.dicweapontarget" :key="index" :value="item.id.toString()" :title="item.description">{{ item.description }}</a-select-option>
                    </template>
                    <template v-if="record.translate.indexOf('燃油数据') != -1">
                      <a-select-option v-for="(item,index) in dicData.fuel" :key="index" :value="item.id.toString()" :title="item.description">{{ item.description }}</a-select-option>
                    </template>
                    <template v-if="record.translate.indexOf('物理尺寸级别') != -1">
                      <a-select-option v-for="(item,index) in dicData.aircraftfacilityphysicalsize" :key="index" :value="item.id.toString()" :title="item.description">{{ item.description }}</a-select-option>
                    </template>
                    <template v-if="record.translate.indexOf('航空保障类型') != -1">
                      <a-select-option v-for="(item,index) in dicData.aircraftfacilitytype" :key="index" :value="item.id.toString()" :title="item.description">{{ item.description }}</a-select-option>
                    </template>
                    <template v-if="record.translate.indexOf('装甲') != -1">
                      <a-select-option v-for="(item,index) in dicData.armortype" :key="index" :value="item.id.toString()" :title="item.description">{{ item.description }}</a-select-option>
                    </template>
                    <template v-if="record.translate.indexOf('跑道长度') != -1">
                      <a-select-option v-for="(item,index) in dicData.aircraftrunwaylength" :key="index" :value="item.id.toString()" :title="item.description">{{ item.description }}</a-select-option>
                    </template>
                    <template v-if="record.translate.indexOf('驾驶员视线等级') != -1">
                      <a-select-option v-for="(item,index) in dicData.aircraftcockpitvisibility" :key="index" :value="item.id.toString()" :title="item.description">{{ item.description }}</a-select-option>
                    </template>
                    <!-- 飞机 -->
                    <template v-if="entityType == 'Aircraft'">
                      <template v-if="record.translate == '类别'">
                        <a-select-option v-for="(item,index) in dicData.aircraftcategory" :key="index" :value="item.id.toString()" :title="item.description">{{ item.description }}</a-select-option>
                      </template>
                      <template v-if="record.translate == '类型'">
                        <a-select-option v-for="(item,index) in dicData.aircrafttype" :key="index" :value="item.id.toString()" :title="item.description">{{ item.description }}</a-select-option>
                      </template>
                    </template>
                    <!-- 水面潜艇 -->
                    <template v-if="entityType == 'Ship'">
                      <template v-if="record.translate == '类别'">
                        <a-select-option v-for="(item,index) in dicData.shipcategory" :key="index" :value="item.id.toString()" :title="item.description">{{ item.description }}</a-select-option>
                      </template>
                      <template v-if="record.translate == '类型'">
                        <a-select-option v-for="(item,index) in dicData.shiptype" :key="index" :value="item.id.toString()" :title="item.description">{{ item.description }}</a-select-option>
                      </template>
                      <template v-if="record.translate == '停靠设施级别'">
                        <a-select-option v-for="(item,index) in dicData.dicshipphysicalsize" :key="index" :value="item.id.toString()" :title="item.description">{{ item.description }}</a-select-option>
                      </template>
                      <template v-if="record.translate == '货物_类型'">
                        <a-select-option v-for="(item,index) in dicData.dicshipcargorytype" :key="index" :value="item.id.toString()" :title="item.description">{{ item.description }}</a-select-option>
                      </template>
                    </template>
                    <!-- 潜艇 -->
                    <template v-if="entityType == 'Submarine'">
                      <template v-if="record.translate == '类别'">
                        <a-select-option v-for="(item,index) in dicData.dicsubmarinecategory" :key="index" :value="item.id.toString()" :title="item.description">{{ item.description }}</a-select-option>
                      </template>
                      <template v-if="record.translate == '类型'">
                        <a-select-option v-for="(item,index) in dicData.dicsubmarinetype" :key="index" :value="item.id.toString()" :title="item.description">{{ item.description }}</a-select-option>
                      </template>
                      <template v-if="record.translate == '停靠设施级别'">
                        <a-select-option v-for="(item,index) in dicData.dicsubmarinephysicalsize" :key="index" :value="item.id.toString()" :title="item.description">{{ item.description }}</a-select-option>
                      </template>
                    </template>
                    <!-- 地面兵力与设施 -->
                    <template v-if="entityType == 'Facility'">
                      <template v-if="record.translate == '类别'">
                        <a-select-option v-for="(item,index) in dicData.dicfacilitycategory" :key="index" :value="item.id.toString()" :title="item.description">{{ item.description }}</a-select-option>
                      </template>
                      <template v-if="record.translate == '类型'">
                        <a-select-option v-for="(item,index) in dicData.diccargorytype" :key="index" :value="item.id.toString()" :title="item.description">{{ item.description }}</a-select-option>
                      </template>
                    </template>
                    <!-- 卫星 -->
                    <template v-if="entityType == 'Satellite'">
                      <template v-if="record.translate == '类别'">
                        <a-select-option v-for="(item,index) in dicData.satellitecategory" :key="index" :value="item.id.toString()" :title="item.description">{{ item.description }}</a-select-option>
                      </template>
                      <template v-if="record.translate == '类型'">
                        <a-select-option v-for="(item,index) in dicData.satellitetype" :key="index" :value="item.id.toString()" :title="item.description">{{ item.description }}</a-select-option>
                      </template>
                    </template>
                    <!-- 武器 -->
                    <template v-if="entityType == 'Weapon'">
                      <template v-if="record.translate == '类型'">
                        <a-select-option v-for="(item,index) in dicData.weapontype" :key="index" :value="item.id.toString()" :title="item.description">{{ item.description }}</a-select-option>
                      </template>
                      <template v-if="record.translate == '生产年代'">
                        <a-select-option v-for="(item,index) in dicData.weapongeneration" :key="index" :value="item.id.toString()" :title="item.description">{{ item.description }}</a-select-option>
                      </template>
                      <template v-if="record.translate == '货物_类型'">
                        <a-select-option v-for="(item,index) in dicData.dicshipcargorytype" :key="index" :value="item.id.toString()" :title="item.description">{{ item.description }}</a-select-option>
                      </template>
                    </template>
                  </a-select>
                </template>
                <template v-if="text == 'combostr'">
                  <!-- 只有武器下的所属国家用到了这个 -->
                  <a-select 
                    size="small"
                    mode="multiple"
                    style="width: 187px !important;" 
                    showSearch 
                    option-filter-prop="children" 
                    :filter-option="filterOption"
                    @focus="getTableRowIndex(index0)"
                    v-model="record.value">
                    <template v-if="record.translate.indexOf('国') != -1">
                      <a-select-option v-for="(item,index) in dicData.operatorcountry" :key="index" :value="item.id.toString()" :title="item.description">{{ item.description }}</a-select-option>
                    </template>
                  </a-select>
                </template>
                <template v-if="text == 'combotree'">
                  <a-tree-select
                    v-model="record.value"
                    size="small"
                    style="width: 187px !important;"
                    :dropdown-style="{ maxHeight: '400px', overflow: 'auto', width: '187px' }"
                    :tree-data="treeData"
                    tree-default-expand-all
                  >
                  </a-tree-select>
                </template>
                <template v-if="text == 'int'">
                  <a-input-number :default-value="1" size="small" style="width: 187px !important;" v-model="record.value" />
                </template>
                <template v-if="text == 'double'">
                  <a-input-number :default-value="1" :precision="10" size="small" style="width: 187px !important;" v-model="record.value" />
                </template>
                <template v-if="text == 'datebox'">
                  <a-date-picker @change="handleDateBoxChange" @focus="getTableRowIndex(index0)" size="small" style="width: 187px !important;" v-model="record.value" />
                </template>
                <template v-if="text == 'datetime' || text == 'datetimespinner'">
                  <a-date-picker 
                    show-time 
                    @change="handleDateBoxChange" 
                    @focus="getTableRowIndex(index0)" 
                    size="small" 
                    style="width: 187px !important;" 
                    v-model="record.value" />
                </template>
                <template v-if="text == 'calendar'">
                  <a-calendar :fullscreen="false" @panelChange="handleCalendarPanelChange" size="small" style="width: 187px !important;" v-model="record.value" />
                </template>
                <template v-if="text == 'timespinner'">
                  <a-time-picker
                    use24-hours 
                    @change="handleTimeBoxChange" 
                    @focus="getTableRowIndex(index0)" 
                    size="small" 
                    style="width: 187px !important;"
                    v-model="record.value" />
                </template>
                <template v-if="text == 'textarea'">
                  <a-textarea size="small" style="width: 187px !important;" v-model="record.value" />
                </template>
                <template v-if="text == 'checkbox'">
                  <a-checkbox 
                    @change="handleCheckBoxChange" 
                    @focus="getTableRowIndex(index0)"
                    v-model="record.value"
                    :defaultChecked="record.value == 1"
                  ></a-checkbox>
                </template>
                <template v-if="text == 'texticon'">
                  <a-input size="small" style="width: 187px !important;" v-model="record.value" />
                </template>
              </template>
            </template>
          </a-table>
        </a-card>
      </a-col>
      <a-col :span="16" id="col2" style="overflow-y: auto;height: 100%;">
        <a-card title="相关图例" style="margin-bottom: 10px;">
          <a-tabs default-active-key="1" @change="handleChangeTabPane1">
            <a-tab-pane tab="图片" key="1">
              <a-spin :spinning="spinningBase64">
                <template v-if="opType == 1">
                  <!-- 上传 + 暂无图片 -->
                  <input
                    accept="image/*"
                    name="upimage"
                    id="upload_file"
                    type="file"
                    data-options="buttonText:'选择',prompt:'请选择文件...'"
                    @change="gen_base64" />
                  <br/>
                  <img src="/images/6.png" alt="" mode="widthFix" style="width: 80%;" v-if="!modelImgSrc" />
                  <img
                    :src="'data:image/jpeg;base64,' + modelImgSrc"
                    alt=""
                    mode="widthFix"
                    onerror="javascript:this.src='/images/6.png';"
                    style="width: 80%;"
                    v-else />
                </template>
                <template v-if="opType == 2">
                  <!-- 上传 + 老图片 -->
                  <input
                    accept="image/*"
                    name="upimage"
                    id="upload_file"
                    type="file"
                    data-options="buttonText:'选择',prompt:'请选择文件...'"
                    @change="gen_base64" />
                  <br/>
                  <img :src="'data:image/jpeg;base64,' + modelImgSrc" alt="" mode="widthFix" onerror="javascript:this.src='/images/6.png';" style="width: 80%;" />
                </template>
                <template v-if="opType == 3">
                  <!-- 上传 + 老图片 -->
                  <input
                    accept="image/*"
                    name="upimage"
                    id="upload_file"
                    type="file"
                    data-options="buttonText:'选择',prompt:'请选择文件...'"
                    @change="gen_base64" />
                  <br/>
                  <img :src="'data:image/jpeg;base64,' + modelImgSrc" alt="" mode="widthFix" onerror="javascript:this.src='/images/6.png';" style="width: 80%;" />
                </template>
                <template v-if="opType == 4">
                  <!-- 老图片 -->
                  <img :src="'data:image/jpeg;base64,' + modelImgSrc" alt="" mode="widthFix" onerror="javascript:this.src='/images/6.png';" style="width: 80%;" />
                </template>
              </a-spin>
            </a-tab-pane>
            <a-tab-pane tab="仿真模型图标" key="2">
              <img 
                :src="dataModel[0].DataModelIcon" 
                alt="" 
                mode="widthFix" 
                onerror="javascript:this.src='/images/6.png';" 
                style="width: 80%;" 
                v-if="dataModel.length > 0 && dataModel[0].DataModelIcon" />
            </a-tab-pane>
          </a-tabs>
        </a-card>
        <a-card title="装备配件">
          <a-tabs>
            <a-tab-pane tab="装配组件" key="1">
              <a-tabs default-active-key="1" @change="handleChangeTabPane2">
                <a-tab-pane :tab="item.translate" v-for="(item,index) in equiAccessList" :key="index">
                  <div class="table-operator" v-if="opType != 4">
                    <a-button icon="plus" style="margin-right: 10px;" @click="addComponentDlg(item)">添加</a-button>
                  </div>
                  <template v-if="opType == 4">
                    <a-table 
                      :columns="equiAccessTabsDataUse.cloumns" 
                      :dataSource="equiAccessTabsDataUse.data" 
                      :pagination="false" 
                      :scroll="{x:true}" 
                      :customRow="rowDetailInfoData"
                      bordered>
                      <template slot="frequency" slot-scope="text">
                        <span v-for="(item1,index1) in dicData.aircraftcode" :key="index1">
                          <span v-if="item1.id == text">
                            {{ item1.description }}
                          </span>
                        </span>
                      </template>
                    </a-table>
                  </template>
                  <template v-else>
                    <a-table 
                      :columns="equiAccessTabsDataUse.cloumns && equiAccessTabsDataUse.cloumns.length> 0 ? [...equiAccessTabsDataUse.cloumns, {title:'操作', width: 120, align:'center', fixed: 'right',scopedSlots:{customRender:'action'}}]:[]" 
                      :dataSource="equiAccessTabsDataUse.data" 
                      :pagination="false" 
                      :scroll="{x:true}" 
                      :rowKey="record=>record.id"
                      :customRow="rowDetailInfoData"
                      bordered>
                      <template slot="frequency" slot-scope="text">
                        <span v-for="(item1,index1) in dicData.aircraftcode" :key="index1">
                          <span v-if="item1.id == text">
                            {{ item1.description }}
                          </span>
                        </span>
                      </template>
                      <template slot="action" slot-scope="text,record">
                        <a-popconfirm placement="top" title="是否确认删除" @confirm.stop="removeComponentInfo(item, record)">
                          <a-button type="link" size="small" @click.stop="()=>{}" >删除</a-button>
                        </a-popconfirm>
                      </template>
                    </a-table>
                  </template>
                </a-tab-pane>
              </a-tabs>
            </a-tab-pane>
            <a-tab-pane tab="扩展属性" key="2" v-if="entityType == 'Weapon' || entityType == 'Comm'">
              <template v-if="entityType == 'Weapon'">

              </template>
              <template v-if="entityType == 'Comm'">

              </template>
            </a-tab-pane>
          </a-tabs>
          
        </a-card>
      </a-col>
    </a-row>
    <div style="display: flex;justify-content: flex-end;align-items: center;margin-top: 30px;">
      <template v-if="opType == 4">
        <a-button @click="closeTheModal">关闭</a-button>
      </template>
      <template v-else>
        <a-button style="margin-right: 10px;" @click="closeTheModal">取消</a-button>
        <a-button type="primary" @click="handleSubmit">保存</a-button>
      </template>
    </div>
    <ComponentDlg
      :visible="componentDlgObj.visible"
      :modalTitle="componentDlgObj.title"
      :entityType="entityType"
      :entityId="entityId"
      :parentId="parentId"
      :dicData="dicData"
      :componentType="componentDlgObj.componentType"
      :componentTypeName="componentDlgObj.componentTypeName"
      @closeTheModal="clsComponentDlg" />
    <DetailComponentDlg 
      :visible="detailComponmObj.visible"
      :entityType="detailComponmObj.entityType"
      :guid="detailComponmObj.guid"
      :id="detailComponmObj.id"
      @closeModal="closeDetailComponmDlg"
    />
    <ComponentDlg
      :visible="dataModelVisible"
      modalTitle="3D仿真模型"
      :entityType="entityType"
      :entityId="parentTableRowId"
      :parentId="parentId"
      :dicData="dicData"
      componentType="AircraftDataModel"
      componentTypeName="3D仿真模型"
      @closeTheModal="handleCloseDataModel" />
  </a-modal>
</template>

<script>
import {
  deleteAction,
  getAction,
  postAction,
  postAction1
} from '@/api/manage'
import { componentEditlistData } from './componentEditlistData.js'
import ComponentDlg from './componentDlg.vue'
import DetailComponentDlg from './detailComponentDlg.vue'
export default {
    name: 'InfoDataModal',
    data() {
        return {
            newId: '',
            populationList: [],
            populationColumn: [
                {
                    title: '',
                    scopedSlots: {
                        customRender: 'serial'
                    }
                },
                {
                    title: '参数',
                    key: 'translate',
                    dataIndex: 'translate',
                    scopedSlots: {
                    customRender: 'translate'
                    }
                },
                {
                    title: '类型',
                    key: 'valuetype',
                    dataIndex: 'valuetype',
                    scopedSlots: {
                    customRender: 'valuetype'
                    }
                }
            ],
            populationTableRowIndex: '',
            equiAccessList: [],
            treeData: [],
            Guid: '',
            equiAccessTabsData: [],
            activeKey: 0,
            equiAccessTabsDataUse: {},
            selectedRowKeys: [],
            componentDlgObj: {
              visible: false,
              title: '',
              componentType: '',
              componentTypeName: ''
            },
            modelImgSrc: '',
            spinningBase64: false,
            detailComponmObj: {},
            rowDetailInfoData: record => ({
              on: {
                click: () => {
                  const arr1 = []
                  arr1.push(record.id)
                  this.selectedRowKeys = arr1
                  this.detailComponmFunc(record)
                }
              }
            }),
            dataModel:[],
            dataModelVisible:false,
            // 删除按钮guid参数
            editGuid: null
        }
    },
    props:{
        visible: {
            type: Boolean,
            default: false
        },
        modalTitle: {
            type: String,
            default: ''
        },
        entityType: {
            type: String,
            default: ''
        },
        parentId: {
            type: Number,
            default: 0
        },
        parentTableRowId: {
            type: Number,
            default: 0
        },
        dicData: {
            type: Object,
            default: () => {}
        },
        opType: {
            type: Number,
            default: 0,//1新增 2复制 3编辑 4详情
        },
    },
    components: {
      ComponentDlg,
      DetailComponentDlg
    },
    computed: {
      entityId () {
        var id = ''
        if (this.opType == 1 || this.opType == 2) {
          id = this.newId
        } else if (this.opType == 3) {
          id = this.parentTableRowId
        }
        return id
      }
    },
    watch:{
        visible(val) {
            if(val) {
                console.log(this.entityType,'this.entityType')
                this.getTreeNode()
                this.getpopulationList()
                this.getTableList()
                if(this.opType == 2 || this.opType == 3 || this.opType == 4) {
                  // this.getImgData()
                }
            }
        }
    },
    methods:{
        getTreeNode() {
            getAction('/basedata/entity/getTreeNode?parentId=' + this.parentId, {}).then((res) => {
                this.treeData = res.data
            })
        },
        getImgData() {
          const entityType1 = this.entityType.toLowerCase()
          this.spinningBase64 = true
          getAction('/basedata/'+ entityType1 + '/getimglist?Id=' + this.parentTableRowId,{}).then((res) => {
            this.spinningBase64 = false
            if (res.data.image) {
              this.modelImgSrc = res.data.image
            }
          })
        },
        getpopulationList() {
            getAction('/dbdata/aircraft/getInfoList',{
                tableName: 'Data' + this.entityType
            }).then((res) => {
                if(this.opType == 1) {
                  // 新增
                  const entityType1 = this.entityType.toLowerCase()
                  getAction('/basedata/'+entityType1+'/getNewId',{}).then((res2) => {
                    this.newId = res2.data
                    for(const i in res.data) {
                        if(this.entityType == 'Weapon') {
                          if(res.data[i].fieldname == 'OperatorCountry') {
                            res.data[i].value = [] // 此法去除国家控件框中默认的一个空标签
                          }
                        }
                        if(res.data[i].translate == '#DBID') {
                            res.data[i].value = res2.data //为了提交时统一取值
                        }
                        if (res.data[i].valuetype == 'combotree' && res.data[i].translate.indexOf('类') != -1) {
                          res.data[i].value = this.parentId // 将父组件里第一步选择的模型分类，在添加时自动带入进来
                        }
                    }
                    this.populationList = res.data
                    console.log(this.populationList,'this.populationList')
                  })
                } else if(this.opType == 2) {
                  // 复制
                  const entityType1 = this.entityType.toLowerCase()
                  getAction('/basedata/'+entityType1+'/getInfo?id='+this.parentTableRowId,{ doFlag: true }).then((res2) => {
                    getAction('/basedata/'+entityType1+'/getNewId',{}).then((res3) => {
                      this.newId = res3.data
                      for(const i in res.data) {
                        for(const j in res2.data) {
                          if(j == res.data[i].fieldname) {
                            console.log(res.data[i],'res.data[i]')
                            res.data[i].value = res2.data[j]
                          }
                          if(res.data[i].translate == '#DBID') {
                            res.data[i].value = res3.data //为了提交时统一取值
                          }
                        }
                      }
                      this.populationList = res.data
                    })
                  })
                } else if(this.opType == 3) {
                  // 编辑
                  // 回显数据
                  const entityType1 = this.entityType.toLowerCase()
                  getAction('/basedata/'+entityType1+'/getInfo?id='+this.parentTableRowId,{ doFlag: true }).then((res2) => {
                    for(const i in res.data) {
                      for(const j in res2.data) {
                        if(j == res.data[i].fieldname) {
                          console.log(res.data[i],'res.data[i]')
                          res.data[i].value = res2.data[j]
                        }
                      }
                    }
                    console.log(res.data)
                    this.populationList = res.data
                  })
                } else if(this.opType == 4) {
                  // 详情
                  // 回显数据
                  const entityType1 = this.entityType.toLowerCase()
                  getAction('/basedata/'+entityType1+'/getInfo?id='+this.parentTableRowId,{}).then((res2) => {
                    for(const i in res.data) {
                      for(const j in res2.data) {
                        if(j == res.data[i].fieldname) {
                          console.log(res.data[i],'res.data[i]3399')
                          res.data[i].value = res2.data[j]
                        }
                      }
                    }
                    this.populationList = res.data
                    console.log(this.populationList, '详情')
                  })
                }
            })
        },
        getTableRowIndex(index) {
          this.populationTableRowIndex = index
        },
        handleDateBoxChange(val,dateStr) {
          for(const i in this.populationList) {
            if(i == this.populationTableRowIndex) {
              this.populationList[i].value = dateStr
            }
          }
        },
        handleTimeBoxChange(val,timeStr) {
          for(const i in this.populationList) {
            if(i == this.populationTableRowIndex) {
              this.populationList[i].value = timeStr
            }
          }
        },
        handleCheckBoxChange(e) {
          console.log(e.target.checked)
          for(const i in this.populationList) {
            if(i == this.populationTableRowIndex) {
              if(e.target.checked) {
                this.populationList[i].value = 1
              } else {
                this.populationList[i].value = 0
              }
            }
          }
        },
        getTableList() {
            getAction('/dbdata/aircraft/getTableList',{
              entityType: this.entityType
            }).then((res) => {
              this.equiAccessList = res.data
              if(this.opType == 1 || this.opType == 2 || this.opType == 3) {
                this.equiAccessTabsDataUse.type = res.data[0].id
                this.equiAccessTabsDataUse.typeName = res.data[0].translate
              }
              if(this.opType == 3 || this.opType == 4) {
                const entityType1 = this.entityType.toLowerCase()
                getAction('/basedata/'+entityType1+'/getInfo?id='+this.parentTableRowId,{}).then((res1) => {
                  if(res1.data.Guid) {
                    this.editGuid = res1.data.Guid
                  }
                  for(const i in res.data) {
                    for(const j in res1.data) {
                      if(j == 'Guid') {
                        this.Guid = res1.data[j]
                        this.accordingEquiAccessItemGetData(res.data[i].id,res.data[i].translate,res1.data[j])
                      }
                    }
                  }
                  getAction('basedata/aircraft/getaircraftdatamodellist',{guid: res1.data.Guid}).then(modelRes=> {
                    this.dataModel = modelRes.data
                  })
                })
              }
            })
        },
        accordingEquiAccessItemGetData(id,typeName,Guid) {
          const id1 = id.toLowerCase()
          const request_Url_last_str = id1 + 'list' // 这个值就是到时候列表存的值
          const request_Url_last_str1 = 'get' + request_Url_last_str
          const request_Url_center_str = this.entityType.toLowerCase()
          const request_Url = '/basedata/' + request_Url_center_str + '/' + request_Url_last_str1
          let columns = []
          console.log('走走',id)
          for(const i in componentEditlistData) {
            if(componentEditlistData[i].type == id) {
              columns = componentEditlistData[i].cols
            }
          }
          getAction(request_Url,{
            guid: Guid
          }).then((res) => {
            if(res.code == 200) {
              this.equiAccessTabsData.push({
                type: id,
                typeName: typeName,
                cloumns: columns,
                data: res.data
              })
              // this.equiAccessTabsData[request_Url_last_str] = res.data
              console.log(this.equiAccessTabsData,'this.equiAccessTabsData')
              for(const i in this.equiAccessList) {
                if(i == this.activeKey) {
                  for(const j in this.equiAccessTabsData) {
                    if(this.equiAccessList[i].id == this.equiAccessTabsData[j].type) {
                      this.equiAccessTabsDataUse = this.equiAccessTabsData[j]
                    }
                  }
                }
              }
            }
          })
        },
        filterOption(input, option) {
          return (
            option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
          )
        },
        handleChangeTabs(key) {
          console.log(key)
        },
        addComponentDlg(item) {
          console.log(item,333)
          const type = item.id
          this.componentDlgObj.visible = true
          console.log(this.equiAccessTabsDataUse, 'this.equiAccessTabsDataUse')
          if (this.equiAccessTabsDataUse.typeName == '杀伤性能') {
            this.componentDlgObj.title = '添加' + '火力强度'
          } else {
            this.componentDlgObj.title = '添加' + this.equiAccessTabsDataUse.typeName
          }
          this.componentDlgObj.componentType = item.id
          this.componentDlgObj.componentTypeName = item.translate
        },
        detailComponmFunc (item) {
          let entityType1 = ''
          if (this.equiAccessTabsDataUse.type) {
            entityType1 = this.equiAccessTabsDataUse.type.substr(this.entityType.length).substr(0,this.equiAccessTabsDataUse.type.substr(this.entityType.length).length - 1)
          }
          console.log(entityType1,'entityType1')
          console.log(item, 'item888')
          this.detailComponmObj = {
            entityType: entityType1,
            guid: item.guid,
            id: item.id,
            visible: true
          }
        },
        closeDetailComponmDlg () {
          this.detailComponmObj = {
            entityType: '',
            guid: '',
            id: '',
            visible: false
          }
          this.getTableList()
        },
        removeComponentInfo(item, data) {
          const type = item.id.substr(this.entityType.length).toLowerCase()
          const entityType = this.entityType.toLowerCase()
          const request_Url = `/basedata/${entityType}/remove${type}`
          let dataKey = ''

          switch (item.id) {
            case this.entityType + 'Codes':
            case this.entityType + 'Targets':
              dataKey = 'cid'
              break
            case this.entityType + 'Signatures':
              dataKey = 'typeId'
              break
            default:
              dataKey= 'guid'
              break
          }
        
          const params = {
            guid: this.editGuid,
            [dataKey === 'guid' ? 'ComponentGuid' : dataKey]: data[dataKey]
          }
      
          deleteAction(request_Url, params).then((res) => {
              if(res.data) {
                this.vueMessage('success','删除成功')
                this.getTableList()
              } else {
                this.vueMessage('error', res.message)
              }
            })
        },
        handleCloseDataModel() {
          this.dataModelVisible =false
          this.getTableList()
        },
        clsComponentDlg() {
          this.componentDlgObj.visible = false
          this.componentDlgObj.title = ''
          this.componentDlgObj.componentType = ''
          this.componentDlgObj.componentTypeName = ''
          this.getTableList()
        },
        onSelectChangeTableCheck(selectedRowKeys) {
          const arr1 = []
          arr1.push(selectedRowKeys[selectedRowKeys.length - 1])
          this.selectedRowKeys = arr1
          // 注：此处表格为单选操作，故不可将selectedRowKeys的值直接赋给this.selectedRowKeys
        },
        gen_base64 (e) {
          var that = this
          function images2Base64(img) {
            console.log(img,'imgh')
            var reader = new FileReader()
            if (img) {
              if (img.type == 'image/jpeg') {
                reader.readAsDataURL(img)
                reader.onload = function () {
                  var base = reader.result
                  var base64 = base.substr(23)
                  that.modelImgSrc = base64
                  console.log(that.modelImgSrc, 'that.modelImgSrc')
                  const entityType1 = that.entityType.toLowerCase()
                  var id1
                  if (that.opType == 1 || that.opType == 2) {
                    id1 = that.newId
                  } else if (that.opType == 3) {
                    id1 = that.parentTableRowId
                  }
                  const params = {
                    id: id1,
                    image: base64
                  }
                  const fileFormData = new FormData()
                  fileFormData.append('file', document.getElementById('upload_file').files[0])
                  postAction('/basedata/'+ entityType1 +'/addimg?id=' + params.id, fileFormData).then((res) => {
                    console.log(res,'333')
                  })
                }
              } else {
                that.$message.warning('图片只支持上传jpg格式！')
              }
            }
          }
          images2Base64(document.getElementById('upload_file').files[0],'998877')
        },
        uploadIVE (e) {
          console.log(document.getElementById('upload_ive').files[0], 'file555')
        },
        handleSubmit() {
            // 'OperatorCountry'.slice(0,2).toLowerCase() + 'OperatorCountry'.slice(2)
            const param = {}
            for(const i in this.populationList) {
                if (this.populationList[i].Id) {
                  this.populationList[i].ID = this.populationList[i].Id
                }
                if(this.entityType == 'Weapon') {
                  if(this.populationList[i].fieldname == 'OperatorCountry') {
                    this.populationList[i].value = this.populationList[i].value.toString()
                  }
                }
                if(this.populationList[i].fieldname) {
                    // const key1 = this.populationList[i].fieldname.slice(0,2).toLowerCase() + this.populationList[i].fieldname.slice(2)
                    const key1 = this.populationList[i].fieldname
                    param[key1] = this.populationList[i].value
                }
            }
            const entityType1 = this.entityType.toLowerCase()
            let request_Url = null
            // if(this.opType == 1 || this.opType == 2) {
            //   request_Url = '/basedata/' + entityType1 + '/add'
            // } else if (this.opType == 3) {
            //   request_Url = '/basedata/' + entityType1 + '/edit'
            // }
            request_Url = '/basedata/' + entityType1 + '/add'
            // const param_str = JSON.stringify(param)
            postAction(request_Url, {
              ...param
            }).then((res) => {
              for(const i in this.populationList) {
                if(this.entityType == 'Weapon') {
                  if(this.populationList[i].fieldname == 'OperatorCountry') {
                    if(this.populationList[i].value && typeof(this.populationList[i].value) == 'string') {
                      this.populationList[i].value = this.populationList[i].value.split(',')
                    }
                  }
                }
              }
              if(res.code == 200) {
                this.vueMessage('success','保存成功')
                this.closeTheModal()
              } else {
                this.vueMessage('error', res.message)
              }
            })
        },
        closeTheModal() {
            if(this.opType == 1 || this.opType == 2) {
              const entityType1 = this.entityType.toLowerCase()
              deleteAction('/basedata/'+ entityType1 +'/removealllist?id=' + this.newId + '&typeName='+entityType1, {}).then((res) => {
                
              })
            }
            this.$emit('closeModal')
            this.equiAccessTabsDataUse = {}
            this.equiAccessTabsData = []
            this.modelImgSrc = ''
        },
        vueMessage(type,msgText) {
          this.$message[type](msgText)
        },
        handleChangeTabPane1(index) {

        },
        handleChangeTabPane2(index) {
          this.activeKey = index
          this.equiAccessTabsDataUse = {}
          if(this.opType == 1 || this.opType == 2 || this.opType == 3) {
            for(const i in this.equiAccessList) {
              if(i == index) {
                this.equiAccessTabsDataUse.type = this.equiAccessList[i].id
                this.equiAccessTabsDataUse.typeName = this.equiAccessList[i].translate
                for(const j in componentEditlistData) {
                  if(componentEditlistData[j].type == this.equiAccessTabsDataUse.type) {
                    this.equiAccessTabsDataUse.columns = componentEditlistData[j].cols
                    console.log(this.equiAccessTabsDataUse,8888)
                  }
                }
              }
            }
          }
          for(const i in this.equiAccessList) {
            if(i == this.activeKey) {
              console.log(1111)
              for(const j in this.equiAccessTabsData) {
                if(this.equiAccessList[i].id == this.equiAccessTabsData[j].type) {
                  console.log(2222)
                  // console.log(this.equiAccessTabsData[j])
                  this.equiAccessTabsDataUse = this.equiAccessTabsData[j]
                  console.log(this.equiAccessTabsDataUse,'this.equiAccessTabsDataUse')
                }
              }
            }
          }
        }
    }
}
</script>

<style scoped>
  #col1::-webkit-scrollbar {
    width: 2px;
  }
  #col2::-webkit-scrollbar {
    width: 2px;
  }
</style>