conditionCard.vue 11 KB

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