zouyu
2023-09-27 ed2f5cbcb482a22fbf799cf14ff3d3152669e7ac
src/components/view/mbom.vue
@@ -1,156 +1,38 @@
<template>
   <div class="record_content">
      <div class="title">
            <el-row>
         <el-row>
            <el-col :span="12" style="line-height: 32px;">物料清单维护</el-col>
            <el-col :span="12" style="text-align: right;">
               <el-button type="primary" icon="el-icon-plus" style="background: #004EA2;" @click="event">新增</el-button>
               <el-button icon="el-icon-delete" @click="dels" >删除</el-button>
               <el-button icon="el-icon-upload2" @click="showImportDialog">导入</el-button>
               <el-button icon="el-icon-download" @click="exportDialogVisible=true">导出</el-button>
               <el-button icon="el-icon-delete" @click="dels">删除</el-button>
            </el-col>
         </el-row>
      </div>
      <div>
            <el-dialog
            title="物料清单的维护"
            :visible.sync="dialogVisible"
            width="80%"
            :before-close="handleClose" :center="true">
            <div>
            <el-form>
            <el-row :gutter="2">
            <el-col :span="8">
               <el-form-item label="类型:">
               <el-select v-model="search.type" size="small" placeholder="请选择" style="width: 224px;margin-right: 30px;">
                  <el-option label="橡胶连接器" :value="0"></el-option>
                  <el-option label="金属连接器" :value="1"></el-option>
                  <el-option label="湿插拔电连接器" :value="2"></el-option>
                  <el-option label="分支组件" :value="3"></el-option>
               </el-select>
               </el-form-item>
            </el-col>
            <el-col :span="8">
               <el-form-item label="工序">
                            <template>
                                <el-select v-model="search.work"
                                placeholder="请选择类型"
                                allow-create
                                filterable
                                @change="workevent"
                                >
                                    <el-option
                                    v-for="(item,index) in process"
                                    :key="item.name"
                                    :label="item.name"
                                    :value="item.name">
                                    </el-option>
                                </el-select>
                                </template>
                        </el-form-item>
            </el-col>
            <el-col :span="8">
               <el-form-item label="工艺名称:">
               <el-select v-model="search.craft" size="small" placeholder="请选择" style="width: 224px;margin-right: 30px;">
                  <el-option
                     v-for="item in craftapi"
                     :key="item.id"
                     :label="item.name"
                     :value="item.id">
                     </el-option>
               </el-select>
            </el-form-item>
            </el-col>
            </el-row>
         </el-form>
            <el-button size="mini" @click="Addrow" >添加行</el-button>
         </div>
         <div style="margin: 10px 0px;">
            <template>
               <el-table
               border
               :data="tableapi"
               height="calc(80vh - 250px)"
               style="width: 100%">
               <el-table-column type="index" label="序号" width="70">
               </el-table-column>
               <el-table-column
                  prop="date"
                  label="供应商名称"
                  width="180">
                  <template slot-scope="scope">
                     <el-input v-model="scope.row.supplier" placeholder="" ></el-input>
                  </template>
               </el-table-column>
               <el-table-column
                  prop=""
                  label="质量追溯号"
                  width="180">
                  <template slot-scope="scope">
                     <el-input v-model="scope.row.qualityTraceability" placeholder="" ></el-input>
                  </template>
               </el-table-column>
               <el-table-column
                  prop="name"
                  label="原材料名称">
                  <template slot-scope="scope">
                     <el-input v-model="scope.row.name" placeholder="" ></el-input>
                  </template>
               </el-table-column>
               <el-table-column
                  prop="address"
                  label="规格型号">
                  <template slot-scope="scope">
                     <el-input v-model="scope.row.specifications" placeholder="" ></el-input>
                  </template>
               </el-table-column>
               <el-table-column
                  prop="unit"
                  label="单位">
                  <template slot-scope="scope">
                     <el-input v-model="scope.row.unit" placeholder="" ></el-input>
                  </template>
               </el-table-column>
               </el-table>
            </template>
         </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="skipshow">确 定</el-button>
            </span>
            </el-dialog>
        </div>
      <div class="choose">
            <span>类型:</span>
         <el-select v-model="search.type" size="small" @change="TYpe" placeholder="请选择" style="width: 224px;margin-right: 30px;">
            <el-option label="橡胶连接器" :value="0"></el-option>
            <el-option label="金属连接器" :value="1"></el-option>
            <el-option label="湿插拔电连接器" :value="2"></el-option>
            <el-option label="分支组件" :value="3"></el-option>
         <span>类型:</span>
         <el-select v-model="search.type" size="small" @change="TYpe" placeholder="请选择"
            style="width: 224px;margin-right: 30px;">
            <el-option v-for="(a, ai) in bigType" :key="ai" :value="a"></el-option>
         </el-select>
         <!-- <span>原材料名称:</span>
         <el-select v-model="search.name" size="small" placeholder="请选择" style="width: 224px;margin-right: 30px;">
            <el-option v-for="(a, ai) in process" key="ai" :label="a.name" :value="a.id"></el-option>
         </el-select>
         <el-button size="mini"><span>重 置</span></el-button>
         <el-button size="mini" type="primary" style="background: #004EA2;"><span>查询</span></el-button> -->
      </div>
      <div class="thing">
         <div class="left">
            <el-input v-model="search.technology" suffix-icon="el-icon-search" placeholder="请输入搜索内容" size="small" clearable ></el-input>
                <el-tree :data="list" ref="tree"
            :props="{children: 'children',label: 'name'}"
            node-key="id" default-expand-all  @node-click="handleNodeClick" >
            <el-input v-model="search.technology" @input="query" suffix-icon="el-icon-search" placeholder="请输入搜索内容"
               size="small" clearable></el-input>
            <el-tree :data="list" ref="tree" style="overflow-y: auto;padding-top: 8px;" highlight-current
               :props="{children: 'children',label: 'name'}" node-key="name" default-expand-all
               @node-click="handleNodeClick">
               <div class="custom-tree-node" slot-scope="{ node, data }">
                  <span><i :class="`node_i ${data.code != '[3]'?'el-icon-folder-opened':'el-icon-tickets'}`"></i>
                  <span><i :class="`node_i ${data.code != '[2]'?'el-icon-folder-opened':'el-icon-tickets'}`"></i>
                     {{data.code}} {{ data.name }}</span>
                  <el-button type="text" size="mini" @click.stop="remove(node, data)">
                     <i class="el-icon-delete"></i>
                  </el-button>
               </div>
            </el-tree>
         </div>
         <div class="right">
                <el-table :data="tableData" border style="width: 100%;overflow-y: auto;min-height: 100%" max-height="100%"
            <el-table :data="tableData" border style="width: 100%;overflow-y: auto;min-height: 100%" max-height="100%"
               @selection-change="handleSelectionChange" default-expand-all>
               <el-table-column type="selection" width="50">
               </el-table-column>
@@ -162,94 +44,307 @@
               </el-table-column>
               <el-table-column label="操作" width="130">
                  <template slot-scope="scope">
                     <!-- <span class="table_do" @click="upContent(scope.row)">编辑&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> -->
                     <span class="table_do" @click="deleteRow(scope.$index, scope.row)">删除</span>
                  </template>
               </el-table-column>
            </el-table>
         </div>
      </div>
      <!-- <el-dialog title="编辑记录内容" :visible.sync="upDia" width="500px">
         <div class="body">
      <el-dialog title="物料清单的维护" :visible.sync="dialogVisible" width="80%" :before-close="handleClose" :center="true">
         <div>
            <el-form>
               <el-row :gutter="2">
                  <el-col :span="8">
                     <el-form-item label="类型:">
                        <el-select v-model="search.type" size="small" placeholder="请选择"
                           style="width: 224px;margin-right: 30px;">
                           <el-option v-for="(a, ai) in bigType" :key="ai" :value="a"></el-option>
                        </el-select>
                     </el-form-item>
                  </el-col>
                  <el-col :span="8">
                     <el-form-item label="工序">
                        <template>
                           <el-select v-model="search.work" placeholder="请选择" allow-create filterable @change="workevent">
                              <el-option v-for="(item,index) in process" :key="item.name" :label="item.name" :value="item.name">
                              </el-option>
                           </el-select>
                        </template>
                     </el-form-item>
                  </el-col>
                  <el-col :span="8">
                     <el-form-item label="工艺名称:">
                        <el-select v-model="search.craft" size="small" placeholder="请选择"
                           style="width: 224px;margin-right: 30px;">
                           <el-option v-for="item in craftapi" :key="item.id" :label="item.name" :value="item.id">
                           </el-option>
                        </el-select>
                     </el-form-item>
                  </el-col>
               </el-row>
            </el-form>
            <el-button size="mini" @click="Addrow">添加行</el-button>
         </div>
      </el-dialog> -->
         <div style="margin: 10px 0px;">
            <template>
               <el-table border :data="tableapi" height="calc(80vh - 250px)" style="width: 100%">
                  <el-table-column type="index" label="序号" width="70">
                  </el-table-column>
                  <el-table-column prop="" label="质量追溯号" width="180">
                     <template slot-scope="scope">
                        <el-input v-model="scope.row.qualityTraceability" placeholder=""></el-input>
                     </template>
                  </el-table-column>
                  <el-table-column prop="name" label="原材料名称">
                     <template slot-scope="scope">
                        <el-input v-model="scope.row.name" placeholder=""></el-input>
                     </template>
                  </el-table-column>
                  <el-table-column prop="address" label="规格型号">
                     <template slot-scope="scope">
                        <el-input v-model="scope.row.specifications" placeholder=""></el-input>
                     </template>
                  </el-table-column>
                  <el-table-column prop="unit" label="单位">
                     <template slot-scope="scope">
                        <el-input v-model="scope.row.unit" placeholder=""></el-input>
                     </template>
                  </el-table-column>
               </el-table>
            </template>
         </div>
         <span slot="footer" class="dialog-footer">
            <el-button @click="dialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="skipshow">确 定</el-button>
         </span>
      </el-dialog>
      <el-dialog title="物料清单导入" :visible.sync="importDialogVisible" width="30%">
         <el-upload ref="upload" class="upload-demo" drag action="#" :auto-upload="false"
         :on-change="handleUpload" multiple>
            <i class="el-icon-upload"></i>
            <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
            <div class="el-upload__tip" slot="tip">
               只能上传xls/xlsx文件,且不超过1MB。
               <a href="#" style="color:#409eff;font-size:10px;text-decoration: underline;" @click="downloadTemplate">下载模板</a>
            </div>
         </el-upload>
         <span slot="footer" class="dialog-footer">
            <el-button @click="importDialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="importMaterial">确 定</el-button>
         </span>
      </el-dialog>
      <el-dialog title="物料清单导出" :visible.sync="exportDialogVisible" width="40%">
         <el-row>
            <el-col :span="4">
               <span>类型选择:</span>
            </el-col>
            <el-col :span="20">
               <el-checkbox :indeterminate="isIndeterminate" v-model="checkAll"
               @change="handleCheckAllChange" name="type" label="全选"></el-checkbox>
               <el-checkbox-group v-model="exportTypeList" @change="handleCheckedChange">
                  <el-checkbox v-for="(item,index) in bigType" :key="index" :label="item" name="type"></el-checkbox>
               </el-checkbox-group>
            </el-col>
         </el-row>
         <span slot="footer" class="dialog-footer">
            <el-button @click="exportDialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="exportMaterial" :loading="exportLoading">
               {{exportLoading ? "加载中" : "确 定"}}
            </el-button>
         </span>
      </el-dialog>
   </div>
</template>
<script>
export default {
   export default {
      data() {
         return {
              search:{},
              list:[],
            process:{},
            exportLoading: false,
            isIndeterminate: true,
            checkAll: false,
            importFileList:[],
            exportTypeList:[],
            importDialogVisible:false,
            exportDialogVisible:false,
            search: {
               type: 0,
               technology: ''
            },
            list: [],
            process: {},
            // handleClose:[],
            checkTreeNode:{
               id:2,
            checkTreeNode: {
               id: '',
            },
            tableData:[],
            tableapi:[{
               supplier:'',
               qualityTraceability:'',
               name:'',
               specifications:'',
               unit:'',
               }],
            search:{
               type:'',
               work:'',
               craft:'',
            },
            addsearch:{},
            upData:{},
            form:{},
            dialogVisible:false,
            typeselect:0,
            input:'',
            craftapi:[],
            }
        },
      mounted() {
         this.selectAllleft()
         this.selectAllMbom()
            tableData: [],
            tableapi: [{
               supplier: '',
               qualityTraceability: '',
               name: '',
               specifications: '',
               unit: '',
            }],
            addsearch: {},
            upData: {},
            form: {},
            dialogVisible: false,
            typeselect: '',
            input: '',
            craftapi: [],
            bigType: []
         }
      },
      methods:{
          workevent(val){
                console.log(val);
                let idx = this.process.findIndex(el => el.name === val)
                this.craftapi = this.process[idx].children
            },
      mounted() {
         this.chooseType()
      },
      watch:{
         importDialogVisible(newVal){
            if(!newVal){
               this.$refs['upload'].clearFiles();
            }
         },
         exportDialogVisible(newVal){
            if(!newVal){
               this.exportTypeList = [];
               this.checkAll = false;
               this.isIndeterminate =  true;
            }
         },
      },
      methods: {
         handleCheckAllChange(val) {
            this.exportTypeList = val ? this.bigType : [];
            this.isIndeterminate = false;
         },
         handleCheckedChange(value) {
            let checkedCount = value.length;
            this.checkAll = checkedCount === this.bigType.length;
            this.isIndeterminate = checkedCount > 0 && checkedCount < this.bigType.length;
         },
         showImportDialog(){
            this.importDialogVisible = true;
         },
         //下载模板
         downloadTemplate(){
            this.$axios.post(this.$api.url.downloadMBomTemplate,
            {typeList:this.bigType.join(',')},
            {
               responseType:'blob',
               headers:{"Content-Type":"application/json"}
            }).then((res)=>{
               this.downloadFun(res);
            }).catch()
         },
         //导入
         importMaterial(){
            console.log(this.importFileList);
         },
         downloadFun(result){
            if(result == null || result == undefined){
               return;
            }
            var nameList = result.headers['content-disposition'];
            nameList = decodeURI(nameList);
            var fileName = nameList.split('=')[1];
            const blob = new Blob([result.data,{type: 'application/vnd.ms-excel'}]);
            const link = document.createElement('a');
            link.download = fileName;
            const URL = window.URL || window.webkitURL;
            link.href= URL.createObjectURL(blob);
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
         },
         // 文件上传
         handleUpload(file, fileList) {
            const maxSize = 1 * 1024 * 1024 * 1024;//1MB
            const xlsType = "application/vnd.ms-excel";
            const xlsxType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
            if(file.raw.type != xlsType && file.raw.type != xlsxType){
               this.$message.warning("导入文件格式不符!");
               this.$refs['upload'].clearFiles();
               return;
            }
            if(Number.parseInt(file.size) > maxSize){
               this.$message.warning("导入文件过大!");
               this.$refs['upload'].clearFiles();
               return;
            }
            this.importFileList = fileList;
         },
         //导出
         exportMaterial(){
            if(this.exportTypeList.length == 0){
               this.$message.warning("请先选择至少一种类型!");
               return;
            }
            this.exportLoading = true;
            this.$axios.post(this.$api.url.exportMBom,
            {typeList:this.exportTypeList.join(',')},
            {
               responseType:'blob',
               headers:{"Content-Type":"application/json"}
            }).then((res)=>{
               this.downloadFun(res);
               this.exportLoading = false;
            }).catch()
         },
         chooseType() {
            this.$axios.get(this.$api.url.chooseType).then(res => {
               this.bigType = res.data;
               this.typeselect = res.data[0];
               this.search.type = res.data[0];
               this.selectAllleft();
               this.selectAllMbom();
            })
         },
         selectDataList() {
            this.list.forEach(a => {
               a.code = '[1]'
               if (a.children != undefined) {
                  a.children.forEach(b => {
                     b.code = '[2]'
                     if (b.children != undefined) {
                        b.children.forEach(c => {
                           c.code = '[3]'
                        })
                     }
                  })
               }
            })
            this.upIndex++
         },
         workevent(val) {
            console.log(val);
            let idx = this.process.findIndex(el => el.name === val)
            this.craftapi = this.process[idx].children
         },
         //新增
         chooseTechFath() {
         this.$axios.get(this.$api.url.chooseTechFath,{
                params:{type:this.typeselect}
            }).then(res => {
            this.process = res.data;
                console.log(this.process);
         }, {
            headers: {
                      "Content-Type": "application/json"
                    }
            })
         },
         addMbom(data) {
            this.$axios.post(this.$api.url.addMbom,data
            // {
               // name:this.tableapi.name,
               // qualityTraceability:this.tableapi.qualityTraceability,
               // specifications:this.tableapi.specifications,
               // supplier:this.tableapi.supplier,
               // techTemId:this.craftapi.id,
               // unit:this.tableapi.unit,
            // }
            , {
            this.$axios.get(this.$api.url.chooseTechFath, {
               params: {
                  type: this.typeselect
               }
            }).then(res => {
               this.process = res.data;
               console.log(this.process);
            }, {
               headers: {
                      "Content-Type": "application/json"
                    }
            }).then(res =>{
               console.log(res);
                  "Content-Type": "application/json"
               }
            })
         },
         addMbom(data, cc) {
            this.$axios.post(this.$api.url.addMbom, {
               mbomModelDto2List: data,
               techTemId: cc,
            }, {
               headers: {
                  "Content-Type": "application/json"
               }
            }).then(res => {
               // console.log(res);
               this.$message.success('添加完成')
               this.selectAllMbom()
               this.tableapi = [{}]
@@ -258,11 +353,11 @@
         //删除
         material(index) {
            console.log(this.upData.id);
            this.$axios.post(this.$api.url.material,{
               id:this.upData.id
            }).then(res =>{
            this.$axios.post(this.$api.url.material, {
               id: this.upData.id
            }).then(res => {
               this.$message.success(res.message)
               this.tableData.splice(index,1)
               this.tableData.splice(index, 1)
               // console.log(res);
            })
@@ -271,67 +366,100 @@
            this.typeselect = val
            this.selectAllleft()
         },
         query() {
            this.selectAllleft()
         },
         //左边
         selectAllleft() {
         this.$axios.get(this.$api.url.selectAllleft,{
            params:{type:this.typeselect}
         }).then(res => {
            this.list = res.data;
            console.log(this.list);
         }, {
            headers: {
                      "Content-Type": "application/json"
                    }
            })
            this.$axios.get(this.$api.url.selectAllleft, {
               params: {
                  type: this.typeselect,
                  message: this.search.technology
               }
            }).then(res => {
               this.list = res.data;
               this.selectDataList()
               this.$nextTick(() => {
                  this.$refs.tree.setCurrentKey(this.list[0].children[0].name) // 默认选中节点第一个
               })
               let one = this.list.filter(item => {
                  return item.children.length > 0
               })[0]
               let name = one.children[0].id
               this.checkTreeNode.id = name
               this.selectAllMbomStart(name)
               this.selectDataList();
            }, {
               headers: {
                  "Content-Type": "application/json"
               }
            })
         },
         selectAllMbomStart(name) {
            this.$axios.get(this.$api.url.selectAllMbom, {
               params: {
                  id: name
               }
            }).then(res => {
               this.tableData = res.data;
            }, {
               headers: {
                  "Content-Type": "application/json"
               }
            })
         },
         //右边
         selectAllMbom() {
         this.$axios.get(this.$api.url.selectAllMbom,{
            params:{id:this.checkTreeNode.id}
         }).then(res => {
            this.tableData = res.data;
            console.log(this.tableData);
         }, {
            headers: {
                      "Content-Type": "application/json"
                    }
            })
            this.$axios.get(this.$api.url.selectAllMbom, {
               params: {
                  id: this.checkTreeNode.id
               }
            }).then(res => {
               this.tableData = res.data;
            }, {
               headers: {
                  "Content-Type": "application/json"
               }
            })
         },
         handleNodeClick(data){
                this.checkTreeNode = data
            console.log(this.checkTreeNode.id);
         handleNodeClick(data) {
            this.checkTreeNode = data
            this.selectAllMbom()
            },
         },
         handleClose(done) {
            this.$confirm('确认关闭?')
            .then(_ => {
               done();
            })
            .catch(_ => {});
               .then(_ => {
                  done();
               })
               .catch(_ => {});
         },
            event(){
                this.dialogVisible = true
         //新增
         event() {
            this.dialogVisible = true
            this.chooseTechFath()
            },
          Addrow() {
         if (this.tableapi == undefined) {
            this.tableapi = new Array();
         }
         let obj = [];
         this.tableapi.push(obj);
         },
         skipshow(){
            console.log('666');
            let data = this.tableapi.at(-1)
            // this.addMbom()
            data.techTemId = this.search.craft
            // console.log(this.search.craft);
            // console.log(data);
            this.addMbom(data)
         //添加行
         Addrow() {
            if (this.tableapi == undefined) {
               this.tableapi = new Array();
            }
            let obj = {};
            this.tableapi.push(obj);
         },
         skipshow() {
            // let data = this.tableapi.at(-1)
            // console.log(this.tableapi);
            let cc = this.search.craft
            this.addMbom(this.tableapi, cc)
            this.dialogVisible = false
         },
         //delAllMbom 批量删除
         delAllMbom() {
            this.$axios.post(this.$api.url.delAllMbom, {
               ids: this.delete
            }).then(res => {
               this.selectAllMbom()
            })
         },
         dels() {
            this.selects.forEach(a => {
@@ -342,21 +470,23 @@
                  }
               }
            })
            let cc = this.selects.map(el => {
               return el.id
            })
            this.delete = cc.join(',')
            this.delAllMbom()
            this.$message.success('删除完成')
         },
         handleSelectionChange(val) {
            this.selects = val;
         },
         deleteRow(index, rows) {
            console.log(rows);
            // this.tableData.splice(index,1)
            this.upData.id = rows.id
            console.log(this.upData);
            this.material(index)
         },
        }
    }
      }
   }
</script>
<style scoped>
@@ -375,7 +505,8 @@
   .title * {
      font-size: 16px;
   }
   .choose-1{
   .choose-1 {
      padding: 5px 24px;
      display: flex;
      align-items: center;
@@ -414,6 +545,7 @@
      height: calc(100% - 20px);
      border-right: 3px solid rgb(245, 247, 251);
      padding: 16px;
      overflow-y: auto;
   }
   .thing .left .custom-tree-node span {