配置产品
当前位置:   article > 正文

Element中Transfer 穿梭框的应用_el-transfer right-check-change

el-transfer right-check-change

1、应用背景

项目中会需要对产品进行选择添加,我们可以用Transfer 穿梭框来实现这一需求。

视图:

 

2、代码实现 

  1. <template>
  2. <div class="bigbox">
  3. <div class="topInfo">配置产品</div>
  4. <div class="scollbox" style="text-align: center">
  5. <el-transfer
  6. style="text-align: left; display: inline-block"
  7. :value="tempValue"
  8. filterable
  9. :left-default-checked="[2, 3]"
  10. :right-default-checked="[1]"
  11. :render-content="renderFunc"
  12. :titles="['未选产品', '已选产品']"
  13. :button-texts="['', '']"
  14. :format="{
  15. noChecked: '${total}',
  16. hasChecked: '${checked}/${total}'
  17. }"
  18. @change="handleChange"
  19. @right-check-change="rightcheckchange"
  20. :data="data"
  21. >
  22. </el-transfer>
  23. </div>
  24. <div class="product-edit-footer">
  25. <el-button @click="cancel()">取 消</el-button>
  26. <el-button type="primary" @click="saveProduct">确定</el-button>
  27. </div>
  28. </div>
  29. </template>
  30. <script>
  31. import {getconfigPlanList} from "../../../../api/http/product";
  32. export default {
  33. props:{
  34. "value" : Array
  35. },
  36. data() {
  37. return {
  38. data: [],
  39. // congfigArr:[],
  40. configInfomsg: "",
  41. isBtnAdded: false,
  42. page: 1,
  43. perPage: 100,
  44. value4: [1],
  45. tempValue:[],
  46. renderFunc(h, option) {
  47. return (
  48. <span>
  49. {option.label}
  50. </span>
  51. );
  52. },
  53. };
  54. },
  55. watch:{
  56. value:{
  57. handler(){
  58. this.tempValue = this.value.map(item => item.productCode) ;
  59. },
  60. immediate : true
  61. }
  62. },
  63. methods: {
  64. handleChange(value) {
  65. this.tempValue = value ;
  66. },
  67. // 请求列表数据
  68. async loadPlainList(condition) {
  69. try {
  70. this.loading = true;
  71. let res = await getconfigPlanList(condition);
  72. // console.log(res);
  73. this.configInfomsg = res.result.productLibraryList;
  74. // console.log('数据信息:',this.configInfomsg);
  75. this.configInfomsg.forEach((item) => {
  76. // console.log(item.productName);
  77. this.data.push({
  78. key: item.productCode,
  79. label: item.productName,
  80. // disabled:this.i===0
  81. });
  82. });
  83. if (res["code"] === 0) {
  84. // console.log('我是状态码0');
  85. } else {
  86. console.log("请求数据失败");
  87. // this.$message.error('获取产品列表信息失败')
  88. }
  89. } catch (error) {
  90. this.loading = false;
  91. // this.$monitor.error(error, MODULE_PRODUCT, '获取产品列表信息异常')
  92. }
  93. },
  94. // 取消按钮
  95. cancel() {
  96. this.tempValue = this.value.map(item => item.productCode) ;
  97. this.$emit("change", false);
  98. },
  99. // 保存按钮
  100. saveProduct() {
  101. let datas = this.configInfomsg.filter(item => this.tempValue.includes(item.productCode)).map(({productCode,productName}) => {
  102. return {productCode,productName} ;
  103. });
  104. this.$emit("input" , datas) ;
  105. this.$emit("change", false);
  106. },
  107. // 右侧选中数组
  108. rightcheckchange(){
  109. // console.log(888,arr,check);
  110. },
  111. },
  112. mounted() {
  113. this.loadPlainList({
  114. // "isProductPlan": 1,
  115. page: this.page,
  116. perPage: this.perPage,
  117. });
  118. },
  119. };
  120. </script>
  121. <style lang="scss">
  122. .topInfo {
  123. font-size: 20px;
  124. margin: 30px 0;
  125. }
  126. .bigbox {
  127. width: 700px;
  128. height: 500px;
  129. background-color: #fff;
  130. position: relative;
  131. top: 200px;
  132. left: 470px;
  133. overflow: hidden;
  134. }
  135. .selectplan {
  136. display: flex;
  137. justify-content: space-between;
  138. span {
  139. flex: 1;
  140. margin: 10px 0px;
  141. }
  142. }
  143. .inputInfo {
  144. position: relative;
  145. margin-bottom: 15px;
  146. margin: 25px 0px;
  147. .findInfo {
  148. // background-color: red;
  149. position: relative;
  150. left: -140px;
  151. }
  152. .rest {
  153. // background-color: red;
  154. position: relative;
  155. left: -130px;
  156. }
  157. }
  158. .el-transfer-panel__item .el-checkbox__input {
  159. position: absolute;
  160. top: 8px;
  161. left: 10px;
  162. }
  163. .transfer-footer {
  164. margin-left: 20px;
  165. padding: 6px 5px;
  166. }
  167. .el-transfer-panel {
  168. width: 225px;
  169. }
  170. .el-transfer-panel__filter .el-input__inner {
  171. width: 90%;
  172. }
  173. .el-transfer-panel__filter {
  174. margin: 13px 0;
  175. }
  176. .product-edit-footer {
  177. margin: 45px 0px;
  178. button {
  179. margin: 0px 20px;
  180. }
  181. }
  182. </style>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/223960
推荐阅读
相关标签