conditionCard.vue 10 KB

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