conditionCard.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. <!-- 个案情境创建时的可选条件 -->
  2. <template>
  3. <div class="conditionCard">
  4. <view class="title">请选择追踪条件(可多选)</view>
  5. <view class="container">
  6. <view class="card" v-for="(data,index) in list" :key="index">
  7. <view class="mark">{{`${index+1}/${list.length}`}}</view>
  8. <view class="cardInner" v-for="(item,key) in childContainer[index].list" :key="key">
  9. <view :class="[item.required == 1?'cardTitle required':'cardTitle']">{{item.name?item.name:''}}
  10. </view>
  11. <view :class="[item.child.length>2?'tabWrap multi':'tabWrap']">
  12. <view :class="[selectedIds.includes(val.id)?'tab on':'tab']" v-for="(val,a) in item.child"
  13. :key="a"
  14. @click="tabClickHandle(val,index,item.multiple,item.child,item)">
  15. <image v-if="selectedIds.includes(val.id)&&item.child.length>2"
  16. src="../../../static/activedGou_white.png" class="bottomMark" mode=""></image>
  17. {{val.name}}
  18. </view>
  19. </view>
  20. </view>
  21. </view>
  22. </view>
  23. </div>
  24. </template>
  25. <script>
  26. import {
  27. mapState
  28. } from "vuex";
  29. export default {
  30. computed: {
  31. ...mapState({
  32. needReload: state => state.creatingSituations.needReload,
  33. condition: state => state.creatingSituations.condition,
  34. theme: state => state.creatingSituations.theme,
  35. editConfig: state => state.creatingSituations.editConfig,
  36. conditionCard: state => state.creatingSituations.conditionCard
  37. })
  38. },
  39. data() {
  40. return {
  41. results: [], //选择结果列表
  42. requireds: [], //必填项
  43. list: [],
  44. childContainer: [],
  45. selectedIds: [],
  46. currentActTabGroupId: null
  47. ,CheckConditionCard:[]
  48. }
  49. },
  50. watch: {
  51. childContainer(prev, cur) {
  52. this.$store.commit({
  53. type: 'creatingSituations/comChangeState',
  54. key: 'condition',
  55. data: {
  56. ...this.condition,
  57. childContainer: prev
  58. }
  59. });
  60. },
  61. results(prev, cur) {
  62. this.$store.commit({
  63. type: 'creatingSituations/comChangeState',
  64. key: 'conditionCard',
  65. data: {
  66. ...this.conditionCard,
  67. checkResults: prev
  68. }
  69. });
  70. },
  71. },
  72. created: function() {
  73. // 编辑的时候不用获取数据
  74. if (this.editConfig && this.editConfig.theme.id === this.theme.id) {
  75. this.$store.commit({
  76. type: 'creatingSituations/comChangeState',
  77. key: 'condition',
  78. data: this.editConfig.condition
  79. });
  80. } else if (this.needReload) {
  81. if (this.theme.id != undefined || this.theme.id != null) {
  82. this.$store.commit({
  83. type: 'creatingSituations/comChangeState',
  84. key: 'condition',
  85. data: {
  86. ...this.condition,
  87. options: [],
  88. conditionIds: [],
  89. childContainer: []
  90. ,CheckConditionCard:[] //add by yfb 20230515
  91. }
  92. });
  93. this.getData();
  94. }
  95. } else {
  96. this.list = this.condition.options;
  97. this.selectedIds = this.condition.conditionIds;
  98. this.childContainer = this.condition.childContainer;
  99. this.results = this.conditionCard.checkResults;
  100. this.CheckConditionCard=this.condition.CheckConditionCard;//add by yfb 20230515
  101. }
  102. },
  103. methods: {
  104. sortFunc(arr) {
  105. return arr.map(item => {
  106. const arr = item.list;
  107. arr.sort((cur, next) => {
  108. return cur.id - next.id
  109. });
  110. return {
  111. ...item,
  112. list: arr
  113. }
  114. })
  115. },
  116. getData(depType) {
  117. const {
  118. id
  119. } = this.theme;
  120. this.$store.dispatch({
  121. type: 'creatingSituations/commActions',
  122. key: 'getTypeListsInGeanCreate',
  123. data: {
  124. depType: 0,
  125. type: id
  126. }
  127. }).then(data => {
  128. if (data) {
  129. this.list = data;
  130. this.childContainer = data.map((item, index) => {
  131. for (let i = 0; i < item.child.length; i++) {
  132. if (item.child[i].required == 1) {
  133. //必填
  134. this.requireds = [...this.requireds, item.child[i]]
  135. }
  136. }
  137. return {
  138. index: index,
  139. list: [item.child[0]]
  140. }
  141. });
  142. this.$store.commit({
  143. type: 'creatingSituations/comChangeState',
  144. key: 'condition',
  145. data: {
  146. ...this.condition,
  147. options: data
  148. }
  149. });
  150. this.$store.commit({
  151. type: 'creatingSituations/comChangeState',
  152. key: 'conditionCard',
  153. data: {
  154. ...this.conditionCard,
  155. requireds: this.requireds
  156. }
  157. });
  158. }
  159. })
  160. },
  161. tabClickHandle(item, index, isMulti, parts, parent) {
  162. // console.log({item, index, isMulti, parts,parent});
  163. // console.log({results:this.results});
  164. const needCancelActiedItems = parts.filter(a => a.id != item.id);
  165. const needCancelActiedIds = needCancelActiedItems.map(b => b.id);
  166. const needCancelActiedcardIds = needCancelActiedItems.map(i => i.subOptionId);
  167. //筛选选项所属卡片信息,即点击选项保存当前卡片信息 add by yfb 20230515
  168. const ActionParents=this.CheckConditionCard.filter(item=>(item!=parent)&&(item.id!=needCancelActiedItems[0].subOptionId));
  169. this.CheckConditionCard=[...ActionParents,parent];
  170. /////////////////////
  171. if (isMulti == 1) {
  172. //isMulti == 1 单选
  173. const leftActivedIds = this.selectedIds.filter(c => !(needCancelActiedIds.includes(c))); //去除非选中项
  174. this.selectedIds = [...leftActivedIds, item.id];
  175. const parentSameIdIndex = this.results.findIndex(item => item.id == parent.id);
  176. if (parentSameIdIndex != -1) {
  177. //之前有选过,需要修改
  178. const _results = this.results.map(a => {
  179. if (a.id == parent.id) {
  180. return {
  181. ...a,
  182. value: item.name,
  183. }
  184. } else {
  185. return a
  186. }
  187. })
  188. this.results = [..._results];
  189. } else {
  190. this.results = [...this.results, {
  191. name: parent.name,
  192. value: item.name,
  193. id: parent.id
  194. }];
  195. }
  196. const filtedResults = this.results.filter(i => !(needCancelActiedcardIds.includes(i.id)));
  197. this.results = [...filtedResults];
  198. }
  199. if (isMulti == 2) {
  200. //isMulti == 2 多选
  201. const index = this.selectedIds.findIndex(a => a == item.id);
  202. // console.log('index',index);
  203. if (index != -1) {
  204. //已选中
  205. this.selectedIds = this.selectedIds.filter(a => a != item.id);
  206. this.CheckConditionCard=this.CheckConditionCard.filter(a=>a.id!=item.subOptionId);// 多选项判断是否有子项内容 add by yfb 20230515
  207. } else {
  208. this.selectedIds = [...this.selectedIds, item.id];
  209. }
  210. this.results = [...this.results, {
  211. name: parent.name,
  212. value: item.name,
  213. id: parent.id
  214. }];
  215. }
  216. if (item.subOptions) {
  217. //subOptionId 关联子选项id,subOptions是否有关联子级选项
  218. const childs = this.list[index].child.filter(d => d.id == item.subOptionId);
  219. const needDeleteChilds = parts.filter(e => e.id != item.id); //获取同层级需要取消高亮的tab
  220. const needDeleteChildIds = needDeleteChilds.map(f => f.id);
  221. const needCancelActivedTabs = needDeleteChilds.filter(f => f.subOptions);
  222. const filtedChildContainer = this.childContainer[index].list.filter(g => !(needDeleteChildIds.includes(
  223. g.id)));
  224. this.CheckConditionCard=[...this.CheckConditionCard,childs[0]];//选完带子项时,加载子项卡片信息 add by yfb 20230515
  225. // console.log('CheckConditionCard',this.CheckConditionCard);
  226. const positionIndex = childs.length>0?filtedChildContainer.findIndex(a => a.id == childs[0].id):-1;
  227. if (isMulti == 1) {
  228. //单选
  229. if (positionIndex == -1) {
  230. this.childContainer[index].list = [...childs, ...filtedChildContainer]
  231. }
  232. }
  233. if (isMulti == 2) {
  234. //多选
  235. if (positionIndex != -1) {
  236. const _list = this.childContainer[index].list;
  237. _list.splice(positionIndex, 1);
  238. this.childContainer[index].list = _list;
  239. } else {
  240. this.childContainer[index].list = [...childs, ...filtedChildContainer]
  241. }
  242. }
  243. } else {
  244. if (isMulti != 2) {
  245. //单选同一组中
  246. const needDeleteChilds = parts.filter(e => e.id != item.id); //获取同层级需要取消高亮的tab
  247. const needDeleteChildIds = needDeleteChilds.map(f => f.subOptionId);
  248. const filtedChildContainer = this.childContainer[index].list.filter(g => {
  249. if (needDeleteChildIds.includes(g.id)) {
  250. const ids = g.child.map(a => a.id);
  251. const selectedIds = this.selectedIds.filter(f => !(ids.includes(f)));
  252. this.selectedIds = selectedIds;
  253. }
  254. return !(needDeleteChildIds.includes(g.id))
  255. })
  256. this.childContainer[index].list = [...filtedChildContainer];
  257. }
  258. }
  259. this.currentActTabGroupId = item.parentId;
  260. this.$store.commit({
  261. type: 'creatingSituations/comChangeState',
  262. key: 'condition',
  263. data: {
  264. ...this.condition,
  265. conditionIds: this.selectedIds,
  266. CheckConditionCard:this.CheckConditionCard //保存选择数据 add by yfb 20230515
  267. }
  268. });
  269. // console.log('data_CheckConditionCard',this.condition.CheckConditionCard);
  270. this.childContainer = this.sortFunc(this.childContainer);
  271. //console.log('this.childContainer',this.childContainer);
  272. // console.log('this.results',this.results);
  273. },
  274. }
  275. }
  276. </script>
  277. <style lang="less" scoped>
  278. .conditionCard {
  279. .container {
  280. padding: 25rpx;
  281. .card {
  282. position: relative;
  283. width: 100%;
  284. padding: 25rpx;
  285. background: #FFFFFF;
  286. border-radius: 15rpx;
  287. margin-bottom: 25rpx;
  288. .mark {
  289. display: flex;
  290. position: absolute;
  291. justify-content: center;
  292. align-items: center;
  293. top: 0;
  294. left: 0;
  295. font-size: 22.5rpx;
  296. font-family: SourceHanSansCN-Medium, SourceHanSansCN;
  297. font-weight: 500;
  298. color: #FFFFFF;
  299. width: 75rpx;
  300. height: 45rpx;
  301. background: linear-gradient(270deg, #66A6FF 0%, #4D88FF 100%);
  302. border-radius: 15rpx 0px 35rpx 0px;
  303. }
  304. .cardInner {
  305. margin-bottom: 25rpx;
  306. .cardTitle {
  307. text-align: center;
  308. font-size: 22.5rpx;
  309. font-family: SourceHanSansCN-Normal, SourceHanSansCN;
  310. font-weight: 400;
  311. color: #525866;
  312. margin-bottom: 25rpx;
  313. &.required {
  314. &::before {
  315. position: relative;
  316. content: '*';
  317. color: rgba(255, 51, 85, 1);
  318. left: -3rpx;
  319. }
  320. }
  321. }
  322. .tabWrap {
  323. display: flex;
  324. flex-direction: row;
  325. justify-content: space-between;
  326. .tab {
  327. width: 48.5%;
  328. text-align: center;
  329. font-size: 25rpx;
  330. margin-bottom: 25rpx;
  331. font-family: SourceHanSansCN-Normal, SourceHanSansCN;
  332. font-weight: 400;
  333. color: #525866;
  334. height: 62.5rpx;
  335. line-height: 60rpx;
  336. background: #F5F7FA;
  337. border-radius: 10rpx;
  338. &.on {
  339. color: #3377FF;
  340. background: #E6EEFF;
  341. }
  342. }
  343. &.multi {
  344. display: flex;
  345. flex-wrap: wrap;
  346. .tab {
  347. position: relative;
  348. width: 23%;
  349. .bottomMark {
  350. position: absolute;
  351. width: 25rpx;
  352. height: 25rpx;
  353. bottom: 0;
  354. right: 0;
  355. }
  356. }
  357. }
  358. }
  359. &:last-child {
  360. margin-bottom: 0;
  361. }
  362. }
  363. }
  364. }
  365. }
  366. </style>