haoxuan
2024-05-07 1cd64a26daed3e0eb7b4ccf74e50267d79eaef09
src/components/makepager/TableCommonView.vue
@@ -155,6 +155,39 @@
              item.getCallMethod(scope.row[item.prop], scope.row)
            }}</span>
          </div>
          <div v-else-if="item.isEditTd">
              <template
                  v-if="scope.row[item.prop+'editType']=='inputFloat'"
                >
                <el-input-number
                  v-model="scope.row[item.prop]"
                  placeholder="请输入"
                  :min="0"
                  :precision="2"
                  :controls="false"
                  size="mini"
                  style="width: calc(100% - 80px); margin-right: 5px"
                  @change="
                    (val) => {
                      commonInputChange(val, item.prop, scope.row, scope)
                    }
                  "
                ></el-input-number>
                <el-button
                  type="text"
                  @click="saveEditShow(item.prop, scope.row, scope)"
                  >保存</el-button
                >
              </template>
              <span v-else>
                  {{ scope.row[item.prop] }}
                <i
                  class="el-icon-edit"
                  style="font-size: 16px; margin-left: 5px; cursor: pointer"
                  @click="handleEditShow(scope.row,scope,item)"
                ></i>
              </span>
          </div>
          <span v-else>{{ scope.row[item.prop] ? scope.row[item.prop] : "--" }}</span>
        </template>
      </el-table-column>
@@ -241,6 +274,36 @@
    },
  },
  methods: {
    // 表格编辑
    handleEditShow(row,scope,item){
      scope.row[item.prop+'editType']=='inputFloat'
      this.$set(this.tableList.tableInfomation[scope.$index],item.prop+'editType','inputFloat')
      this.$forceUpdate()
    },
    commonInputChange(val, prop, row, scope) {
      // if (row.editType=='inputFloat') {
      //   let value = scope.row[prop]
      //   let reg2 = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/
      //   if (!reg2.test(value) || value == 0) {
      //     this.$message.error("需要填写大于0的2位小数!")
      //     return true
      //   }
      //   this.$forceUpdate()
      // }
      this.$emit("inputContent", val, prop, row, scope)
    },
    saveEditShow( prop, row, scope){
      if (row.editType=='inputFloat') {
        let value = scope.row[prop]
        let reg2 = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/
        if (!reg2.test(value) || value == 0) {
          this.$message.error("需要填写大于0的2位小数!")
          return true
        }
        this.$forceUpdate()
      }
      this.$emit("inputContent", prop, row, scope)
    },
    onMaskClick() {
      this.iscolopen = false
    },