index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <script>
  2. import { getOperators } from './operators';
  3. import { Columns } from '../colums';
  4. import { getDicts as getDicts } from '@/api/system/dict/data'
  5. export default {
  6. name:'Sizer',
  7. props:{
  8. value:{
  9. type:[Array],
  10. require:true,
  11. },
  12. candidate:{
  13. type:[Array],
  14. require:true,
  15. },
  16. },
  17. components:{
  18. ElDraggable: () => import("@/components/draggable/index.vue"),
  19. ElFileUpload: () => import("@/components/FileUpload/index.vue"),
  20. ElPopoverSelectV2: () => import("@/components/popover-select-v2/index.vue"),
  21. ElPopoverMultipleSelectV2: () =>
  22. import("@/components/popover-select-v2/multiple.vue"),
  23. ElPopoverTreeSelect: () =>
  24. import("@/components/popover-tree-select/index.vue"),
  25. ElPopoverMultipleTreeSelect: () =>
  26. import("@/components/popover-tree-select/multiple.vue"),
  27. ElDateWrapper: () => import("@/components/date-wrapper/index.vue"),
  28. },
  29. computed:{
  30. innerValue:{
  31. get(){
  32. return this.$props.value;
  33. },
  34. set(value){
  35. this.$emit("input",value);
  36. },
  37. }
  38. },
  39. data(){
  40. return {
  41. showColumns:Columns,
  42. }
  43. },
  44. methods:{
  45. // 增
  46. onRowAdd(){
  47. this.innerValue.push({
  48. ...this.$init.params([...this.showColumns]),
  49. attr: {
  50. is: 'el-input'
  51. }
  52. });
  53. },
  54. // 删
  55. onRowRemove(prop){
  56. console.log(prop,'prop');
  57. const { $index, row } = prop;
  58. this.innerValue.splice($index,1)
  59. },
  60. // 条件选择
  61. canidateChange(prop){
  62. let {$index, row} = prop;
  63. let selectValue = this.candidate.filter(({item}) => item.key === row.candidate)[0];
  64. let operators = selectValue ? getOperators(this.judgeOperatorType(selectValue.attr)) : [];
  65. let attr = selectValue.attr ? selectValue.attr : { is: 'el-input'};
  66. console.log(attr.is,'attr');
  67. // 方案存储
  68. this.innerValue = this.innerValue.map((tableItem,index) =>{
  69. if(row.candidate === tableItem.candidate && $index === index){
  70. tableItem.options = '';
  71. tableItem.value = '';
  72. tableItem.operators = operators;
  73. tableItem.attr = attr
  74. }
  75. return tableItem
  76. })
  77. // 值框的选择
  78. // this.showColumns = this.showColumns
  79. },
  80. // 操作选择
  81. optionChange(prop){
  82. console.log(prop,'prop');
  83. // this.$emit("update:value",this.innerValue);
  84. },
  85. judgeOperatorType(type){
  86. switch (type.is) {
  87. case 'el-popover-multiple-select-v2':
  88. return 'array';
  89. case 'el-popover-multiple-tree-select':
  90. return 'array';
  91. case 'el-input-number':
  92. return 'number';
  93. case 'el-date-picker':
  94. return 'datetime';
  95. case 'el-select':
  96. let dictName = type.dictName;
  97. if(dictName === 'sys_number_yes_no'
  98. || dictName === 'sys_yes_no'
  99. || dictName === 'sys_true_false' ){
  100. return 'boolean';
  101. }
  102. return 'string';
  103. default:
  104. return 'string';
  105. }
  106. },
  107. },
  108. created(){
  109. }
  110. }
  111. </script>
  112. <template>
  113. <el-main>
  114. <el-table
  115. :data="innerValue"
  116. style="width: 100%"
  117. :show-header="false"
  118. :height="320"
  119. empty-text=" "
  120. v-bind="$attrs"
  121. v-on="$listeners"
  122. >
  123. <el-table-column
  124. v-for="({item,attr},index) in showColumns"
  125. :key="item.key + index"
  126. :prop="item.key"
  127. :label="item.title"
  128. :fixed="item.fixed"
  129. :width="item.width || 200"
  130. show-overflow-tooltip
  131. >
  132. <template slot-scope="scope">
  133. <el-select
  134. v-if="item.key === 'candidate'"
  135. v-model="scope.row[item.key]"
  136. :size="$attrs.size"
  137. filterable
  138. placeholder="请选择"
  139. @change="canidateChange(scope)"
  140. >
  141. <el-option
  142. v-for="(c, index) in candidate"
  143. :key="index + c.item.key"
  144. :label="c.item.title"
  145. :value="c.item.key"
  146. ></el-option>
  147. </el-select>
  148. <el-select
  149. v-if="item.key === 'options'"
  150. v-model="scope.row[item.key]"
  151. :size="$attrs.size"
  152. placeholder="请选择"
  153. @change="optionChange"
  154. >
  155. <el-option
  156. v-for="op in scope.row['operators']"
  157. :key="op.value"
  158. :label="op.label"
  159. :value="op.value">
  160. </el-option>
  161. </el-select>
  162. <template v-if="item.key === 'value'">
  163. <component
  164. v-if="scope.row.attr.is === 'el-select'"
  165. v-bind="scope.row.attr"
  166. :size="$attrs.size"
  167. v-model="scope.row[item.key]"
  168. >
  169. <template>
  170. <el-option
  171. v-for="item in dict.type[attr.dictName]"
  172. :key="item.value"
  173. :label="item.label"
  174. :value="item.value"
  175. >
  176. </el-option>
  177. </template>
  178. </component>
  179. <component
  180. v-else-if="scope.row.attr.is === 'el-popover-select-v2'"
  181. v-bind="scope.row.attr"
  182. v-model="scope.row[item.key]"
  183. :title="item.title"
  184. :size="$attrs.size"
  185. :source.sync="scope.row"
  186. style="width: 100%"
  187. >
  188. </component>
  189. <component
  190. v-else
  191. v-bind="scope.row.attr"
  192. :size="$attrs.size"
  193. v-model="scope.row[item.key]"
  194. style="width: 100%"
  195. >
  196. </component>
  197. </template>
  198. </template>
  199. </el-table-column>
  200. <el-table-column label="操作" width="50">
  201. <template slot-scope="scope">
  202. <i class="el-icon-delete"
  203. @click.prevent="onRowRemove(scope)"
  204. style="cursor: pointer;"
  205. ></i>
  206. </template>
  207. </el-table-column>
  208. </el-table>
  209. <el-row>
  210. <el-col style="padding-left: 10px;">
  211. <el-button
  212. type="text"
  213. @click.native.prevent="onRowAdd"
  214. >
  215. <i class="el-icon-plus"></i>
  216. 新增筛选条件
  217. </el-button>
  218. </el-col>
  219. </el-row>
  220. </el-main>
  221. </template>
  222. <style lang="scss" scoped>
  223. ::v-deep.el-table::before{
  224. display: none;
  225. }
  226. ::v-deep.el-table {
  227. th,td,th.is-leaf{
  228. border:none;
  229. }
  230. .el-table__cell{
  231. padding: 2px 0;
  232. }
  233. }
  234. </style>