123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- <template>
- <div class="module-box link-select">
- <div class="module-box__title">
- <label class="module-box__label">{{title}}</label>
- </div>
- <div class="link-select__confirm">
- <div class="btn" v-if="selectedCategoryList && selectedCategoryList.length === 0" @click="openDialog">
- <span class="iconfont"></span> 添加类别
- </div>
- <div class="info" v-else>
- <div><span>{{selectedCategoryList[0].categoryName}}</span><span v-if="selectedCategoryList.length > 1">+{{selectedCategoryList.length-1}}</span></div>
- <div class="operation">
- <i class="iconfont" @click="openDialog"></i>
- <i class="iconfont" @click="deleteCategory"></i>
- </div>
- </div>
- </div>
- <el-dialog width="500" title="选择类别" :visible.sync="categoryVisible">
- <el-select v-if="terminal === 4"
- v-model="categoryValue"
- multiple
- collapse-tags
- placeholder="请选择">
- <el-option
- v-for="item in categoryList"
- :key="item.id"
- :label="item.categoryName"
- :value="item.id">
- </el-option>
- </el-select>
- <el-cascader v-else
- ref="cascader"
- :options="categoryList" :props="{ multiple: true,label: 'categoryName',value: 'id',children: 'childs' }"
- clearable></el-cascader>
- <span slot="footer" class="dialog-footer">
- <el-button @click="categoryVisible = false">取 消</el-button>
- <el-button type="primary" @click="categoryChanged">确 定</el-button>
- </span>
- </el-dialog>
- </div>
- </template>
- <script>
- import api from '@@/components/canvasShow/config/api'
- import {sendReqMixin} from '@@/components/canvasShow/config/mixin'
- import {checkEmptyChild} from '@@/config/common'
- import { mapGetters } from 'vuex'
- export default {
- name: 'tool-select-category',
- mixins: [sendReqMixin],
- data () {
- return {
- props: { multiple: true },
- selectName: '',
- categoryValue: [],
- selectedCategoryList: [],
- categoryList: [],
- categoryVisible: false
- }
- },
- props: {
- title: {
- type: String,
- default: '链接'
- },
- category: {
- type: Array,
- default: () => []
- }
- },
- mounted () {
- this.getCategory()
- this.selectedCategoryList = this.category
- },
- computed: {
- ...mapGetters([
- 'terminal'
- ])
- },
- methods: {
-
- getCategory () {
- var _this = this
- let params = {
- url: api.getClassify,
- method: 'GET'
- }
- this.sendReq(params, (res) => {
- _this.categoryList = res.data
- checkEmptyChild(_this.categoryList)
- })
- },
-
- openDialog () {
- this.categoryVisible = true
- },
-
- categoryChanged () {
- this.categoryVisible = false
- if (this.terminal === 4) {
- this.selectedCategoryList = this.categoryList.filter((item) => {
- for (let i = 0; i < this.categoryValue.length; i++) {
- if (this.categoryValue[i] === item.id) {
- return true
- }
- }
- })
- } else {
- let nodesArr = this.$refs['cascader'].getCheckedNodes()
- if (nodesArr) {
- nodesArr = nodesArr.filter((item) => {
- return item.children.length === 0
- })
- this.selectedCategoryList = []
- for (let i = 0; i < nodesArr.length; i++) {
- this.selectedCategoryList.push(nodesArr[i].data)
- }
- }
- }
- this.$emit('update:category', this.selectedCategoryList)
- },
-
- deleteCategory () {
- this.categoryValue = []
- this.$emit('update:category', [])
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .link-select{
- &__select{
- width: 100%;
- }
- &__confirm{
- margin-top: 10px;
- .btn{
- text-align: center;
- background-color: $mainColor;
- color: #fff;
- height: 36px;
- line-height: 36px;
- border-radius: 4px;
- cursor: pointer;
- }
- .info{
- height: 36px;
- line-height: 36px;
- border-radius: 4px;
- padding: 0 10px;
- border:1px solid $mainColor;
- display: flex;
- justify-content: space-between;
- span{
- background-color: #f4f4f5;
- border:1px solid #e9e9eb;
- color: #909399;
- height: 26px;
- padding: 0 8px;
- line-height: 24px;
- border-radius: 4px;
- margin: 5px 6px 5px 0px;
- display: inline-block;
- }
- .operation{
- float: right;
- i{
- width: 35px;
- display: inline-block;
- height: 35px;
- line-height: 35px;
- text-align: center;
- cursor: pointer;
- }
- }
- }
- }
- }
- </style>
|