Transfer.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <template>
  2. <div>
  3. <slot name="header">
  4. <el-row type="flex">
  5. <el-col>
  6. <el-select v-model="value" class="select_height" placeholder="请选择">
  7. <el-option
  8. v-for="item in options"
  9. :key="item.value"
  10. :label="item.label"
  11. :value="item.value"
  12. >
  13. </el-option>
  14. </el-select>
  15. </el-col>
  16. <el-col><el-button>确定</el-button></el-col>
  17. </el-row>
  18. </slot>
  19. <div>
  20. <el-row type="flex" align="moddle" class="transfer">
  21. <el-col class="left_box" :span="9">
  22. <h4 class="transfer_title">可选经销商</h4>
  23. <el-checkbox-group
  24. v-model="leftData"
  25. class="left_box_flex"
  26. @change="handelLeftCheck"
  27. >
  28. <el-checkbox
  29. v-for="(item, index) in dataL"
  30. :key="index"
  31. :label="item"
  32. :disabled="rightDisabled"
  33. ></el-checkbox>
  34. </el-checkbox-group>
  35. </el-col>
  36. <el-col class="middle_box" :span="6">
  37. <el-row>
  38. <el-col>
  39. <el-button :disabled="isDisabled" @click="handleJudge('AddAll')"
  40. >全部添加</el-button
  41. ></el-col
  42. >
  43. <el-col>
  44. <el-button :disabled="isDisabled" @click="handleJudge('AddPart')"
  45. >增加</el-button
  46. ></el-col
  47. >
  48. <el-col>
  49. <el-button
  50. :disabled="isDisabled"
  51. @click="handleJudge('DeletePart')"
  52. >删除</el-button
  53. ></el-col
  54. >
  55. <el-col>
  56. <el-button
  57. :disabled="isDisabled"
  58. @click="handleJudge('DeleteAll')"
  59. >全部删除</el-button
  60. ></el-col
  61. >
  62. </el-row>
  63. </el-col>
  64. <el-col class="right_box" :span="9">
  65. <h4 class="transfer_title">已选经销商</h4>
  66. <el-checkbox-group v-model="rightData" class="right_box_flex">
  67. <el-checkbox
  68. v-for="(item, index) in dataR"
  69. :key="index"
  70. :label="item"
  71. :disabled="leftDisabled"
  72. ></el-checkbox>
  73. </el-checkbox-group>
  74. </el-col>
  75. </el-row>
  76. </div>
  77. <slot name="footer">
  78. <el-row>
  79. <el-button type="primary" size="default" @click="">保存</el-button>
  80. <el-button type="primary" size="default" @click="">提交审核</el-button>
  81. <el-button type="primary" size="default" @click="">重置</el-button>
  82. </el-row>
  83. </slot>
  84. </div>
  85. </template>
  86. <script>
  87. export default {
  88. data() {
  89. return {
  90. leftData: [],
  91. dataL: [1, 3, 2],
  92. dataR: [],
  93. rightData: [],
  94. options: [
  95. {
  96. value: "选项1",
  97. label: "黄金糕",
  98. },
  99. {
  100. value: "选项2",
  101. label: "双皮奶",
  102. },
  103. {
  104. value: "选项3",
  105. label: "蚵仔煎",
  106. },
  107. {
  108. value: "选项4",
  109. label: "龙须面",
  110. },
  111. {
  112. value: "选项5",
  113. label: "北京烤鸭",
  114. },
  115. ],
  116. value: "",
  117. };
  118. },
  119. computed: {
  120. /**
  121. * @return(bool) isDisabled
  122. * 禁用功能按钮
  123. */
  124. isDisabled() {
  125. return !(this.leftData.length || this.rightData.length);
  126. },
  127. /**
  128. * @return(bool) leftDisabled
  129. * 禁用左边框选择
  130. */
  131. leftDisabled() {
  132. return this.leftData.some((i) => i !== "");
  133. },
  134. /**
  135. * @return(bool) rightDisabled
  136. * 禁用右边框选择
  137. */
  138. rightDisabled() {
  139. return this.rightData.some((i) => i !== "");
  140. },
  141. },
  142. methods: {
  143. handelLeftCheck(direction) {},
  144. //添加全部数据
  145. handleAllData(direction) {
  146. if (direction === "left") {
  147. if (!this.dataL.length) return;
  148. this.dataR = [...this.dataR, ...this.dataL];
  149. this.dataL = [];
  150. this.leftData = [];
  151. } else {
  152. if (!this.dataR.length) return;
  153. this.dataL = [...this.dataL, ...this.dataR];
  154. this.dataR = [];
  155. this.rightData = [];
  156. }
  157. },
  158. //添加部分或单个数据
  159. handlePartData(direction) {
  160. if (direction === "left") {
  161. if (!this.dataL.length) return;
  162. this.dataR = [...this.dataR, ...this.leftData];
  163. this.dataL.forEach((k, d) => {
  164. this.leftData.forEach((e) => {
  165. if (e == k) {
  166. this.dataL.splice(d, 1);
  167. this.leftData = [];
  168. return;
  169. }
  170. });
  171. });
  172. } else {
  173. if (!this.dataL.length) return;
  174. this.dataL = [...this.dataL, ...this.rightData];
  175. this.dataR.forEach((k, d) => {
  176. this.rightData.forEach((e) => {
  177. if (e == k) {
  178. this.dataR.splice(d, 1);
  179. this.rightData = [];
  180. return;
  181. }
  182. });
  183. });
  184. }
  185. },
  186. //删除全部数据
  187. handleAllDelete(direction) {
  188. if (direction === "left") {
  189. if (!this.dataL.length) return;
  190. this.dataL = [];
  191. this.leftData = [];
  192. } else {
  193. if (!this.dataR.length) return;
  194. this.dataR = [];
  195. this.rightData = [];
  196. }
  197. },
  198. //删除部分或单个数据
  199. handlePartDelete(direction) {
  200. if (direction === "left") {
  201. this.dataL.forEach((k, d) => {
  202. this.leftData.forEach((e) => {
  203. if (e == k) {
  204. this.dataL.splice(d, 1);
  205. this.leftData = [];
  206. return;
  207. }
  208. });
  209. });
  210. } else {
  211. this.dataR.forEach((k, d) => {
  212. this.rightData.forEach((e) => {
  213. if (e == k) {
  214. this.dataR.splice(d, 1);
  215. this.rightData = [];
  216. return;
  217. }
  218. });
  219. });
  220. }
  221. },
  222. // 判断能操作那边框
  223. handleJudge(type) {
  224. if (this.leftDisabled) {
  225. // 左边框功能操作
  226. this.hanleType(type, "left");
  227. } else {
  228. // 右边框功能操作
  229. this.hanleType(type, "right");
  230. }
  231. },
  232. // 获取事件类型
  233. hanleType(type, direction) {
  234. switch (type) {
  235. case "AddAll":
  236. this.handleAllData(direction);
  237. break;
  238. case "AddPart":
  239. this.handlePartData(direction);
  240. break;
  241. case "DeleteAll":
  242. this.handleAllDelete(direction);
  243. break;
  244. case "DeletePart":
  245. this.handlePartDelete(direction);
  246. break;
  247. }
  248. },
  249. },
  250. };
  251. </script>
  252. <style lang="scss" scoped>
  253. // 穿梭框
  254. .transfer {
  255. margin: 20px 0;
  256. &_title {
  257. margin: 20px 20px 0 20px;
  258. }
  259. .left_box {
  260. width: 430px;
  261. height: 450px;
  262. border: 1px solid #eee;
  263. &_flex {
  264. display: flex;
  265. flex-direction: column;
  266. margin: 20px;
  267. .el-checkbox {
  268. padding: 10px 0;
  269. }
  270. }
  271. }
  272. .right_box {
  273. width: 430px;
  274. height: 450px;
  275. border: 1px solid #eee;
  276. &_flex {
  277. display: flex;
  278. flex-direction: column;
  279. margin: 20px;
  280. .el-checkbox {
  281. padding: 10px 0;
  282. }
  283. }
  284. }
  285. }
  286. .middle_box {
  287. text-align: center;
  288. height: 430px;
  289. display: flex;
  290. align-content: center;
  291. justify-content: center;
  292. align-items: center;
  293. }
  294. .el-row .el-col {
  295. margin: 20px 0;
  296. }
  297. .select_height {
  298. width: 100%;
  299. }
  300. </style>