From c26deaa0190c0ed42b398f3e5696013127a6c10f Mon Sep 17 00:00:00 2001 From: 小小儁爺 <1694218219@qq.com> Date: 星期二, 11 三月 2025 16:17:51 +0800 Subject: [PATCH] 1.看板修改 --- src/views/materialManager/unitList.vue | 1383 ++++++++++++++++++++++++++++---------------------------- 1 files changed, 694 insertions(+), 689 deletions(-) diff --git a/src/views/materialManager/unitList.vue b/src/views/materialManager/unitList.vue index 301ab2b..2500004 100644 --- a/src/views/materialManager/unitList.vue +++ b/src/views/materialManager/unitList.vue @@ -1,689 +1,694 @@ -<template> - <div> - <div class="body" :style="{height:mainHeight+'px'}"> - <div style="display: flex"> - <!-- background:rgba(248,248,250,1);--> - <div style="width: 300px;margin: 10px 10px 0 0;background: #fff"> - - <div style="margin: 20px 10px 0 10px;display: flex;justify-content: space-between;"> - <div style="display: flex;"> - <div - style="width: 5px;height: 100%;border-radius: 5px;" - :style="{background:$store.state.settings.theme}" - /> - <div style="margin-left: 8px;">璁¢噺鍗曚綅</div> - </div> - - <!-- <div style="margin-right:10px">--> - <!-- <i class="el-icon-plus" style="cursor: pointer;color: #999" />--> - <!-- </div>--> - - </div> - - <el-tree - ref="treeLeftRef" - key="treeLeftKey" - style="padding: 10px;overflow: auto;" - :style="{height:(tableHeight+150)+'px'}" - :data="treeLeft" - node-key="code" - highlight-current - :props="defaultPropsLeft" - :default-expand-all="true" - :expand-on-click-node="false" - @node-click="nodeClick" - /> - - </div> - - <div style="width: calc(100% - 300px)"> - <div class="bodyTopButtonGroup"> - <el-button v-waves type="primary" icon="el-icon-circle-plus-outline" @click="add('add')">鏂板</el-button> - <el-button v-waves type="info" icon="el-icon-refresh" @click="getSaveSearchUnit">鍚屾璁¢噺鍗曚綅</el-button> - </div> - - <div class="elTableDiv"> - <el-table - ref="tableDataRef" - class="tableFixed" - :data="tableData" - :height="isExpandForm?tableHeight:(tableHeight+80)+'px'" - border - row-class-name="custom-row" - :style="{width: 100+'%',height:isExpandForm?tableHeight:(tableHeight+80)+'px',}" - highlight-current-row - :header-cell-style="this.$headerCellStyle" - :cell-style="this.$cellStyle" - @sort-change="sortChange" - > - <el-table-column - prop="rowNum" - width="50" - fixed - label="搴忓彿" - /> - <el-table-column - prop="code" - label="璁¢噺鍗曚綅缂栫爜" - sortable="custom" - > - <template slot-scope="{row}"> - {{ row.isGroup === '0' ? row.code :(!isMainUnitHidden?row.code:'') }} - </template> - </el-table-column> - <el-table-column - prop="name" - label="璁¢噺鍗曚綅鍚嶇О" - sortable="custom" - /> - <el-table-column - v-if="!isMainUnitHidden" - prop="isMainUnit" - label="涓昏閲�" - sortable="custom" - > - <template slot-scope="{row}"> - {{ row.isMainUnit === '1' ? '鏄�' : '鍚�' }} - </template> - </el-table-column> - <el-table-column - v-if="!isMainUnitHidden" - prop="changeRate" - label="鎹㈢畻鐜�" - sortable="custom" - /> - - <!-- <el-table-column--> - <!-- prop="data_sources"--> - <!-- label="鏁版嵁鏉ユ簮"--> - <!-- sortable="custom"--> - <!-- />--> - <el-table-column - prop="lm_user" - label="鍒涘缓浜哄憳" - sortable="custom" - /> - <el-table-column - prop="lm_date" - label="鍒涘缓鏃堕棿" - sortable="custom" - /> - <el-table-column - label="鎿嶄綔" - width="120" - fixed="right" - > - <template slot-scope="{row}"> - <div class="operationClass"> - <el-tooltip class="item" effect="dark" content="缂栬緫" placement="top"> - <i - class="el-icon-edit-outline" - :style="{color:$store.state.settings.theme}" - @click="edit('edit',row)" - /> - </el-tooltip> - - <el-tooltip v-del-tab-index class="item" effect="dark" content="鍒犻櫎" placement="top"> - <i - class="el-icon-delete" - :style="{color:$store.state.settings.theme}" - @click="del(row)" - /> - </el-tooltip> - </div> - </template> - </el-table-column> - </el-table> - </div> - <!--鍒嗛〉--> - <pagination - :total="total" - :page.sync="form.page" - :limit.sync="form.rows" - align="right" - layout="total,prev, pager, next,sizes,jumper" - popper-class="select_bottom" - @pagination="getTUnitData" - /> - </div> - - </div> - - </div> - - <el-dialog - v-el-drag-dialog - :title="operation==='add'?'鏂板':'缂栬緫'" - :visible.sync="dialogVisible" - width="800px" - :close-on-click-modal="false" - top="15vh" - @closed="handleClose" - @close="handleClose" - > - <el-form - ref="dialogForm" - inline - :rules="dialogFormRules" - :model="dialogForm" - label-width="120px" - style="display: flex;justify-content: space-between;align-content: flex-end" - > - - <el-form-item :label="dialogForm.tunittype==='S'? '璁¢噺鍗曚綅鍚嶇О':'璁¢噺鍗曚綅缁勫悕绉�'" prop="unitname"> - <el-input v-model="dialogForm.unitname" style="width: 200px" /> - </el-form-item> - - <el-form-item v-if="dialogForm.tunittype==='M'"> - <el-button v-waves type="primary" icon="el-icon-circle-plus-outline" @click="tableDataDialogAdd">鏂板琛� - </el-button> - </el-form-item> - - </el-form> - - <div v-if="dialogForm.tunittype==='M'"> - <el-table - ref="tableDataDialogRef" - class="tableFixed" - :data="tableDataDialog" - row-class-name="custom-row" - height="400" - border - :style="{width: 100+'%',height:'400px',}" - highlight-current-row - :header-cell-style="this.$headerCellStyle" - :cell-style="this.$cellStyle" - > - - <el-table-column - type="index" - width="50" - fixed - label="搴忓彿" - /> - <el-table-column - prop="unitname" - label="璁¢噺鍗曚綅鍚嶇О" - > - <template slot-scope="{row}"> - <el-input - v-if="row.isVisible===1" - v-model="row.unitname" - placeholder="璇疯緭鍏�" - /> - <div v-else> {{ row.unitname }}</div> - </template> - - </el-table-column> - <el-table-column - - label="涓昏閲�" - prop="checkboxSelected" - > - <template slot-scope="{row}"> - - <el-select - v-if="row.isVisible===1" - v-model="row.checkboxSelected" - :popper-append-to-body="false" - :disabled="row.checkboxSelected==='1'" - placeholder="璇烽�夋嫨" - filterable - @change="val=>checkboxSelectedChange(val,row)" - > - <el-option - v-for="item in checkboxSelectedArr" - :key="item.code" - :label="item.name" - :value="item.code" - /> - </el-select> - <div v-else> {{ row.checkboxSelected === '1' ? '鏄�' : '鍚�' }}</div> - </template> - </el-table-column> - - <el-table-column - prop="changeRate" - label="鎹㈢畻鐜�" - > - <template slot-scope="{row}"> - <el-input - v-if="row.isVisible===1" - v-model="row.changeRate" - :disabled="row.checkboxSelected==='1'" - placeholder="璇疯緭鍏�" - oninput="value=value.replace(/[^0-9.]/g,'')" - /> - <div v-else> {{ row.changeRate }}</div> - </template> - </el-table-column> - <el-table-column - prop="rateDescription" - label="鎹㈢畻璇存槑" - /> - <el-table-column - label="鎿嶄綔" - width="120" - fixed="right" - > - <template slot-scope="{row}"> - <div class="operationClass"> - <el-tooltip class="item" effect="dark" content="缂栬緫" placement="top"> - <i - v-if="row.isVisible===0&&tableDataDialog.filter(i=>i.isVisible===1).length===0" - class="el-icon-edit-outline" - :style="{color:$store.state.settings.theme}" - @click="tableDataDialogEdit(row)" - /> - </el-tooltip> - <el-tooltip v-del-tab-index class="item" effect="dark" content="鍒犻櫎" placement="top"> - <i - v-if="row.isVisible===0&&tableDataDialog.filter(i=>i.isVisible===1).length===0" - class="el-icon-delete" - :style="{color:$store.state.settings.theme}" - @click="tableDataDialogDel(row)" - /> - </el-tooltip> - <el-tooltip class="item" effect="dark" content="淇濆瓨" placement="top"> - <i - v-if="row.isVisible===1" - class="el-icon-circle-check" - style="cursor:pointer;" - :style="{color:$store.state.settings.theme}" - @click="tableDataDialogSave(row)" - /> - </el-tooltip> - </div> - </template> - </el-table-column> - - </el-table> - - </div> - - <span slot="footer" class="dialog-footer"> - <div class="footerButton"> - <el-button v-waves @click="dialogVisibleCancel">鍙� 娑�</el-button> - <el-button - v-waves - type="primary" - :loading="$store.state.app.buttonIsDisabled" - :disabled="$store.state.app.buttonIsDisabled" - @click="dialogVisibleConfirm" - >纭� 瀹�</el-button> - </div> - </span> - </el-dialog> - - </div> -</template> - -<script> -import Pagination from '@/components/Pagination' -import elDragDialog from '@/directive/el-drag-dialog' -import waves from '@/directive/waves' -import { SaveSearchUnit } from '@/api/ErpSyncMes' -import { AddUpdateTUnit, DeleteTUnit, TUnitData, TUnitGroup, TUnitGroupProject } from '@/api/ProductModel' - -export default { - name: 'UnitList', - components: { - Pagination - }, - directives: { elDragDialog, waves }, - data() { - return { - // mouseHoverType: 'mouseout', - isExpandForm: false, - mainHeight: 0, - tableHeight: 0, - form: { - tunittype: '', // 鍗曡閲�(S) 澶氳閲�(M) - tunitgroupcode: '', // 璁¢噺鍗曚綅缁勭紪鐮� - prop: 'isGroup', // 鎺掑簭瀛楁 - order: 'asc', // 鎺掑簭瀛楁 - page: 1, // 绗嚑椤� - rows: 20 // 姣忛〉澶氬皯鏉� - }, - total: 10, - tableData: [], - dialogVisible: false, - dialogForm: { - tunittype: '', // 鍗曡閲�(S) 澶氳閲�(M) - tunitgroupcode: '', // 璁¢噺鍗曚綅缁勭紪鐮� - unitcode: '', - unitname: '', - data_sources: 'MES' - }, - operation: '', - dialogFormRules: { - unitname: [ - { required: true, message: '璇疯緭鍏ュ悕绉�', trigger: ['blur', 'change'] } - ] - }, - - defaultPropsLeft: { - children: 'children', - label: 'name' - }, - treeLeft: [], - - tableDataDialog: [], - - checkboxSelectedArr: [ - { code: '0', name: '鍚�' }, - { code: '1', name: '鏄�' } - ], - - isMainUnitHidden: true - - } - }, - activated() { window.addEventListener('resize', this.getHeight) this.getHeight() }, created() { - - }, - mounted() { - window.addEventListener('resize', this.getHeight) - this.getHeight() - this.handleGetApi('') - }, - methods: { - async handleGetApi(code) { - await this.getTUnitGroup(code) - await this.getTUnitData() - }, - async getSaveSearchUnit() { - const res = await SaveSearchUnit() - if (res.code === '200') { - await this.handleGetApi(this.$refs.treeLeftRef.getCurrentKey()) - this.$notify.success('璁¢噺鍗曚綅鍚屾鎴愬姛锛�') - } - }, - async getTUnitGroup(code) { - const { data: res } = await TUnitGroup() - - this.treeLeft = [ - { - code: '', name: '鍏ㄩ儴', children: [ - { code: 'S', name: '鍗曡閲�' }, - { code: 'M', name: '澶氳閲�', children: res } - ] - } - ] - this.$nextTick(() => { - this.$refs.treeLeftRef.setCurrentKey(code) - }) - }, - async getTUnitData() { - const res = await TUnitData(this.form) - - this.tableData = res.data - this.total = res.count - }, - - async getTUnitGroupProject(unitcode) { - const data = { - unitcode, isgroup: '1' - } - const res = await TUnitGroupProject(data) - res.data.forEach((i, index) => { - i.unitname = i.name - i.unitcode = i.code - i.uuid = new Date().getTime() + index - i.isVisible = 0 - // i.idunitgroup = unitcode - i.checkboxSelected = i.isMainUnit === '1' ? '1' : '0' - }) - this.tableDataDialog = res.data - }, - - // 鎺掑簭鏀瑰彉鏃� - sortChange({ column, prop, order }) { - if (order === 'descending') { - order = 'desc' - } else if (order === 'ascending') { - order = 'asc' - } else { - order = 'desc' - } - this.form.order = order - this.form.prop = prop - this.getTUnitData() - }, - async nodeClick(obj, Node, VueComponent) { - if (obj.code === 'S' || obj.code === 'M' || obj.code === '') { - this.form.tunittype = obj.code - this.form.tunitgroupcode = '' - await this.getTUnitData(obj.code) - this.isMainUnitHidden = true - this.$nextTick(() => { - this.$refs.tableDataRef.doLayout() - }) - } else { - this.form.tunittype = 'M' - this.form.tunitgroupcode = obj.code - await this.getTUnitData(obj.code) - this.isMainUnitHidden = false - this.$nextTick(() => { - this.$refs.tableDataRef.doLayout() - }) - } - }, - add(operation) { - if (this.$refs.treeLeftRef.getCurrentKey() === 'S' || this.$refs.treeLeftRef.getCurrentKey() === 'M') { - this.dialogForm.tunittype = this.$refs.treeLeftRef.getCurrentKey() - } else { - return this.$message.error('璇峰厛閫夋嫨鏍戜笂鐨勫崟璁¢噺鎴栧璁¢噺锛�') - } - this.operation = operation - this.dialogVisible = true - this.dialogForm.OperType = 'Add' - }, - // 淇敼鎸夐挳 - async edit(operation, row) { - this.operation = operation - this.dialogVisible = true - this.dialogForm.OperType = 'Update' - - this.$nextTick(() => { - if (this.$refs.treeLeftRef.getCurrentKey() === 'S' || this.$refs.treeLeftRef.getCurrentKey() === 'M' || this.$refs.treeLeftRef.getCurrentKey() === '') { - this.dialogForm.tunittype = row.isGroup === '0' ? 'S' : 'M' - this.dialogForm.tunitgroupcode = row.isGroup === '0' ? row.code : row.idunitgroup - this.dialogForm.unitcode = row.code - this.dialogForm.unitname = row.name - this.dialogForm.data_sources = row.data_sources - } else { - this.dialogForm.tunittype = 'M' - this.dialogForm.tunitgroupcode = row.idunitgroup - this.dialogForm.unitcode = row.idunitgroup - this.dialogForm.unitname = this.treeLeft[0].children[1].children.find(i => i.code === this.$refs.treeLeftRef.getCurrentKey()).name - this.dialogForm.data_sources = row.data_sources - } - - if (this.dialogForm.tunittype === 'M') { - this.getTUnitGroupProject(row.idunitgroup) - } - }) - }, - - // 鍒犻櫎鎸夐挳 - async del(row) { - this.$confirm('鏄惁纭鍒犻櫎?', '鎻愮ず', { - confirmButtonText: '纭畾', - cancelButtonText: '鍙栨秷', - type: 'warning' - }).then(() => { - if (this.$refs.treeLeftRef.getCurrentKey() === 'S' || this.$refs.treeLeftRef.getCurrentKey() === 'M' || this.$refs.treeLeftRef.getCurrentKey() === '') { - // this.dialogForm.tunittype = this.$refs.treeLeftRef.getCurrentKey() - } else { - if (row.isMainUnit === '1' || this.tableData.length === 2) { - return this.$message.info('璁¢噺鍗曚綅缁勪笅锛屽繀椤绘湁涓�涓富璁¢噺鍜岃嚦灏戜竴涓緟璁¢噺锛�') - } - } - - const data = { - data_sources: row.data_sources, - tunittype: row.isGroup === '0' ? 'S' : 'M', - - tunitgroupcode: row.isGroup === '0' ? '' : row.idunitgroup, - tunitcode: row.isGroup === '0' ? row.code : (this.$refs.treeLeftRef.getCurrentKey() === 'M' ? '' : row.code) - } - DeleteTUnit(data).then(res => { - if (res.code === '200') { - this.$notify.success('鍒犻櫎鎴愬姛!') - if (this.form.page > 1 && this.tableData.length === 1) { - this.form.page-- - } - - this.handleGetApi(this.$refs.treeLeftRef.getCurrentKey()) - } - }) - }).catch(() => { - this.$notify.info('宸插彇娑堝垹闄�') - }) - }, - // 瀵硅瘽妗嗗叧闂簨浠� - handleClose() { - this.dialogForm.tunittype = '' - this.dialogForm.tunitgroupcode = '' - this.dialogForm.unitcode = '' - this.dialogForm.unitname = '' - this.dialogForm.data_sources = 'MES' - this.tableDataDialog = [] - this.$refs.dialogForm.clearValidate() - }, - // 瀵硅瘽妗嗗彇娑� - dialogVisibleCancel() { - this.dialogVisible = false - }, - // 瀵硅瘽妗嗙‘璁� - dialogVisibleConfirm() { - this.$refs.dialogForm.validate(valid => { - if (valid) { - if (this.tableDataDialog.find(i => i.isVisible === 1)) { - return this.$message.info('璇峰厛淇濆瓨褰撳墠琛岋紒') - } - - let data - if (this.dialogForm.tunittype === 'S') { // 鍗曡閲忔柊澧烇紝淇敼 - data = [{ - unitcode: this.dialogForm.unitcode, - unitname: this.dialogForm.unitname, - children: [ - { - 'unitcode': this.dialogForm.unitcode, - 'unitname': this.dialogForm.unitname, - 'isMainUnit': '0', - 'changeRate': '1', - 'isSingleUnit': '1', - 'disabled': '0', - 'isGroup': '0', - 'rateDescription': '', - 'idunitgroup': '' - } - ] - }] - } - if (this.dialogForm.tunittype === 'M') { // 澶氳閲忔柊澧烇紝淇敼 - if (this.tableDataDialog.length === 0) { - return this.$message.info('璁¢噺鍗曚綅缁勪腑鑷冲皯鍖呭惈涓�涓閲忓崟浣嶏紒') - } - if (this.tableDataDialog.length === 1) { - return this.$message.info('璁¢噺鍗曚綅缁勪笅锛屽繀椤绘湁涓�涓富璁¢噺鍜岃嚦灏戜竴涓緟璁¢噺锛�') - } - - this.tableDataDialog.forEach((i, index) => { - i.unitcode = i.unitcode ? i.unitcode : 'U' + index.toString() - i.isMainUnit = i.checkboxSelected === '1' ? '1' : '0' - i.isSingleUnit = '0' - i.disabled = '0' - i.isGroup = '1' - i.idunitgroup = this.dialogForm.tunitgroupcode - }) - data = [{ - unitcode: this.dialogForm.unitcode, - unitname: this.dialogForm.unitname, - children: this.tableDataDialog - }] - } - console.log(data) - this.$store.state.app.buttonIsDisabled = true - AddUpdateTUnit(data, this.dialogForm.data_sources, this.dialogForm.tunittype, this.dialogForm.tunitgroupcode, this.dialogForm.OperType).then(res => { - if (res.code === '200') { - this.$notify.success(this.operation === 'add' ? '娣诲姞鎴愬姛锛�' : '淇敼鎴愬姛锛�') - this.dialogVisible = false - this.$store.state.app.buttonIsDisabled = false - this.handleGetApi(this.$refs.treeLeftRef.getCurrentKey()) - } else { - this.$store.state.app.buttonIsDisabled = false - this.$notify.error(this.operation === 'add' ? '娣诲姞澶辫触锛�' : '淇敼澶辫触锛�') - } - }) - } - }) - }, - - tableDataDialogAdd() { - if (this.tableDataDialog.find(i => i.isVisible === 1)) { - return this.$message.info('璇峰厛淇濆瓨涓婁竴鏉℃暟鎹紒') - } - - this.tableDataDialog.push({ - unitname: '', - changeRate: 1, - uuid: new Date().getTime(), - checkboxSelected: this.tableDataDialog.length === 0 ? '1' : '0', - isVisible: 1, - data_sources: 'MES' - }) - console.log(this.tableDataDialog) - }, - tableDataDialogEdit(row) { - row.isVisible = 1 - }, - tableDataDialogDel(row) { - if (row.checkboxSelected === '1') { - return this.$message.info('涓昏閲忓崟浣嶄笉鑳藉垹闄わ紒') - } - this.tableDataDialog = this.tableDataDialog.filter(i => i.uuid !== row.uuid) - }, - tableDataDialogSave(row) { - if (!row.unitname) { - return this.$message.info('璁¢噺鍗曚綅鍚嶇О涓嶈兘涓虹┖锛�') - } - if (!row.changeRate) { - return this.$message.info('鎹㈢畻鐜囦笉鑳戒负绌猴紒') - } - if (this.tableDataDialog.filter(i => i.unitname === row.unitname).length > 1) { - return this.$message.info('澶氳閲忕粍鍐呰閲忓崟浣嶅悕绉颁笉鑳介噸澶嶏紒') - } - // console.log(row, 234) - row.isVisible = 0 - if (this.tableDataDialog.length > 1) { - const unitname = this.tableDataDialog.find(i => i.checkboxSelected === '1').unitname - this.tableDataDialog.forEach(i => { - if (i.checkboxSelected === '0') { - i.rateDescription = '1' + i.unitname + '=' + i.changeRate + unitname - } else { - i.rateDescription = '' - } - }) - } - }, - checkboxSelectedChange(val, row) { - row.changeRate = 1 - this.tableDataDialog.forEach(item => { - item.checkboxSelected = item.uuid === row.uuid ? '1' : '0' - }) - }, - // 鑾峰彇椤甸潰楂樺害 - getHeight() { - this.$nextTick(() => { - this.mainHeight = window.innerHeight - 85 - this.tableHeight = this.mainHeight - 220 - this.$refs.tableDataRef.doLayout() - }) - } - } -} -</script> +<template> + <div> + <div class="body" :style="{height:mainHeight+'px'}"> + <div style="display: flex"> + <!-- background:rgba(248,248,250,1);--> + <div style="width: 300px;margin: 10px 10px 0 0;background: #fff"> + + <div style="margin: 20px 10px 0 10px;display: flex;justify-content: space-between;"> + <div style="display: flex;"> + <div + style="width: 5px;height: 100%;border-radius: 5px;" + :style="{background:$store.state.settings.theme}" + /> + <div style="margin-left: 8px;">璁¢噺鍗曚綅</div> + </div> + + <!-- <div style="margin-right:10px">--> + <!-- <i class="el-icon-plus" style="cursor: pointer;color: #999" />--> + <!-- </div>--> + + </div> + + <el-tree + ref="treeLeftRef" + key="treeLeftKey" + style="padding: 10px;overflow: auto;" + :style="{height:(tableHeight+150)+'px'}" + :data="treeLeft" + node-key="code" + highlight-current + :props="defaultPropsLeft" + :default-expand-all="true" + :expand-on-click-node="false" + @node-click="nodeClick" + /> + + </div> + + <div style="width: calc(100% - 300px)"> + <div class="bodyTopButtonGroup"> + <el-button v-waves type="primary" icon="el-icon-circle-plus-outline" @click="add('add')">鏂板</el-button> + <el-button v-waves type="info" icon="el-icon-refresh" @click="getSaveSearchUnit">鍚屾璁¢噺鍗曚綅</el-button> + </div> + + <div class="elTableDiv"> + <el-table + ref="tableDataRef" + class="tableFixed" + :data="tableData" + :height="isExpandForm?tableHeight:(tableHeight+80)+'px'" + border + row-class-name="custom-row" + :style="{width: 100+'%',height:isExpandForm?tableHeight:(tableHeight+80)+'px',}" + highlight-current-row + :header-cell-style="this.$headerCellStyle" + :cell-style="this.$cellStyle" + @sort-change="sortChange" + > + <el-table-column + prop="rowNum" + width="50" + fixed + label="搴忓彿" + /> + <el-table-column + prop="code" + label="璁¢噺鍗曚綅缂栫爜" + sortable="custom" + > + <template slot-scope="{row}"> + {{ row.isGroup === '0' ? row.code :(!isMainUnitHidden?row.code:'') }} + </template> + </el-table-column> + <el-table-column + prop="name" + label="璁¢噺鍗曚綅鍚嶇О" + sortable="custom" + /> + <el-table-column + v-if="!isMainUnitHidden" + prop="isMainUnit" + label="涓昏閲�" + sortable="custom" + > + <template slot-scope="{row}"> + {{ row.isMainUnit === '1' ? '鏄�' : '鍚�' }} + </template> + </el-table-column> + <el-table-column + v-if="!isMainUnitHidden" + prop="changeRate" + label="鎹㈢畻鐜�" + sortable="custom" + /> + + <!-- <el-table-column--> + <!-- prop="data_sources"--> + <!-- label="鏁版嵁鏉ユ簮"--> + <!-- sortable="custom"--> + <!-- />--> + <el-table-column + prop="lm_user" + label="鍒涘缓浜哄憳" + sortable="custom" + /> + <el-table-column + prop="lm_date" + label="鍒涘缓鏃堕棿" + sortable="custom" + /> + <el-table-column + label="鎿嶄綔" + width="120" + fixed="right" + > + <template slot-scope="{row}"> + <div class="operationClass"> + <el-tooltip class="item" effect="dark" content="缂栬緫" placement="top"> + <i + class="el-icon-edit-outline" + :style="{color:$store.state.settings.theme}" + @click="edit('edit',row)" + /> + </el-tooltip> + + <el-tooltip v-del-tab-index class="item" effect="dark" content="鍒犻櫎" placement="top"> + <i + class="el-icon-delete" + :style="{color:$store.state.settings.theme}" + @click="del(row)" + /> + </el-tooltip> + </div> + </template> + </el-table-column> + </el-table> + </div> + <!--鍒嗛〉--> + <pagination + :total="total" + :page.sync="form.page" + :limit.sync="form.rows" + align="right" + layout="total,prev, pager, next,sizes,jumper" + popper-class="select_bottom" + @pagination="getTUnitData" + /> + </div> + + </div> + + </div> + + <el-dialog + v-el-drag-dialog + :title="operation==='add'?'鏂板':'缂栬緫'" + :visible.sync="dialogVisible" + width="800px" + :close-on-click-modal="false" + top="15vh" + @closed="handleClose" + @close="handleClose" + > + <el-form + ref="dialogForm" + inline + :rules="dialogFormRules" + :model="dialogForm" + label-width="120px" + style="display: flex;justify-content: space-between;align-content: flex-end" + > + + <el-form-item :label="dialogForm.tunittype==='S'? '璁¢噺鍗曚綅鍚嶇О':'璁¢噺鍗曚綅缁勫悕绉�'" prop="unitname"> + <el-input v-model="dialogForm.unitname" style="width: 200px" /> + </el-form-item> + + <el-form-item v-if="dialogForm.tunittype==='M'"> + <el-button v-waves type="primary" icon="el-icon-circle-plus-outline" @click="tableDataDialogAdd">鏂板琛� + </el-button> + </el-form-item> + + </el-form> + + <div v-if="dialogForm.tunittype==='M'"> + <el-table + ref="tableDataDialogRef" + class="tableFixed" + :data="tableDataDialog" + row-class-name="custom-row" + height="400" + border + :style="{width: 100+'%',height:'400px',}" + highlight-current-row + :header-cell-style="this.$headerCellStyle" + :cell-style="this.$cellStyle" + > + + <el-table-column + type="index" + width="50" + fixed + label="搴忓彿" + /> + <el-table-column + prop="unitname" + label="璁¢噺鍗曚綅鍚嶇О" + > + <template slot-scope="{row}"> + <el-input + v-if="row.isVisible===1" + v-model="row.unitname" + placeholder="璇疯緭鍏�" + /> + <div v-else> {{ row.unitname }}</div> + </template> + + </el-table-column> + <el-table-column + + label="涓昏閲�" + prop="checkboxSelected" + > + <template slot-scope="{row}"> + + <el-select + v-if="row.isVisible===1" + v-model="row.checkboxSelected" + :popper-append-to-body="false" + :disabled="row.checkboxSelected==='1'" + placeholder="璇烽�夋嫨" + filterable + @change="val=>checkboxSelectedChange(val,row)" + > + <el-option + v-for="item in checkboxSelectedArr" + :key="item.code" + :label="item.name" + :value="item.code" + /> + </el-select> + <div v-else> {{ row.checkboxSelected === '1' ? '鏄�' : '鍚�' }}</div> + </template> + </el-table-column> + + <el-table-column + prop="changeRate" + label="鎹㈢畻鐜�" + > + <template slot-scope="{row}"> + <el-input + v-if="row.isVisible===1" + v-model="row.changeRate" + :disabled="row.checkboxSelected==='1'" + placeholder="璇疯緭鍏�" + oninput="value=value.replace(/[^0-9.]/g,'')" + /> + <div v-else> {{ row.changeRate }}</div> + </template> + </el-table-column> + <el-table-column + prop="rateDescription" + label="鎹㈢畻璇存槑" + /> + <el-table-column + label="鎿嶄綔" + width="120" + fixed="right" + > + <template slot-scope="{row}"> + <div class="operationClass"> + <el-tooltip class="item" effect="dark" content="缂栬緫" placement="top"> + <i + v-if="row.isVisible===0&&tableDataDialog.filter(i=>i.isVisible===1).length===0" + class="el-icon-edit-outline" + :style="{color:$store.state.settings.theme}" + @click="tableDataDialogEdit(row)" + /> + </el-tooltip> + <el-tooltip v-del-tab-index class="item" effect="dark" content="鍒犻櫎" placement="top"> + <i + v-if="row.isVisible===0&&tableDataDialog.filter(i=>i.isVisible===1).length===0" + class="el-icon-delete" + :style="{color:$store.state.settings.theme}" + @click="tableDataDialogDel(row)" + /> + </el-tooltip> + <el-tooltip class="item" effect="dark" content="淇濆瓨" placement="top"> + <i + v-if="row.isVisible===1" + class="el-icon-circle-check" + style="cursor:pointer;" + :style="{color:$store.state.settings.theme}" + @click="tableDataDialogSave(row)" + /> + </el-tooltip> + </div> + </template> + </el-table-column> + + </el-table> + + </div> + + <span slot="footer" class="dialog-footer"> + <div class="footerButton"> + <el-button v-waves @click="dialogVisibleCancel">鍙� 娑�</el-button> + <el-button + v-waves + type="primary" + :loading="$store.state.app.buttonIsDisabled" + :disabled="$store.state.app.buttonIsDisabled" + @click="dialogVisibleConfirm" + >纭� 瀹�</el-button> + </div> + </span> + </el-dialog> + + </div> +</template> + +<script> +import Pagination from '@/components/Pagination' +import elDragDialog from '@/directive/el-drag-dialog' +import waves from '@/directive/waves' +import { SaveSearchUnit } from '@/api/ErpSyncMes' +import { AddUpdateTUnit, DeleteTUnit, TUnitData, TUnitGroup, TUnitGroupProject } from '@/api/ProductModel' + +export default { + name: 'UnitList', + components: { + Pagination + }, + directives: { elDragDialog, waves }, + data() { + return { + // mouseHoverType: 'mouseout', + isExpandForm: false, + mainHeight: 0, + tableHeight: 0, + form: { + tunittype: '', // 鍗曡閲�(S) 澶氳閲�(M) + tunitgroupcode: '', // 璁¢噺鍗曚綅缁勭紪鐮� + prop: 'isGroup', // 鎺掑簭瀛楁 + order: 'asc', // 鎺掑簭瀛楁 + page: 1, // 绗嚑椤� + rows: 20 // 姣忛〉澶氬皯鏉� + }, + total: 10, + tableData: [], + dialogVisible: false, + dialogForm: { + tunittype: '', // 鍗曡閲�(S) 澶氳閲�(M) + tunitgroupcode: '', // 璁¢噺鍗曚綅缁勭紪鐮� + unitcode: '', + unitname: '', + data_sources: 'MES' + }, + operation: '', + dialogFormRules: { + unitname: [ + { required: true, message: '璇疯緭鍏ュ悕绉�', trigger: ['blur', 'change'] } + ] + }, + + defaultPropsLeft: { + children: 'children', + label: 'name' + }, + treeLeft: [], + + tableDataDialog: [], + + checkboxSelectedArr: [ + { code: '0', name: '鍚�' }, + { code: '1', name: '鏄�' } + ], + + isMainUnitHidden: true + + } + }, + activated() { + window.addEventListener('resize', this.getHeight) + this.getHeight() + this.handleGetApi('') + }, + created() { + + }, + mounted() { + window.addEventListener('resize', this.getHeight) + this.getHeight() + this.handleGetApi('') + }, + methods: { + async handleGetApi(code) { + await this.getTUnitGroup(code) + await this.getTUnitData() + }, + async getSaveSearchUnit() { + const res = await SaveSearchUnit() + if (res.code === '200') { + await this.handleGetApi(this.$refs.treeLeftRef.getCurrentKey()) + this.$notify.success('璁¢噺鍗曚綅鍚屾鎴愬姛锛�') + } + }, + async getTUnitGroup(code) { + const { data: res } = await TUnitGroup() + + this.treeLeft = [ + { + code: '', name: '鍏ㄩ儴', children: [ + { code: 'S', name: '鍗曡閲�' }, + { code: 'M', name: '澶氳閲�', children: res } + ] + } + ] + this.$nextTick(() => { + this.$refs.treeLeftRef.setCurrentKey(code) + }) + }, + async getTUnitData() { + const res = await TUnitData(this.form) + + this.tableData = res.data + this.total = res.count + }, + + async getTUnitGroupProject(unitcode) { + const data = { + unitcode, isgroup: '1' + } + const res = await TUnitGroupProject(data) + res.data.forEach((i, index) => { + i.unitname = i.name + i.unitcode = i.code + i.uuid = new Date().getTime() + index + i.isVisible = 0 + // i.idunitgroup = unitcode + i.checkboxSelected = i.isMainUnit === '1' ? '1' : '0' + }) + this.tableDataDialog = res.data + }, + + // 鎺掑簭鏀瑰彉鏃� + sortChange({ column, prop, order }) { + if (order === 'descending') { + order = 'desc' + } else if (order === 'ascending') { + order = 'asc' + } else { + order = 'desc' + } + this.form.order = order + this.form.prop = prop + this.getTUnitData() + }, + async nodeClick(obj, Node, VueComponent) { + if (obj.code === 'S' || obj.code === 'M' || obj.code === '') { + this.form.tunittype = obj.code + this.form.tunitgroupcode = '' + await this.getTUnitData(obj.code) + this.isMainUnitHidden = true + this.$nextTick(() => { + this.$refs.tableDataRef.doLayout() + }) + } else { + this.form.tunittype = 'M' + this.form.tunitgroupcode = obj.code + await this.getTUnitData(obj.code) + this.isMainUnitHidden = false + this.$nextTick(() => { + this.$refs.tableDataRef.doLayout() + }) + } + }, + add(operation) { + if (this.$refs.treeLeftRef.getCurrentKey() === 'S' || this.$refs.treeLeftRef.getCurrentKey() === 'M') { + this.dialogForm.tunittype = this.$refs.treeLeftRef.getCurrentKey() + } else { + return this.$message.error('璇峰厛閫夋嫨鏍戜笂鐨勫崟璁¢噺鎴栧璁¢噺锛�') + } + this.operation = operation + this.dialogVisible = true + this.dialogForm.OperType = 'Add' + }, + // 淇敼鎸夐挳 + async edit(operation, row) { + this.operation = operation + this.dialogVisible = true + this.dialogForm.OperType = 'Update' + + this.$nextTick(() => { + if (this.$refs.treeLeftRef.getCurrentKey() === 'S' || this.$refs.treeLeftRef.getCurrentKey() === 'M' || this.$refs.treeLeftRef.getCurrentKey() === '') { + this.dialogForm.tunittype = row.isGroup === '0' ? 'S' : 'M' + this.dialogForm.tunitgroupcode = row.isGroup === '0' ? row.code : row.idunitgroup + this.dialogForm.unitcode = row.code + this.dialogForm.unitname = row.name + this.dialogForm.data_sources = row.data_sources + } else { + this.dialogForm.tunittype = 'M' + this.dialogForm.tunitgroupcode = row.idunitgroup + this.dialogForm.unitcode = row.idunitgroup + this.dialogForm.unitname = this.treeLeft[0].children[1].children.find(i => i.code === this.$refs.treeLeftRef.getCurrentKey()).name + this.dialogForm.data_sources = row.data_sources + } + + if (this.dialogForm.tunittype === 'M') { + this.getTUnitGroupProject(row.idunitgroup) + } + }) + }, + + // 鍒犻櫎鎸夐挳 + async del(row) { + this.$confirm('鏄惁纭鍒犻櫎?', '鎻愮ず', { + confirmButtonText: '纭畾', + cancelButtonText: '鍙栨秷', + type: 'warning' + }).then(() => { + if (this.$refs.treeLeftRef.getCurrentKey() === 'S' || this.$refs.treeLeftRef.getCurrentKey() === 'M' || this.$refs.treeLeftRef.getCurrentKey() === '') { + // this.dialogForm.tunittype = this.$refs.treeLeftRef.getCurrentKey() + } else { + if (row.isMainUnit === '1' || this.tableData.length === 2) { + return this.$message.info('璁¢噺鍗曚綅缁勪笅锛屽繀椤绘湁涓�涓富璁¢噺鍜岃嚦灏戜竴涓緟璁¢噺锛�') + } + } + + const data = { + data_sources: row.data_sources, + tunittype: row.isGroup === '0' ? 'S' : 'M', + + tunitgroupcode: row.isGroup === '0' ? '' : row.idunitgroup, + tunitcode: row.isGroup === '0' ? row.code : (this.$refs.treeLeftRef.getCurrentKey() === 'M' ? '' : row.code) + } + DeleteTUnit(data).then(res => { + if (res.code === '200') { + this.$notify.success('鍒犻櫎鎴愬姛!') + if (this.form.page > 1 && this.tableData.length === 1) { + this.form.page-- + } + + this.handleGetApi(this.$refs.treeLeftRef.getCurrentKey()) + } + }) + }).catch(() => { + this.$notify.info('宸插彇娑堝垹闄�') + }) + }, + // 瀵硅瘽妗嗗叧闂簨浠� + handleClose() { + this.dialogForm.tunittype = '' + this.dialogForm.tunitgroupcode = '' + this.dialogForm.unitcode = '' + this.dialogForm.unitname = '' + this.dialogForm.data_sources = 'MES' + this.tableDataDialog = [] + this.$refs.dialogForm.clearValidate() + }, + // 瀵硅瘽妗嗗彇娑� + dialogVisibleCancel() { + this.dialogVisible = false + }, + // 瀵硅瘽妗嗙‘璁� + dialogVisibleConfirm() { + this.$refs.dialogForm.validate(valid => { + if (valid) { + if (this.tableDataDialog.find(i => i.isVisible === 1)) { + return this.$message.info('璇峰厛淇濆瓨褰撳墠琛岋紒') + } + + let data + if (this.dialogForm.tunittype === 'S') { // 鍗曡閲忔柊澧烇紝淇敼 + data = [{ + unitcode: this.dialogForm.unitcode, + unitname: this.dialogForm.unitname, + children: [ + { + 'unitcode': this.dialogForm.unitcode, + 'unitname': this.dialogForm.unitname, + 'isMainUnit': '0', + 'changeRate': '1', + 'isSingleUnit': '1', + 'disabled': '0', + 'isGroup': '0', + 'rateDescription': '', + 'idunitgroup': '' + } + ] + }] + } + if (this.dialogForm.tunittype === 'M') { // 澶氳閲忔柊澧烇紝淇敼 + if (this.tableDataDialog.length === 0) { + return this.$message.info('璁¢噺鍗曚綅缁勪腑鑷冲皯鍖呭惈涓�涓閲忓崟浣嶏紒') + } + if (this.tableDataDialog.length === 1) { + return this.$message.info('璁¢噺鍗曚綅缁勪笅锛屽繀椤绘湁涓�涓富璁¢噺鍜岃嚦灏戜竴涓緟璁¢噺锛�') + } + + this.tableDataDialog.forEach((i, index) => { + i.unitcode = i.unitcode ? i.unitcode : 'U' + index.toString() + i.isMainUnit = i.checkboxSelected === '1' ? '1' : '0' + i.isSingleUnit = '0' + i.disabled = '0' + i.isGroup = '1' + i.idunitgroup = this.dialogForm.tunitgroupcode + }) + data = [{ + unitcode: this.dialogForm.unitcode, + unitname: this.dialogForm.unitname, + children: this.tableDataDialog + }] + } + console.log(data) + this.$store.state.app.buttonIsDisabled = true + AddUpdateTUnit(data, this.dialogForm.data_sources, this.dialogForm.tunittype, this.dialogForm.tunitgroupcode, this.dialogForm.OperType).then(res => { + if (res.code === '200') { + this.$notify.success(this.operation === 'add' ? '娣诲姞鎴愬姛锛�' : '淇敼鎴愬姛锛�') + this.dialogVisible = false + this.$store.state.app.buttonIsDisabled = false + this.handleGetApi(this.$refs.treeLeftRef.getCurrentKey()) + } else { + this.$store.state.app.buttonIsDisabled = false + this.$notify.error(this.operation === 'add' ? '娣诲姞澶辫触锛�' : '淇敼澶辫触锛�') + } + }) + } + }) + }, + + tableDataDialogAdd() { + if (this.tableDataDialog.find(i => i.isVisible === 1)) { + return this.$message.info('璇峰厛淇濆瓨涓婁竴鏉℃暟鎹紒') + } + + this.tableDataDialog.push({ + unitname: '', + changeRate: 1, + uuid: new Date().getTime(), + checkboxSelected: this.tableDataDialog.length === 0 ? '1' : '0', + isVisible: 1, + data_sources: 'MES' + }) + console.log(this.tableDataDialog) + }, + tableDataDialogEdit(row) { + row.isVisible = 1 + }, + tableDataDialogDel(row) { + if (row.checkboxSelected === '1') { + return this.$message.info('涓昏閲忓崟浣嶄笉鑳藉垹闄わ紒') + } + this.tableDataDialog = this.tableDataDialog.filter(i => i.uuid !== row.uuid) + }, + tableDataDialogSave(row) { + if (!row.unitname) { + return this.$message.info('璁¢噺鍗曚綅鍚嶇О涓嶈兘涓虹┖锛�') + } + if (!row.changeRate) { + return this.$message.info('鎹㈢畻鐜囦笉鑳戒负绌猴紒') + } + if (this.tableDataDialog.filter(i => i.unitname === row.unitname).length > 1) { + return this.$message.info('澶氳閲忕粍鍐呰閲忓崟浣嶅悕绉颁笉鑳介噸澶嶏紒') + } + // console.log(row, 234) + row.isVisible = 0 + if (this.tableDataDialog.length > 1) { + const unitname = this.tableDataDialog.find(i => i.checkboxSelected === '1').unitname + this.tableDataDialog.forEach(i => { + if (i.checkboxSelected === '0') { + i.rateDescription = '1' + i.unitname + '=' + i.changeRate + unitname + } else { + i.rateDescription = '' + } + }) + } + }, + checkboxSelectedChange(val, row) { + row.changeRate = 1 + this.tableDataDialog.forEach(item => { + item.checkboxSelected = item.uuid === row.uuid ? '1' : '0' + }) + }, + // 鑾峰彇椤甸潰楂樺害 + getHeight() { + this.$nextTick(() => { + this.mainHeight = window.innerHeight - 85 + this.tableHeight = this.mainHeight - 220 + this.$refs.tableDataRef.doLayout() + }) + } + } +} +</script> -- Gitblit v1.9.3