Blame view

src/views/system/sqywgz/components/djqxsd.vue 7.07 KB
任超 committed
1 2 3 4
<!--
  功能:登记情形设定
-->
<template>
任超 committed
5
  <div class='djqxsd'>
任超 committed
6
    <el-form :model="ruleForm">
任超 committed
7 8 9
      <el-row>
        <el-col :span="5">
          <el-form-item label="登记业务编码">
任超 committed
10
            {{ ruleForm.djywbm }}
任超 committed
11 12
          </el-form-item>
        </el-col>
任超 committed
13 14
        <el-col :span="12">
          <el-form-item label="登记业务名称">
任超 committed
15
            {{ ruleForm.djywmc }}
任超 committed
16 17 18 19
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
任超 committed
20
    <lb-table :column="column" border :key="key" :pagination="false" heightNumSetting :data="tableData">
任超 committed
21 22 23 24
    </lb-table>
  </div>
</template>
<script>
任超 committed
25
import { upward, down } from '@/utils/operation'
任超 committed
26
export default {
任超 committed
27 28
  props: {
    ruleForm: {
任超 committed
29 30 31
      type: Object, default: () => {
        return {}
      }
32 33 34 35 36
    },
    djqx: {
      type: Array, default: () => {
        return []
      }
任超 committed
37 38
    }
  },
任超 committed
39 40
  data () {
    return {
41
      input: '',
任超 committed
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
      key: 0,
      rules: {
        djywbm: [
          { required: true, message: '登记业务编码', trigger: 'blur' },
        ],
        djywmc: [
          { required: true, message: '登记业务名称', trigger: 'blur' },
        ],
      },
      column: [
        {
          width: '60',
          renderHeader: (h, scope) => {
            return <i class="el-icon-plus pointer" onClick={() => { this.handleAdd() }} style="color:#409EFF"></i>
          },
          render: (h, scope) => {
            return (
              <i class="el-icon-minus pointer" onClick={() => { this.handleMinus(scope.$index, scope.row) }}></i>
            )
          }
        },
        {
          width: '60',
          label: '序号',
          type: 'index'
        },
        {
69
          prop: 'nodecode',
任超 committed
70
          width: '105',
任超 committed
71 72 73
          label: '登记情形编码',
          render: (h, scope) => {
            return (
74
              <div>
75
                <el-input placeholder="登记情形编码" class={{ repeat: scope.row.repeat }} disabled={scope.row.sftsdjqx == '1'}
任超 committed
76
                  value={scope.row[scope.column.property]}
77 78 79
                  onInput={(val) => { scope.row[scope.column.property] = val }} onBlur={() => { this.nodecodeBlur(scope.$index, scope.row) }} maxlength="8">
                </el-input>
              </div>
任超 committed
80 81 82 83
            )
          }
        },
        {
84
          prop: 'nodename',
任超 committed
85 86 87
          label: '登记情形名称',
          render: (h, scope) => {
            return (
88
              <div>
89
                <el-input placeholder="登记情形名称" disabled={scope.row.sftsdjqx == '1'}
任超 committed
90
                  value={scope.row[scope.column.property]}
91 92
                  onInput={(val) => { scope.row[scope.column.property] = val }}></el-input>
              </div>
任超 committed
93 94 95 96 97
            )
          }
        },
        {
          label: '是否启用登记情形',
任超 committed
98
          width: '140',
任超 committed
99 100
          render: (h, scope) => {
            return (
101 102 103
              <el-radio-group v-model={scope.row.enabled} disabled={scope.row.sftsdjqx == '1'} onChange={(val) => { scope.row[scope.column.property] = val }}>
                <el-radio label={'1'}>启用</el-radio>
                <el-radio label={'0'}>禁用</el-radio>
任超 committed
104 105 106 107 108
              </el-radio-group>
            )
          }
        },
        {
任超 committed
109
          prop: 'djyy',
任超 committed
110 111 112
          label: '登记原因模板',
          render: (h, scope) => {
            return (
113
              <div>
114
                <el-input placeholder="登记原因模板" disabled={scope.row.sftsdjqx == '1'} value={scope.row[scope.column.property]}
任超 committed
115
                  onInput={(val) => { scope.row[scope.column.property] = val }}></el-input>
116 117
              </div>

任超 committed
118 119 120 121 122
            )
          }
        },
        {
          label: '是否启用模板',
任超 committed
123
          width: '140',
任超 committed
124 125
          render: (h, scope) => {
            return (
126 127 128
              <el-radio-group v-model={scope.row.sfqydjyymb} disabled={scope.row.sftsdjqx == '1'} onChange={(val) => { scope.row[scope.column.property] = val }}>
                <el-radio label={'1'}>启用</el-radio>
                <el-radio label={'0'}>禁用</el-radio>
任超 committed
129 130 131 132 133 134
              </el-radio-group>
            )
          }
        },
        {
          label: '移动',
任超 committed
135
          width: '100',
任超 committed
136 137 138
          render: (h, scope) => {
            return (
              <div>
139 140
                <el-button type='text' disabled={scope.$index == 0} onClick={() => { this.moveUpward(scope.$index, scope.row) }}>上移</el-button>
                <el-button type='text' disabled={(scope.$index + 1) == this.tableData.length} onClick={() => { this.moveDown(scope.$index, scope.row) }}>下移</el-button >
任超 committed
141 142 143 144 145
              </div>
            )
          }
        }
      ],
任超 committed
146
      tableData: []
任超 committed
147 148 149 150 151
    }
  },
  watch: {
    tableData: {
      handler (newValue, oldValue) {
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
        let that = this
        if (!_.isEqual(newValue, this.djqx)) {
          let temp = newValue.some((item, index, array) => {
            return item.repeat;
          })
          if (temp) {
            that.$emit('updateValue', {
              djqx: newValue,
              btnDisabled: true
            })
          } else {
            that.$emit('updateValue', {
              djqx: newValue,
              btnDisabled: false
            })
          }
        }
      },
      deep: true
    },
    djqx: {
      handler: function (newValue) {
        this.tableData = _.cloneDeep(newValue)
175
        this.addIndexes()
任超 committed
176 177 178 179 180
      },
      deep: true
    }
  },
  methods: {
181 182 183 184 185 186 187 188
    // 添加索引
    addIndexes (data = this.tableData, isAdd = true) {
      data.forEach((item, index) => {
        if (isAdd) {
          item.index = index + 1
        }
      })
    },
任超 committed
189
    handleAdd () {
190 191 192 193
      this.$nextTick(() => {
        let container = this.$el.querySelector('.el-table__body-wrapper');
        container.scrollTop = container.scrollHeight;
      })
任超 committed
194 195 196 197 198 199 200
      this.tableData.push(
        {
          nodecode: '',
          nodename: '',
          enabled: '1',
          djyy: '',
          sfqydjyymb: '0'
201
        }
任超 committed
202
      )
203
      this.addIndexes()
任超 committed
204
      this.key++
任超 committed
205
    },
任超 committed
206
    handleMinus (index, row) {
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
      this.$confirm('此操作将永久删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.tableData.splice(index, 1)
        this.$message({
          type: 'success',
          message: '删除成功!'
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
任超 committed
223
    },
任超 committed
224 225 226 227 228 229 230 231 232 233
    nodecodeBlur (index, row) {
      let list = _.cloneDeep(this.tableData).filter(item => item.bsmSqyw != row.bsmSqyw)
      let arr = list.map(item => item.nodecode)
      if (arr.includes(row.nodecode)) {
        this.$set(row, 'repeat', true)
        this.$message.error('登记情形编码不能重复');
      } else {
        this.$set(row, 'repeat', false)
      }
    },
任超 committed
234 235
    // 上移下移
    moveUpward (index, row) {
任超 committed
236
      upward(index, this.tableData)
237
      this.key++
任超 committed
238 239
    },
    moveDown (index, row) {
任超 committed
240
      down(index, this.tableData)
241
      this.key++
任超 committed
242
    }
任超 committed
243 244 245
  }
}
</script>
任超 committed
246 247 248 249 250 251 252
<style lang='scss'>
.djqxsd {
  .repeat {
    .el-input__inner {
      border-color: red !important;
    }
  }
任超 committed
253
}
任超 committed
254
</style>