单元的点击下拉,点击输入,点击picker

1. 点击输入input(EditCell)

<!--
 * @Author: wangzhendong
 * @Descripttion: file content
 * @Date: 2021-09-17 09:29:31
 * @LastEditors: wangzhendong
 * @LastEditTime: 2021-10-09 10:11:24
 * @FilePath: \amIrpWeb_project\src\pc\views\BondTrade\PmIntentInstruction\components\EditCell.vue
-->
<template>
  <div @click="onFieldClick" class="edit-cell">
    <!-- <el-tooltip
      v-if="!editMode && !showInput"
      :placement="tooltipPlacement"
      :open-delay="tooltipDelay"
      :content="tooltipContent"
    >
      <div
        tabindex="0"
        class="cell-content"
        :class="{ 'edit-enabled-cell': canEdit }"
        @keyup.enter="onFieldClick"
      >
        <span v-if="value">
          {{ value }}
        </span>
        <span v-else class="ownPlaceHolder">{{ ownPlaceHolder }}</span>
      </div>
    </el-tooltip> -->


        <div
        tabindex="0"
        class="cell-content"
        :class="{ 'edit-enabled-cell': canEdit }"
        @keyup.enter="onFieldClick"
      >
        <span v-if="value">
          {{ value }}
        </span>
        <span v-else class="ownPlaceHolder">{{ ownPlaceHolder }}</span>
      </div>
    <component
      :is="editableComponent"
      v-if="editMode || showInput"
      ref="input"
      @keyup.enter.native="onInputExit"
      @change="onInputChange"
      v-on="listeners"
      v-bind="$attrs"
      v-model="model"
      style="width: 100%"
    >
      <slot name="edit-component-slot"></slot>
    </component>
  </div>
</template>
<script>
import _ from "lodash";
export default {
  name: "SjEditCell",
  inheritAttrs: false,
  props: {
    value: {
      type: [String, Number],
      default: ""
    },
    tooltipContent: {
      type: String,
      default: "点击编辑"
    },
    tooltipDelay: {
      type: Number,
      default: 500
    },
    tooltipPlacement: {
      type: String,
      default: "top-start"
    },
    showInput: {
      type: Boolean,
      default: false
    },
    editableComponent: {
      type: String,
      default: "hr-input"
    },
    closeEvent: {
      type: String,
      default: "blur"
    },
    canEdit: {
      type: Boolean,
      default: true
    },
    jyxtCallBack: {
      type: Function,
      required: false
    },
    ownPlaceHolder: {
      type: String,
      default: "请输入"
    },
    selectOptions: {
      type: Array
    }
  },
  data() {
    return {
      editMode: false
    };
  },
  computed: {
    model: {
      get() {
        return this.value;
      },
      set(val) {
        this.$emit("input", val);
      }
    },
    listeners() {
      return {
        [this.closeEvent]: this.onInputExit,
        ...this.$listeners
      };
    }
  },
  methods: {
    onFieldClick() {
      if (this.canEdit) {
        this.editMode = true;
        this.$nextTick(() => {
          const inputRef = this.$refs.input;
          if (inputRef && inputRef.focus) {
            inputRef.focus();
            if (this.$props.Cb) {
              this.model = this.$props.cb();
            }
          }
        });
      }
    },
    onInputExit() {
      this.editMode = false;
    },
    onInputChange(val) {
      this.$emit("input", val);
    }
  }
};
</script>

<style scoped>
.cell-content {
  padding-left: 5px;
  border: 1px solid transparent;
}
.edit-enabled-cell {
  cursor: pointer;
  height: 24px !important;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ownPlaceHolder {
  display: flex;
  align-items: center;
  color: #c0c4cc !important;
  font-size: 12px;
}
</style>

1.1 使用

  {
          prop: "name",
          label: "姓名",
          minWidth: 110,
          width: 110,
          sort: true,
          cellStyle: ({ data }) => {
            let bc = {};
            if (
              this.hasSessionFlag &&
              data.existErrorColumnList &&
              data.existErrorColumnList.includes("name")
            ) {
              bc = { backgroundColor: "#FFCCC7" };
            }
            return bc;
          },
          render: (h, { row }) => {
            const flag =
              this.hasSessionFlag &&
              row.existErrorColumnList &&
              row.existErrorColumnList.includes("name");
            return (
              <div title={row.name}>
                <EditCell
                  slot-scope={row}
                  v-model={row.name}
                  showName={row.name}
                  placeholder="请输入"
                  size="mini"
                  editable-component="el-input"
                  tooltipContent="点击编辑"
                  ownPlaceHolder=""
                  canEdit={flag}
                />
              </div>
            );
          }
        }

2. 点击出现picker(EditPicker)

<!--
 * @Author: wangzhendong
 * @Descripttion: file content
 * @Date: 2021-10-13 14:46:26
 * @LastEditors: wangzhendong
 * @LastEditTime: 2021-10-18 14:51:20
 * @FilePath: \amIrpWeb_project\src\pc\views\BondTrade\PmIntentInstruction\components\EditSelectCell.vue
-->
<template>
  <div @click="onFieldClick" class="edit-cell">
    <div
      tabindex="0"
      class="cell-content"
      :class="{ 'edit-enabled-cell': canEdit }"
      @keyup.enter="onFieldClick"
    >
      <span v-if="showName"> {{ showName }}</span>
      <span v-else class="ownPlaceHolder">{{ ownPlaceHolder }}</span>
    </div>
    <el-date-picker
      placeholder="选择日期"
      size="mini"
      type="date"
      value-format=	"yyyy-MM-dd"
      v-if="editMode || showInput"
      filterable
      ref="input"
      @change="changeVal"
      @blur="blur"
      v-bind="$attrs"
      v-model="model"
      style="width: 100%"
    ></el-date-picker>
  </div>
</template>
<script>
import _ from "lodash";
import EventBus from "@/pc/eventBus";
export default {
  name: "SjEditSelectCell",
  inheritAttrs: false,
  props: {
    value: {
      type: [String, Number, Array],
      default: ""
    },
    showName: {
      type: [String, Number, Array]
    },
    tooltipContent: {
      type: String,
      default: "点击编辑"
    },
    tooltipDelay: {
      type: Number,
      default: 500
    },
    tooltipPlacement: {
      type: String,
      default: "top-start"
    },
    showInput: {
      type: Boolean,
      default: false
    },
    closeEvent: {
      type: String,
      default: "blur"
    },
    canEdit: {
      type: Boolean,
      default: true
    },
    cb: {
      type: Function,
      required: false
    },
    ownPlaceHolder: {
      type: String,
      default: "请输入"
    },
    selectOptions: {
      type: Array
    },
    row: {
      type: Object
    },
    cellType: {
      type: String
    },
    checkMore: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      test: "",
      loading: false,
      localOptions: [],
      editMode: false
    };
  },
  computed: {
    options() {
      return this.selectOptions?.length > 0 ? this.selectOptions : this.localOptions;
    },
    model: {
      get() {
        return this.value;
      },
      set(val) {
        this.$emit("input", val);
      }
    }
  },
  methods: {
    onFieldClick() {
      if (this.canEdit) {
        this.editMode = true;
        this.$nextTick(() => {
          const inputRef = this.$refs.input;
          if (inputRef && inputRef.focus) {
            inputRef.focus();
            if (this.$props.cb) {
              this.$props.cb();
            }
          }
          this.$emit("cellClick");
        });
      }
    },
    changeVal(val) {
      this.$emit("input", val);
      this.editMode = false;
    },
    blur() {
      setTimeout(() => {
        this.editMode = false;
      }, 100);
    }
  }
};
</script>

<style scoped>
.cell-content {
  padding-left: 5px;
  border: 1px solid transparent;
}
.edit-enabled-cell {
  cursor: pointer;
  height: 24px !important;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ownPlaceHolder {
  display: flex;
  justify-content: center;
  color: #c0c4cc !important;
  font-size: 12px;
}
</style>

2.1 使用

  {
          prop: "serviceDate",
          label: "服务时间",
          minWidth: 110,
          width: 110,
          sort: true,
          cellStyle: ({ data }) => {
            let bc = {};
            if (
              this.hasSessionFlag &&
              data.errorColumnList &&
              data.errorColumnList.includes("serviceDate")
            ) {
              bc = { backgroundColor: "#FFCCC7" };
            }
            return bc;
          },
          render: (h, { row }) => {
            const flag =
              this.hasSessionFlag &&
              row.errorColumnList &&
              row.errorColumnList.includes("serviceDate");
            return (
              <div title={row.phoneCode}>
                <EditPicker
                  slot-scope={row}
                  v-model={row.serviceDate}
                  showName={row.serviceDate}
                  placeholder="请输入"
                  size="mini"
                  editable-component="el-input"
                  tooltipContent="点击编辑"
                  ownPlaceHolder=""
                  canEdit={flag}
                />
              </div>
            );
          }
        }

2.12 效果

3.0 EditSelectCell(点击下拉)

<!--
 * @Author: wangzhendong
 * @Descripttion: file content
 * @Date: 2021-10-13 14:46:26
 * @LastEditors: wangzhendong
 * @LastEditTime: 2021-10-18 14:51:20
 * @FilePath: \amIrpWeb_project\src\pc\views\BondTrade\PmIntentInstruction\components\EditSelectCell.vue
-->
<template>
  <div @click="onFieldClick" class="edit-cell">
    <!-- <el-tooltip
      v-if="!editMode && !showInput"
      :placement="tooltipPlacement"
      :open-delay="tooltipDelay"
      :content="tooltipContent"
    >
     
    </el-tooltip> -->

     <div
        tabindex="0"
        class="cell-content"
        :class="{ 'edit-enabled-cell': canEdit }"
        @keyup.enter="onFieldClick"
      >
        <span v-if="showName" class="show-name"> {{ showName }}</span>
        <span v-else class="ownPlaceHolder">{{ ownPlaceHolder }}</span>
      </div>
    <el-select
      placeholder="可搜索"
      :loading="loading"
      size="mini"
      v-if="editMode || showInput"
      filterable
      ref="input"
      @change="changeVal"
      @blur="blur"
      @visible-change="visibleChange"
      v-bind="$attrs"
      v-model="model"
      style="width: 100%"
    >
      <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
      </el-option>
    </el-select>
  </div>
</template>
<script>
import { listPositionDictList } from "@/pc/api/ExternalEvaluate";
import _ from "lodash";
import EventBus from "@/pc/eventBus";
export default {
  name: "SjEditSelectCell",
  inheritAttrs: false,
  props: {
    value: {
      type: [String, Number, Array],
      default: ""
    },
    showName: {
      type: [String, Number, Array]
    },
    tooltipContent: {
      type: String,
      default: "点击编辑"
    },
    tooltipDelay: {
      type: Number,
      default: 500
    },
    tooltipPlacement: {
      type: String,
      default: "top-start"
    },
    showInput: {
      type: Boolean,
      default: false
    },
    closeEvent: {
      type: String,
      default: "blur"
    },
    canEdit: {
      type: Boolean,
      default: true
    },
    cb: {
      type: Function,
      required: false
    },
    ownPlaceHolder: {
      type: String,
      default: "请输入"
    },
    selectOptions: {
      type: Array
    },
    row: {
      type: Object
    },
    cellType: {
      type: String
    },
    checkMore: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      test: "",
      loading: false,
      localOptions: [],
      editMode: false
    };
  },
  computed: {
    options() {
      return this.selectOptions?.length > 0 ? this.selectOptions : this.localOptions;
    },
    model: {
      get() {
        return this.value;
      },
      set(val) {
        this.$emit("input", val);
      }
    }
  },
  methods: {
    onFieldClick() {
      if (this.canEdit) {
        this.editMode = true;
        this.$nextTick(() => {
          const inputRef = this.$refs.input;
          if (inputRef && inputRef.focus) {
            inputRef.focus();
            if (this.$props.cb) {
              this.$props.cb();
            }
          }
          this.$emit("cellClick");
        });
      }
    },
    changeVal(val) {
      this.$emit("input", val);
      if (this.cellType === "position") {
        const data = this.localOptions.find(item => item.value == val)?.label;
        this.$emit("click", data);
      } else {
        
        this.$emit("click", val);
      }

      this.editMode = false;
    },
    blur() {
      setTimeout(() => {
        this.editMode = false;
      }, 100);
    },
    visibleChange(value) {
      if (this.cellType === "position" && value) {
        if (this.row.station) {
          this.listPositionDictList(this.row.station);
        } else {
          this.$message.warning("请先选择岗位");
        }
      }
    },

    // 根据岗位获取职务
    listPositionDictList(value) {
      this.loading = true;
      listPositionDictList({ parentId: value })
        .then(res => {
          if (res.length > 0) {
            this.localOptions = res.map(item => ({ label: item.caption, value: item.id }));
          } else {
            this.localOptions = [];
          }
          EventBus.$off("getPositionOption", this.localOptions);
        })
        .finally(() => {
          this.loading = false;
        });
    }
  }
};
</script>

<style scoped>
.cell-content {
  padding-left: 5px;
  border: 1px solid transparent;
}
.edit-enabled-cell {
  cursor: pointer;
  height: 24px !important;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ownPlaceHolder {
  display: flex;
  justify-content: center;
  color: #c0c4cc !important;
  font-size: 12px;
}
.show-name {
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-block;
}
</style>

 3.1 使用

  {
          prop: "stationName",
          label: "岗位",
          sort: true,
          minWidth: 110,
          width: 110,
          cellStyle: ({ data }) => {
            let bc = {};
            if (
              this.hasSessionFlag &&
              data.existErrorColumnList &&
              data.existErrorColumnList.includes("station")
            ) {
              bc = { backgroundColor: "#FFCCC7" };
            }
            return bc;
          },
          render: (h, { row }) => {
            const flag =
              this.hasSessionFlag &&
              row.existErrorColumnList &&
              row.existErrorColumnList.includes("station");
            return (
              <div title={row.stationName}>
                <EditSelectCell
                  v-model={row.station}
                  showName={row.stationName}
                  placeholder="请输入"
                  size="mini"
                  editable-component="el-input"
                  tooltipContent="点击编辑"
                  ownPlaceHolder=""
                  selectOptions={this.stationOption}
                  onClick={() => {
                    row.stationName = this.stationOption.find(
                      item => item.value == row.station
                    )?.label;
                  }}
                  canEdit={flag}
                />
              </div>
            );
          }
        }

3.3 效果

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

好喝的西北风

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值