condition.vue 6.7 KB

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