condition.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <template>
  2. <div>
  3. <div v-for="(item, index) in condition" :key="index">
  4. <div v-if="index > 0"><el-divider>或满足以下条件</el-divider></div>
  5. <div class="type-item">
  6. <div class="conicon"
  7. style="width: 100%; text-align: right; position: relative; right: -15px; top: -5px; color: red"
  8. v-if="index > 0">
  9. <el-icon @click="delScene(index)">
  10. <CircleClose />
  11. </el-icon>
  12. </div>
  13. <div class="flex-warp item_list">
  14. <div v-for="(vo, i) in item" :key="i">
  15. <div class="items">
  16. <el-button
  17. style="background: #fff; color: #000;border: 1px solid #d9cde3;margin-left: 10px;margin-right: 10px;"
  18. v-if="i > 0">并且</el-button>
  19. <el-popover placement="bottom" trigger="click" ref="popoverRef" v-model:visible="vo.isPopoverVisible">
  20. <template #reference>
  21. <el-button style="background: #9adbff4d; color: #00a4fe;border: 1px solid #00a4fe4d;">{{
  22. vo.parameter_text ||
  23. '请选择参数' }}</el-button>
  24. </template>
  25. <div class="popover-content">
  26. <ul>
  27. <li v-for="(option, d) in columnList" :key="d" @click="setParameter(vo, option)" >
  28. {{ option.name }}
  29. </li>
  30. </ul>
  31. </div>
  32. </el-popover>
  33. <el-popover placement="bottom" trigger="click" v-model:visible="vo.isPopoverVisible1">
  34. <template #reference>
  35. <el-button style="background: #a3caff4d; color: #2f54eb;border: 1px solid #2f54eb4d;">{{
  36. vo.operator_text ||
  37. '操作符' }}</el-button>
  38. </template>
  39. <div class="popover-content">
  40. <ul>
  41. <li v-for="option in vo.operatorList" :key="option.Key"
  42. @click="vo.operator = option.Key; vo.operator_text = option.Name; vo.isPopoverVisible1 = false; saveData();">
  43. {{ option.Name }}</li>
  44. </ul>
  45. </div>
  46. </el-popover>
  47. <el-popover placement="bottom" trigger="click">
  48. <template #reference>
  49. <el-button style="background: #bc7dee1a; color: #692ca7;border: 1px solid #bc7dee80;">{{ vo.value ||
  50. '参数值' }}</el-button>
  51. </template>
  52. <div class="popover-content">
  53. <el-input v-model="vo.value" placeholder="请输入参数值" @input="saveData" />
  54. </div>
  55. </el-popover>
  56. <el-icon size="16" v-if="i>0" @click="DelSceneItem(i, index)" style="position: relative;top: -13px;">
  57. <CircleClose />
  58. </el-icon>
  59. </div>
  60. </div>
  61. <div style=" padding-top: 12px;" @click="addSceneItem(index)">
  62. <el-icon size="18" style=" font-size: 24px;">
  63. <CirclePlus size="18" />
  64. </el-icon>
  65. </div>
  66. </div>
  67. </div>
  68. </div>
  69. <div class="mt15"><el-button @click="addScene()">增加或条件</el-button></div>
  70. </div>
  71. </template>
  72. <script lang="ts" setup>
  73. import { PropType, ref } from 'vue'
  74. import { CirclePlus, CircleClose, Right } from '@element-plus/icons-vue';
  75. const emit = defineEmits(['EditPen']);
  76. interface IConditionItem {
  77. [x: string]: any;
  78. parameter?: string;
  79. operator?: string;
  80. value?: string;
  81. }
  82. interface Column {
  83. termTypes: any[];
  84. }
  85. const props = defineProps({
  86. condition: {
  87. type: Array as PropType<IConditionItem[]> | undefined,
  88. default: () => []
  89. },
  90. columnList: {
  91. type: Array as PropType<Column[]>,
  92. default: () => []
  93. },
  94. operate_index: {
  95. type: Number,
  96. default: () => 0
  97. }
  98. })
  99. const setParameter = (vo: IConditionItem, item: any) => {
  100. vo.parameter_text = item.name;
  101. vo.parameter = item.column;
  102. // operatorList.value=item.termTypes
  103. vo.operatorList = item.termTypes;
  104. vo.isPopoverVisible = false; // 关闭弹窗
  105. saveData();
  106. }
  107. const saveData = () => {
  108. emit('EditPen', props.operate_index);
  109. }
  110. const addSceneItem = (index: number) => {
  111. props.condition[index].push({
  112. 'parameter': '',
  113. 'operator': '',
  114. 'value': ''
  115. })
  116. saveData();
  117. }
  118. const DelSceneItem = (index: number, parentIndex: number) => {
  119. props.condition[parentIndex].splice(index, 1);
  120. saveData();
  121. }
  122. const addScene = () => {
  123. props.condition.push([{
  124. 'parameter': '',
  125. 'operator': '',
  126. 'value': ''
  127. }]);
  128. };
  129. const delScene = (index: number) => {
  130. props.condition.splice(index, 1);
  131. }
  132. const initItem = () => {
  133. props.condition.forEach((item) => {
  134. item.forEach((vo:any) => {
  135. let operator = vo.operator;
  136. let matchedColumn = props.columnList.find((column:any) =>
  137. column.termTypes.some((term:any) => term.Key === operator)
  138. );
  139. if (matchedColumn) {
  140. vo.operatorList = matchedColumn.termTypes;
  141. } else {
  142. vo.operatorList = []; // 如果没有匹配的列,设置为空数组
  143. }
  144. });
  145. });
  146. };
  147. initItem();
  148. </script>
  149. <style scoped lang="scss">
  150. .popover-content {
  151. padding: 0px;
  152. }
  153. .popover-content ul {
  154. list-style-type: none;
  155. padding: 0;
  156. }
  157. .popover-content li {
  158. cursor: pointer;
  159. padding: 5px;
  160. }
  161. .popover-content li:hover {
  162. background-color: #e6f7ff;
  163. }
  164. .type-item {
  165. margin-top: 15px;
  166. .conicon {
  167. width: 55px;
  168. height: 5px;
  169. font-size: 24px;
  170. line-height: 28px;
  171. cursor: pointer;
  172. }
  173. .item_list {
  174. // background: #fff;
  175. .items {
  176. padding: 10px;
  177. .el-select {
  178. width: 99px;
  179. }
  180. .el-select--default {
  181. --el-select-border-color-hover: var(--el-border-color-hover);
  182. --el-select-disabled-border: var(--el-disabled-border-color);
  183. --el-select-font-size: var(--el-font-size-base);
  184. --el-select-close-hover-color: var(--el-text-color-secondary);
  185. --el-select-input-color: var(--el-text-color-placeholder);
  186. --el-select-multiple-input-color: var(--el-text-color-regular);
  187. --el-select-input-focus-border-color: var(--el-color-primary);
  188. --el-select-input-font-size: 14px;
  189. }
  190. }
  191. }
  192. .title {
  193. height: 40px;
  194. .icon {
  195. margin-left: 2px;
  196. margin-right: 10px;
  197. width: 5px;
  198. height: 20px;
  199. background-color: #315efb;
  200. }
  201. }
  202. .product {
  203. .el-form-item {
  204. margin-left: 30px;
  205. margin-bottom: 10px;
  206. margin-top: 10px;
  207. }
  208. }
  209. }</style>