Blame view

src/views/system/qtjfjmb/components/djbdisposition.vue 8.79 KB
xiaomiao committed
1 2 3 4 5 6
<!--
 * @Description:
 * @Autor: renchao
 * @LastEditTime: 2023-07-19 16:04:58
-->
<template>
xiaomiao committed
7
  <div style="text-align: center" class="transfer">
xiaomiao committed
8 9
    <el-transfer
      filterable
xiaomiao committed
10 11 12 13
      :filter-method="filterMethod"
      filter-placeholder="请输入关键词搜索"
      v-model="value"
      target-order="unshift"
xiaomiao committed
14 15
      :left-default-checked="[]"
      :right-default-checked="[]"
xiaomiao committed
16
      :titles="['待选合集', '已选合集']"
xiaomiao committed
17
      :button-texts="['转到左边', '转到右边']"
xiaomiao committed
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
      @right-check-change="choose"
      :data="datalist"
      v-loading="loading"
    >
      <div slot-scope="{ option }">
        <div
          class="default-tranfer-item"
          @mouseenter="indexKey = option.key"
          @mouseleave="indexKey = null"
        >
          <span>{{ option.despriction }}</span>
          <div
            v-show="value.includes(option.key) && indexKey === option.key"
            class="button-group"
          >
            <!--  阻止事件冒泡  -->
            <!-- 自定义数据项,将上、下、底部、顶部的排序功能放在数据项里面 -->
            <em
              class="el-icon-top"
              @click.stop.prevent="publicMobileMethod('handleUp', option.key)"
            ></em>
            <em
              class="iconfont icon-huidaodingbu"
              @click.stop.prevent="publicMobileMethod('handleTop', option.key)"
            ></em>
            <em
              class="el-icon-bottom"
              @click.stop.prevent="publicMobileMethod('handleDown', option.key)"
            ></em>
            <em
              class="el-icon-download"
              @click.stop.prevent="
                publicMobileMethod('handleBottom', option.key)
              "
            ></em>
          </div>
        </div>
      </div>
xiaomiao committed
56 57
    </el-transfer>
    <div class="btn">
xiaomiao committed
58 59
      <el-button @click="$popupCacel">取消</el-button>
      <el-button type="primary" @click="submitForm" plain>确定</el-button>
xiaomiao committed
60
    </div>
xiaomiao committed
61 62 63 64 65 66
    <!-- <footer class="footer">
        <div>
          <el-button class="cancel" size="mini" @click="$popupCacel">取消</el-button>
          <el-button class="determine" size="mini" @click="submitForm">确定</el-button>
        </div>
      </footer> -->
xiaomiao committed
67 68 69 70
  </div>
</template>

<script>
xiaomiao committed
71 72 73 74 75 76
import { getFieldList, getFieldListByQlxx, save } from "@/api/SysDjbFieldDO";
export default {
  props: {
    formData: {
      type: Object,
      default: () => {},
xiaomiao committed
77
    },
xiaomiao committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
  },
  data() {
    return {
      loading: true,
      datalist:[],
      list: [], // 全部数据
      value: [], // 选中数据
      item: [], // 右侧勾选数据
      chuanlist: [],
      indexKey: null, // 高亮显示
      filterMethod(query, item) {
        return item.despriction.indexOf(query) > -1;
      },
    };
  },
  mounted() {
    this.generateData();
  },

  methods: {
    /**
yuanbo committed
99 100
     * @description: 初始数据集
     * @author: renchao
xiaomiao committed
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
     */
    generateData() {
      const data = [];
      this.value = [];
      getFieldList({ qllx: this.formData.qllx }).then((res) => {
        if (res.code === 200) {
          let listss = res.result;
          listss.forEach((item, index) => {
            this.list.push({
              key: index,
              name: item.name,
              despriction: item.despriction,
            });
          });
          getFieldListByQlxx({ qllx: this.formData.qllx }).then((res) => {
            let listss = res.result;
            if (res.code === 200) {
              this.list.forEach((el, idx) => {
                listss.forEach((item) => {
                  if (el.name == item.name) {
                    this.value.push(idx);
                  }
                });
              });
               this.datalist=this.list
xiaomiao committed
126
               this.loading=false
xiaomiao committed
127 128 129 130
            }
          });
        }
      });
xiaomiao committed
131
    },
xiaomiao committed
132
    /**
yuanbo committed
133 134
     * @description: 确定选择
     * @author: renchao
xiaomiao committed
135 136 137 138 139 140 141 142 143 144 145 146
     */
    submitForm() {
      this.value.forEach((item) => {
        this.chuanlist.push(this.list[item]);
      });

      save(this.formData.bsmMb, this.chuanlist).then((res) => {
        if (res.code == 200) {
          this.$popupCacel();
          this.$message({
            message: "保存成功",
            type: "success",
xiaomiao committed
147
          });
xiaomiao committed
148 149 150 151 152 153 154 155 156
        } else {
          this.$message({
            message: "保存失败",
            type: "error",
          });
        }
      });
    },
    /**
yuanbo committed
157
     * @description: 监听右侧选中
yuanbo committed
158 159
     * @param {*} value
     * @author: renchao
xiaomiao committed
160 161 162 163 164
     */
    choose(value) {
      this.item = value;
    },
    /**
yuanbo committed
165
     * @description: 右侧数据点击排序
yuanbo committed
166 167 168
     * @param {*} direction
     * @param {*} key
     * @author: renchao
xiaomiao committed
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
     */
    publicMobileMethod(direction, key) {
      const self = this;
      let index;
      // 判断是否超出一条
      const item = self.item;
      if (item.length === 1 || item.length === 0) {
        self.value.forEach((val, indexs) => {
          // 获取需移动数据的下标
          if (val === key) {
            index = indexs;
          }
        });
        if (
          index === 0 &&
          direction !== "handleBottom" &&
          direction !== "handleDown"
        ) {
          return self.$message("没有上移的空间了");
        }
        if (
          index === self.value.length - 1 &&
          direction !== "handleUp" &&
          direction !== "handleTop"
        ) {
          return self.$message("没有下移的空间了");
        }
        // 改变的数组
        const changeItem = self.value[index];
        // 根据下标在数组中删除该数据
        self.value.splice(index, 1);
        // 判断加入数组位置
        if (direction) {
          // 置顶
          direction === "handleTop" && self.value.unshift(changeItem);
          // 置底
          direction === "handleBottom" && self.value.push(changeItem);
          // 上移
          direction === "handleUp" &&
            self.value.splice(index - 1, 0, changeItem);
          // 下移
          direction === "handleDown" &&
            self.value.splice(index + 1, 0, changeItem);
xiaomiao committed
212
        }
xiaomiao committed
213 214 215
      } else {
        self.$message.error("只能选择一条数据进行上下移动");
      }
xiaomiao committed
216
    },
xiaomiao committed
217 218 219 220 221 222
  },
};
</script>
<style scoped lang="scss">
@import "~@/styles/mixin.scss";
@import "~@/styles/dialogBoxheader.scss";
xiaomiao committed
223

xiaomiao committed
224 225 226 227
.determine.el-button--mini {
  background-color: #2a76cd;
  color: #ffffff;
}
xiaomiao committed
228

xiaomiao committed
229 230 231 232 233 234 235 236 237
.el-transfer__button.cancel,
.el-button--mini.cancel {
  &:focus,
  &:hover {
    background: #ffffff;
    border-color: #2a76cd;
    color: #2a76cd;
  }
}
xiaomiao committed
238

xiaomiao committed
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
.el-transfer {
  display: flex;
  justify-content: space-between;
  align-items: center;

  .el-transfer-panel__item {
    margin-right: 0;
  }

  .default-tranfer-item {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;

    .button-group {
      em {
        margin-right: 8px;
xiaomiao committed
257 258 259
      }
    }
  }
xiaomiao committed
260 261 262 263 264 265 266 267 268 269 270 271 272
  /deep/.el-checkbox-group {
    .el-checkbox {
      display: flex;
      position: relative;
      .el-checkbox__input {
        position: absolute;
        left: 10px;
      }
    }
    .el-checkbox:last-of-type {
      margin-right: 30px;
    }
  }
xiaomiao committed
273

xiaomiao committed
274 275 276 277
  .el-input.el-input--small {
    .el-input__inner {
      border-radius: 4px;
    }
xiaomiao committed
278
  }
xiaomiao committed
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

  .el-transfer__buttons {
    padding: 0;
    margin: 0 17px;

    .el-transfer__button {
      display: block;
      margin: 0 0 5px 0;
      padding: 4px 8px;
    }

    .el-button--primary.el-transfer__button {
      display: flex;
      justify-content: center;
      align-items: center;
      background: #2a76cd;
      border-color: #2a76cd;
    }

    .el-button--primary.is-disabled {
      background-color: #a0cfff;
      border-color: #a0cfff;
    }
  }

  .el-checkbox__input.is-indeterminate {
    .el-checkbox__inner {
      background: #2a76cd;
      border-color: #2a76cd;
    }
  }

  .el-transfer-panel {
    width: 49%;
    border-radius: 0;
xiaomiao committed
314
  }
xiaomiao committed
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 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369

  .el-transfer-panel__body {
    .el-checkbox__label {
      &:hover {
        color: #2a76cd;
      }
    }
  }

  .el-transfer-panel__header {
    .el-checkbox {
      .el-checkbox__label {
        font-size: 14px;

        span {
          left: 100px;
        }
      }
    }
  }

  .el-transfer-panel__footer {
    top: 0;
    left: 61%;
    background-color: transparent;
    display: flex;
    width: 30%;
    justify-content: right;
    border-color: transparent;

    .el-button--text {
      color: #b5b5b5;
      margin-left: 5px;

      .icon-huidaodingbu {
        font-size: 16px;
      }

      em {
        font-size: 14px;
        font-weight: 600;
      }
    }
  }

  .el-transfer-panel:first-child {
    .el-transfer-panel__header {
      .el-checkbox {
        .el-checkbox__label {
          span {
            left: 84px;
          }
        }
      }
    }
xiaomiao committed
370 371
  }
}
xiaomiao committed
372 373 374 375 376 377 378 379 380

/deep/.el-transfer {
  .el-transfer-panel {
    width: 400px;
    height: 700px;
    .el-transfer-panel__list.is-filterable {
      height: 606px;
    }
  }
xiaomiao committed
381 382
}
</style>