123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303 |
- <template>
- <div>
- <slot name="header">
- <el-row type="flex">
- <el-col>
- <el-select v-model="value" class="select_height" placeholder="请选择">
- <el-option
- v-for="item in options"
- :key="item.value"
- :label="item.label"
- :value="item.value"
- >
- </el-option>
- </el-select>
- </el-col>
- <el-col><el-button>确定</el-button></el-col>
- </el-row>
- </slot>
- <div>
- <el-row type="flex" align="moddle" class="transfer">
- <el-col class="left_box" :span="9">
- <h4 class="transfer_title">可选经销商</h4>
- <el-checkbox-group
- v-model="leftData"
- class="left_box_flex"
- @change="handelLeftCheck"
- >
- <el-checkbox
- v-for="(item, index) in dataL"
- :key="index"
- :label="item"
- :disabled="rightDisabled"
- ></el-checkbox>
- </el-checkbox-group>
- </el-col>
- <el-col class="middle_box" :span="6">
- <el-row>
- <el-col>
- <el-button :disabled="isDisabled" @click="handleJudge('AddAll')"
- >全部添加</el-button
- ></el-col
- >
- <el-col>
- <el-button :disabled="isDisabled" @click="handleJudge('AddPart')"
- >增加</el-button
- ></el-col
- >
- <el-col>
- <el-button
- :disabled="isDisabled"
- @click="handleJudge('DeletePart')"
- >删除</el-button
- ></el-col
- >
- <el-col>
- <el-button
- :disabled="isDisabled"
- @click="handleJudge('DeleteAll')"
- >全部删除</el-button
- ></el-col
- >
- </el-row>
- </el-col>
- <el-col class="right_box" :span="9">
- <h4 class="transfer_title">已选经销商</h4>
- <el-checkbox-group v-model="rightData" class="right_box_flex">
- <el-checkbox
- v-for="(item, index) in dataR"
- :key="index"
- :label="item"
- :disabled="leftDisabled"
- ></el-checkbox>
- </el-checkbox-group>
- </el-col>
- </el-row>
- </div>
- <slot name="footer">
- <el-row>
- <el-button type="primary" size="default" @click="">保存</el-button>
- <el-button type="primary" size="default" @click="">提交审核</el-button>
- <el-button type="primary" size="default" @click="">重置</el-button>
- </el-row>
- </slot>
- </div>
- </template>
- <script>
- export default {
- data() {
- return {
- leftData: [],
- dataL: [1, 3, 2],
- dataR: [],
- rightData: [],
- options: [
- {
- value: "选项1",
- label: "黄金糕",
- },
- {
- value: "选项2",
- label: "双皮奶",
- },
- {
- value: "选项3",
- label: "蚵仔煎",
- },
- {
- value: "选项4",
- label: "龙须面",
- },
- {
- value: "选项5",
- label: "北京烤鸭",
- },
- ],
- value: "",
- };
- },
- computed: {
- /**
- * @return(bool) isDisabled
- * 禁用功能按钮
- */
- isDisabled() {
- return !(this.leftData.length || this.rightData.length);
- },
- /**
- * @return(bool) leftDisabled
- * 禁用左边框选择
- */
- leftDisabled() {
- return this.leftData.some((i) => i !== "");
- },
- /**
- * @return(bool) rightDisabled
- * 禁用右边框选择
- */
- rightDisabled() {
- return this.rightData.some((i) => i !== "");
- },
- },
- methods: {
- handelLeftCheck(direction) {},
- //添加全部数据
- handleAllData(direction) {
- if (direction === "left") {
- if (!this.dataL.length) return;
- this.dataR = [...this.dataR, ...this.dataL];
- this.dataL = [];
- this.leftData = [];
- } else {
- if (!this.dataR.length) return;
- this.dataL = [...this.dataL, ...this.dataR];
- this.dataR = [];
- this.rightData = [];
- }
- },
- //添加部分或单个数据
- handlePartData(direction) {
- if (direction === "left") {
- if (!this.dataL.length) return;
- this.dataR = [...this.dataR, ...this.leftData];
- this.dataL.forEach((k, d) => {
- this.leftData.forEach((e) => {
- if (e == k) {
- this.dataL.splice(d, 1);
- this.leftData = [];
- return;
- }
- });
- });
- } else {
- if (!this.dataL.length) return;
- this.dataL = [...this.dataL, ...this.rightData];
- this.dataR.forEach((k, d) => {
- this.rightData.forEach((e) => {
- if (e == k) {
- this.dataR.splice(d, 1);
- this.rightData = [];
- return;
- }
- });
- });
- }
- },
- //删除全部数据
- handleAllDelete(direction) {
- if (direction === "left") {
- if (!this.dataL.length) return;
- this.dataL = [];
- this.leftData = [];
- } else {
- if (!this.dataR.length) return;
- this.dataR = [];
- this.rightData = [];
- }
- },
- //删除部分或单个数据
- handlePartDelete(direction) {
- if (direction === "left") {
- this.dataL.forEach((k, d) => {
- this.leftData.forEach((e) => {
- if (e == k) {
- this.dataL.splice(d, 1);
- this.leftData = [];
- return;
- }
- });
- });
- } else {
- this.dataR.forEach((k, d) => {
- this.rightData.forEach((e) => {
- if (e == k) {
- this.dataR.splice(d, 1);
- this.rightData = [];
- return;
- }
- });
- });
- }
- },
- // 判断能操作那边框
- handleJudge(type) {
- if (this.leftDisabled) {
- // 左边框功能操作
- this.hanleType(type, "left");
- } else {
- // 右边框功能操作
- this.hanleType(type, "right");
- }
- },
- // 获取事件类型
- hanleType(type, direction) {
- switch (type) {
- case "AddAll":
- this.handleAllData(direction);
- break;
- case "AddPart":
- this.handlePartData(direction);
- break;
- case "DeleteAll":
- this.handleAllDelete(direction);
- break;
- case "DeletePart":
- this.handlePartDelete(direction);
- break;
- }
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- // 穿梭框
- .transfer {
- margin: 20px 0;
- &_title {
- margin: 20px 20px 0 20px;
- }
- .left_box {
- width: 430px;
- height: 450px;
- border: 1px solid #eee;
- &_flex {
- display: flex;
- flex-direction: column;
- margin: 20px;
- .el-checkbox {
- padding: 10px 0;
- }
- }
- }
- .right_box {
- width: 430px;
- height: 450px;
- border: 1px solid #eee;
- &_flex {
- display: flex;
- flex-direction: column;
- margin: 20px;
- .el-checkbox {
- padding: 10px 0;
- }
- }
- }
- }
- .middle_box {
- text-align: center;
- height: 430px;
- display: flex;
- align-content: center;
- justify-content: center;
- align-items: center;
- }
- .el-row .el-col {
- margin: 20px 0;
- }
- .select_height {
- width: 100%;
- }
- </style>
|