123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396 |
- <template>
- <div class="direction-exclusion">
- <a-input-search
- v-model:value="search"
- :placeholder="
- type === 'crowd' ? '请输入人群包名称或ID' : '请输入媒体包名称或ID'
- "
- style="width: 200px"
- @input="onSearch"
- />
- <br />
- <div class="common-box list-box">
- <div class="title-box">
- <!-- 人群定向 -->
- <h3 style="width: 120px" v-if="type === 'crowd'">人群包</h3>
- <h3 style="width: 184px" v-else>定向包</h3>
- <h3 style="width: 100px" v-if="type === 'crowd'">创建时间</h3>
- <h3 :style="type === 'crowd' ? 'width: 70px' : 'width: 90px'">操作</h3>
- </div>
- <div class="list">
- <a-empty v-show="list.length == 0"></a-empty>
- <!-- 人群定向循环列表 -->
- <p v-for="item in list" :key="item.id">
- <span
- v-if="type === 'crowd'"
- :title="item.name"
- style="width: 110px"
- class="item-name"
- >{{ item.name }}</span
- >
- <span
- v-else
- :title="item.name"
- style="width: 180px"
- class="item-name"
- >{{ item.name }}</span
- >
- <span
- style="width: 100px; margin: 0 20px 0 10px"
- v-if="type === 'crowd'"
- >{{ item.time }}</span
- >
- <span :style="'width:' + type === 'crowd' ? '70px' : '90px'">
- <a-button
- style="padding: 4px"
- type="link"
- @click="addDirection(item)"
- :disabled="directionList.idList.includes(item.id)"
- >定向</a-button
- >
- <a-button
- style="padding: 0"
- type="link"
- @click="addExclusion(item)"
- :disabled="exclusionList.idList.includes(item.id)"
- >排除</a-button
- >
- </span>
- </p>
- </div>
- </div>
- <div class="common-box selected-box">
- <div class="title-box">
- <span
- style="
- display: block;
- font-weight: bold;
- line-height: 30px;
- float: left;
- font-size: 13px;
- "
- >已选</span
- >
- <h3 class="clear-all" @click="clearAll">全部清空</h3>
- </div>
- <div class="tabs">
- <span
- :class="selectedKey === 'direction' ? 'tabs-active' : ''"
- @click="selectedKey = 'direction'"
- >定向({{ directionList.itemList.length }})</span
- >
- <span
- :class="selectedKey === 'exclusion' ? 'tabs-active' : ''"
- @click="selectedKey = 'exclusion'"
- >排除({{ exclusionList.itemList.length }})</span
- >
- </div>
- <div class="selected-item">
- <div v-show="selectedKey === 'direction'">
- <p v-for="item in directionList.itemList" :key="item.id">
- <span>{{ item.name }}</span>
- <i
- class="iconfont icon-guanbi"
- @click="deleteDirectionItem(item.id)"
- ></i>
- </p>
- </div>
- <div v-show="selectedKey === 'exclusion'">
- <p v-for="item in exclusionList.itemList" :key="item.id">
- <span>{{ item.name }}</span>
- <i
- class="iconfont icon-guanbi"
- @click="deleteExclusionItem(item.id)"
- ></i>
- </p>
- </div>
- </div>
- </div>
- </div>
- </template>
- <script lang="ts">
- import { defineComponent, reactive, toRefs, ref } from "vue";
- import { getMediaPackage } from "@/api";
- import { message } from "ant-design-vue";
- // 1691995913023502
- const DirectionExclusion = defineComponent({
- props: ["compType"],
- setup() {
- const state = reactive({
- search: "", // 过滤
- selectedKey: "direction",
- type: "crowd", // 人群组件/媒体组件
- list: ref<any[]>([]),
- originList: [
- {
- name: "测试人群包A测试人群包A测试人群包A",
- time: "2020-01-10",
- id: 1,
- },
- {
- name: "测试人群包B",
- time: "2020-01-10",
- id: 2,
- },
- {
- name: "测试人群包B",
- time: "2020-01-10",
- id: 3,
- },
- {
- name: "测试人群包B",
- time: "2020-01-10",
- id: 4,
- },
- {
- name: "测试人群包B",
- time: "2020-01-10",
- id: 5,
- },
- {
- name: "测试人群包B",
- time: "2020-01-10",
- id: 6,
- },
- {
- name: "测试人群包B",
- time: "2020-01-10",
- id: 7,
- },
- {
- name: "测试人群包B",
- time: "2020-01-10",
- id: 8,
- },
- ],
- directionList: {
- itemList: ref<any[]>([]), // 渲染数组
- idList: ref<any[]>([]), // 传参数组
- },
- exclusionList: {
- itemList: ref<any[]>([]), // 渲染数组
- idList: ref<any[]>([]), // 传参数组
- },
- });
- return { ...toRefs(state) };
- },
- mounted() {
- this.type = this.$props.compType === "media" ? "media" : "crowd";
- this.list = JSON.parse(JSON.stringify(this.originList));
- this.getList();
- },
- methods: {
- async getList() {
- this.list = [];
- let { data } = await getMediaPackage({
- advertiser_id: this.$route.query.advertiser_id,
- page: 1,
- page_size: 99,
- });
- console.log("定向包数据", data);
- if (data.list.length > 0) {
- data.list.forEach((item: any) => {
- this.list.push({ name: item.name, id: item.flow_package_id });
- });
- }
- },
- // 添加定向
- addDirection(val: any) {
- this.directionList.itemList.push(val);
- this.directionList.idList.push(val.id);
- if (this.exclusionList.idList.includes(val.id)) {
- this.deleteExclusionItem(val.id);
- }
- this.selectedKey = "direction";
- },
- // 添加排除
- addExclusion(val: any) {
- this.exclusionList.itemList.push(val);
- this.exclusionList.idList.push(val.id);
- if (this.directionList.idList.includes(val.id)) {
- this.deleteDirectionItem(val.id);
- }
- this.selectedKey = "exclusion";
- },
- // 全部删除
- clearAll() {
- this.directionList.itemList = [];
- this.directionList.idList = [];
- this.exclusionList.itemList = [];
- this.exclusionList.idList = [];
- },
- // 根据id删除定向项
- deleteDirectionItem(id: any) {
- this.directionList.idList.splice(
- this.directionList.idList.indexOf(id),
- 1
- );
- this.directionList.itemList.forEach((item: any) => {
- if (item.id === id) {
- this.directionList.itemList.splice(
- this.directionList.itemList.indexOf(item),
- 1
- );
- }
- });
- },
- // 根据id删除排除项
- deleteExclusionItem(id: any) {
- this.exclusionList.idList.splice(
- this.exclusionList.idList.indexOf(id),
- 1
- );
- this.exclusionList.itemList.forEach((item: any) => {
- if (item.id === id) {
- this.exclusionList.itemList.splice(
- this.exclusionList.itemList.indexOf(item),
- 1
- );
- }
- });
- },
- // 返回过滤结果
- onSearch() {
- this.list = this.originList.filter((item: any) => {
- return (
- item.name.indexOf(this.search) > -1 ||
- item.id.indexOf(this.search) > -1
- );
- });
- },
- // 获取父组件数据回显
- showData(directionArr: any, exclusionArr: any) {
- if (directionArr.length > 0) {
- this.list.forEach((item) => {
- if (directionArr.includes(item.value)) {
- this.directionList.idList.push(item.value);
- this.directionList.itemList.push(item);
- }
- });
- }
- if (exclusionArr.length > 0) {
- this.list.forEach((item) => {
- if (exclusionArr.includes(item.value)) {
- this.exclusionList.idList.push(item.value);
- this.exclusionList.itemList.push(item);
- }
- });
- }
- },
- // 返回给父组件数据
- backData() {
- console.log(this.directionList);
- let data = {
- direction: this.directionList.idList,
- exclusion: this.exclusionList.idList,
- };
- return data;
- },
- },
- });
- export default DirectionExclusion;
- </script>
- <style lang="scss" scoped>
- .direction-exclusion {
- width: 560px;
- overflow: hidden;
- .common-box {
- height: 210px;
- float: left;
- border: 1px solid rgb(210, 210, 210);
- border-radius: 2px;
- .title-box {
- padding: 0 10px;
- height: 30px;
- border-bottom: 1px solid rgb(210, 210, 210);
- h3 {
- font-size: 13px;
- font-weight: bold;
- height: 30px;
- line-height: 30px;
- float: left;
- margin-bottom: 0;
- }
- .clear-all {
- font-size: 13px;
- font-weight: normal;
- color: gray;
- float: right;
- cursor: pointer;
- }
- }
- .list {
- height: 180px;
- padding: 4px 10px;
- overflow: auto;
- p {
- height: 28px;
- line-height: 28px;
- .item-name {
- display: block;
- float: left;
- white-space: nowrap;
- text-overflow: ellipsis;
- overflow: hidden;
- word-break: break-all;
- }
- }
- }
- }
- .list-box {
- width: 320px;
- }
- .selected-box {
- width: 200px;
- margin-left: 20px;
- .tabs {
- width: 100%;
- display: flex;
- justify-content: space-around;
- span {
- cursor: pointer;
- display: inline-block;
- line-height: 30px;
- }
- .tabs-active {
- color: rgb(80, 138, 245);
- border-bottom: 3px solid rgb(80, 138, 245);
- }
- }
- .selected-item {
- height: 140px;
- padding: 0px 10px;
- overflow: auto;
- p {
- background: rgb(240, 240, 240);
- height: 26px;
- line-height: 26px;
- display: flex;
- align-items: center;
- justify-content: space-around;
- margin-top: 6px;
- font-size: 13px;
- span {
- display: inline-block;
- width: 130px;
- white-space: nowrap;
- text-overflow: ellipsis;
- overflow: hidden;
- word-break: break-all;
- border-radius: 2px;
- }
- i {
- cursor: pointer;
- font-size: 13px;
- &:hover {
- color: skyblue;
- }
- }
- }
- }
- }
- }
- </style>
|