conditionCard.vue 11 KB

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