ludc
2023-07-28 554874a4bec50d7e29f256f8930ef4f521a5f1ac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<template>
<el-dialog :visible.sync="dialogPush" append-to-body  :close-on-click-modal="false"  @close="recoverPage" title="导出">
  <div style="margin-bottom: 10px">
    <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>
  </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 >取消</el-button>
  </div>
</el-dialog>
</template>
 
<script>
import {exportCode} from '@/api/GetItem'
import func from "@/util/func";
export default {
name: "MasterTransfer",
  props:['visible','tableHeadData','codeClassifyOid','tableData','selectRow'],
  data(){
    return {
      data: [],
      value: [],
      filterMethod(query, item) {
        return item.label.indexOf(query) > -1;
      },
      dialogPush:this.visible,
      radio:0,
      tableHeadFindData:[],
      tableExportData:[],
      option:{
        title: '文档标题',
        column: [{
          label: '主数据',
          prop: 'header',
          children: []
        }],
        data: []
      }
    };
  },
  watch:{
    //监听初始化
    visible (){
      this.dialogPush = this.visible;
    },
    //表头数据 用来渲染穿梭框
    tableHeadData:{
      handler(newval,oldval){
        console.log(newval)
       if(newval){
         //excel表头数据转换
         this.tableHeadFindData=newval.map(obj => obj.label);
         this.tableHeadFindData.forEach((city, index) => {
           this.data.push({
             label: city,
             key: index,
           });
         });
         //excel表格数据转换
         this.option.column[0].children=newval.map(obj => {
           return {
             label: obj.label,
             prop: obj.prop
           }
         })
       }
      }
},
    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] = "否";
            }
          }
        return obj;
      });
    },
    codeClassifyOid:{
      handler(newval,oldval){
      }
    }
  },
  computed:{
 
  },
  mounted() {
  },
  methods:{
    //关闭页面
    recoverPage(){
      this.$emit('update:visible', false);
    },
    handleExcel(){
      // this.$Export.excel({
      //   title: this.option.title,
      //   columns: this.option.column,
      //   data: this.option.data
      // });
      if(this.radio === 0){
        if(this.selectRow.length<=0){
          this.$message.warning('请选择要导出的模板')
        }else {
          //已选择多选
          const selectList=[]
          //已选择属性
          let exportArr={}
          const ids = this.selectRow.map(item => item.oid).join(',')
          this.selectRow.forEach(item=>{
            selectList.push(
             item.oid
            )
          })
          this.value.map(index => this.tableHeadData[index].prop).forEach((item, index) => {
            exportArr[`attrIdIndexMap[${index}]`] = item
          })
          exportCode({codeClassifyOid:this.codeClassifyOid,'conditionMap[oid]':ids,...exportArr}).then(res=>{
            // console.log('res',res)
            if(res){
              func.downloadFileByBlob(res);
              window.URL.revokeObjectURL(src); //释放掉blob对象
            }
          })
 
        }
      };
    },
  }
}
</script>
 
<style scoped lang="scss">
 
</style>