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 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
| <template> <div class="f-mt"> <el-table :data="data" style="width: 100%;" row-key="id" :indent="6" :default-expand-all="default_expand_all" border :tree-props="{ children: 'children', hasChildren: 'hasChildren' }" > <el-table-column prop="name" label="指标名称"> <template slot-scope="scope"> {{ scope.row.name }} <f-tips v-if="scope.row.method" top="25%" :width="400">{{ scope.row.method }}</f-tips> </template> </el-table-column> <el-table-column prop="systemValue" label="前台系统取值(元)"> <template slot-scope="scope"> <el-tooltip effect="dark" :content="scope.row.show_system_desc" placement="top" > <el-button type="text">{{ format(scope.row.systemValue) }}</el-button> </el-tooltip> </template> </el-table-column> <el-table-column prop="manualValue" label="手工补录(元)"> <template slot-scope="scope"> <el-form> <el-form-item :key="scope.row.id" :error="valid[scope.row.id + '_' + scope.row.name]" > <el-tooltip effect="dark" :content="scope.row.show_manual_desc" placement="top" > <el-input size="medium" @input=" checkInput( scope.row.manualValue, scope.row.id, scope.row.name ) " v-model="scope.row.manualValue" placeholder="请输入" ></el-input> </el-tooltip> </el-form-item> </el-form> </template> </el-table-column> <el-table-column prop="total" label="合计(元)"> <template slot-scope="scope"> <el-tooltip effect="dark" :content="scope.row.show_system_desc" placement="top" > <span> {{ scope.row.can_edit ? format( ( Number(scope.row.systemValue) + Number(scope.row.manualValue) ).toFixed(2) ) : format(scope.row.total) }} </span> </el-tooltip> </template> </el-table-column> <el-table-column prop="houses" label="楼栋均摊(元)" width="620"> <template slot-scope="scope"> <el-form :inline="true" label-position="right" label-width="120px"> <el-form-item v-for="(item, index) in scope.row.show_houses" :label="item.name" :key="index" :error="valid[item.id + '_' + scope.row.name]" > <el-tooltip effect="dark" placement="top" :content="item.show_system_desc" > <el-input size="medium" style="width: 130px;" :disabled="!item.can_edit" @input=" checkInput(item.value, item.id, scope.row.name, scope.row) " v-model="item.value" placeholder="请输入修改数值" ></el-input> </el-tooltip> </el-form-item> <el-button class="show-btn" v-if="scope.row.houses && scope.row.houses.length > 2" type="text" @click="handleMore(scope.row)" >查看更多</el-button > </el-form> </template> </el-table-column> </el-table> </div> </template>
<script> function makeMsg(oriMsg, msg) { return `${oriMsg}${msg ? ',' + msg : ''}` } export default { name: 'table-form', props: { data: { type: [Array], required: true }, // 控制树展开折叠 default_expand_all: { type: Boolean, required: true } }, data() { return { valid: {}, title: '', form: { houses: [] }, rules: {}, visible: false, active: ['1'], error_info: [], d_loading: false, list: [], field: { visible: false, loading: false, title: '' } } }, watch: {}, computed: {}, methods: { /** * 编辑 ,校验输入合法 * @param {*} value * @param {*} id * @param {*} name * @param {*} item 当前编辑的item */ checkInput(value, id, name, item) { let i = 14 let f = 2 let all_true = false this.valid[id + '_' + name] = '' let reg = new RegExp(`^-?\\d{1,${i}}(\\.\\d{1,${f}})?$`) if (!reg.test(value)) { this.valid[id + '_' + name] = `最多${i}位整数${f}位小数` } // 校验是否还存在其他valid for (let v in this.valid) { if (this.valid[v]) { all_true = false break } else { all_true = true } } let res = 0 if (item.houses && item.houses.length) { item.houses.forEach((h) => { res = Utils.floatAdd(res, h.value, 2) }) } item.manualValue = res // 同步更新当前手工补录值 this.$emit('checkInput', all_true) // 通过输入合法性校验 },
// 查看更多楼栋信息 handleMore(data) { this.form = _.clone(data) this.title = data.name this.visible = true },
// 查看明细 goTo(url) { this.$emit('goTo', url) },
/** * 正浮点数限制 * @param {Number} i 整数最大位数 * @param {Number} f 小数最大位数 * @param {Object} options 配置 * isMoreThanZero: 是否强制大于0 * canNegative: 是否允许输入负数 */ float(i, f, options = {}) { return { validator: (rule, value, callback) => { let reg let msg if (f == 0) { reg = new RegExp(`^-?\\d{1,${i}}$`) } else { reg = new RegExp(`^-?\\d{1,${i}}(\\.\\d{1,${f}})?$`) } if (!value) { callback() } else { if (reg.test(value)) { if ( (options.isMoreThanZero && Number(value) <= 0) || (!options.canNegative && Number(value) < 0) ) { msg = '请输入大于零的数值' } else { callback() } } else { msg = `最多${i}位整数` if (f != 0) { msg += `${f}位小数` } } } if (msg) { callback(new Error(makeMsg(msg, options.extraMsg))) } }, trigger: 'blur' } }, /* 不允许输入全部是空格 */ notAllBlank(label) { return { validator: (rule, value = '', callback) => { if (value.trim().length == 0) { callback(new Error(`${label}不能全部是空格`)) } else { callback() } }, trigger: 'blur' } }, /** * 千分位 * @param {*} str 字符串数字 */ format(str) { if (!str) return str str = str.toString() let minus = false if (/^-/.test(str)) { minus = true str = str.replace(/^-/, '') } let [int, float] = str.split('.') let result = [] for (let i = 0; i < int.length; i++) { result = [int[int.length - i - 1], ...result] if (i % 3 == 2 && i != int.length - 1) { result = [',', ...result] } } if (float) { return `${minus ? '-' : ''}${result.join('')}.${float}` } return `${minus ? '-' : ''}${result.join('')}` } } } </script> <style lang="less" scoped> @import '~__assets/var.less'; @import url('//at.alicdn.com/t/font_1712723_tp9lsy2fuua.css');
.f-fr { float: right; }
.f-tooltip { max-width: 700px !important; word-wrap: break-word !important; }
.show-btn { position: absolute; right: 20px; top: 13px; }
/deep/ .cell { user-select: text; }
/deep/ .el-table__row { td { &:last-child { .cell { max-height: 60px; } } } }
.dialog-total { height: 32px; text-align: right; }
.error-info { color: @c-err; font-size: 16px; line-height: 24px; }
.f-i-btn { font-size: 16px; } </style>
|