|
@@ -0,0 +1,491 @@
|
|
|
+<template>
|
|
|
+ <div class="tags-box">
|
|
|
+ <div class="tags-inputs">
|
|
|
+ <div class="tag-input">
|
|
|
+ <div class="tag-labels"></div>
|
|
|
+ <input type="text" class="clear-input" maxlength="5" oninput="this.value=this.value.replace(/\s+/g,'')">
|
|
|
+ <div class="tag-placeholder">新增标签回车保存</div>
|
|
|
+ </div>
|
|
|
+ <div class="add-tag-button">添加并使用</div>
|
|
|
+ </div>
|
|
|
+ <div class="tags-list clearfix"></div>
|
|
|
+ <div class="tags-footer">
|
|
|
+ <div class="tags-button button-confirm">确认添加</div>
|
|
|
+ <div class="tags-button button-cancel">暂不添加</div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+export default {
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ datas: []
|
|
|
+ }
|
|
|
+ },
|
|
|
+ mounted() {
|
|
|
+ this.initCollectEvent()
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ showTip (text, duration) {
|
|
|
+ if (duration) {
|
|
|
+ duration = 1000
|
|
|
+ }
|
|
|
+ var _html = ''
|
|
|
+ _html += '<div class="custom-toast"><div class="mask" style="background-color: transparent;"></div><div class="toast-container">'
|
|
|
+ _html += '<span>' + text + '</span></div></div>'
|
|
|
+ $('body').append(_html)
|
|
|
+ setTimeout(function () {
|
|
|
+ $('.custom-toast').fadeOut().remove()
|
|
|
+ }, duration)
|
|
|
+ },
|
|
|
+ tagsShow(data) {
|
|
|
+ this.datas = data.data
|
|
|
+ var top = data.liHeight * (data.i + 1) + 'px'
|
|
|
+ if (data.show) {
|
|
|
+ $('.tags-box').slideToggle(function () {
|
|
|
+ window.activeTags = []
|
|
|
+ $('.tag-labels').empty()
|
|
|
+ $('.clear-input').val('')
|
|
|
+ $('.tags-list').find('.tags-item').removeClass('tags-active')
|
|
|
+ $('.tag-placeholder').show()
|
|
|
+ }).css({
|
|
|
+ top: top,
|
|
|
+ right: 0
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+ initCollectEvent () {
|
|
|
+ const _this = this
|
|
|
+ function toastFn (text, duration) {
|
|
|
+ _this.showTip(text, duration)
|
|
|
+ }
|
|
|
+ // 自定义标签
|
|
|
+ // 标签输入框事件
|
|
|
+ $('.tags-box').click(function (e) {
|
|
|
+ e.stopPropagation()
|
|
|
+ })
|
|
|
+
|
|
|
+ $('.tag-input').click(function (e) {
|
|
|
+ e.stopPropagation()
|
|
|
+ $(this).children('.tag-placeholder').hide()
|
|
|
+ $(this).children('input').focus()
|
|
|
+ })
|
|
|
+ // 标签输入框回车事件
|
|
|
+ $('.tag-input .clear-input').keydown(function (event) {
|
|
|
+ event.stopPropagation()
|
|
|
+ if (event.keyCode == 13) {
|
|
|
+ if (!$('.tags-box').is(':hidden')) {
|
|
|
+ $('.tags-inputs .add-tag-button').trigger('click')
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ // 标签输入框失去焦点事件
|
|
|
+ $('.tag-input .clear-input').blur(function () {
|
|
|
+ if ($('.tag-labels').children().length == 0 && $(this).val() == '') {
|
|
|
+ $('.tag-placeholder').show()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ // 添加标签按钮事件
|
|
|
+ $('.tags-inputs .add-tag-button').on('click', function () {
|
|
|
+ var input = $('.tag-input .clear-input')
|
|
|
+ if (input.val().length >= 2 && input.val().length < 6) {
|
|
|
+ // ajax提交自定义标签
|
|
|
+ addTagsAjax(input.val())
|
|
|
+ }
|
|
|
+ })
|
|
|
+ // 点击确定按钮,绑定标签
|
|
|
+ $('.tags-footer .button-confirm').on('click', function () {
|
|
|
+ if (!$('.tags-box').is(':hidden')) {
|
|
|
+ var lids = ''
|
|
|
+ var lname = ''
|
|
|
+ $('.tags-item.tags-active').each(function () {
|
|
|
+ if ($(this).attr('data-id')) {
|
|
|
+ if (lids != '') {
|
|
|
+ lids += ','
|
|
|
+ }
|
|
|
+ if (lname != '') {
|
|
|
+ lname += ','
|
|
|
+ }
|
|
|
+ lids += $(this).attr('data-id')
|
|
|
+ lname += $(this).text()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ var params = {
|
|
|
+ name: _this.datas,
|
|
|
+ mold: 1,
|
|
|
+ D: false,
|
|
|
+ label: lids
|
|
|
+ }
|
|
|
+ // 执行保存绑定标签操作
|
|
|
+ // if (params.label !== '') {
|
|
|
+ saveChooseTags(params, function () {
|
|
|
+ $('.tags-footer .button-cancel').trigger('click')
|
|
|
+ })
|
|
|
+ // }
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ $('.tags-footer .button-cancel').on('click', function () {
|
|
|
+ $('.tags-box').slideToggle(function () {
|
|
|
+ // 标签弹框消失时 清除上次选择的标签分类
|
|
|
+ activeTags = []
|
|
|
+ $('.tag-labels').empty()
|
|
|
+ $('.clear-input').val('')
|
|
|
+ $('.tags-list').find('.tags-item').removeClass('tags-active')
|
|
|
+ $('.tag-placeholder').show()
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ window.activeTags = [] // 选中的自定义标签 作为全局变量使用
|
|
|
+ // 解绑自定义标签
|
|
|
+ function deleteInputTag (item) {
|
|
|
+ var index = $(item).parent().attr('data-index')
|
|
|
+ var id = $(item).parent().attr('data-id')
|
|
|
+ activeTags.splice(index, 1)
|
|
|
+ inputTagList()
|
|
|
+ $('.tags-item[data-id="' + id + '"]').removeClass('tags-active')
|
|
|
+ }
|
|
|
+
|
|
|
+ window.deleteInputTag = deleteInputTag
|
|
|
+
|
|
|
+ function inputTagList () {
|
|
|
+ var ht = ''
|
|
|
+ $('.tag-labels').html(ht)
|
|
|
+ activeTags.forEach(function (v, i) {
|
|
|
+ ht += '<span class="tag-label" data-index=' + i + ' data-id="' + v.lid + '">'
|
|
|
+ ht += '<em>' + v.lname + '</em>'
|
|
|
+ ht += '<i class="tag-close" onclick="deleteInputTag(this)"></i>'
|
|
|
+ ht += '</span>'
|
|
|
+ })
|
|
|
+ $('.tag-labels').html(ht)
|
|
|
+ if ($('.tag-labels').children('.tag-label').length > 0) {
|
|
|
+ $('.tag-placeholder').hide()
|
|
|
+ }
|
|
|
+ checkTagDisabled()
|
|
|
+ }
|
|
|
+
|
|
|
+ // 渲染标签列表数据
|
|
|
+ function renderTagsList (data) {
|
|
|
+ if (data && data.length > 0) {
|
|
|
+ var ht = ''
|
|
|
+ data.forEach(function (v, i) {
|
|
|
+ ht += '<span class="tags-item" data-count=' + v.count + ' data-id=' + v.lid + '>' + v.lanme + '</span>'
|
|
|
+ })
|
|
|
+ $('.tags-list').html(ht)
|
|
|
+ activeTags.forEach(function (s, j) {
|
|
|
+ $('.tags-list .tags-item[data-id="' + s.lid + '"]').addClass('tags-active')
|
|
|
+ })
|
|
|
+ $('.tags-item').click(function (e) {
|
|
|
+ e.stopPropagation()
|
|
|
+ if ($(this).hasClass('disabled')) return
|
|
|
+ var id = $(this).attr('data-id')
|
|
|
+ var name = $(this).text()
|
|
|
+ $(this).toggleClass('tags-active')
|
|
|
+ if ($(this).hasClass('tags-active')) {
|
|
|
+ activeTags.push({
|
|
|
+ lid: id,
|
|
|
+ lname: name
|
|
|
+ })
|
|
|
+ inputTagList()
|
|
|
+ } else {
|
|
|
+ var newArr = activeTags.filter(function (item) {
|
|
|
+ return item.lid != id
|
|
|
+ })
|
|
|
+ activeTags = newArr
|
|
|
+ console.log(activeTags, newArr, 'quxiao')
|
|
|
+ inputTagList()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ inputTagList()
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取用户自定义标签
|
|
|
+ function getUserTags () {
|
|
|
+ $.ajax({
|
|
|
+ type: 'post',
|
|
|
+ url: '/entnicheNew/customer/getLabel?t=' + Date.now(),
|
|
|
+ success: function (r) {
|
|
|
+ if (r.error_code == 0 && $.isArray(r.data)) {
|
|
|
+ renderTagsList(r.data.reverse())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ window.getUserTags = getUserTags
|
|
|
+ // 添加标签后认领接口
|
|
|
+ function saveChooseTags (params, callback) {
|
|
|
+ $.ajax({
|
|
|
+ type: 'post',
|
|
|
+ url: '/entnicheNew/customer/attention',
|
|
|
+ contentType: 'application/json',
|
|
|
+ data: JSON.stringify(params),
|
|
|
+ dataType: 'json',
|
|
|
+ success: function (r) {
|
|
|
+ if (r.error_code == 0 && r.data) {
|
|
|
+ _this.$toast('认领成功!')
|
|
|
+ _this.$emit('getClientList', true)
|
|
|
+ callback && callback()
|
|
|
+ } else {
|
|
|
+ if (r.error_msg) {
|
|
|
+ _this.$toast(r.error_msg, 3000)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ // 新增标签
|
|
|
+ function addTagsAjax (name) {
|
|
|
+ $.ajax({
|
|
|
+ type: 'post',
|
|
|
+ url: '/entnicheNew/customer/addLabel',
|
|
|
+ data: {
|
|
|
+ name: name
|
|
|
+ },
|
|
|
+ dataType: 'json',
|
|
|
+ success: function (r) {
|
|
|
+ if (r.data) {
|
|
|
+ $('.tag-input .clear-input').val('')
|
|
|
+ // 添加标签成功后 绑定标签
|
|
|
+ if (activeTags.length < 3) {
|
|
|
+ activeTags.push({
|
|
|
+ lid: r.data,
|
|
|
+ lname: name
|
|
|
+ })
|
|
|
+ }
|
|
|
+ getUserTags()
|
|
|
+ } else {
|
|
|
+ // toastFn(r.error_msg, 1000)
|
|
|
+ toastFn('标签已经存在,无需添加', 1000)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ function checkTagDisabled () {
|
|
|
+ if (activeTags.length >= 3) {
|
|
|
+ // 禁用标签
|
|
|
+ $('.tags-list').find('.tags-item:not(.tags-active)').addClass('disabled')
|
|
|
+ } else {
|
|
|
+ // 解除禁用
|
|
|
+ $('.tags-list').find('.disabled').removeClass('disabled')
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function baiduEvent (str) {
|
|
|
+ try {
|
|
|
+ // eslint-disable-next-line no-undef
|
|
|
+ _hmt.push(['_trackEvent', '大会员-pc', 'click', str])
|
|
|
+ } catch (e) {
|
|
|
+ console.log('未初始化百度统计')
|
|
|
+ }
|
|
|
+ }
|
|
|
+ getUserTags()
|
|
|
+ },
|
|
|
+ }
|
|
|
+}
|
|
|
+</script>
|
|
|
+
|
|
|
+<style>
|
|
|
+.tags-box {
|
|
|
+ display: none;
|
|
|
+ position: absolute;
|
|
|
+ top: 0;
|
|
|
+ right: 0;
|
|
|
+ width: 332px;
|
|
|
+ padding: 20px 16px;
|
|
|
+ background: #FFFFFF;
|
|
|
+ border: 1px solid #ECECEC;
|
|
|
+ box-sizing: border-box;
|
|
|
+ border-radius: 8px;
|
|
|
+ box-shadow: 0px 0px 28px 0px rgba(0, 0, 0, 0.08);
|
|
|
+ z-index: 99;
|
|
|
+}
|
|
|
+
|
|
|
+.tags-box .tags-inputs {
|
|
|
+ position: relative;
|
|
|
+ width: 100%;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: space-between;
|
|
|
+}
|
|
|
+
|
|
|
+.tags-box .tags-inputs .tag-input {
|
|
|
+ width: 100%;
|
|
|
+ padding: 0;
|
|
|
+ min-height: 34px;
|
|
|
+ max-height: 74px;
|
|
|
+ overflow-y: scroll;
|
|
|
+ display: inline-block;
|
|
|
+ border: 1px solid #ccc;
|
|
|
+ border-radius: 4px;
|
|
|
+ background-color: #fff;
|
|
|
+ cursor: text;
|
|
|
+}
|
|
|
+
|
|
|
+.tags-inputs .tag-input::-webkit-scrollbar {
|
|
|
+ width: 8px;
|
|
|
+}
|
|
|
+
|
|
|
+.tags-inputs .tag-input::-webkit-scrollbar-thumb {
|
|
|
+ border-radius: 4px;
|
|
|
+ background-color: #ECECEC;
|
|
|
+}
|
|
|
+
|
|
|
+.tag-input > .tag-labels {
|
|
|
+ display: inline;
|
|
|
+ vertical-align: middle;
|
|
|
+}
|
|
|
+
|
|
|
+.tag-input > .clear-input {
|
|
|
+ display: inline-block;
|
|
|
+ padding: 0 10px;
|
|
|
+ width: 100%;
|
|
|
+ height: 36px;
|
|
|
+ line-height: 1;
|
|
|
+ background: #fff;
|
|
|
+ border-radius: 2px;
|
|
|
+ vertical-align: middle;
|
|
|
+ border: none;
|
|
|
+ background-color: transparent;
|
|
|
+ box-shadow: none;
|
|
|
+ box-sizing: border-box;
|
|
|
+ font-size: 14px;
|
|
|
+ color: #1d1d1d;
|
|
|
+}
|
|
|
+
|
|
|
+.tag-input > .tag-labels > .tag-label {
|
|
|
+ display: inline-block;
|
|
|
+ padding: 5px 12px;
|
|
|
+ font-size: 14px;
|
|
|
+ line-height: 1.2;
|
|
|
+ margin: 5px;
|
|
|
+ cursor: pointer;
|
|
|
+ border: 1px solid #ECECEC;
|
|
|
+ box-sizing: border-box;
|
|
|
+ border-radius: 4px;
|
|
|
+ background: #F5F6F7;
|
|
|
+ color: #1D1D1D;
|
|
|
+}
|
|
|
+
|
|
|
+.tag-close {
|
|
|
+ display: inline-block;
|
|
|
+ width: 16px;
|
|
|
+ height: 16px;
|
|
|
+ margin-left: 8px;
|
|
|
+ background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAABYlAAAWJQFJUiTwAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAEwSURBVHgB7ZWxDYMwEEXPER1NRmEFJggUiJpJQiahRhSECViBUdzQIYgdgYQIPnwXmkT+DcbY/s9n3wHg5PTPKoriejRGYB+rqrpP0xT1fR9mWSaBaO77fiuEeCZJ8gAqwGyez68dBWIxV83gbSJEboK47HXWda1DF626Ar2gTUi35lo6iqbxuwBxHEvP80JF3lEg9sxhjp5pDnoHdCSGYWjVDj4W3B4HZo4dHQpgC8E1twI4gtANrrk1AAYxP1nmJAAEArjmZIADiI5TsC5AlJRS5zWcJVIEDLd9LXIUrCNgSjVqsWIBYHnOqZhrHR6BTZGhVEwSAKXCcSHEGebfQBjvAKe8cv6iRgC1i4ZijkHotUxz0TtQlmWuFrpxKtxyHOM4Nmma5sAVJaednH5SLxmyS6JIrGjkAAAAAElFTkSuQmCC);
|
|
|
+ background-position: center 2px;
|
|
|
+ background-repeat: no-repeat;
|
|
|
+ background-size: contain;
|
|
|
+}
|
|
|
+
|
|
|
+.tag-placeholder {
|
|
|
+ position: absolute;
|
|
|
+ top: 12px;
|
|
|
+ left: 16px;
|
|
|
+ color: #bbb;
|
|
|
+ font-size: 14px;
|
|
|
+}
|
|
|
+
|
|
|
+.tags-box .tags-list {
|
|
|
+ margin-top: 12px;
|
|
|
+ overflow-y: auto;
|
|
|
+ height: 220px;
|
|
|
+}
|
|
|
+
|
|
|
+.tags-box .tags-list::-webkit-scrollbar {
|
|
|
+ width: 8px;
|
|
|
+}
|
|
|
+
|
|
|
+.tags-box .tags-list::-webkit-scrollbar-thumb {
|
|
|
+ border-radius: 4px;
|
|
|
+ background-color: #ECECEC;
|
|
|
+}
|
|
|
+
|
|
|
+.tags-box .tags-list .tags-item {
|
|
|
+ float: left;
|
|
|
+ min-width: 44px;
|
|
|
+ padding: 0 8px;
|
|
|
+ margin: 10px 8px 0 0;
|
|
|
+ height: 24px;
|
|
|
+ line-height: 24px;
|
|
|
+ border-radius: 4px;
|
|
|
+ border: 1px solid #ECECEC;
|
|
|
+ box-sizing: border-box;
|
|
|
+ color: #1D1D1D;
|
|
|
+ text-align: center;
|
|
|
+ font-size: 14px;
|
|
|
+ background: #F5F6F7;
|
|
|
+ cursor: pointer;
|
|
|
+}
|
|
|
+
|
|
|
+.tags-box .tags-list .tags-active {
|
|
|
+ padding: 0 8px 0 24px !important;
|
|
|
+ background: #2CB7CA url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAABYlAAAWJQFJUiTwAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAADPSURBVHgB7ZNREcIwDIYjYRImYRLmZHPAHAwHlUAdIAEJSKiESgjpEY7Qg7uFdXnKd5eXdMmfpX8BHMdxDEDEgSJQ9GANiU4UGZ9cwBISXPFNGWIAKyrxZLr+suq/xdkwV4oFlFBNR3ET4veS0zaJosGoqOtZ8EVUi4tGWbM+rklC/Ax7KH++dY18ZbmZuGi8iKbhxzdTJT5DSyo/LNXZSZxljV80A3T4aayR86vIJTzyjX8xZTATF0NIU24y5xFDSFNGU3ExxNzsmTmO4zAPYEiZdz83IV0AAAAASUVORK5CYII=) no-repeat 6px center !important;
|
|
|
+ color: #fff !important;
|
|
|
+ background-size: 16px !important;
|
|
|
+ border: 0 !important;
|
|
|
+}
|
|
|
+
|
|
|
+.tags-item.disabled {
|
|
|
+ color: #8E8E8E !important;
|
|
|
+ border-color: #ECECEC!important;
|
|
|
+ cursor: not-allowed!important;
|
|
|
+}
|
|
|
+
|
|
|
+.tag-label em {
|
|
|
+ font-style: normal;
|
|
|
+}
|
|
|
+
|
|
|
+.add-tag-button {
|
|
|
+ margin-left: 16px;
|
|
|
+ color: #2cb7ca;
|
|
|
+ font-size: 14px;
|
|
|
+ line-height: 22px;
|
|
|
+ white-space: nowrap;
|
|
|
+ cursor: pointer;
|
|
|
+}
|
|
|
+
|
|
|
+.tags-footer {
|
|
|
+ margin-top: 20px;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: center;
|
|
|
+}
|
|
|
+
|
|
|
+.tags-button {
|
|
|
+ padding: 3px 17px;
|
|
|
+ color: #1d1d1d;
|
|
|
+ font-size: 14px;
|
|
|
+ line-height: 22px;
|
|
|
+ border-radius: 4px;
|
|
|
+ border: 1px solid #e0e0e0;
|
|
|
+ text-shadow: 0px 0px 28px 0px rgba(0, 0, 0, 0.08);
|
|
|
+ cursor: pointer;
|
|
|
+}
|
|
|
+
|
|
|
+.button-confirm {
|
|
|
+ margin-right: 16px;
|
|
|
+ color: #fff;
|
|
|
+ background: #2cb7ca;
|
|
|
+ border-color: #2cb7ca;
|
|
|
+}
|
|
|
+
|
|
|
+.custom-toast .toast-container{
|
|
|
+ position: fixed;
|
|
|
+ top: 50%;
|
|
|
+ left: 50%;
|
|
|
+ width: auto;
|
|
|
+ padding: 16px 32px;
|
|
|
+ font-size: 16px;
|
|
|
+ background: rgba(0, 0, 0, 0.65);
|
|
|
+ border-radius: 8px;
|
|
|
+ color: #fff;
|
|
|
+ transform: translateX(-50%) translateY(-50%);
|
|
|
+ z-index: 99;
|
|
|
+}
|
|
|
+</style>
|