123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427 |
- <!-- 个案情境创建时的可选条件 -->
- <template>
- <div class="conditionCard">
- <view class="title">请选择追踪条件(可多选)</view>
- <view class="container">
- <view class="card" v-for="(data,index) in list" :key="index">
- <view class="mark">{{`${index+1}/${list.length}`}}</view>
- <view class="cardInner" v-for="(item,key) in childContainer[index].list" :key="key">
- <view :class="[item.required == 1?'cardTitle required':'cardTitle']">{{item.name?item.name:''}}
- </view>
- <view :class="[item.child.length>2?'tabWrap multi':'tabWrap']">
- <view :class="[selectedIds.includes(val.id)?'tab on':'tab']" v-for="(val,a) in item.child"
- :key="a"
- @click="tabClickHandle(val,index,item.multiple,item.child,item)">
- <image v-if="selectedIds.includes(val.id)&&item.child.length>2"
- src="../../../static/activedGou_white.png" class="bottomMark" mode=""></image>
- {{val.name}}
- </view>
- </view>
- </view>
- </view>
- </view>
- </div>
- </template>
- <script>
- import {
- mapState
- } from "vuex";
- export default {
- computed: {
- ...mapState({
- needReload: state => state.creatingSituations.needReload,
- condition: state => state.creatingSituations.condition,
- theme: state => state.creatingSituations.theme,
- editConfig: state => state.creatingSituations.editConfig,
- conditionCard: state => state.creatingSituations.conditionCard
- })
- },
- data() {
- return {
- results: [], //选择结果列表
- requireds: [], //必填项
- list: [],
- childContainer: [],
- selectedIds: [],
- currentActTabGroupId: null,
- }
- },
- watch: {
- childContainer(prev, cur) {
- this.$store.commit({
- type: 'creatingSituations/comChangeState',
- key: 'condition',
- data: {
- ...this.condition,
- childContainer: prev
- }
- });
- },
- results(prev, cur) {
- this.$store.commit({
- type: 'creatingSituations/comChangeState',
- key: 'conditionCard',
- data: {
- ...this.conditionCard,
- checkResults: prev
- }
- });
- },
- },
- created: function() {
- // 编辑的时候不用获取数据
- if (this.editConfig && this.editConfig.theme.id === this.theme.id) {
- this.$store.commit({
- type: 'creatingSituations/comChangeState',
- key: 'condition',
- data: this.editConfig.condition
- });
- } else if (this.needReload) {
- if (this.theme.id != undefined || this.theme.id != null) {
- this.$store.commit({
- type: 'creatingSituations/comChangeState',
- key: 'condition',
- data: {
- ...this.condition,
- options: [],
- conditionIds: [],
- childContainer: []
- }
- });
- this.getData();
- }
- } else {
- this.list = this.condition.options;
- this.selectedIds = this.condition.conditionIds;
- this.childContainer = this.condition.childContainer;
- this.results = this.conditionCard.checkResults;
- }
- },
- methods: {
- sortFunc(arr) {
- return arr.map(item => {
- const arr = item.list;
- arr.sort((cur, next) => {
- return cur.id - next.id
- });
- return {
- ...item,
- list: arr
- }
- })
- },
- getData(depType) {
- const {
- id
- } = this.theme;
- this.$store.dispatch({
- type: 'creatingSituations/commActions',
- key: 'getTypeListsInGeanCreate',
- data: {
- depType: 0,
- type: id
- }
- }).then(data => {
- if (data) {
- this.list = data;
- this.childContainer = data.map((item, index) => {
- for (let i = 0; i < item.child.length; i++) {
- if (item.child[i].required == 1) {
- //必填
- this.requireds = [...this.requireds, item.child[i]]
- }
- }
- return {
- index: index,
- list: [item.child[0]]
- }
- });
- this.$store.commit({
- type: 'creatingSituations/comChangeState',
- key: 'condition',
- data: {
- ...this.condition,
- options: data
- }
- });
- this.$store.commit({
- type: 'creatingSituations/comChangeState',
- key: 'conditionCard',
- data: {
- ...this.conditionCard,
- requireds: this.requireds
- }
- });
- }
- })
- },
- tabClickHandle(item, index, isMulti, parts, parent) {
- // console.log({item, index, isMulti, parts,parent});
- // console.log({results:this.results});
-
- const needCancelActiedItems = parts.filter(a => a.id != item.id);
- const needCancelActiedIds = needCancelActiedItems.map(b => b.id);
- const needCancelActiedcardIds = needCancelActiedItems.map(i => i.subOptionId);
- if (isMulti == 1) {
- //isMulti == 1 单选
-
- const leftActivedIds = this.selectedIds.filter(c => !(needCancelActiedIds.includes(c))); //去除非选中项
- this.selectedIds = [...leftActivedIds, item.id];
- const parentSameIdIndex = this.results.findIndex(item => item.id == parent.id);
- if (parentSameIdIndex != -1) {
- //之前有选过,需要修改
- const _results = this.results.map(a => {
- if (a.id == parent.id) {
- return {
- ...a,
- value: item.name,
- }
- } else {
- return a
- }
- })
- this.results = [..._results];
- } else {
- this.results = [...this.results, {
- name: parent.name,
- value: item.name,
- id: parent.id
- }];
- }
- const filtedResults = this.results.filter(i => !(needCancelActiedcardIds.includes(i.id)));
- this.results = [...filtedResults];
- }
- if (isMulti == 2) {
- //isMulti == 2 多选
- const index = this.selectedIds.findIndex(a => a == item.id);
- if (index != -1) {
- //已选中
- this.selectedIds = this.selectedIds.filter(a => a != item.id);
- } else {
- this.selectedIds = [...this.selectedIds, item.id];
- }
- this.results = [...this.results, {
- name: parent.name,
- value: item.name,
- id: parent.id
- }];
- }
- if (item.subOptions) {
- //subOptionId 关联子选项id,subOptions是否有关联子级选项
-
-
- const childs = this.list[index].child.filter(d => d.id == item.subOptionId);
- const needDeleteChilds = parts.filter(e => e.id != item.id); //获取同层级需要取消高亮的tab
- const needDeleteChildIds = needDeleteChilds.map(f => f.id);
- const needCancelActivedTabs = needDeleteChilds.filter(f => f.subOptions);
- const filtedChildContainer = this.childContainer[index].list.filter(g => !(needDeleteChildIds.includes(
- g.id)));
-
-
- const positionIndex = childs.length>0?filtedChildContainer.findIndex(a => a.id == childs[0].id):-1;
- if (isMulti == 1) {
- //单选
- if (positionIndex == -1) {
- this.childContainer[index].list = [...childs, ...filtedChildContainer]
- }
- }
- if (isMulti == 2) {
- //多选
- if (positionIndex != -1) {
- const _list = this.childContainer[index].list;
- _list.splice(positionIndex, 1);
- this.childContainer[index].list = _list;
- } else {
- this.childContainer[index].list = [...childs, ...filtedChildContainer]
- }
- }
- } else {
- if (isMulti != 2) {
- //单选同一组中
- const needDeleteChilds = parts.filter(e => e.id != item.id); //获取同层级需要取消高亮的tab
- const needDeleteChildIds = needDeleteChilds.map(f => f.subOptionId);
- const filtedChildContainer = this.childContainer[index].list.filter(g => {
- if (needDeleteChildIds.includes(g.id)) {
- const ids = g.child.map(a => a.id);
- const selectedIds = this.selectedIds.filter(f => !(ids.includes(f)));
- this.selectedIds = selectedIds;
- }
- return !(needDeleteChildIds.includes(g.id))
- })
- this.childContainer[index].list = [...filtedChildContainer];
- }
- }
- this.currentActTabGroupId = item.parentId;
- this.$store.commit({
- type: 'creatingSituations/comChangeState',
- key: 'condition',
- data: {
- ...this.condition,
- conditionIds: this.selectedIds
- }
- });
- this.childContainer = this.sortFunc(this.childContainer);
-
- // console.log('this.childContainer',this.childContainer);
- // console.log('this.results',this.results);
- },
- }
- }
- </script>
- <style lang="less" scoped>
- .conditionCard {
- .container {
- padding: 25rpx;
- .card {
- position: relative;
- width: 100%;
- padding: 25rpx;
- background: #FFFFFF;
- border-radius: 15rpx;
- margin-bottom: 25rpx;
- .mark {
- display: flex;
- position: absolute;
- justify-content: center;
- align-items: center;
- top: 0;
- left: 0;
- font-size: 22.5rpx;
- font-family: SourceHanSansCN-Medium, SourceHanSansCN;
- font-weight: 500;
- color: #FFFFFF;
- width: 75rpx;
- height: 45rpx;
- background: linear-gradient(270deg, #66A6FF 0%, #4D88FF 100%);
- border-radius: 15rpx 0px 35rpx 0px;
- }
- .cardInner {
- margin-bottom: 25rpx;
- .cardTitle {
- text-align: center;
- font-size: 22.5rpx;
- font-family: SourceHanSansCN-Normal, SourceHanSansCN;
- font-weight: 400;
- color: #525866;
- margin-bottom: 25rpx;
- &.required {
- &::before {
- position: relative;
- content: '*';
- color: rgba(255, 51, 85, 1);
- left: -3rpx;
- }
- }
- }
- .tabWrap {
- display: flex;
- flex-direction: row;
- justify-content: space-between;
- .tab {
- width: 48.5%;
- text-align: center;
- font-size: 25rpx;
- margin-bottom: 25rpx;
- font-family: SourceHanSansCN-Normal, SourceHanSansCN;
- font-weight: 400;
- color: #525866;
- height: 62.5rpx;
- line-height: 60rpx;
- background: #F5F7FA;
- border-radius: 10rpx;
- &.on {
- color: #3377FF;
- background: #E6EEFF;
- }
- }
- &.multi {
- display: flex;
- flex-wrap: wrap;
- .tab {
- position: relative;
- width: 23%;
- .bottomMark {
- position: absolute;
- width: 25rpx;
- height: 25rpx;
- bottom: 0;
- right: 0;
- }
- }
- }
- }
- &:last-child {
- margin-bottom: 0;
- }
- }
- }
- }
- }
- </style>
|