<!-- * @Description: * @Autor: renchao * @LastEditTime: 2023-10-24 17:15:25 --> <template> <div class="clmlmx-box"> <lb-table :column="column" :key="key" row-key="bsmSj" ref="listTable" :heightNumSetting="true" :calcHeight="600" :pagination="false" :data="tableData"> </lb-table> <div class="text-center"> <el-button @click="handleCancel">取消</el-button> <el-button type="primary" @click="handleSubmit" v-if="formData.ableOperation && tableData.length>0" :loading="loading">保存</el-button> </div> </div> </template> <script> import Vue from 'vue' import Sortable from 'sortablejs' import store from '@/store/index.js' import { ywPopupCacel } from "@/utils/popup.js"; import { updateClml } from "@/api/clxx.js"; export default { props: { formData: { type: Object, default: () => { return {} } } }, data () { return { loading: false, sortable: null, column: [ { prop: "isrequired", label: "是否必选", width: "80", render: (h, scope) => { if (scope.row.isrequired === "1") { return ( <div> <span>必选</span> </div> ); } else { return ( <div> <span>可选</span> </div> ) } } }, { label: "材料名称", render: (h, scope) => { return ( (this.formData.ableOperation && scope.row.sfxjcl == '1') ? <el-input value={scope.row.sjmc} onInput={(val) => { scope.row.sjmc = val }}></el-input> : <span>{scope.row.sjmc}</span> ) } }, { label: "材料类型", width: "110", render: (h, scope) => { return ( this.formData.ableOperation ? <el-select value={scope.row.sjlx} onChange={(val) => { scope.row.sjlx = val }}> { store.getters.dictData['A40'].map(option => { return ( <el-option label={option.dname} value={option.dcode}></el-option> ) }) } </el-select> : <span>{this.dicStatus(scope.row.sjlx, "A40")}</span> ) } }, { prop: "sjsl", label: "收件数量", width: "80", render: (h, scope) => { return ( (this.formData.ableOperation) ? <el-input value={scope.row.sjsl} onInput={(val) => { scope.row.sjsl = val }}></el-input> : <span>{ scope.row.sjsl }</span> ) } }, { label: "扫描时间", width: "140", render: (h, scope) => { return ( <span>{scope.row.sjsj}</span> ) } }, { label: "页数", width: "60", render: (h, scope) => { if (scope.row.ys && scope.row.ys > 0) { return ( <div> <span>{scope.row.ys}</span> </div> ); } else { return ( <div> <span>0</span> </div> ); } }, }, { label: "是否新建材料", width: "80", render: (h, scope) => { if (scope.row.sfxjcl && scope.row.sfxjcl == '1') { return ( <span>是</span> ); } else { return ( <span>否</span> ); } }, }, { label: "操作", width: "100", render: (h, scope) => { return ( <el-button type="text" icon="el-icon-delete" disabled={!(scope.row.ys == 0 && scope.row.sfxjcl == '1') || !this.formData.ableOperation} onClick={() => { this.handleDelete(scope.$index, scope.row); }} > 删除 </el-button> ) } } ], key: 0, tableData: [] } }, watch: { 'formData.data': { handler: function (val, oldVal) { this.tableData = _.cloneDeep(val) }, immediate: true, deep: true } }, mounted () { this.initSort() console.log(this.formData); }, beforeDestroy () { if (this.sortable) { this.sortable.destroy(); } }, methods: { handleCancel () { ywPopupCacel() }, handleSubmit () { this.loading = true store.dispatch('user/reWorkFresh', false) updateClml(this.tableData, this.formData.bsmSldy, Vue.prototype.$currentRoute.query.bsmSlsq).then(res => { this.loading = false if (res.code == 200) { this.$message({ message: '保存成功', type: 'success' }) ywPopupCacel() store.dispatch('user/reWorkFresh', true) } }).catch(() => { this.loading = false }) }, /** * @description: 材料目录删除 * @param {*} index * @param {*} row */ handleDelete (index, row) { this.$confirm('此操作将永久删除该 是否继续?', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }).then(() => { this.tableData.splice(index, 1); }).catch(() => { this.$message({ type: 'info', message: '已取消删除' }) }) }, initSort () { const el = this.$refs.listTable.$el.querySelectorAll('.el-table__body-wrapper > table > tbody')[0] this.sortable = Sortable.create(el, { ghostClass: 'sortable-ghost', setData: function (dataTransfer) { dataTransfer.setData('Text', '') }, onEnd: evt => { const targetRow = this.tableData.splice(evt.oldIndex, 1)[0]; this.tableData.splice(evt.newIndex, 0, targetRow); } }) }, dicStatus (val, code) { let data = store.getters.dictData[code], name = '暂无' if (data) { data.map((item) => { if (item.dcode == val) { name = item.dname } }) return name } }, } } </script> <style scoped lang='scss'> @import "~@/styles/mixin.scss"; .clmlmx-box { margin: 0 auto; .title { text-align: center; height: 60px; line-height: 60px; border: 1px solid #dfe6ec; font-size: 20px; background: #81d3f81a; margin-bottom: -1px; } } </style>