<template>
  <div>
    <!-- 物料新增/编辑模态框 -->
    <el-dialog :title="modalData.title" top="18vh" :close-on-click-modal="false" v-drag :visible.sync="modalFlag" width="72vw">
      <el-form :inline="true" label-position="top" :model="modalData" :rules="rules" style="margin-top: -5px;">
        <el-form :inline="true" label-position="top" :model="modalData" :rules="rules">
          <el-form-item label="物料编码" prop="partNo">
            <el-input v-model="modalData.partNo" disabled style="width: 128px"></el-input>
          </el-form-item>
          <el-form-item label="物料描述" prop="partDesc" style="margin-left: -10px">
            <el-input v-model="modalData.partDesc" clearable style="width: 396px"></el-input>
          </el-form-item>
          <el-form-item label="物料描述（英文）">
            <el-input v-model="modalData.partDesceEn" style="width: 527px"></el-input>
          </el-form-item>
        </el-form>
        <el-form :inline="true" label-position="top" :model="modalData" :rules="rules" style="margin-top: -5px;">
          <el-form-item prop="spec" label="规格">
            <el-input v-model="modalData.spec" style="width: 527px"></el-input>
          </el-form-item>
          <el-form-item label="BU" prop="bu">
            <el-select v-model="modalData.bu" placeholder="请选择" @change="getPreviousPartNo" :disabled="modalDisableFlag" style="width: 90px">
              <el-option
                v-for = "i in userBuList"
                :key = "i.buNo"
                :label = "i.buDesc"
                :value = "i.buNo">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="active" label="是否在用">
            <el-select v-model="modalData.active" style="width: 80px">
              <el-option label="是" value="Y"></el-option>
              <el-option label="否" value="N"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="partType2" label="零件类型">
            <el-select v-model="modalData.partType2" style="width: 120px">
              <el-option label="成品" value="Manufactured"></el-option>
              <el-option label="半成品" value="Manufactured Recipe"></el-option>
              <el-option label="原材料" value="Purchased (raw)"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="模板(新增)">
            <span style="cursor: pointer" slot="label" @click="handleTemplateAdd"><a herf="#">模板(新增)</a></span>
            <el-select v-model="modalData.tempNo" @change="chooseTemplate" style="width: 105px">
              <el-option
                v-for="option in templateList"
                :key="option.templateNo"
                :label="option.templateName"
                :value="option.templateNo">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item v-if="modalData.flag === '1'" style="margin-top: 23px">
            <el-checkbox v-model="modalData.tblBaseFlag" true-label="Y">复制属性({{previousPartNo}})</el-checkbox>
          </el-form-item>
        </el-form>
        <el-tabs v-model="inventoryPartTable" style="width: 100%;height: 340px;" @tab-click="tabClick" type="border-card">
          <!-- 主信息页签 -->
          <el-tab-pane label="General" name="General">
            <el-form :inline="true" label-position="top" :model="modalData" :rules="rules" style="margin-top: -5px;">
              <el-form-item prop="umId2">
                <span style="cursor: pointer" slot="label" @click="getBaseList(510)"><a herf="#">计量单位</a></span>
                <el-input v-model="modalData.umId2" @blur="umIdBlur(510)" style="width: 8vw"></el-input>
                <el-input v-model="modalData.umName" disabled style="width: 23.5vw"></el-input>
              </el-form-item>
              <el-form-item v-if="modalData.partType2 === 'Purchased (raw)'" prop="familyID">
                <span style="cursor: pointer" slot="label" @click="getBaseList(214)"><a herf="#">物料分类</a></span>
                <el-input v-model="modalData.familyID" @blur="partFamilyBlur(214)" style="width: 8vw"></el-input>
                <el-input v-model="modalData.familyName" disabled style="width: 23.5vw"></el-input>
              </el-form-item>
              <el-form-item v-else>
                <span style="cursor: pointer" slot="label" @click="getBaseList(214)"><a herf="#">物料分类</a></span>
                <el-input v-model="modalData.familyID" @blur="partFamilyBlur(214)" style="width: 8vw"></el-input>
                <el-input v-model="modalData.familyName" disabled style="width: 23.5vw"></el-input>
              </el-form-item>
            </el-form>
            <el-form :inline="true" label-position="top" :model="modalData" :rules="rules" style="margin-top: -5px;">
              <el-form-item v-if="modalData.partType2 === 'Purchased (raw)'">
                <span style="cursor: pointer" slot="label" @click="getBaseList(211)"><a herf="#">商品组1</a></span>
                <el-input v-model="modalData.productGroupId1" @blur="productGroupId1Blur(211)" style="width: 8vw"></el-input>
                <el-input v-model="modalData.productGroupName1" disabled style="width: 23.5vw"></el-input>
              </el-form-item>
              <el-form-item v-else prop="productGroupId1">
                <span style="cursor: pointer" slot="label" @click="getBaseList(211)"><a herf="#">商品组1</a></span>
                <el-input v-model="modalData.productGroupId1" @blur="productGroupId1Blur(211)" style="width: 8vw"></el-input>
                <el-input v-model="modalData.productGroupName1" disabled style="width: 23.5vw"></el-input>
              </el-form-item>
              <el-form-item v-if="modalData.partType2 === 'Purchased (raw)'">
                <span style="cursor: pointer" slot="label" @click="getBaseList(212)"><a herf="#">商品组2</a></span>
                <el-input v-model="modalData.productGroupId2" @blur="productGroupId2Blur(212)" style="width: 8vw"></el-input>
                <el-input v-model="modalData.productGroupName2" disabled style="width: 23.5vw"></el-input>
              </el-form-item>
              <el-form-item v-else prop="productGroupId2">
                <span style="cursor: pointer" slot="label" @click="getBaseList(212)"><a herf="#">商品组2</a></span>
                <el-input v-model="modalData.productGroupId2" @blur="productGroupId2Blur(212)" style="width: 8vw"></el-input>
                <el-input v-model="modalData.productGroupName2" disabled style="width: 23.5vw"></el-input>
              </el-form-item>
            </el-form>
            <el-form :inline="true" label-position="top" :model="modalData" :rules="rules" style="margin-top: -5px;">
              <el-form-item>
                <span style="cursor: pointer" slot="label" @click="getBaseList(213)"><a herf="#">商品组3</a></span>
                <el-input v-model="modalData.productGroupId3" @blur="productGroupId3Blur(213)" style="width: 8vw"></el-input>
                <el-input v-model="modalData.productGroupName3" disabled style="width: 23.5vw"></el-input>
              </el-form-item>
              <el-form-item prop="codeNo">
                <span style="cursor: pointer" v-if="!modalDisableFlag" slot="label" @click="getBaseList(219)"><a herf="#">属性模板</a></span>
                <span v-else slot="label">属性模板</span>
                <el-input v-model="modalData.codeNo" :disabled="modalDisableFlag" @blur="modelBlur(219)" style="width: 8vw"></el-input>
                <el-input v-model="modalData.codeDesc" disabled style="width: 23.5vw"></el-input>
              </el-form-item>
            </el-form>
            <div v-show="modalData.partType2==='Manufactured'" >
              <el-form :inline="true" label-position="top" :model="modalData" :rules="rules" style="margin-top: -5px;">
                <el-form-item prop="templateNo">
                  <span style="cursor: pointer" slot="label" @click="getBaseList(518)"><a herf="#">BOM模板</a></span>
                  <el-input v-model="modalData.templateNo" @blur="bomTemplateBlur(518)" style="width: 8vw"></el-input>
                  <el-input v-model="modalData.templateName" disabled style="width: 23.5vw"></el-input>
                </el-form-item>
              </el-form>
            </div>
            <div v-show="modalData.partType2!=='Manufactured'">
              <el-form :inline="true" label-position="top" :model="modalData" style="margin-top: -5px;">
                <el-form-item>
                  <span style="cursor: pointer" slot="label" @click="getBaseList(518)"><a herf="#">BOM模板</a></span>
                  <el-input v-model="modalData.templateNo" @blur="bomTemplateBlur(518)" style="width: 8vw"></el-input>
                  <el-input v-model="modalData.templateName" disabled style="width: 23.5vw"></el-input>
                </el-form-item>
              </el-form>
            </div>
            <el-form :inline="true" label-position="top" :model="modalData" :rules="rules" style="margin-top: -5px;">
              <el-form-item label="备注" style="height: 135px">
                <el-input type="textarea" v-model="modalData.remark" :rows="5" resize='none' show-word-limit style="width: 65vw"></el-input>
              </el-form-item>
            </el-form>
          </el-tab-pane>
          <!-- 物料属性页签 -->
          <el-tab-pane v-if="modalDisableFlag" label="物料属性" style="margin-top: -10px" name="part_item">
            <el-form label-position="top" style="margin-left: 2px;">
              <el-button type="primary" @click="addOrDelItem">新增</el-button>
              <el-button type="primary" :loading="loading" @click="clickSave">{{ attributeDialog?'编辑':'保存' }}</el-button>
            </el-form>
            <div class="rq " v-if="attributeDialog">
              <el-table
                :data="partItemList"
                height="233px"
                border
                style="width: 100%;">
                <el-table-column
                  v-for="(item,index) in columnItemList" :key="index"
                  :sortable="item.columnSortable"
                  :prop="item.columnProp"
                  :header-align="item.headerAlign"
                  :show-overflow-tooltip="item.showOverflowTooltip"
                  :align="item.align"
                  :fixed="item.fixed==''?false:item.fixed"
                  :min-width="item.columnWidth"
                  :label="item.columnLabel">
                  <template slot-scope="scope">
                    <div v-if="item.columnProp !== 'textValue' && item.columnProp !== 'numValue'">
                      <span v-if="!item.columnHidden">{{scope.row[item.columnProp]}}</span>
                      <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
                    </div>
                    <div v-else>
                      <template v-if="item.columnProp==='textValue' && scope.row.valueTypeDb==='T'">
                        {{ scope.row['textValue'] }}
                      </template>
                      <template v-else-if="item.columnProp==='textValue' && scope.row.valueTypeDb==='N'">
                        {{ scope.row['numValue'] }}
                      </template>
                    </div>
                  </template>
                </el-table-column>
              </el-table>
            </div>
            <div class="rq " v-else>
              <el-table
                :data="copyAttributeList"
                height="233px"
                border
                style="width: 100%">
                <el-table-column
                  v-for="(item,index) in columnItemList" :key="index"
                  :sortable="item.columnSortable"
                  :prop="item.columnProp"
                  :header-align="item.headerAlign"
                  :show-overflow-tooltip="item.showOverflowTooltip"
                  :align="item.align"
                  :fixed="item.fixed===''?false:item.fixed"
                  :min-width="item.columnWidth"
                  :label="item.columnLabel">
                  <template slot-scope="scope">
                    <div v-if="item.columnProp !== 'textValue' && item.columnProp !== 'numValue'">
                      <span v-if="!item.columnHidden">{{ scope.row[item.columnProp] }}</span>
                      <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
                    </div>
                    <div v-else>
                      <div v-if="scope.row.valueChooseFlag !== 'Y'">
                        <el-input-number v-model="scope.row.numValue" style="padding: 0;width: 100%" v-if="scope.row.valueTypeDb === 'N'" :controls="false"></el-input-number>
                        <el-input v-model="scope.row.textValue" v-else></el-input>
                      </div>
                      <div v-else>
                        <el-select style="width: 100%;" v-if="scope.row.valueTypeDb === 'T'" v-model="scope.row.textValue">
                          <el-option :value="i.availableValue" :label="i.availableValue" v-for="(i,key) in scope.row.availableValueList" :key="key"></el-option>
                        </el-select>
                        <el-select style="width: 100%;" v-else v-model="scope.row.numValue">
                          <el-option :value="i.availableValue" :label="i.availableValue" v-for="(i,key) in scope.row.availableValueList" :key="key"></el-option>
                        </el-select>
                      </div>
                    </div>
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </el-tab-pane>
          <!-- 代理商页签 -->
          <el-tab-pane v-if="modalDisableFlag" label="代理商" style="margin-top: -10px" name="part_agent">
            <el-form label-position="top" style="margin-left: 2px;">
              <el-button type="primary" @click="savePartAgent">新增</el-button>
            </el-form>
            <el-table
              :data="partAgentList"
              height="233px"
              border
              style="width: 100%;">
              <el-table-column
                v-for="(item,index) in columnAgentList" :key="index"
                :sortable="item.columnSortable"
                :prop="item.columnProp"
                :header-align="item.headerAlign"
                :show-overflow-tooltip="item.showOverflowTooltip"
                :align="item.align"
                :fixed="item.fixed==''?false:item.fixed"
                :min-width="item.columnWidth"
                :label="item.columnLabel">
                <template slot-scope="scope">
                  <span v-if="!item.columnHidden">{{scope.row[item.columnProp]}}</span>
                  <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
                </template>
              </el-table-column>
              <el-table-column
                header-align="center"
                align="center"
                width="100"
                fixed="right"
                label="操作">
                <template slot-scope="scope">
                  <el-link style="cursor: pointer" @click="deleteAgent2(scope.row)">删除</el-link>
                </template>
              </el-table-column>
            </el-table>
          </el-tab-pane>
          <!-- 制造商页签 -->
          <el-tab-pane v-if="modalDisableFlag" label="制造商" style="margin-top: -10px" name="part_manufacturer">
            <el-form label-position="top" style="margin-left: 2px;">
              <el-button type="primary" @click="savePartManufacturer">新增</el-button>
            </el-form>
            <el-table
              :data="partManufacturerList"
              height="233px"
              border
              style="width: 100%;">
              <el-table-column
                v-for="(item,index) in columnManufacturerList" :key="index"
                :sortable="item.columnSortable"
                :prop="item.columnProp"
                :header-align="item.headerAlign"
                :show-overflow-tooltip="item.showOverflowTooltip"
                :align="item.align"
                :fixed="item.fixed==''?false:item.fixed"
                :min-width="item.columnWidth"
                :label="item.columnLabel">
                <template slot-scope="scope">
                  <span v-if="!item.columnHidden">{{scope.row[item.columnProp]}}</span>
                  <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
                </template>
              </el-table-column>
              <el-table-column
                header-align="center"
                align="center"
                width="100"
                fixed="right"
                label="操作">
                <template slot-scope="scope">
                  <el-link style="cursor: pointer" @click="deleteManufacturer2(scope.row)">删除</el-link>
                </template>
              </el-table-column>
            </el-table>
          </el-tab-pane>
          <!-- 默认库位页签 -->
          <el-tab-pane v-if="modalDisableFlag" label="默认库位" style="margin-top: -10px" name="default_locations">
            <el-form label-position="top" style="margin-left: 2px;">
              <el-button type="primary" @click="saveDefaultLocation()">新增</el-button>
            </el-form>
            <el-table
              :data="defaultLocationList"
              height="233px"
              border
              style="width: 100%;">
              <el-table-column
                v-for="(item,index) in columnLocationList" :key="index"
                :sortable="item.columnSortable"
                :prop="item.columnProp"
                :header-align="item.headerAlign"
                :show-overflow-tooltip="item.showOverflowTooltip"
                :align="item.align"
                :fixed="item.fixed==''?false:item.fixed"
                :min-width="item.columnWidth"
                :label="item.columnLabel">
                <template slot-scope="scope">
                  <span v-if="!item.columnHidden">{{scope.row[item.columnProp]}}</span>
                  <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
                </template>
              </el-table-column>
              <el-table-column
                header-align="center"
                align="center"
                width="100"
                fixed="right"
                label="操作">
                <template slot-scope="scope">
                  <el-link style="cursor: pointer" @click="deleteLocation2(scope.row)">删除</el-link>
                </template>
              </el-table-column>
            </el-table>
          </el-tab-pane>
          <!-- 文档页签 -->
          <el-tab-pane v-if="modalDisableFlag" label="文档" style="margin-top: -10px" name="part_file">
            <el-form label-position="top" style="margin-left: 2px;">
              <el-button type="primary" @click="uploadFile">上传文件</el-button>
            </el-form>
            <el-table
              :data="fileContentList"
              height="233px"
              border
              style="width: 100%; ">
              <el-table-column
                v-for="(item,index) in columnFileList" :key="index"
                :sortable="item.columnSortable"
                :prop="item.columnProp"
                :header-align="item.headerAlign"
                :show-overflow-tooltip="item.showOverflowTooltip"
                :align="item.align"
                :fixed="item.fixed==''?false:item.fixed"
                :min-width="item.columnWidth"
                :label="item.columnLabel">
                <template slot-scope="scope">
                  <span v-if="!item.columnHidden">{{scope.row[item.columnProp]}}</span>
                  <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
                </template>
              </el-table-column>
              <el-table-column
                fixed="right"
                header-align="center"
                align="center"
                width="130"
                label="操作">
                <template slot-scope="scope">
                  <el-link style="cursor: pointer" @click="previewFile(scope.row)">预览</el-link>
                  <el-link style="cursor: pointer" @click="downloadFile(scope.row)">下载</el-link>
                  <el-link style="cursor: pointer" @click="deleteFile(scope.row)">删除</el-link>
                </template>
              </el-table-column>
            </el-table>
          </el-tab-pane>
        </el-tabs>
      </el-form>
      <el-footer style="height:35px;margin-top: 20px;text-align:center">
        <div v-if="modalData.flag === '1'">
          <el-button type="primary" :loading="saveLoading" @click="saveData(false)">应用</el-button>
          <el-button type="primary" :loading="saveLoading" @click="saveData(true)">保存</el-button>
        </div>
        <div v-else-if="modalData.flag === '3'">
          <el-button type="primary" :loading="saveLoading" @click="saveData(false)">应用</el-button>
          <el-button type="primary" :loading="saveLoading" @click="saveData(true)">保存</el-button>
        </div>
        <div v-else>
          <el-button type="primary" :loading="saveLoading" @click="saveData()">保存</el-button>
          <el-button type="primary" @click="modalFlag = false">关闭</el-button>
        </div>
      </el-footer>
    </el-dialog>

    <!-- 物料属性-> 快速新增 -->
    <el-dialog title="新增" :close-on-click-modal="false" v-drag :visible.sync="fastAddFlag" width="1000px">
      <div style="font-size: 12px">
        <el-form :inline="true" label-position="top" :model="itemData">
          <el-form-item :label="'属性编码'">
            <el-input v-model="itemData.propertiesItemNo" clearable style="width: 120px"></el-input>
          </el-form-item>
          <el-form-item :label="'属性名称'">
            <el-input v-model="itemData.itemDesc" clearable style="width: 150px"></el-input>
          </el-form-item>
          <el-form-item :label="' '">
            <el-button type="primary" @click="queryPartItem()">查询</el-button>
          </el-form-item>
        </el-form>
      </div>
      <el-container style="margin-top: 0px;">
        <el-main style="width: 350px;padding: 1px">
          <span style="font-size: 12px" >可选属性</span>
          <el-table
            height="400px"
            :data="itemList1"
            border
            ref="itemTable1"
            @row-click="itemClickRow1"
            @selection-change="selectionItem1"
            highlight-current-row
            style="width: 100%">
            <el-table-column
              type="selection"
              header-align="center"
              align="center"
              width="50">
            </el-table-column>
            <el-table-column
              prop="itNo"
              header-align="center"
              align="center"
              min-width="80"
              label="属性编码">
            </el-table-column>
            <el-table-column
              prop="itemDesc"
              header-align="center"
              align="center"
              min-width="200"
              label="属性名称">
            </el-table-column>
          </el-table>
        </el-main>
        <el-main style="width: 10px;padding: 1px">
          <div style="margin-top: 200px;margin-left: 18px">
            <el-button type="primary" @click="addItem()">添加>></el-button>
          </div>
          <div style="margin-top: 15px;margin-left: 18px">
            <el-button type="primary" @click="deleteItem()">删除<<</el-button>
          </div>
        </el-main>
        <el-main style="width: 350px;padding: 1px">
          <span style="font-size: 12px" >已有属性</span>
          <el-table
            height="400px"
            :data="itemList2"
            border
            ref="itemTable2"
            @row-click="itemClickRow2"
            @selection-change="selectionItem2"
            highlight-current-row
            style="width: 100%">
            <el-table-column
              type="selection"
              header-align="center"
              align="center"
              width="50">
            </el-table-column>
            <el-table-column
              prop="itNo"
              header-align="center"
              align="center"
              min-width="80"
              label="属性编码">
            </el-table-column>
            <el-table-column
              prop="itemDesc"
              header-align="center"
              align="center"
              min-width="200"
              label="属性名称">
            </el-table-column>
          </el-table>
        </el-main>
      </el-container>
      <el-footer style="height:40px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="fastAddFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <!-- 代理商-> 快速新增 -->
    <el-dialog title="新增" @close="refreshDetailList" :close-on-click-modal="false" v-drag :visible.sync="agentModelFlag" width="900px">
      <div style="font-size: 12px">
        <el-form :inline="true" label-position="top" :model="agentData">
          <el-form-item :label="'代理商编码'">
            <el-input v-model="agentData.agentId" clearable style="width: 120px"></el-input>
          </el-form-item>
          <el-form-item :label="'代理商名称'">
            <el-input v-model="agentData.agentName" clearable style="width: 120px"></el-input>
          </el-form-item>
          <el-form-item :label="' '">
            <el-button type="primary" @click="getAgentList">查询</el-button>
          </el-form-item>
        </el-form>
      </div>
      <el-container style="margin-top: 0px;">
        <el-main style="width: 350px; padding: 1px">
          <span style="font-size: 12px" >可选代理商</span>
          <el-table
            height="400px"
            :data="agentList1"
            border
            ref="agentTable1"
            @row-click="agentClickRow1"
            @selection-change="selectionAgent1"
            highlight-current-row
            style="width: 100%">
            <el-table-column
              type="selection"
              header-align="center"
              align="center"
              width="50">
            </el-table-column>
            <el-table-column
              prop="agentId"
              header-align="center"
              align="center"
              min-width="80"
              label="代理商编码">
            </el-table-column>
            <el-table-column
              prop="agentName"
              header-align="center"
              align="center"
              min-width="120"
              label="代理商名称">
            </el-table-column>
          </el-table>
        </el-main>
        <el-main style="width: 111px;padding: -1px">
          <div style="margin-top: 182px;margin-left: 18px">
            <el-button type="primary" @click="addAgent">添加>></el-button>
          </div>
          <div style="margin-top: 15px;margin-left: 18px">
            <el-button type="primary" @click="deleteAgent">删除<<</el-button>
          </div>
        </el-main>
        <el-main style="width: 350px;padding: 1px">
          <span style="font-size: 12px" >已有代理商</span>
          <el-table
            height="400px"
            :data="agentList2"
            border
            ref="agentTable2"
            @row-click="agentClickRow2"
            @selection-change="selectionAgent2"
            highlight-current-row
            style="width: 100%">
            <el-table-column
              type="selection"
              header-align="center"
              align="center"
              width="50">
            </el-table-column>
            <el-table-column
              prop="agentId"
              header-align="center"
              align="center"
              min-width="80"
              label="代理商编码">
            </el-table-column>
            <el-table-column
              prop="agentName"
              header-align="center"
              align="center"
              min-width="120"
              label="代理商名称">
            </el-table-column>
          </el-table>
        </el-main>
      </el-container>
      <el-footer style="height:40px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="agentModelFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <!-- 制造商-> 快速新增 -->
    <el-dialog title="新增" @close="refreshDetailList" :close-on-click-modal="false" v-drag :visible.sync="manufacturerModelFlag" width="900px">
      <div style="font-size: 12px">
        <el-form :inline="true" label-position="top" :model="manufacturerData">
          <el-form-item :label="'制造商编码'">
            <el-input v-model="manufacturerData.manufacturerId" clearable style="width: 120px"></el-input>
          </el-form-item>
          <el-form-item :label="'制造商名称'">
            <el-input v-model="manufacturerData.manufacturerName" clearable style="width: 120px"></el-input>
          </el-form-item>
          <el-form-item :label="' '">
            <el-button type="primary" @click="getManufacturerList()">查询</el-button>
          </el-form-item>
        </el-form>
      </div>
      <el-container style="margin-top: 0px;">
        <el-main style="width: 350px; padding: 1px">
          <span style="font-size: 12px" >可选制造商</span>
          <el-table
            height="400px"
            :data="manufacturerList1"
            border
            ref="manufacturerTable1"
            @row-click="manufacturerClickRow1"
            @selection-change="selectionManufacturer1"
            highlight-current-row
            style="width: 100%">
            <el-table-column
              type="selection"
              header-align="center"
              align="center"
              width="50">
            </el-table-column>
            <el-table-column
              prop="manufacturerId"
              header-align="center"
              align="center"
              min-width="80"
              label="制造商编码">
            </el-table-column>
            <el-table-column
              prop="manufacturerName"
              header-align="center"
              align="center"
              min-width="120"
              label="制造商名称">
            </el-table-column>
          </el-table>
        </el-main>
        <el-main style="width: 111px;padding: -1px">
          <div style="margin-top: 182px;margin-left: 18px">
            <el-button type="primary" @click="addManufacturer()">添加>></el-button>
          </div>
          <div style="margin-top: 15px;margin-left: 18px">
            <el-button type="primary" @click="deleteManufacturer()">删除<<</el-button>
          </div>
        </el-main>
        <el-main style="width: 350px;padding: 1px">
          <span style="font-size: 12px" >已有制造商</span>
          <el-table
            height="400px"
            :data="manufacturerList2"
            border
            ref="manufacturerTable2"
            @row-click="manufacturerClickRow2"
            @selection-change="selectionManufacturer2"
            highlight-current-row
            style="width: 100%">
            <el-table-column
              type="selection"
              header-align="center"
              align="center"
              width="50">
            </el-table-column>
            <el-table-column
              prop="manufacturerId"
              header-align="center"
              align="center"
              min-width="80"
              label="制造商编码">
            </el-table-column>
            <el-table-column
              prop="manufacturerName"
              header-align="center"
              align="center"
              min-width="120"
              label="制造商名称">
            </el-table-column>
          </el-table>
        </el-main>
      </el-container>
      <el-footer style="height:40px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="manufacturerModelFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <!-- 默认库位-> 快速新增 -->
    <el-dialog title="新增" @close="refreshDetailList" :close-on-click-modal="false" v-drag :visible.sync="locationModelFlag" width="900px">
      <div style="font-size: 12px">
        <el-form :inline="true" label-position="top" :model="locationData">
          <el-form-item :label="'库位编码'">
            <el-input v-model="locationData.locationId" clearable style="width: 120px"></el-input>
          </el-form-item>
          <el-form-item :label="'库位名称'">
            <el-input v-model="locationData.locationName" clearable style="width: 120px"></el-input>
          </el-form-item>
          <el-form-item :label="' '">
            <el-button type="primary" @click="getLocationList()">查询</el-button>
          </el-form-item>
        </el-form>
      </div>
      <el-container style="margin-top: 0px;">
        <el-main style="width: 350px; padding: 1px">
          <span style="font-size: 12px" >可选库位</span>
          <el-table
            height="400px"
            :data="locationList1"
            border
            ref="locationTable1"
            @row-click="locationClickRow1"
            @selection-change="selectionLocation1"
            highlight-current-row
            style="width: 100%">
            <el-table-column
              type="selection"
              header-align="center"
              align="center"
              width="50">
            </el-table-column>
            <el-table-column
              prop="locationId"
              header-align="center"
              align="center"
              min-width="80"
              label="库位编码">
            </el-table-column>
            <el-table-column
              prop="locationName"
              header-align="center"
              align="center"
              min-width="120"
              label="库位名称">
            </el-table-column>
          </el-table>
        </el-main>
        <el-main style="width: 111px;padding: -1px">
          <div style="margin-top: 182px;margin-left: 18px">
            <el-button type="primary" @click="addLocation()">添加>></el-button>
          </div>
          <div style="margin-top: 15px;margin-left: 18px">
            <el-button type="primary" @click="deleteLocation()">删除<<</el-button>
          </div>
        </el-main>
        <el-main style="width: 350px;padding: 1px">
          <span style="font-size: 12px" >已有库位</span>
          <el-table
            height="400px"
            :data="locationList2"
            border
            ref="locationTable2"
            @row-click="locationClickRow2"
            @selection-change="selectionLocation2"
            highlight-current-row
            style="width: 100%">
            <el-table-column
              type="selection"
              header-align="center"
              align="center"
              width="50">
            </el-table-column>
            <el-table-column
              prop="locationId"
              header-align="center"
              align="center"
              min-width="80"
              label="库位编码">
            </el-table-column>
            <el-table-column
              prop="locationName"
              header-align="center"
              align="center"
              min-width="120"
              label="库位名称">
            </el-table-column>
          </el-table>
        </el-main>
      </el-container>
      <el-footer style="height:40px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="locationModelFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <el-dialog :title="'模板新增'" top="18vh" :close-on-click-modal="false" v-drag :visible.sync="templateAddFlag" width="850px">
      <el-form :inline="true" :rules="tempRules" label-position="top" :model="tempData" style="margin-top: -5px;">
        <el-form-item label="BU" prop="bu">
          <el-select v-model="tempData.bu" placeholder="请选择" @change="getPreviousPartNo" style="width: 380px">
            <el-option
              v-for = "i in userBuList"
              :key = "i.buNo"
              :label = "i.buDesc"
              :value = "i.buNo">
            </el-option>
          </el-select>
        </el-form-item>
<!--        <el-form-item label="模板编码" prop="templateNo">-->
<!--          <el-input v-model="tempData.templateNo" clearable style="width: 240px"></el-input>-->
<!--        </el-form-item>-->
        <el-form-item label="模板名称" prop="templateName">
          <el-input v-model="tempData.templateName" clearable style="width: 380px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" :rules="tempRules" label-position="top" :model="tempData" style="margin-top: -5px;">
        <el-form-item prop="umId">
          <span style="cursor: pointer" slot="label" @click="getBaseList(510)"><a herf="#">计量单位</a></span>
          <el-input v-model="tempData.umName" disabled style="width: 380px"></el-input>
        </el-form-item>
        <el-form-item prop="familyId">
          <span style="cursor: pointer" slot="label" @click="getBaseList(214)"><a herf="#">物料分类</a></span>
          <el-input v-model="tempData.familyName" disabled style="width: 380px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" :rules="tempRules" label-position="top" :model="tempData" style="margin-top: -5px;">
        <el-form-item prop="productGroupId1">
          <span style="cursor: pointer" slot="label" @click="getBaseList(211)"><a herf="#">商品组1</a></span>
          <el-input v-model="tempData.productGroupName1" disabled style="width: 380px"></el-input>
        </el-form-item>
        <el-form-item prop="productGroupId2">
          <span style="cursor: pointer" slot="label" @click="getBaseList(212)"><a herf="#">商品组2</a></span>
          <el-input v-model="tempData.productGroupName2" disabled style="width: 380px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" :rules="tempRules" label-position="top" :model="tempData" style="margin-top: -5px;">
        <el-form-item prop="productGroupId3">
          <span style="cursor: pointer" slot="label" @click="getBaseList(213)"><a herf="#">商品组3</a></span>
          <el-input v-model="tempData.productGroupName3" disabled style="width: 380px"></el-input>
        </el-form-item>
        <el-form-item prop="codeNo">
          <span style="cursor: pointer" slot="label" @click="getBaseList(219)"><a herf="#">属性模板</a></span>
          <el-input v-model="tempData.codeDesc" disabled style="width: 380px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" :rules="tempRules" label-position="top" :model="tempData" style="margin-top: -5px;">
        <el-form-item prop="bomTemplateNo">
          <span style="cursor: pointer" slot="label" @click="getBaseList(518)"><a herf="#">BOM模板</a></span>
          <el-input v-model="tempData.bomTemplateName" disabled style="width: 380px"></el-input>
        </el-form-item>
      </el-form>
      <el-footer style="height:40px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="templateAdd">保存</el-button>
        <el-button type="primary" @click="templateAddFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <!-- chooseList模态框 -->
    <Chooselist ref="baseList" @getBaseData="getBaseData"></Chooselist>

    <!-- 上传文件的modal -->
    <partUploadFile ref="partUploadFile" @refreshPageTables="getFileContentData" v-drag></partUploadFile>
  </div>
</template>

<script>
import {
  partInformationSearch, // 物料信息列表查询
  partInformationSave, // 物料信息新增
  partInformationEdit, // 物料信息编辑
  partInformationDelete, // 物料信息删除
  getPartItem, // 查询物料属性
  getAgentList, // 获取代理商列表
  getPartAgent, // 获取物料代理商
  getAgentListBy, // 根据条件查询可选代理商
  addPartAgent, // 新增物料代理商
  deletePartAgent, // 删除物料代理商
  deleteAgent, // 删除物料代理商(单删)
  getManufacturerList, // 获取制造商列表
  getPartManufacturer, // 获取物料制造商
  getManufacturerListBy, // 根据条件查询可选制造商
  addPartManufacturer, // 新增物料制造商
  deletePartManufacturer, // 删除物料制造商
  deleteManufacturer, // 删除物料制造商(单删)
  getLocationList, // 获取库位列表
  getDefaultLocation, // 获取物料库位
  getLocationListBy, // 根据条件查询可选库位
  addDefaultLocation, // 新增物料库位
  deleteDefaultLocation, // 删除物料库位
  deleteLocation, // 删除物料库位(单删)
  commitItemValue, // 修改物料属性值
  getItemLists, // 获取模板属性
  addPartItem, // 新增物料属性
  deletePartItem, // 删除物料属性
  queryPartItem,
  copyPart, // 复制物料
  getProjectPartNo, // 获取物料编码
  verifyData, // 校验参数
  getPreviousPartNo, // 获取上一个物料编码
} from '@/api/part/partInformation.js'
import {
  savePartInfo,
  getPartInfoByNo, // 获取物料信息
  saveMainPartInfo, // mainPart维护
} from "@/api/part/quicklyCreateBom.js"
import {getFileContentList, downLoadObjectFile} from '@/api/eam/eam_object_list.js'
import {getSiteAndBuByUserName} from "@/api/qc/qc.js"
import {deleteObjectFile} from '@/api/eam/eam.js'
import Chooselist from '@/views/modules/common/Chooselist_eam'
import partUploadFile from "./part_upload_file"
import {updateInquiryDetailStatusAndPart} from "../../../api/inquiry/inquiryDetail";
import {EventBus} from "../../../main";
import {getChooselist1} from "../../../api/chooselist/chooselist";
import {chooseTemplate, getTemplateList, templateAdd} from "../../../api/part/quicklyCreateBom";
export default {
  name: 'partCreate',
  components: {
    Chooselist,
    partUploadFile
  },
  watch: {
    modalData: {
      deep: true,
      handler: function (newV, oldV) {
        this.modalData.partNo = this.modalData.partNo.toUpperCase()
      }
    },
    'modalData.bu': {
      deep: true,
      handler: function (newV, oldV) {
        this.getTemplateList()
      }
    },
    templateAddFlag: {
      deep: true,
      handler: function (newV, oldV) {
        if (newV===false) {
          this.tempData = {
            site: this.$store.state.user.site,
            bu: '',
            templateNo: '',
            templateName: '',
            umId: '',
            umName: '',
            familyId: '',
            familyName: '',
            productGroupId1: '',
            productGroupName1: '',
            productGroupId2: '',
            productGroupName2: '',
            productGroupId3: '',
            productGroupName3: '',
            codeNo: '',
            codeDesc: '',
            bomTemplateNo: '',
            bomTemplateName: '',
          }
        }
      }
    },
    'tempData.bu': {
      deep: true,
      handler: function (newV, oldV) {
        this.tempData.buNo = newV.split('_')[1]
      }
    }
  },
  props: {
    initData:{
      type: Object,
      requester: true
    }
  },
  data() {
    return {
      userBuList: [],
      // ======== 分页 ========
      pageIndex: 1,
      pageSize: 20,
      totalPage: 0,
      selectedDataNum: 0,
      tempCodeNo: '',
      // 条件查询
      searchData: {
        site: '',
        userName: this.$store.state.user.name,
        buNo: '',
        partNo: '',
        startDate: '',
        endDate: '',
        partDesc: '',
        page: 1,
        limit: 10
      },
      // 其它
      loading: false,
      // 初始页签
      activeTable: 'part_item',
      inventoryPartTable: 'General',
      // ======== 数据对象 ========
      modalData: {
        flag: '',
        title: '',
        site: '',
        buNo: this.initData.buNo,
        bu: '',
        partNo: '',
        partDesc: '',
        tempNo: '',
        umId2: '',
        umName: '',
        spec: '',
        active: '',
        partType2: '',
        standardBoxQty: '',
        productGroupId1: '',
        productGroupName1: '',
        productGroupId2: '',
        productGroupName2: '',
        productGroupId3: '',
        productGroupName3: '',
        familyID: '',
        familyName: '',
        partDesceEn: '',
        remark: '',
        codeNo: '',
        codeDesc: '',
        tblBaseFlag: '',
        templateNo: '',
        templateName: '',
        id: '',
        testPartId: '',
        testPartDesc: '',
        partBomStatus: '',
        updateBy: ''
      },
      // 定义tempData
      tempData: {
        site: this.$store.state.user.site,
        bu: '',
        buNo: '',
        templateNo: '',
        templateName: '',
        umId: '',
        umName: '',
        familyId: '',
        familyName: '',
        productGroupId1: '',
        productGroupName1: '',
        productGroupId2: '',
        productGroupName2: '',
        productGroupId3: '',
        productGroupName3: '',
        codeNo: '',
        codeDesc: '',
        bomTemplateNo: '',
        bomTemplateName: '',
      },
      itemData: {
        site: this.$store.state.user.site,
        partNo: '',
        propertiesItemNo: '',
        codeNo: '',
        itemDesc: '',
        textValue: '',
        numValue: '',
        recordType: ''
      },
      agentData: {
        site: '',
        buNo: '',
        agentId: '',
        agentName: '',
      },
      manufacturerData: {
        site: '',
        buNo: '',
        manufacturerId: '',
        manufacturerName: '',
      },
      locationData: {
        site: '',
        buNo: '',
        locationId: '',
        locationName: '',
      },
      copyPartData: {
        site: '',
        partNo: '',
        partDesc: '',
        copyGeneral: 'Y',
        copyCosts: '',
        copyPlanningData: '',
        copyManufacturing: '',
        copyDefaultLocation: '',
        copyRevision: '',
        previousVersion: {},
        createBy: ''
      },
      // ======== 数据列表 ========
      dataList: [],
      partItemList: [],
      updatePartItemList: [],
      partAgentList: [],
      partManufacturerList: [],
      defaultLocationList: [],
      fileContentList: [],
      availableValueList:[],
      agentList: [],
      agentSelections: [],
      agentSelections1: [],
      agentSelections2: [],
      agentList1: [],
      agentList2: [],
      manufacturerList: [],
      manufacturerSelections: [],
      manufacturerSelections1: [],
      manufacturerSelections2: [],
      manufacturerList1: [],
      manufacturerList2: [],
      locationList: [],
      locationSelections: [],
      locationSelections1: [],
      locationSelections2: [],
      locationList1: [],
      locationList2: [],
      itemSelections1: [],
      itemSelections2: [],
      itemList1:[],
      itemList2:[],
      revisionList: [],
      bomAlternativeList: [],
      routingAlternativeList: [],
      copyAttributeList: [],
      fileList: [],
      templateList: [],
      // ======== 列表表头 ========
      columnList: [
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table1Bu',
          tableId: '601001Table1',
          tableName: '物料信息表',
          columnProp: 'buDesc',
          headerAlign: 'center',
          align: 'center',
          columnLabel: 'BU',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 80
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table1PartNo',
          tableId: '601001Table1',
          tableName: '物料信息表',
          columnProp: 'partNo',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '物料编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table1PartDesc',
          tableId: '601001Table1',
          tableName: '物料信息表',
          columnProp: 'partDesc',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '物料描述',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 300
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table1PartDesceEn',
          tableId: '601001Table1',
          tableName: '物料信息表',
          columnProp: 'partDesceEn',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '物料描述（英文）',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 300
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table1Spec',
          tableId: '601001Table1',
          tableName: '物料信息表',
          columnProp: 'spec',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '规格',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 300
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table1ActiveDesc',
          tableId: '601001Table1',
          tableName: '物料信息表',
          columnProp: 'activeDesc',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '是否在用',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 80
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table1PartType2Desc',
          tableId: '601001Table1',
          tableName: '物料信息表',
          columnProp: 'partType2Desc',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '零件类型',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table1UmId',
          tableId: '601001Table1',
          tableName: '物料信息表',
          columnProp: 'umId2',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '计量单位编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table1UmName',
          tableId: '601001Table1',
          tableName: '物料信息表',
          columnProp: 'umName',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '计量单位名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 150
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table1FamilyID',
          tableId: '601001Table1',
          tableName: '物料信息表',
          columnProp: 'familyID',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '物料分类编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table1FamilyName',
          tableId: '601001Table1',
          tableName: '物料信息表',
          columnProp: 'familyName',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '物料分类名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 150
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table1OtherGroup1',
          tableId: '601001Table1',
          tableName: '物料信息表',
          columnProp: 'productGroupId1',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '商品组1编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table1OtherGroupName1',
          tableId: '601001Table1',
          tableName: '物料信息表',
          columnProp: 'productGroupName1',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '商品组1名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 150
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table1OtherGroup2',
          tableId: '601001Table1',
          tableName: '物料信息表',
          columnProp: 'productGroupId2',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '商品组2编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table1OtherGroupName2',
          tableId: '601001Table1',
          tableName: '物料信息表',
          columnProp: 'productGroupName2',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '商品组2名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 150
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table1OtherGroup3',
          tableId: '601001Table1',
          tableName: '物料信息表',
          columnProp: 'productGroupId3',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '商品组3编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table1OtherGroupName3',
          tableId: '601001Table1',
          tableName: '物料信息表',
          columnProp: 'productGroupName3',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '商品组3名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 150
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table1CodeNo',
          tableId: '601001Table1',
          tableName: '物料信息表',
          columnProp: 'codeNo',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '属性模板编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 150
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table1CodeDesc',
          tableId: '601001Table1',
          tableName: '物料信息表',
          columnProp: 'codeDesc',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '属性模板名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 200
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table1Remark',
          tableId: '601001Table1',
          tableName: '物料信息表',
          columnProp: 'remark',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '备注',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 300
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table1CreateDate',
          tableId: '601001Table1',
          tableName: '物料信息表',
          columnProp: 'createDate',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '创建时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 150
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table1CreateBy',
          tableId: '601001Table1',
          tableName: '物料信息表',
          columnProp: 'createBy',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '创建人',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100
        },
      ],
      columnItemList:  [
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table2PropertiesItemID',
          tableId: "601001Table2",
          tableName: "物料属性表",
          columnProp: 'propertiesItemNo',
          headerAlign: "center",
          align: "center",
          columnLabel: '属性编码',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 100,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table2PropertiesItemDesc',
          tableId: "601001Table2",
          tableName: "物料属性表",
          columnProp: 'itemDesc',
          headerAlign: "center",
          align: "center",
          columnLabel: '属性名称',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 120,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table2ValueType',
          tableId: "601001Table2",
          tableName: "物料属性表",
          columnProp: 'valueType',
          headerAlign: "center",
          align: "center",
          columnLabel: '属性类型',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 100,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table2ValueChooseFlag',
          tableId: "601001Table2",
          tableName: "物料属性表",
          columnProp: 'textValue',
          headerAlign: "center",
          align: "center",
          columnLabel: '属性值',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 100,
        },
      ],
      updateColumnItemList: [
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table6PropertiesItemID',
          tableId: "601001Table6",
          tableName: "物料属性表",
          columnProp: 'propertiesItemNo',
          headerAlign: "center",
          align: "center",
          columnLabel: '属性编码',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 90,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table6PropertiesItemDesc',
          tableId: "601001Table6",
          tableName: "物料属性表",
          columnProp: 'itemDesc',
          headerAlign: "center",
          align: "center",
          columnLabel: '属性名称',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 90,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table6ValueType',
          tableId: "601001Table6",
          tableName: "物料属性表",
          columnProp: 'valueType',
          headerAlign: "center",
          align: "center",
          columnLabel: '属性类型',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 70,
        },
      ],
      columnAgentList:  [
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table3AgentId',
          tableId: "601001Table3",
          tableName: "物料代理商表",
          columnProp: 'agentId',
          headerAlign: "center",
          align: "center",
          columnLabel: '代理商编码',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table3AgentName',
          tableId: "601001Table3",
          tableName: "物料代理商表",
          columnProp: 'agentName',
          headerAlign: "center",
          align: "center",
          columnLabel: '代理商名称',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table3Active',
          tableId: '601001Table3',
          tableName: '物料代理商表',
          columnProp: 'active',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '是否在用',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table3CreateDate',
          tableId: '601001Table3',
          tableName: '物料代理商表',
          columnProp: 'createDate',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '创建时间',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table3CreateBy',
          tableId: '601001Table3',
          tableName: '物料代理商表',
          columnProp: 'createBy',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '创建人',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table3UpdateDate',
          tableId: '601001Table3',
          tableName: '物料代理商表',
          columnProp: 'updateDate',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '更新时间',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table3UpdateBy',
          tableId: '601001Table3',
          tableName: '物料代理商表',
          columnProp: 'updateBy',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '更新人',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
        }
      ],
      columnManufacturerList:  [
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table5ManufacturerId',
          tableId: "601001Table5",
          tableName: "物料制造商表",
          columnProp: 'manufacturerId',
          headerAlign: "center",
          align: "center",
          columnLabel: '制造商编码',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table5ManufacturerName',
          tableId: "601001Table5",
          tableName: "物料制造商表",
          columnProp: 'manufacturerName',
          headerAlign: "center",
          align: "center",
          columnLabel: '制造商名称',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table5Active',
          tableId: '601001Table5',
          tableName: '物料制造商表',
          columnProp: 'active',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '是否在用',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table5CreateDate',
          tableId: '601001Table5',
          tableName: '物料制造商表',
          columnProp: 'createDate',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '创建时间',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table5CreateBy',
          tableId: '601001Table5',
          tableName: '物料制造商表',
          columnProp: 'createBy',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '创建人',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table5UpdateDate',
          tableId: '601001Table5',
          tableName: '物料制造商表',
          columnProp: 'updateDate',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '更新时间',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table5UpdateBy',
          tableId: '601001Table5',
          tableName: '物料制造商表',
          columnProp: 'updateBy',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '更新人',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
        }
      ],
      columnLocationList:  [
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table7LocationId',
          tableId: "601001Table7",
          tableName: "物料库位表",
          columnProp: 'locationId',
          headerAlign: "center",
          align: "center",
          columnLabel: '库位编码',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table7LocationName',
          tableId: "601001Table7",
          tableName: "物料库位表",
          columnProp: 'locationName',
          headerAlign: "center",
          align: "center",
          columnLabel: '库位名称',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table7warehouseId',
          tableId: "601001Table7",
          tableName: "物料库位表",
          columnProp: 'warehouseId',
          headerAlign: "center",
          align: "center",
          columnLabel: '仓库编码',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table7Active',
          tableId: '601001Table7',
          tableName: '物料库位表',
          columnProp: 'active',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '是否在用',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table7CreateDate',
          tableId: '601001Table7',
          tableName: '物料库位表',
          columnProp: 'createDate',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '创建时间',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table7CreateBy',
          tableId: '601001Table7',
          tableName: '物料库位表',
          columnProp: 'createBy',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '创建人',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table7UpdateDate',
          tableId: '601001Table7',
          tableName: '物料库位表',
          columnProp: 'updateDate',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '更新时间',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table7UpdateBy',
          tableId: '601001Table7',
          tableName: '物料库位表',
          columnProp: 'updateBy',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '更新人',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
        }
      ],
      columnFileList: [
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table4FileName',
          tableId: '601001Table4',
          tableName: '文件信息表',
          columnProp: 'fileName',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '文件名称',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 200,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table4FileRemark',
          tableId: '601001Table4',
          tableName: '文件信息表',
          columnProp: 'url',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '文件路径',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 300,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table4CreateDate',
          tableId: '601001Table4',
          tableName: '文件信息表',
          columnProp: 'createDate',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '上传时间',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 170,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 601001,
          serialNumber: '601001Table4CreatedBy',
          tableId: '601001Table4',
          tableName: '文件信息表',
          columnProp: 'createdBy',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '上传人',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: '',
          columnWidth: 120,
        }
      ],
      // ======== 必填规则 ========
      rules: {
        bu: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ],
        partNo: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ],
        partDesc: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ],
        umId2: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ],
        codeNo: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ],
        active: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ],
        partType2: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ],
        familyID: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ],
        productGroupId1: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ],
        productGroupId2: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ],
        templateNo: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ]
      },
      tempRules: {
        bu: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ],
        templateNo: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ],
        templateName: [
          {
            required: true,
            message: ' ',
            trigger: ['blur','change']
          }
        ]
      },
      // ======== 复选数据集 ========
      partSelections: [],
      bomAlternativeSelections: [],
      routingAlternativeSelections: [],
      // ======== 选中的当前行数据 ========
      partCurrentRow: {},
      // ======== 模态框开关控制 ========
      authSearch: false,
      authSave: false,
      authUpdate: false,
      authDelete: false,
      modalFlag: false,
      modalDisableFlag: false,
      itemChooseFlag: false,
      itemTextDisableFlag: false,
      itemNumberDisableFlag: false,
      itemModalDisableFlag: false,
      itemModalFlag: false,
      agentModelFlag: false,
      manufacturerModelFlag: false,
      updateItemModelFlag: false,
      fastAddFlag: false,
      locationModelFlag: false,
      copyPartModelFlag: false,
      attributeDialog: true,
      uploadDialog: false,
      menuId: this.$route.meta.menuId,
      previousPartNo: '',
      saveLoading: false,
      templateAddFlag: false,
    }
  },

  created () {
    // 获取用户的 site 和 bu
    this.getSiteAndBuByUserName()
    this.modalData.id = this.initData.id
    this.modalData.testPartId = this.initData.testPartId
    this.modalData.testPartDesc = this.initData.testPartDesc
    this.modalData.partBomStatus = this.initData.partBomStatus
    this.modalData.updateBy = this.$store.state.user.name
  },

  methods: {

    // 初始化组件的参数
    init () {
      this.modalData = {
        flag: '1',
        title: '物料新增',
        site: '',
        buNo: '',
        bu: this.userBuList[0].buNo,
        partNo: '',
        partDesc: '',
        umId2: '',
        umName: '',
        spec: '',
        active: 'Y',
        partType2: 'Purchased (raw)',
        standardBoxQty: '',
        productGroupId1: '',
        productGroupName1: '',
        productGroupId2: '',
        productGroupName2: '',
        productGroupId3: '',
        productGroupName3: '',
        familyID: '',
        familyName: '',
        partDesceEn: '',
        remark: '',
        codeNo: '',
        codeDesc: '',
        tblBaseFlag: '',
        createBy: this.$store.state.user.name,
        templateNo: '',
        templateName: ''
      }
      this.inventoryPartTable = 'General'
      this.modalDisableFlag = false
      this.modalFlag = true
      this.getPreviousPartNo()
    },

    // 物料信息编辑模态框
    updateModal (data) {
      // 如果物料编码为*，说明是询价传过来的 走新增方法
      if (data.partNo === '*') {
        this.addModal(data)
      } else {
        this.updateModalByNo(data)
      }
    },

    // mainPart 新增模态框
    addModal (data) {
      this.modalData = {
        flag: '3',
        title: '物料新增',
        site: data.site,
        buNo: data.buNo,
        bu: data.site + '_' + data.buNo,
        partNo: data.partNo,
        partDesc: data.partDesc,
        umId2: '',
        umName: '',
        spec: '',
        active: 'Y',
        partType2: 'Manufactured',
        standardBoxQty: '',
        productGroupId1: '',
        productGroupName1: '',
        productGroupId2: '',
        productGroupName2: '',
        productGroupId3: '',
        productGroupName3: '',
        familyID: '',
        familyName: '',
        partDesceEn: '',
        remark: '',
        codeNo: '',
        codeDesc: '',
        tblBaseFlag: '',
        createBy: this.$store.state.user.name,
        templateNo: '',
        templateName: ''
      }
      this.inventoryPartTable = 'General'
      this.modalDisableFlag = false
      this.modalFlag = true
      this.getPreviousPartNo()
    },

    // 修改
    updateModalByNo (data) {
      getPartInfoByNo(data).then(({data}) => {
        if (data && data.code === 0) {
          this.modalData = {
            ...data.row,
            flag: '2',
            title: '物料编辑',
            bu: data.row.site + '_' + data.row.buNo,
            tblBaseFlag: '',
            createBy: this.$store.state.user.name,
          }
          this.inventoryPartTable = 'General'
          this.modalDisableFlag = true
          this.modalFlag = true
        } else {
          this.$alert(data.msg, '错误', {
            confirmButtonText: '确定'
          })
        }
      })
    },

    // 获取上一个物料编码
    getPreviousPartNo () {
      let tempData = {
        site: this.modalData.bu.split('_')[0],
        type: 'thePreviousPartItem',
        thirdType: this.modalData.bu.split('_')[1],
        secondType: this.$store.state.user.name
      }
      getPreviousPartNo(tempData).then(({data}) => {
        if (data && data.code === 0) {
          this.previousPartNo = data.previousPartNo
        } else {
          this.previousPartNo = ''
        }
      })
    },

    // 获取用户的bu
    getSiteAndBuByUserName () {
      let tempData = {
        username: this.$store.state.user.name,
      }
      getSiteAndBuByUserName(tempData).then(({data}) => {
        if (data.code === 0) {
          this.userBuList = data.rows
        }
      })
    },

    // 物料信息新增/编辑
    saveData (isClose) {
      if (!this.attributeDialog) {
        this.$message.warning('请保存属性更改！')
        return
      }
      if (this.modalData.partDesc === '' || this.modalData.partDesc == null) {
        this.$message.warning('请填写物料描述！')
        return
      }
      if (this.modalData.bu === '' || this.modalData.bu == null) {
        this.$message.warning('请选择BU！')
        return
      }
      if (this.modalData.active === '' || this.modalData.active == null) {
        this.$message.warning('请选择是否在用！')
        return
      }
      if (this.modalData.partType2 === '' || this.modalData.partType2 == null) {
        this.$message.warning('请选择零件类型！')
        return
      }
      if (this.modalData.umId2 === '' || this.modalData.umId2 == null) {
        this.$message.warning('请选择计量单位！')
        return
      }
      if (this.modalData.partType2 === 'Purchased (raw)' && (this.modalData.familyID === '' || this.modalData.familyID == null)) {
        this.$message.warning('请选择物料分类！')
        return
      }
      if (this.modalData.partType2 !== 'Purchased (raw)' && (this.modalData.productGroupId1 === '' || this.modalData.productGroupId1 == null)) {
        this.$message.warning('请选择商品组1！')
        return
      }
      if (this.modalData.partType2 !== 'Purchased (raw)' && (this.modalData.productGroupId2 === '' || this.modalData.productGroupId2 == null)) {
        this.$message.warning('请选择商品组2！')
        return
      }
      if (this.modalData.codeNo === '' || this.modalData.codeNo == null) {
        this.$message.warning('请选择属性模板！')
        return
      }
      this.saveLoading = true
      if (this.modalData.flag === '1') {
        savePartInfo(this.modalData).then(({data}) => {
          if (data && data.code === 0) {
            this.modalData = data.rows
            this.modalData.flag = '1'
            this.modalData.title = '物料编辑'
            if (isClose) {
              // 保存
              this.modalFlag = false
              // 刷新BOM页面数据
              this.$emit('refreshPageTables', data.rows)
            }
            this.modalDisableFlag = true
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {}
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
          this.saveLoading = false
        }).catch(() => {
          this.saveLoading = false
        })
      } else if (this.modalData.flag === '3') {
        savePartInfo(this.modalData).then(({data}) => {
          if (data && data.code === 0) {
            this.modalData = data.rows
            this.modalData.title = '物料编辑'
            if (isClose) {
              // 保存
              this.modalFlag = false
            }
            // 刷新页面数据
            this.$emit('refreshPageTables2', data.rows)
            this.modalDisableFlag = true
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {}
            })
            this.saveQuicklyCreate()
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
          this.saveLoading = false
        }).catch(() => {
          this.saveLoading = false
        })
      } else {
        // mainPart维护
        saveMainPartInfo(this.modalData).then(({data}) => {
          if (data && data.code === 0) {
            // 保存
            this.modalFlag = false
            // 刷新页面数据
            this.$emit('refreshPageTables2', data.rows)
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {}
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
          this.saveLoading = false
        }).catch(() => {
          this.saveLoading = false
        })
      }
    },

    // 列表表格选择替换
    tabClick (tab, event) {
      this.refreshCurrentTabTable()
    },

    // 刷新页签的table数据
    refreshCurrentTabTable () {
      if (this.inventoryPartTable === 'part_item') {
        this.getPartItem()
      } else if (this.inventoryPartTable === 'part_agent') {
        this.getPartAgent()
      } else if (this.inventoryPartTable === 'part_file') {
        this.getFileContentData()
      } else if (this.inventoryPartTable === 'part_manufacturer') {
        this.getPartManufacturer()
      } else if (this.inventoryPartTable === 'default_locations') {
        this.getDefaultLocation()
      }
    },

    // 关闭模态框后刷新列表
    refreshDetailList () {
      this.getPartAgent()
      this.getPartManufacturer()
      this.getDefaultLocation()
    },

    // ======== 属性 ========
    // 查询物料属性
    getPartItem () {
      let tempData = {
        site: this.modalData.site,
        buNo: this.modalData.buNo,
        partNo: this.modalData.partNo,
        codeNo: this.modalData.codeNo,
        recordType: 'IP'
      }
      getPartItem(tempData).then(({data}) => {
        if (data && data.code === 0) {
          this.partItemList = data.rows
        } else {
          this.partItemList = []
        }
      })
    },

    /**
     * 查询物料代理商
     */
    getPartAgent () {
      let tempData = {
        site: this.modalData.site,
        buNo: this.modalData.buNo,
        partNo: this.modalData.partNo,
      }
      getPartAgent(tempData).then(({data}) => {
        if (data && data.code === 0) {
          this.partAgentList = data.rows
        } else {
          this.partAgentList = []
        }
      })
    },

    /**
     * 查询物料制造商
     */
    getPartManufacturer () {
      let tempData = {
        site: this.modalData.site,
        buNo: this.modalData.buNo,
        partNo: this.modalData.partNo,
      }
      getPartManufacturer(tempData).then(({data}) => {
        if (data && data.code === 0) {
          this.partManufacturerList = data.rows
        } else {
          this.partManufacturerList = []
        }
      })
    },


    // 保存属性
    clickSave () {
      if (!this.attributeDialog) { // 保存
        this.updateItemValue()
      } else { // 编辑
        this.copyAttributeList = JSON.parse(JSON.stringify(this.partItemList))
        this.attributeDialog = false
      }
    },

    // 编辑物料属性
    updateItemValue () {
      this.loading = true
      let tempData = {
        itemList: JSON.parse(JSON.stringify(this.copyAttributeList))
      }
      commitItemValue(tempData).then(({data}) => {
        if (data && data.code === 0) {
          this.getPartItem()
          this.$emit('update-part-item')
          this.attributeDialog = true
          this.$message({
            message: '操作成功',
            type: 'success',
            duration: 1500,
            onClose: () => {}
          })
        } else {
          this.$alert(data.msg, '错误', {
            confirmButtonText: '确定'
          })
        }
        this.loading = false
      }).catch((error) => {
        this.$message.error(error)
        this.loading = false
      })
    },

    // 新增/删除物料属性
    addOrDelItem () {
      if (!this.attributeDialog) {
        this.$message.warning('请保存更改！')
        return
      }
      this.itemSelections1 = null
      this.itemSelections2 = null
      this.itemData.propertiesItemNo = ''
      this.itemData.itemDesc = ''
      let tempData = {
        site: this.modalData.site,
        buNo: this.modalData.buNo,
        partNo: this.modalData.partNo,
        codeNo: this.modalData.codeNo,
        recordType: 'IP'
      }
      getItemLists(tempData).then(({data}) => {
        this.itemList1 = data.row1
        this.itemList2 = data.row2
      })
      this.fastAddFlag = true
    },

    // 查询物料属性
    queryPartItem () {
      this.itemData.codeNo = this.modalData.codeNo
      this.itemData.partNo = this.modalData.partNo
      queryPartItem(this.itemData).then(({data}) => {
        if (data && data.code === 0) {
          this.itemList1 = data.rows
        } else {
          this.itemList1 = []
        }
      })
    },

    // 可选属性
    itemClickRow1 (row) {
      this.$refs.itemTable1.toggleRowSelection(row)
    },

    // 已有属性
    itemClickRow2 (row) {
      this.$refs.itemTable2.toggleRowSelection(row)
    },

    // 复选属性
    selectionItem1 (val) {
      this.itemSelections1 = val
    },

    // 复选属性
    selectionItem2 (val) {
      this.itemSelections2 = val
    },

    // 物料项目新增
    addItem () {
      if (this.itemSelections1 == null || this.itemSelections1.length === 0) {
        this.$message.warning('请选择可选属性！')
        return
      }
      let inData = {
        site: this.modalData.site,
        buNo: this.modalData.buNo,
        partNo: this.modalData.partNo,
        codeNo: this.modalData.codeNo,
        codeDesc: this.modalData.codeDesc,
        recordType: 'IP',
        itemList: this.itemSelections1
      }
      addPartItem(inData).then(({data}) => {
        if (data && data.code === 0) {
          getItemLists(inData).then(({data}) => {
            this.itemList1 = data.row1
            this.itemList2 = data.row2
          })
          this.getPartItem()
          this.itemSelections1 = []
        } else {
          this.$alert(data.msg, '错误', {
            confirmButtonText: '确定'
          })
        }
      })
    },

    // 物料项目删除
    deleteItem () {
      if (this.itemSelections2 == null || this.itemSelections2.length === 0) {
        this.$alert("请选择已有属性！", '提示', {
          confirmButtonText: '确定'
        })
        return false
      }
      let inData = {
        site: this.modalData.site,
        buNo: this.modalData.buNo,
        partNo: this.modalData.partNo,
        codeNo: this.modalData.codeNo,
        codeDesc: this.modalData.codeDesc,
        recordType: 'IP',
        itemList: this.itemSelections2
      }
      deletePartItem(inData).then(({data}) => {
        if (data && data.code === 0) {
          getItemLists(inData).then(({data}) => {
            this.itemList1 = data.row1
            this.itemList2 = data.row2
          })
          this.getPartItem()
          this.itemSelections2 = []
        } else {
          this.$alert(data.msg, '错误', {
            confirmButtonText: '确定'
          })
        }
      })
    },

    // ======== 代理商 ========
    // 选择代理商
    getAgentList () {
      // 查询所有代理商
      getAgentListBy(this.agentData).then(({data}) => {
        if (data && data.code === 0) {
          this.agentList1 = data.rows
        } else {
          this.$alert(data.msg, '错误', {
            confirmButtonText: '确定'
          })
        }
      })
    },

    // 新增代理商模态框
    savePartAgent () {
      this.agentSelections1 = null
      this.agentSelections2 = null
      getAgentList(this.modalData).then(({data}) => {
        this.agentList1 = data.row1
        this.agentList2 = data.row2
      })
      this.agentData = {
        site: this.modalData.site,
        buNo: this.modalData.buNo,
        agentId: '',
        agentName: '',
      }
      this.agentModelFlag = true
    },

    // 可选代理商
    agentClickRow1 (row) {
      this.$refs.agentTable1.toggleRowSelection(row)
    },

    // 已有代理商
    agentClickRow2 (row) {
      this.$refs.agentTable2.toggleRowSelection(row)
    },

    // 代理商复选
    selectionAgent1 (val) {
      this.agentSelections1 = val
    },

    // 代理商复选
    selectionAgent2 (val) {
      this.agentSelections2 = val
    },

    // 添加代理商
    addAgent () {
      if (this.agentSelections1 == null || this.agentSelections1.length === 0) {
        this.$message.warning('请选择可选代理商！')
        return
      }
      let inData = {
        site: this.modalData.site,
        buNo: this.modalData.buNo,
        partNo: this.modalData.partNo,
        agentList: this.agentSelections1
      }
      addPartAgent(inData).then(({data}) => {
        if (data && data.code === 0) {
          getAgentList(this.modalData).then(({data}) => {
            this.agentList1 = data.row1
            this.agentList2 = data.row2
          })
          this.agentSelections1 = []
        } else {
          this.$alert(data.msg, '错误', {
            confirmButtonText: '确定'
          })
        }
      })
    },

    // 删除物料代理商
    deleteAgent () {
      if(this.agentSelections2 == null || this.agentSelections2.length === 0){
        this.$message.warning('请选择已有代理商！')
        return
      }
      let inData = {
        site: this.modalData.site,
        buNo: this.modalData.buNo,
        partNo: this.modalData.partNo,
        agentList: this.agentSelections2
      }
      deletePartAgent(inData).then(({data}) => {
        if (data && data.code === 0) {
          getAgentList(this.modalData).then(({data}) => {
            this.agentList1 = data.row1
            this.agentList2 = data.row2
          })
          this.agentSelections2 = []
        } else {
          this.$alert(data.msg, '错误', {
            confirmButtonText: '确定'
          })
        }
      })
    },

    // 单删
    deleteAgent2 (row) {
      this.$confirm(`是否删除该代理商?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteAgent(row).then(({data}) => {
          if (data && data.code === 0) {
            this.getPartAgent()
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {}
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      })
    },

    // ======== 制造商 ========
    // 选择制造商
    getManufacturerList () {
      // 查询所有代理商
      getManufacturerListBy(this.manufacturerData).then(({data}) => {
        if (data && data.code === 0) {
          this.manufacturerList1 = data.rows
        } else {
          this.$alert(data.msg, '错误', {
            confirmButtonText: '确定'
          })
        }
      })
    },

    // 新增制造商模态框
    savePartManufacturer () {
      this.manufacturerSelections1 = null
      this.manufacturerSelections2 = null
      getManufacturerList(this.modalData).then(({data}) => {
        this.manufacturerList1 = data.row1
        this.manufacturerList2 = data.row2
      })
      this.manufacturerData = {
        site: this.modalData.site,
        buNo: this.modalData.buNo,
        manufacturerId: '',
        manufacturerName: '',
      }
      this.manufacturerModelFlag = true
    },

    // 可选制造商
    manufacturerClickRow1 (row) {
      this.$refs.manufacturerTable1.toggleRowSelection(row)
    },

    // 已有制造商
    manufacturerClickRow2 (row) {
      this.$refs.manufacturerTable2.toggleRowSelection(row)
    },

    // 制造商复选
    selectionManufacturer1 (val) {
      this.manufacturerSelections1 = val
    },

    // 制造商复选
    selectionManufacturer2 (val) {
      this.manufacturerSelections2 = val
    },

    // 添加制造商
    addManufacturer () {
      if (this.manufacturerSelections1 == null || this.manufacturerSelections1.length === 0) {
        this.$message.warning('请选择可选制造商！')
        return
      }
      let inData = {
        site: this.modalData.site,
        buNo: this.modalData.buNo,
        partNo: this.modalData.partNo,
        manufacturerList: this.manufacturerSelections1
      }
      addPartManufacturer(inData).then(({data}) => {
        if (data && data.code === 0) {
          getManufacturerList(this.modalData).then(({data}) => {
            this.manufacturerList1 = data.row1
            this.manufacturerList2 = data.row2
          })
          this.manufacturerSelections1 = []
        } else {
          this.$alert(data.msg, '错误', {
            confirmButtonText: '确定'
          })
        }
      })
    },

    // 删除物料制造商
    deleteManufacturer () {
      if (this.manufacturerSelections2 == null || this.manufacturerSelections2.length === 0) {
        this.$message.warning('请选择已有制造商！')
        return
      }
      let inData = {
        site: this.modalData.site,
        buNo: this.modalData.buNo,
        partNo: this.modalData.partNo,
        manufacturerList: this.manufacturerSelections2
      }
      deletePartManufacturer(inData).then(({data}) => {
        if (data && data.code === 0) {
          getManufacturerList(this.modalData).then(({data}) => {
            this.manufacturerList1 = data.row1
            this.manufacturerList2 = data.row2
          })
          this.manufacturerSelections2 = []
        } else {
          this.$alert(data.msg, '错误', {
            confirmButtonText: '确定'
          })
        }
      })
    },

    // 单删
    deleteManufacturer2 (row) {
      this.$confirm(`是否删除该制造商?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteManufacturer(row).then(({data}) => {
          if (data && data.code === 0) {
            this.getPartManufacturer()
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {}
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      })
    },

    // ======== 库位 ========
    // 选择默认库位
    getLocationList () {
      // 查询所有库位
      getLocationListBy(this.locationData).then(({data}) => {
        if (data && data.code === 0) {
          this.locationList1 = data.rows
        } else {
          this.$alert(data.msg, '错误', {
            confirmButtonText: '确定'
          })
        }
      })
    },

    // 新增库位模态框
    saveDefaultLocation () {
      this.locationSelections1 = null
      this.locationSelections2 = null
      getLocationList(this.modalData).then(({data}) => {
        this.locationList1 = data.row1
        this.locationList2 = data.row2
      })
      this.locationData = {
        site: this.modalData.site,
        buNo: this.modalData.buNo,
        locationId: '',
        locationName: '',
      }
      this.locationModelFlag = true
    },

    // 可选库位
    locationClickRow1 (row) {
      this.$refs.locationTable1.toggleRowSelection(row)
    },

    // 已有库位
    locationClickRow2 (row) {
      this.$refs.locationTable2.toggleRowSelection(row)
    },

    // 库位复选
    selectionLocation1 (val) {
      this.locationSelections1 = val
    },

    // 库位复选
    selectionLocation2 (val) {
      this.locationSelections2 = val
    },

    // 添加库位
    addLocation () {
      if (this.locationSelections1 == null || this.locationSelections1.length === 0) {
        this.$message.warning('请选择可选库位！')
        return
      }
      let inData = {
        site: this.modalData.site,
        buNo: this.modalData.buNo,
        partNo: this.modalData.partNo,
        locationList: this.locationSelections1
      }
      addDefaultLocation(inData).then(({data}) => {
        if (data && data.code === 0) {
          getLocationList(this.modalData).then(({data}) => {
            this.locationList1 = data.row1
            this.locationList2 = data.row2
          })
          this.locationSelections1 = []
        } else {
          this.$alert(data.msg, '错误', {
            confirmButtonText: '确定'
          })
        }
      })
    },

    // 删除库位
    deleteLocation () {
      if (this.locationSelections2 == null || this.locationSelections2.length === 0) {
        this.$message.warning('请选择已有库位！')
        return
      }
      let inData = {
        site: this.modalData.site,
        buNo: this.modalData.buNo,
        partNo: this.modalData.partNo,
        locationList: this.locationSelections2
      }
      deleteDefaultLocation(inData).then(({data}) => {
        if (data && data.code === 0) {
          getLocationList(this.modalData).then(({data}) => {
            this.locationList1 = data.row1
            this.locationList2 = data.row2
          })
          this.locationSelections2 = []
        } else {
          this.$alert(data.msg, '错误', {
            confirmButtonText: '确定'
          })
        }
      })
    },

    // 单删
    deleteLocation2 (row) {
      this.$confirm(`是否删除该库位?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteLocation(row).then(({data}) => {
          if (data && data.code === 0) {
            this.getDefaultLocation()
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {}
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      })
    },

    // ======== 附件的相关方法 ========
    // 获取物料附件列表
    getFileContentData () {
      let currentData = {
        orderRef1: this.modalData.site,
        orderRef2: this.modalData.partNo,
        orderRef3: 'part',
        orderRef4: this.modalData.buNo,
      }
      getFileContentList(currentData).then(({data}) => {
        if (data && data.code === 200) {
          this.fileContentList = data.rows
        } else {
          this.fileContentList = []
        }
      })
    },

    // 上传文件
    uploadFile () {
      let currentData = {
        titleCon: '物料附件上传',
        site: this.modalData.site,
        buNo: this.modalData.buNo,
        createBy: this.$store.state.user.name,
        partNo: this.modalData.partNo,
        folder: 'part'
      }
      this.uploadDialog = true
      // 打开组件去做新增业务
      this.$nextTick(() => {
        this.$refs.partUploadFile.init(currentData);
      })
    },

    // 文件删除
    deleteFile (row) {
      this.$confirm('确定要删除此文件?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteObjectFile(row).then(({data}) => {
          if (data && data.code === 0) {
            this.getFileContentData()
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {}
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      }).catch(() => {
      })
    },

    // 文件下载
    downloadFile (row) {
      downLoadObjectFile(row).then(({data}) => {
        // 不限制文件下载类型
        const blob = new Blob([data], {type:'application/octet-stream;charset=utf-8'})
        // 下载文件名称
        const fileName = row.fileName
        // a标签下载
        const linkNode = document.createElement('a')
        linkNode.download = fileName // a标签的download属性规定下载文件的名称
        linkNode.style.display = 'none'
        linkNode.href = URL.createObjectURL(blob) // 生成一个Blob URL
        document.body.appendChild(linkNode)
        linkNode.click() // 模拟在按钮上的一次鼠标单击
        URL.revokeObjectURL(linkNode.href) // 释放URL 对象
        document.body.removeChild(linkNode)
      })
    },

    // 预览
    previewFile (row) {
      // 预览文件
      let image = ['jpg', 'jpeg', 'png', 'gif', 'bmp']
      let type = ''
      if (image.includes(row.fileType.toLowerCase())) {
        type = 'image/' + row.fileType
      }
      let video = ['mp4', 'avi', 'mov', 'wmv', 'flv']
      if (video.includes(row.fileType.toLowerCase())) {
        type = 'video/' + row.fileType
      }
      let txt = ['txt']
      if (txt.includes(row.fileType.toLowerCase())) {
        type = 'text/plain'
      }
      let office = ['doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx']
      if (office.includes(row.fileType.toLowerCase())) {
        this.$message.warning(`暂不支持预览${row.fileType.toLowerCase()}文件`)
        return
      }
      let pdf = ['pdf']
      if (pdf.includes(row.fileType.toLowerCase())) {
        type = 'application/pdf'
      }
      if (type === ''){
        this.$message.warning(`暂不支持预览${row.fileType.toLowerCase()}文件`)
        return;
      }
      downLoadObjectFile(row).then(({data}) => {
        const blob = new Blob([data], { type: type });
        // 创建URL来生成预览
        const fileURL = URL.createObjectURL(blob);
        // 在新标签页中打开文件预览
        const newTab = window.open(fileURL, '_blank')
      })
    },

    // ======== 基础数据失焦事件 ========
    // 计量单位输入校验
    umIdBlur (tagNo) {
      if (this.modalData.umId2 != null && this.modalData.umId2 !== '') {
        let tempData = {
          tagno: tagNo,
          conditionSql: " and UMID = '" + this.modalData.umId2 + "'" + " and site  = '" + this.modalData.bu.split('_')[0] + "'"
        }
        verifyData(tempData).then(({data}) => {
          if (data && data.code === 0) {
            if (data.baseListData.length > 0) {
              this.modalData.umId2 = data.baseListData[0].UMID
              this.modalData.umName = data.baseListData[0].UMName
              return
            }
          }
        })
      }
      this.modalData.umName = ''
    },

    // 商品组1输入校验
    productGroupId1Blur (tagNo) {
      if (this.modalData.productGroupId1 != null && this.modalData.productGroupId1 !== '') {
        let tempData = {
          tagno: tagNo,
          conditionSql: " and product_group_id = '" + this.modalData.productGroupId1 + "'" + " and site  = '" + this.modalData.bu.split('_')[0] + "'" + " and bu_no  = '" + this.modalData.bu.split('_')[1] + "'"
        }
        verifyData(tempData).then(({data}) => {
          if (data && data.code === 0) {
            if (data.baseListData.length > 0) {
              this.modalData.productGroupId1 = data.baseListData[0].product_group_id
              this.modalData.productGroupName1 = data.baseListData[0].product_group_name
              return
            }
          }
        })
      }
      this.modalData.productGroupName1 = ''
    },

    // 商品组2输入校验
    productGroupId2Blur (tagNo) {
      if (this.modalData.productGroupId2 != null && this.modalData.productGroupId2 !== '') {
        let tempData = {
          tagno: tagNo,
          conditionSql: " and product_group_id = '" + this.modalData.productGroupId2 + "'" + " and site  = '" + this.modalData.bu.split('_')[0] + "'" + " and bu_no  = '" + this.modalData.bu.split('_')[1] + "'"
        }
        verifyData(tempData).then(({data}) => {
          if (data && data.code === 0) {
            if (data.baseListData.length > 0) {
              this.modalData.productGroupId2 = data.baseListData[0].product_group_id
              this.modalData.productGroupName2 = data.baseListData[0].product_group_name
              return
            }
          }
        })
      }
      this.modalData.productGroupName2 = ''
    },

    // 商品组3输入校验
    productGroupId3Blur (tagNo) {
      if (this.modalData.productGroupId3 != null && this.modalData.productGroupId3 !== '') {
        let tempData = {
          tagno: tagNo,
          conditionSql: " and product_group_id = '" + this.modalData.productGroupId3 + "'" + " and site  = '" + this.modalData.bu.split('_')[0] + "'" + " and bu_no  = '" + this.modalData.bu.split('_')[1] + "'"
        }
        verifyData(tempData).then(({data}) => {
          if (data && data.code === 0) {
            if (data.baseListData.length > 0) {
              this.modalData.productGroupId3 = data.baseListData[0].product_group_id
              this.modalData.productGroupName3 = data.baseListData[0].product_group_name
              return
            }
          }
        })
      }
      this.modalData.productGroupName3 = ''
    },

    // 物料分类输入校验
    partFamilyBlur (tagNo) {
      if (this.modalData.familyID != null && this.modalData.familyID !== '') {
        let tempData = {
          tagno: tagNo,
          conditionSql: " and family_id = '" + this.modalData.familyID + "'" + " and site  = '" + this.modalData.bu.split('_')[0] + "'" + " and bu_no  = '" + this.modalData.bu.split('_')[1] + "'"
        }
        verifyData(tempData).then(({data}) => {
          if (data && data.code === 0) {
            if (data.baseListData.length > 0) {
              this.modalData.familyID = data.baseListData[0].family_id
              this.modalData.familyName = data.baseListData[0].family_name
              return
            }
          }
        })
      }
      this.modalData.familyName = ''
    },

    // 属性输入校验
    modelBlur (tagNo) {
      if (this.modalData.codeNo != null && this.modalData.codeNo !== '') {
        let tempData = {
          tagno: tagNo,
          conditionSql: " and code_no = '" + this.modalData.codeNo + "'" + " and site  = '" + this.modalData.bu.split('_')[0] + "'" + " and bu_no  = '" + this.modalData.bu.split('_')[1] + "'"
        }
        verifyData(tempData).then(({data}) => {
          if (data && data.code === 0) {
            if (data.baseListData.length > 0) {
              this.modalData.codeNo = data.baseListData[0].code_no
              this.modalData.codeDesc = data.baseListData[0].code_desc
              return
            }
          }
        })
      }
      this.modalData.codeDesc = ''
    },

    // BOM模板输入校验
    bomTemplateBlur (tagNo) {
      if (this.modalData.templateNo != null && this.modalData.templateNo !== '') {
        let tempData = {
          tagno: tagNo,
          conditionSql: " and template_no = '" + this.modalData.templateNo + "'" + " and site  = '" + this.modalData.bu.split('_')[0] + "'"
        }
        verifyData(tempData).then(({data}) => {
          if (data && data.code === 0) {
            if (data.baseListData.length > 0) {
              this.modalData.templateNo = data.baseListData[0].template_no
              this.modalData.templateName = data.baseListData[0].template_name
              return
            }
          }
        })
      }
      this.modalData.templateName = ''
    },


    // ======== chooseList相关方法 ========
    // 获取基础数据列表S
    getBaseList (val, type) {
      this.tagNo = val
      this.tempCodeNo = this.modalData.codeNo
      this.$nextTick(() => {
        let strVal = ''
        let conSql = ''
        if (!this.templateAddFlag){
          if (this.modalData.bu === null || this.modalData.bu === '') {
            this.$message.warning("请选择BU!")
            return
          } else {
            conSql = " and site = '" + this.modalData.bu.split('_')[0] + "'" + " and bu_no = '" + this.modalData.bu.split('_')[1] + "'"
          }
          if (val === 510) {
            strVal = this.modalData.umId2
            conSql = " and site = '" + this.modalData.bu.split('_')[0] + "'"
          } else if (val === 211) {
            strVal = this.modalData.productGroupId1
          } else if (val === 212) {
            strVal = this.modalData.productGroupId2
          } else if (val === 213) {
            strVal = this.modalData.productGroupId3
          } else if (val === 214) {
            strVal = this.modalData.familyID
          } else if (val === 219) {
            strVal = this.modalData.codeNo
          } else if (val === 518) {
            strVal = this.modalData.templateNo
            conSql = " and site = '" + this.modalData.bu.split('_')[0] + "'"
          }
        } else {
          if (this.tempData.bu === null || this.tempData.bu === '') {
            this.$message.warning("请选择BU!")
            return
          } else {
            conSql = " and site = '" + this.tempData.bu.split('_')[0] + "'" + " and bu_no = '" + this.tempData.bu.split('_')[1] + "'"
          }
          if (val === 510) {
            strVal = this.tempData.umId
            conSql = " and site = '" + this.tempData.bu.split('_')[0] + "'"
          } else if (val === 211) {
            strVal = this.tempData.productGroupId1
          } else if (val === 212) {
            strVal = this.tempData.productGroupId2
          } else if (val === 213) {
            strVal = this.tempData.productGroupId3
          } else if (val === 214) {
            strVal = this.tempData.familyID
          } else if (val === 219) {
            strVal = this.tempData.codeNo
          } else if (val === 518) {
            strVal = this.tempData.bomTemplateNo
            conSql = " and site = '" + this.tempData.bu.split('_')[0] + "'"
          }
        }
        this.$refs.baseList.init(val, strVal, conSql)
      })
    },
    // 列表方法的回调
    getBaseData (val) {
      if(!this.templateAddFlag){
        if (this.tagNo === 510) {
          this.modalData.umId2 = val.UMID
          this.modalData.umName = val.UMName
        } else if (this.tagNo === 211) {
          this.modalData.productGroupId1 = val.product_group_id
          this.modalData.productGroupName1 = val.product_group_name
        } else if (this.tagNo === 212) {
          this.modalData.productGroupId2 = val.product_group_id
          this.modalData.productGroupName2 = val.product_group_name
        } else if (this.tagNo === 213) {
          this.modalData.productGroupId3 = val.product_group_id
          this.modalData.productGroupName3 = val.product_group_name
        } else if (this.tagNo === 214) {
          this.modalData.familyID = val.family_id
          this.modalData.familyName = val.family_name
        } else if (this.tagNo === 219) {
          if (this.modalData.flag === '2') {
            if (val.code_no != this.tempCodeNo) {
              this.$confirm(`更换属性模板将替换下方物料属性数据，请确认?`, '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
              }).then(() => {
                this.modalData.codeNo = val.code_no
                this.$set(this.modalData, 'codeDesc', val.code_desc)
              }).catch(() => {
              })
            }
          } else {
            this.modalData.codeNo = val.code_no
            this.$set(this.modalData, 'codeDesc', val.code_desc)
          }
        } else if (this.tagNo === 518) {
          this.modalData.templateNo = val.template_no
          this.modalData.templateName = val.template_name
        }
      } else {
        if (this.tagNo === 510) {
          this.tempData.umId = val.UMID
          this.tempData.umName = val.UMName
        } else if (this.tagNo === 211) {
          this.tempData.productGroupId1 = val.product_group_id
          this.tempData.productGroupName1 = val.product_group_name
        } else if (this.tagNo === 212) {
          this.tempData.productGroupId2 = val.product_group_id
          this.tempData.productGroupName2 = val.product_group_name
        } else if (this.tagNo === 213) {
          this.tempData.productGroupId3 = val.product_group_id
          this.tempData.productGroupName3 = val.product_group_name
        } else if (this.tagNo === 214) {
          this.tempData.familyId = val.family_id
          this.tempData.familyName = val.family_name
        } else if (this.tagNo === 219) {
          this.tempData.codeNo = val.code_no
          this.$set(this.tempData, 'codeDesc', val.code_desc)
        } else if (this.tagNo === 518) {
          this.tempData.bomTemplateNo = val.template_no
          this.$set(this.tempData, 'bomTemplateName', val.template_name)
        }
      }
    },

    templateAdd() {
      if (this.tempData.bu === null || this.tempData.bu === ''){
        this.$message.warning("请选择BU!")
        return
      }
      if (this.tempData.templateNo === null || this.tempData.templateNo === ''){
        this.$message.warning("请填写模板编码!")
        return
      }
      if (this.tempData.templateName === null || this.tempData.templateName === ''){
        this.$message.warning("请填写模板名称!")
        return
      }
      templateAdd(this.tempData).then(({data}) => {
        if (data&&data.code===0){
          this.getTemplateList()
          this.templateAddFlag = false
          this.$message({
            message: '操作成功',
            type: 'success',
            duration: 1500,
            onClose: () => {}
          })
        } else {
          this.$alert(data.msg, '错误', {
            confirmButtonText: '确定'
          })
        }
      })
    },

    getTemplateList() {
      this.modalData.buNo = this.modalData.bu.split('_')[1]
      getTemplateList(this.modalData).then(({data}) => {
        if (data && data.code === 0) {
          this.templateList = data.rows
        }
      })
    },

    chooseTemplate(){
      chooseTemplate(this.modalData).then(({data}) => {
        if (data&&data.code===0) {
          Object.keys(data.data).forEach(key => {
            if (key !== 'tempNo') {
              this.modalData[key] = data.data[key];
            }
          });
          this.modalData.umId2 = data.data.umId
          this.modalData.familyID = data.data.familyId
          this.modalData.templateNo = data.data.bomTemplateNo
          this.modalData.templateName = data.data.bomTemplateName
        }
      })
    },

    saveQuicklyCreate(){
      let inData = {
        id: this.initData.id,
        testPartId: this.initData.testPartId,
        testPartDesc: this.initData.partDesc,
        partBomStatus: this.initData.partBomStatus,
        updateBy: this.$store.state.user.name,
      }
        updateInquiryDetailStatusAndPart(inData).then(({data}) => {
          if (data && data.code === 0) {
            EventBus.$emit('refreshInquiryOneDetail1')
            EventBus.$emit('refreshInquiryOneDetail2')
          } else {
            this.$alert('自动完成失败,请手动点击完成键', '错误', {
              confirmButtonText: '确定'
          })
        }
      })
    },

    handleTemplateAdd() {
      this.tempData.templateNo = 'TEMPLATE' + Date.now()
      this.templateAddFlag = true
    }
  }
}
</script>
