石广澎
2023-10-20 4cb068fb1d51129be7199cbd83fb0ef1f97915e2
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
<template>
  <win-md :title="setting.title" @close="close" :width="'800px'">
    <div style="min-height: 300px">
      <el-table
        v-loading="loading"
        border
        :data="tableData"
        style="width: 100%;margin-top: 15px">
        <el-table-column
          prop="tempProjectName"
          align="center"
          width="200"
          label="模板"/>
        <el-table-column
          align="center"
          label="选择节点">
          <template slot-scope="{row,$index}">
            <el-cascader
              :key="$index"
              style="width: 100%;"
              v-model="row.tempStageNodeIds"
              :options="row.options"
              :show-all-levels="false"
              :props="{ multiple: true, emitPath: false,value:'id', label:'name'}"
              clearable></el-cascader>
          </template>
        </el-table-column>
      </el-table>
    </div>
 
    <div slot="footer" align="center" class="dialog-footer">
      <my-button name="取消" site="form" @click="close"/>
      <my-button name="保存" site="form" @click="save"/>
    </div>
  </win-md>
</template>
 
<script>
import winMd from '@/components/win/win-md'
import myButton from '@/components/myButton/myButton'
import {getList, getTree, upd} from "@/api/projectConfig/kanbanNode";
 
export default {
  name: 'nodeChoose',
  components: {winMd, myButton},
  props: {
    // setting 中须至少包含控制dialog显示或隐藏的属性,其余属性可拓展
    // 将添加/修改的大量数据及逻辑从列表页面中分离出来,避免列表页面代码过多,审查困难
    // 若此页面须回传数据至父页面,可在引用组件时添加事件,本页面使用this.$emit('事件名',参数1,参数2...)回传数据
    setting: {
      type: Object,
      default: () => {
      }
    }
  },
  data() {
    return {
      loading: false,
      options: [],
      tableData: []
    }
  },
  mounted() {
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.loading = true
      getList({id: this.setting.id}).then(res => {
        let count = res.length
        res.map((item) => {
          getTree({tempProjectId: item.id}).then(ret => {
            item.options = ret
            count--
            if (count < 1) {
              this.tableData = res
              this.loading = false
            }
          })
        })
      })
    },
    close() {
      this.loading = false
      this.tableData = []
      this.$emit('close')
    },
    save() {
      let arr = []
      if (this.tableData.every(item => item.tempStageNodeIds.length === 0)) {
        this.$modal.msgError('请选择节点')
        return;
      }
      for (let i = 0; i < this.tableData.length; i++) {
        const item = this.tableData[i]
        item.tempStageNodeIds.map(node => {
          item.tempStageNodeId = node
          arr.push({...item})
        })
      }
      arr.map(item => {
        item.tempProjectId = item.id
        delete item.tempStageNodeIds
        delete item.id
        delete item.options
        delete item.tempProjectName
      })
      this.loading = true
      upd({
        id: this.setting.id,
        tempProjectBoardNode: arr
      }).then(res => {
        this.loading = false
        if (res) {
          this.$message.success('保存成功!')
          this.close()
          this.$emit('search')
        } else {
          this.$message.error('保存失败')
        }
      }).catch(() => {
        this.loading = false
      })
    }
  }
}
</script>