田源
2023-08-08 0efcf618f642c4c42315a26e49c0749abc9ebb32
Source/UBCS-WEB/src/components/Master/MasterTransfer.vue
@@ -1,53 +1,56 @@
<template>
<el-dialog :visible.sync="dialogPush" append-to-body  :close-on-click-modal="false"  @close="escHandler" title="导出" style="width: 1550px; margin: auto">
  <div style="margin-bottom: 20px;">
    <div>
      <span>导出方式:</span>
      <el-radio-group v-model="radio">
        <el-radio :label="0">选择</el-radio>
        <el-radio :label="1">全部</el-radio>
        <el-radio :label="2">页码</el-radio>
      </el-radio-group>
      <span v-if="radio === 2" style="margin-left: 20px;"><el-input style="width: 150px" v-model="pageExport"></el-input> (输入页码或者页面范围,如:1-10))</span>
  <el-dialog :close-on-click-modal="false" :visible.sync="dialogPush" append-to-body style="width: 1550px; margin: auto" title="导出"
             @close="escHandler">
    <div style="margin-bottom: 20px;">
      <div>
        <span>导出方式:</span>
        <el-radio-group v-model="radio">
          <el-radio :label="0">选择</el-radio>
          <el-radio :label="1">全部</el-radio>
          <el-radio :label="2">页码</el-radio>
        </el-radio-group>
        <span v-if="radio === 2" style="margin-left: 20px;"><el-input v-model="pageExport"
                                                                      style="width: 150px"></el-input> (输入页码或者页面范围,如:1-10))</span>
      </div>
    </div>
  </div>
  <div style="text-align: center">
  <el-transfer
    style="text-align: left; display: inline-block;height: 400px"
    filterable
    :filter-method="filterMethod"
    filter-placeholder="关键词搜索"
    v-model="value"
    :titles="['未选属性', '已选属性']"
    :data="data">
  </el-transfer>
  </div>
  <div style="display: flex;justify-content: flex-end;">
    <el-button size="small" plain type="success" @click="handleExcel">确定</el-button>
    <el-button size="small" plain @click="escHandler">取消</el-button>
  </div>
</el-dialog>
    <div style="text-align: center">
      <el-transfer
        v-model="value"
        :data="data"
        :filter-method="filterMethod"
        :titles="['未选属性', '已选属性']"
        filter-placeholder="关键词搜索"
        filterable
        style="text-align: left; display: inline-block;height: 400px">
      </el-transfer>
    </div>
    <div style="display: flex;justify-content: flex-end;">
      <el-button plain size="small" type="success" @click="handleExcel">确定</el-button>
      <el-button plain size="small" @click="escHandler">取消</el-button>
    </div>
  </el-dialog>
</template>
<script>
import {exportCode,FindData} from '@/api/GetItem'
import {exportCode, FindData} from '@/api/GetItem'
import func from "@/util/func";
export default {
name: "MasterTransfer",
  props:['visible','tableHeadData','codeClassifyOid','tableData','selectRow','templateOid','limit'],
  data(){
  name: "MasterTransfer",
  props: ['visible', 'tableHeadData', 'codeClassifyOid', 'tableData', 'selectRow', 'templateOid', 'limit'],
  data() {
    return {
      pageExport:"",
      pageExport: "",
      data: [],
      value: [],
      filterMethod(query, item) {
        return item.label.indexOf(query) > -1;
      },
      dialogPush:this.visible,
      radio:0,
      tableHeadFindData:[],
      tableExportData:[],
      option:{
      dialogPush: this.visible,
      radio: 0,
      tableHeadFindData: [],
      tableExportData: [],
      option: {
        title: '文档标题',
        column: [{
          label: '主数据',
@@ -56,14 +59,14 @@
        }],
        data: []
      },
      exportArr:{},
      exportArrTwo:{},
      ids:""
      exportArr: {},
      exportArrTwo: {},
      ids: ""
    };
  },
  watch:{
  watch: {
    //监听初始化
    visible (){
    visible() {
      this.dialogPush = this.visible;
    },
    //表头数据 用来渲染穿梭框
@@ -90,160 +93,175 @@
        }
      }
    },
    tableData(){
    tableData() {
      // 将值里面的true或false改变为是或否
      this.option.data = this.tableData.map(obj => {
          for (let prop in obj) {
            if (obj[prop] === "true") {
              obj[prop] = "是";
            } else if (obj[prop] === "false") {
              obj[prop] = "否";
            }
        for (let prop in obj) {
          if (obj[prop] === "true") {
            obj[prop] = "是";
          } else if (obj[prop] === "false") {
            obj[prop] = "否";
          }
        }
        return obj;
      });
    },
    codeClassifyOid:{
      handler(newval,oldval){
    codeClassifyOid: {
      handler(newval, oldval) {
      }
    },
    value:{
      handler(newval,oldval){
        console.log('value',newval)
    value: {
      handler(newval, oldval) {
        console.log('value', newval)
      }
    }
  },
  computed:{
  },
  computed: {},
  mounted() {
  },
  methods:{
    escHandler(){
  methods: {
    escHandler() {
      this.$emit('update:visible', false);
      this.value=[];
      this.radio=0
      this.value = [];
      this.radio = 0
    },
    //关闭页面
    recoverPage(){
    recoverPage() {
      this.$emit('update:visible', false);
    },
    handleExcel(){
        this.value.map(index => this.tableHeadData[index].prop).forEach((item, index) => {
          this.exportArr[`attrIdIndexMap[${index}]`] = item
        })
        if(this.radio === 0){
          if(this.selectRow.length<=0){
            this.$message.warning('请选择要导出的模板')
          }else {
            //已选择多选
            const selectList=[]
            //已选择属性
            let exportArr={}
            this.ids = this.selectRow.map(item => item.oid).join(',')
            this.selectRow.forEach(item=>{
              selectList.push(
                item.oid
              )
            })
            if(this.value <= 0){
              this.tableHeadData.map(item => item.prop)
                .forEach((prop, index) => {
                  this.exportArrTwo[`attrIdIndexMap[${index}]`] = prop;
                });
              exportCode({codeClassifyOid:this.codeClassifyOid,'conditionMap[oid]':this.ids,...this.exportArrTwo,limit:-1}).then(res=>{
                // console.log('res',res)
                if(res){
                  func.downloadFileByBlobHandler(res);
                  this.escHandler()
                }
              })
            }else {
              exportCode({codeClassifyOid:this.codeClassifyOid,'conditionMap[oid]':this.ids,...this.exportArr}).then(res=>{
                // console.log('res',res)
                if(res){
                  func.downloadFileByBlobHandler(res);
                  this.escHandler()
                }
              })
            }
            }
        }else if(this.radio === 1){
          if(this.value <= 0){
    handleExcel() {
      this.value.map(index => this.tableHeadData[index].prop).forEach((item, index) => {
        this.exportArr[`attrIdIndexMap[${index}]`] = item
      })
      if (this.radio === 0) {
        if (this.selectRow.length <= 0) {
          this.$message.warning('请选择要导出的模板')
        } else {
          //已选择多选
          const selectList = []
          //已选择属性
          let exportArr = {}
          this.ids = this.selectRow.map(item => item.oid).join(',')
          this.selectRow.forEach(item => {
            selectList.push(
              item.oid
            )
          })
          if (this.value <= 0) {
            this.tableHeadData.map(item => item.prop)
              .forEach((prop, index) => {
                this.exportArrTwo[`attrIdIndexMap[${index}]`] = prop;
              });
            exportCode({codeClassifyOid:this.codeClassifyOid,...this.exportArrTwo,limit:-1}).then(res=>{
              // console.log('res',res)
              if(res){
                func.downloadFileByBlobHandler(res);
                this.escHandler()
              }
            })
          }else {
            exportCode({codeClassifyOid:this.codeClassifyOid,...this.exportArr,limit:-1}).then(res=>{
              // console.log('res',res)
              if(res){
                func.downloadFileByBlobHandler(res);
                this.escHandler()
              }
            })
          }
        }else if(this.radio === 2){
          const input = this.pageExport.trim();
          let start, end;
          if (input.includes('-')) {
            if (input.indexOf('-') !== input.lastIndexOf('-')) {
              this.$message.warning('输入格式错误:只能输入一个 - 号隔开');
              return;
            }
            //包含-解析
            const range = input.split('-');
            start = Number(range[0]);
            end = Number(range[1]);
            if (isNaN(start) || isNaN(end)) {
              this.$message.warning('输入格式错误');
              return;
            }
          } else {
            //不包含-解析
            start = Number(input);
            end = start;
            if (isNaN(start)) {
              this.$message.warning('输入格式错误');
              return;
            }
          }
          if(this.value >=1 ){
            exportCode({ codeClassifyOid: this.codeClassifyOid, ...this.exportArr, limit: this.limit, page: start, endPage: end }).then((res) => {
            exportCode({
              codeClassifyOid: this.codeClassifyOid,
              'conditionMap[oid]': this.ids, ...this.exportArrTwo,
              limit: -1
            }).then(res => {
              // console.log('res',res)
              if (res) {
                func.downloadFileByBlobHandler(res);
                this.escHandler()
              }
            });
          }else {
            this.tableHeadData.map(item => item.prop)
              .forEach((prop, index) => {
                this.exportArrTwo[`attrIdIndexMap[${index}]`] = prop;
              });
            exportCode({codeClassifyOid:this.codeClassifyOid,...this.exportArrTwo,limit:this.limit,page: start, endPage: end}).then(res=>{
            })
          } else {
            exportCode({
              codeClassifyOid: this.codeClassifyOid,
              'conditionMap[oid]': this.ids, ...this.exportArr
            }).then(res => {
              // console.log('res',res)
              if(res){
              if (res) {
                func.downloadFileByBlobHandler(res);
                this.escHandler()
              }
            })
          }
        }
      } else if (this.radio === 1) {
        if (this.value <= 0) {
          this.tableHeadData.map(item => item.prop)
            .forEach((prop, index) => {
              this.exportArrTwo[`attrIdIndexMap[${index}]`] = prop;
            });
          exportCode({codeClassifyOid: this.codeClassifyOid, ...this.exportArrTwo, limit: -1}).then(res => {
            // console.log('res',res)
            if (res) {
              func.downloadFileByBlobHandler(res);
              this.escHandler()
            }
          })
        } else {
          exportCode({codeClassifyOid: this.codeClassifyOid, ...this.exportArr, limit: -1}).then(res => {
            // console.log('res',res)
            if (res) {
              func.downloadFileByBlobHandler(res);
              this.escHandler()
            }
          })
        }
      } else if (this.radio === 2) {
        const input = this.pageExport.trim();
        let start, end;
        if (input.includes('-')) {
          if (input.indexOf('-') !== input.lastIndexOf('-')) {
            this.$message.warning('输入格式错误:只能输入一个 - 号隔开');
            return;
          }
          //包含-解析
          const range = input.split('-');
          start = Number(range[0]);
          end = Number(range[1]);
          if (isNaN(start) || isNaN(end)) {
            this.$message.warning('输入格式错误');
            return;
          }
        } else {
          //不包含-解析
          start = Number(input);
          end = start;
          if (isNaN(start)) {
            this.$message.warning('输入格式错误');
            return;
          }
        }
        if (this.value >= 1) {
          exportCode({
            codeClassifyOid: this.codeClassifyOid, ...this.exportArr,
            limit: this.limit,
            page: start,
            endPage: end
          }).then((res) => {
            // console.log('res',res)
            if (res) {
              func.downloadFileByBlobHandler(res);
              this.escHandler()
            }
          });
        } else {
          this.tableHeadData.map(item => item.prop)
            .forEach((prop, index) => {
              this.exportArrTwo[`attrIdIndexMap[${index}]`] = prop;
            });
          exportCode({
            codeClassifyOid: this.codeClassifyOid, ...this.exportArrTwo,
            limit: this.limit,
            page: start,
            endPage: end
          }).then(res => {
            // console.log('res',res)
            if (res) {
              func.downloadFileByBlobHandler(res);
              this.escHandler()
            }
          })
        }
      }
    },
  }
}
</script>
<style scoped lang="scss">
<style lang="scss" scoped>
</style>