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 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
| <template> <div class="app-container"> <!-- 添加对话框 --> <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddDetails">添加</el-button> <el-button type="success" icon="el-icon-delete" size="mini" @click="handleDeleteDetails">删除</el-button> <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteAllDetails">清空</el-button> <el-table style="width: 100%;margin-top: 20px" :header-cell-style="{background:'#8be6c1'}" :data="handleList" :row-class-name="rowClassName" @selection-change="handleDetailSelectionChange" ref="tb"> <el-table-column type="selection" width="45" align="center"/> <el-table-column label="序号" align="center" prop="xh" width="50"></el-table-column> <el-table-column label="不良类型" align="center" prop="badType" width="130"> <template slot-scope="scope"> <el-select clearable v-model="handleList[scope.row.xh-1].badType"> <el-option v-for="item in badTypes" :key="item.id" :label="item.name" :value="item.id"/> </el-select> </template> </el-table-column> <el-table-column label="行动项" align="center" prop="actionItem" width="130"> <template slot-scope="scope"> <el-input v-model.trim="handleList[scope.row.xh-1].actionItem" type="text" size="small" placeholder="请输入行动项"/> </template> </el-table-column> <el-table-column label="负责人" width="130" prop="masterPerson"> <template slot-scope="scope"> <el-select clearable v-model="handleList[scope.row.xh-1].masterPerson"> <el-option v-for="item in employees" :key="item.id" :label="item.name" :value="item.id"/> </el-select> </template> </el-table-column> <el-table-column label="部门" width="130" prop="deptName"> <template slot-scope="scope"> <el-select clearable v-model="handleList[scope.row.xh-1].dept"> <el-option v-for="item in depts" :key="item.id" :label="item.deptName" :value="item.id"/> </el-select> </template> </el-table-column> <el-table-column label="指派日期" width="200" prop="assignTime"> <template slot-scope="scope"> <div class="block"> <el-date-picker v-model="handleList[scope.row.xh-1].assignTime" type="datetime" placeholder="选择日期时间" align="right" :picker-options="pickerOptions"> </el-date-picker> </div> </template> </el-table-column> <el-table-column label="完成日期" width="200" prop="finishTime"> <template slot-scope="scope"> <div class="block"> <el-date-picker v-model="handleList[scope.row.xh-1].finishTime" type="datetime" placeholder="选择日期时间" align="right" :picker-options="pickerOptions"> </el-date-picker> </div> </template> </el-table-column> <el-table-column label="状态" align="center" prop="status" width="130"> <template slot-scope="scope"> <el-select clearable v-model="handleList[scope.row.xh-1].status"> <el-option v-for="item in states" :key="item.value" :label="item.label" :value="item.value"/> </el-select> </template> </el-table-column> </el-table> </div> </template>
<script> export default { name: "Table2", data() { return { // 表单参数 form: {}, employees: [], depts: [], states: [{ value: '0', label: '未处理' }, { value: '1', label: '处理中' }, { value: '2', label: '完成' }], pickerOptions: { shortcuts: [{ text: '今天', onClick(picker) { picker.$emit('pick', new Date()) } }, { text: '昨天', onClick(picker) { const date = new Date() date.setTime(date.getTime() - 3600 * 1000 * 24) picker.$emit('pick', date) } }, { text: '一周前', onClick(picker) { const date = new Date() date.setTime(date.getTime() - 3600 * 1000 * 24 * 7) picker.$emit('pick', date) } }] }, // 选中的从表数据 checkedDetail: [], handleList: [], badTypes: [] } }, methods:{ // 清空数据 handleDeleteAllDetails() { if (this.handleList == undefined && this.handleList.length==0) { this.$alert("没有可删除的数据", "提示", { confirmButtonText: "确定", }) } else { this.$modal.confirm('确认删除所有行吗?').then(res => { this.handleList = undefined }) } }, // 删除一行 handleDeleteDetails() { if (this.checkedDetail.length == 0) { this.$alert("请先选择要删除的数据", "提示", { confirmButtonText: "确定", }) } else { this.handleList.splice(this.checkedDetail[0].xh - 1, 1) } }, // 添加一行 handleAddDetails() { if (this.handleList == undefined) { this.handleList = new Array() } let obj = {} obj.badType = 1 obj.actionItem = '' obj.masterPerson = '' obj.assignTime = '' obj.finishTime = '' obj.status = '' this.handleList.push(obj) }, // 单选框选中数据 handleDetailSelectionChange(selection) { if (selection.length > 1) { this.$refs.tb.clearSelection() this.$refs.tb.toggleRowSelection(selection.pop()) } else { this.checkedDetail = selection } }, rowClassName({row, rowIndex}) { row.xh = rowIndex + 1 }, } } </script>
<style scoped>
</style>
|