pur-search-index-pc.js 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069
  1. function getRandomString (len) {
  2. let randomString = ''
  3. if (len) {
  4. const $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'
  5. const maxPos = $chars.length
  6. for (let i = 0; i < len; i++) {
  7. randomString += $chars.charAt(Math.floor(Math.random() * maxPos))
  8. }
  9. } else {
  10. randomString = Math.random().toString(36).substring(2)
  11. }
  12. return randomString
  13. }
  14. // toast上限提示
  15. function toastFn (text, duration = 1000) {
  16. // if (duration) {
  17. // duration = 1000
  18. // }
  19. var _html = ""
  20. _html+='<div class="custom-toast"><div class="mask" style="background-color: transparent;"></div><div class="toast-container">'
  21. _html+='<span>' + text + '</span></div></div>'
  22. $('body').append(_html)
  23. setTimeout(function(){
  24. $(".custom-toast").fadeOut().remove();
  25. },duration)
  26. }
  27. function formatKeywordsList (res) {
  28. // if (!res || !res.a_items) return
  29. // const data = res.a_items
  30. const newArr = []
  31. res.forEach((v) => {
  32. if (v.a_key) {
  33. v.a_key.forEach((s) => {
  34. newArr.push(s)
  35. })
  36. }
  37. })
  38. return newArr
  39. }
  40. function ewmMoveHover() {
  41. var $div = $(".search-right-wx .search-right-wx-inner"),
  42. $parent = $(".search-right-wx");
  43. $parent.on("mouseover",function(){
  44. $div.css({
  45. "transform":"scale(1)",
  46. "transition":"transform 0.8s"
  47. })
  48. })
  49. $parent.on("mouseout",function(){
  50. $div.css({
  51. "transform":"scale(0)",
  52. "transition":"transform 0.2s"
  53. })
  54. })
  55. }
  56. var vm = new Vue({
  57. el: '#pur-search-container',
  58. delimiters: ['${', '}'],
  59. components: {
  60. areaCityComponent: areaCityComponent,
  61. selectListComponent: selectListComponent,
  62. priceComponent: priceComponent,
  63. noData: noDataComponent
  64. },
  65. data: function () {
  66. return {
  67. searchContent: '',
  68. tabActive: 'cgdw',
  69. filterShow: true,
  70. indusData: ['财政', '传媒', '城管', '采矿业', '出版广电', '档案', '党委办', '电信行业', '法院',
  71. '发改', '工信', '公安', '国资委', '公共资源交易',
  72. '海关', '教育', '军队', '交通', '纪委', '金融业', '建筑业', '检察院', '机关事务',
  73. '科技', '民政', '民宗', '农业', '能源化工', '农林牧渔', '批发零售', '气象', '人行', '人社', '人大',
  74. '税务', '水利', '市政', '审计', '商务', '司法', '社会团体', '市场监管', '生态环境',
  75. '统计', '统战', '体育', '文旅', '卫健委', '学校', '宣传', '信息技术',
  76. '医疗', '银保监', '运输物流', '应急管理',
  77. '组织', '政协', '住建', '证监', '政府办', '制造业', '政务中心', '住宿餐饮', '自然资源'
  78. ],
  79. indusList:[],
  80. caiIndex: [],
  81. qutive: true,
  82. indusList1:[],
  83. caiIndex1: [],
  84. qutive1: true,
  85. qyCheck: [],
  86. qyData: [],
  87. allChecked: false,
  88. singleChecked: false,
  89. follow: false,
  90. claim: false,
  91. jobData: [],
  92. entArea: {},
  93. arrs6: [],
  94. listState: {
  95. loaded: false, // 是否已经搜索过
  96. loading: false,
  97. pageNum: 1, // 当前页, 从0开始
  98. pageSize: 50, // 每页多少条数据
  99. total: 0, // 一共多少条数据
  100. list: [] // 查询请求返回的数据
  101. },
  102. preSearch: {
  103. hover: false,
  104. focus: false,
  105. list: []
  106. },
  107. showMore: true,
  108. industryExp: {
  109. name: '全部行业',
  110. selected: false,
  111. level: 0,
  112. children: [],
  113. id: ''
  114. },
  115. datas: '',
  116. attentionName: [],
  117. claimcheckName: [],
  118. showmoreBtn: true,
  119. industryListMap: [],
  120. getIndustryListMap: [],
  121. industryListMapExp: {
  122. '建筑工程': ['勘察设计', '工程施工', '监理咨询', '材料设备', '机电安装'],
  123. '水利水电': ['水利工程', '发电工程', '航运工程', '其他工程'],
  124. '能源化工': ['原材料', '仪器仪表', '新能源', '设备物资', '化工产品', '设备'],
  125. '弱电安防': ['综合布线', '智能系统', '智能家居'],
  126. '信息技术': ['系统集成及安全', '软件开发', '运维服务', '其他'],
  127. '行政办公': ['办公家具', '通用办公设备', '专业设备', '办公用品', '生活用品'],
  128. '机械设备': ['矿山机械', '工程机械', '机械零部件', '机床相关', '车辆', '其他机械设备'],
  129. '交通工程': ['道路','轨道','桥梁','隧道','其他'],
  130. '医疗卫生': ['设备','耗材','药品'],
  131. '市政设施': ['道路','绿化','线路管网','综合项目'],
  132. '服务采购': ['法律咨询','会计','物业','审计','安保','仓储物流','广告宣传印刷','其他'],
  133. '农林牧渔': ['生产物资','生产设备','相关服务']
  134. },
  135. getInfoTypeList: [],
  136. selectName: []
  137. }
  138. },
  139. watch: {
  140. tabActive: function (newVal, oldVal) {
  141. if (newVal === 'zb') {
  142. if (this.searchContent) {
  143. location.href = '/jylab/supsearch/index.html?keywords=' + this.searchContent + '&publishtime=thisyear'
  144. } else {
  145. location.href = '/jylab/supsearch/index.html'
  146. }
  147. } else if (newVal === 'qy') {
  148. if (this.searchContent) {
  149. location.href = '/jylab/entSearch/index.html?keywords=' + this.searchContent
  150. } else {
  151. location.href = '/jylab/entSearch/index.html'
  152. }
  153. }
  154. }
  155. },
  156. computed: {
  157. purListShow: function () {
  158. return this.searchContent.trim().length >= 2 && this.preSearch.list.length && (this.preSearch.focus || this.preSearch.hover)
  159. },
  160. },
  161. created: function () {
  162. this.initIndustryMap()
  163. this.qyCustmer()
  164. this.jobRange()
  165. this.getList(1)
  166. },
  167. mounted: function () {
  168. this.initCollectEvent()
  169. this.initDOMEvents()
  170. ewmMoveHover()
  171. this.$on('updatescope', (data) => {
  172. this.setData.keyList = data
  173. })
  174. },
  175. methods: {
  176. updatescope(data) {
  177. // console.log(data)
  178. },
  179. // 采购单位模糊搜索
  180. getPreSearchList: utils.debounce(function () {
  181. var data = {
  182. name: this.searchContent.trim()
  183. }
  184. if (data.name.length < 2) return
  185. $.ajax({
  186. url: '/entnicheNew/customer/buyer/association',
  187. method: 'POST',
  188. data: data,
  189. success: function (res) {
  190. if (res.error_code === 0) {
  191. if (res.data) {
  192. this.preSearch.list = res.data.list || []
  193. }
  194. } else {
  195. this.checkLogin()
  196. }
  197. }.bind(this)
  198. })
  199. }, 200),
  200. goSearch(name) {
  201. this.searchContent = name
  202. this.preSearch.hover = false
  203. this.listState.pageNum = 1
  204. this.entArea = {}
  205. this.indusList = []
  206. this.indusList1 = []
  207. this.industryExp = []
  208. this.qyCheck = []
  209. this.doSearch()
  210. },
  211. checkLogin: function () {
  212. var moduleOpen = $('body').hasClass('modal-open')
  213. if (moduleOpen) return
  214. if (!loginflag) {
  215. $("#bidLogin").modal("show");
  216. }
  217. },
  218. yeFan() {
  219. location.href = '/jylab/purScopebusniess/index.html'
  220. },
  221. // 整理数据列表
  222. initIndustryMap () {
  223. const industryListMap = []
  224. // 全部
  225. const all = JSON.parse(JSON.stringify(this.industryExp))
  226. all.selected = true
  227. all.id = `lv0-${getRandomString(8).toLowerCase()}`
  228. industryListMap.push(all)
  229. for (const key in this.industryListMapExp) {
  230. const level1 = JSON.parse(JSON.stringify(this.industryExp))
  231. level1.name = key
  232. level1.level = 1
  233. level1.id = `lv1-${getRandomString(8).toLowerCase()}`
  234. const level2Arr = []
  235. this.industryListMapExp[key].forEach(item => {
  236. const level2 = JSON.parse(JSON.stringify(this.industryExp))
  237. level2.name = item
  238. level2.level = 2
  239. level2.id = `lv2-${getRandomString(8).toLowerCase()}`
  240. level2Arr.push(level2)
  241. })
  242. level1.children = level2Arr
  243. industryListMap.push(level1)
  244. }
  245. this.industryListMap = industryListMap
  246. const tempArr = []
  247. this.industryListMap.forEach(v => {
  248. const tempNode = v
  249. tempNode.zindex = 1
  250. tempArr.push(tempNode)
  251. tempNode?.children.forEach(s => {
  252. const tempS = s
  253. tempS.zindex = 2
  254. tempArr.push(tempS)
  255. })
  256. })
  257. this.getIndustryListMap = tempArr
  258. },
  259. // 按钮点击事件
  260. changeIndustryState (item) {
  261. // 循环所有数据,判断并改变状态
  262. switch (item.level) {
  263. case 0: {
  264. this.setIndustryState()
  265. break
  266. }
  267. case 1: {
  268. item.selected = !item.selected
  269. this.industryListMap[0].selected = false
  270. // 二级子按钮状态跟随一级按钮
  271. item.children.forEach(level2 => {
  272. level2.selected = item.selected
  273. })
  274. break
  275. }
  276. case 2: {
  277. item.selected = !item.selected
  278. // 找到当前点击的父级元素
  279. this.industryListMap.forEach(level1 => {
  280. const selectedStateArr = []
  281. if (item.level !== 0) {
  282. level1.children.forEach(level2 => {
  283. selectedStateArr.push(level2.selected)
  284. })
  285. if (selectedStateArr.indexOf(false) === -1) {
  286. level1.selected = true
  287. } else {
  288. level1.selected = false
  289. }
  290. }
  291. })
  292. this.industryListMap[0].selected = false
  293. break
  294. }
  295. default: {
  296. console.log('未知level')
  297. }
  298. }
  299. if (item.level !== 0) {
  300. const allSelected = this.checkAllSelectedState()
  301. if (allSelected.allSelected || allSelected.allNotSelected) {
  302. this.setIndustryState()
  303. }
  304. }
  305. if (this.selectorType === 'line') {
  306. this.onChange()
  307. }
  308. this.searchContent = ''
  309. this.doSearch()
  310. },
  311. // 检查是否全部选中了/全部不选中
  312. checkAllSelectedState () {
  313. // 一级标签选中状态(如果一级标签全部被选中,则说明,全部按钮被选中)
  314. const level1StateArr = []
  315. // 所有标签选中状态
  316. const allSelectedArr = []
  317. this.industryListMap.forEach(level1 => {
  318. if (level1.level !== 0) {
  319. level1StateArr.push(level1.selected)
  320. allSelectedArr.push(level1.selected)
  321. level1.children.forEach(level2 => {
  322. allSelectedArr.push(level2.selected)
  323. })
  324. }
  325. })
  326. return {
  327. // 找不到false,就说明全部被选中
  328. allSelected: level1StateArr.indexOf(false) === -1,
  329. // 找不到true,就说明没有一个被选中
  330. allNotSelected: allSelectedArr.indexOf(true) === -1
  331. }
  332. },
  333. /**
  334. * 初始化页面选中状态
  335. * @param { Array | undefined } data 要恢复的数据
  336. */
  337. setIndustryState (data) {
  338. // 设置全部按钮
  339. if (!data || Object.keys(data).length === 0) {
  340. // 其他全部设置不选中,全部按钮设置选中
  341. this.industryListMap.forEach(item => {
  342. item.selected = false
  343. item.children.forEach(iitem => {
  344. iitem.selected = false
  345. })
  346. })
  347. this.industryListMap[0].selected = true
  348. } else {
  349. this.setIndustryState()
  350. this.industryListMap[0].selected = false
  351. this.industryListMap.forEach(item => {
  352. if (data[item.name]) {
  353. // 如果恢复数组长度等于页面二级标签长度,则一级标签点亮
  354. if (data[item.name].length === item.children.length) {
  355. item.selected = true
  356. }
  357. item.children.forEach(function (iitem) {
  358. if (data[item.name].indexOf(iitem.name) !== -1) {
  359. iitem.selected = true
  360. }
  361. })
  362. }
  363. })
  364. }
  365. },
  366. // 获取选中的数据
  367. getSelected () {
  368. const map = {}
  369. this.industryListMap.forEach(item => {
  370. const mapArr = []
  371. if (item.level !== 0) {
  372. item.children.forEach(iitem => {
  373. if (iitem.selected) {
  374. mapArr.push(iitem.name)
  375. }
  376. })
  377. }
  378. if (mapArr.length !== 0) {
  379. map[item.name] = mapArr
  380. }
  381. })
  382. const tempArr = []
  383. Object.keys(map).forEach(v => {
  384. const tempItem = map[v]
  385. if (Array.isArray(tempItem)) {
  386. tempItem.forEach(vv => {
  387. tempArr.push(`${v}_${vv}`)
  388. })
  389. }
  390. })
  391. return tempArr
  392. },
  393. doSearch: function () {
  394. $('.tags-box').hide()
  395. this.listState.pageNum = 1
  396. this.getList(1, 'search')
  397. },
  398. getList: function (p, str) {
  399. let obj = {
  400. entName: this.searchContent.trim(),
  401. area: this.entArea,
  402. buyerclass: this.indusList,
  403. business_scope: this.indusList1,
  404. industry: this.getSelected(),
  405. entcustomer: this.qyCheck,
  406. pageSize: this.listState.pageSize,
  407. pageNum: this.listState.pageNum - 1,
  408. }
  409. this.listState.loading = true
  410. this.listState.loaded = false
  411. const _this = this
  412. let arrs = [], arr1 = []
  413. $.ajax({
  414. url: '/entnicheNew/customer/corList',
  415. method: 'POST',
  416. data: JSON.stringify(obj),
  417. contentType:'application/json;charset=utf-8',
  418. success: function (res) {
  419. if (res.error_code === 0 && $.isArray(res.data.list)) {
  420. if (res.data.list.length > this.listState.pageSize) {
  421. arrs = res.data.list.slice((p - 1) * this.listState.pageSize, (p - 1) * this.listState.pageSize + this.listState.pageSize) || []
  422. } else {
  423. arrs = res.data.list
  424. }
  425. arrs.forEach(v => {
  426. arr1.push(v.Buyer)
  427. })
  428. if (arrs.length == 0) {
  429. this.listState.list = []
  430. } else {
  431. _this.attentionCheck(arrs, String(arr1))
  432. }
  433. this.listState.total = res.data.list.length
  434. this.listState.loading = false
  435. } else {
  436. if (res.error_msg) {
  437. toastFn(res.error_msg, 2000)
  438. }
  439. this.listState.list = []
  440. }
  441. }.bind(this),
  442. complete: function () {
  443. this.listState.loading = false
  444. this.listState.loaded = true
  445. }.bind(this)
  446. })
  447. },
  448. onPageChange: function (p) {
  449. $('.tags-box').hide()
  450. this.listState.pageNum = p
  451. this.getList(p)
  452. },
  453. goTitle(name) {
  454. // location.href = '/entpc/unit_portrayal/' + name
  455. window.open('/entpc/unit_portrayal/' + name)
  456. },
  457. // 全选
  458. allChange() {
  459. const str1 = $('.check-all').prop('checked')
  460. const str2 = $('.custom-checkbox:not(".check-all")')
  461. const arr = $('.custom-checkbox:not(".check-all"):checked')
  462. let arrs1 = []
  463. if (str1) {
  464. str2.prop('checked', true)
  465. this.listState.list.forEach(v => {
  466. arrs1.push(v.Buyer)
  467. })
  468. } else {
  469. str2.prop('checked', false)
  470. arrs1 = []
  471. }
  472. this.selectName = arrs1
  473. },
  474. // 单选
  475. singleChange () {
  476. let arr1 = []
  477. $('.custom-checkbox:not(".check-all"):checked').each(function(){
  478. if ($(this).attr('dataname')) {
  479. arr1.push($(this).attr('dataname'))
  480. }
  481. })
  482. if (arr1.length == this.listState.list.length) {
  483. $('.check-all').prop('checked', true)
  484. } else {
  485. $('.check-all').prop('checked', false)
  486. }
  487. this.selectName = arr1
  488. var tempArray1 = this.arrDefault(this.selectName, this.attentionName)
  489. var tempArray2 = this.arrDefault(this.selectName, this.claimcheckName)
  490. if (tempArray1.length == 0) {
  491. this.follow = true
  492. if (this.selectName.length == 0) {
  493. this.follow = false
  494. }
  495. } else {
  496. this.follow = false
  497. }
  498. if (tempArray2.length == 0) {
  499. this.claim = true
  500. if (this.selectName.length == 0) {
  501. this.claim = false
  502. }
  503. } else {
  504. this.claim = false
  505. }
  506. },
  507. // 是否关注企业
  508. attentionCheck(arrs, item) {
  509. const _this = this
  510. $.ajax({
  511. url: '/entnicheNew/customer/check',
  512. method: 'POST',
  513. data: JSON.stringify({names: item}),
  514. contentType:'application/json;charset=utf-8',
  515. success: function (res) {
  516. if (res.data.names) {
  517. this.attentionName = res.data.names
  518. }
  519. arrs.forEach(v => {
  520. if (res.data.names.indexOf(v.Buyer) > -1) {
  521. v.follow1 = true
  522. } else {
  523. v.follow1 = false
  524. }
  525. })
  526. _this.claimcheck(arrs, item)
  527. }.bind(this)
  528. })
  529. },
  530. // 是否认领企业
  531. claimcheck(arrs, item) {
  532. $.ajax({
  533. url: '/entnicheNew/customer/claimcheck',
  534. method: 'POST',
  535. data: JSON.stringify({names: item}),
  536. contentType:'application/json;charset=utf-8',
  537. success: function (res) {
  538. if (res.data.names) {
  539. this.claimcheckName = res.data.names
  540. }
  541. arrs.forEach(v => {
  542. if (res.data.names.indexOf(v.Buyer) > -1) {
  543. v.claim1 = true
  544. } else {
  545. v.claim1 = false
  546. }
  547. })
  548. this.listState.list = arrs
  549. }.bind(this)
  550. })
  551. },
  552. // 关注、认领接口
  553. attention(item, type, str, per) {
  554. let obj = {}, _this = this
  555. if (type == 0) {
  556. obj = {
  557. name: per ? item : item.Buyer,
  558. province: per ? '' : item.WProvince,
  559. city: per ? '' : item.WCity,
  560. mold: type,
  561. B: per ? str : item.follow1,
  562. }
  563. } else {
  564. obj = {
  565. name: per ? item : item.Buyer,
  566. province: per ? '' : item.WProvince,
  567. city: per ? '' : item.WCity,
  568. mold: type,
  569. D: per ? str : item.claim1
  570. }
  571. }
  572. $.ajax({
  573. url: '/entnicheNew/customer/attention',
  574. method: 'POST',
  575. data: JSON.stringify(obj),
  576. contentType:'application/json;charset=utf-8',
  577. success: function (res) {
  578. if (res.data == false) {
  579. if (res.error_msg) {
  580. toastFn(res.error_msg, 2000)
  581. }
  582. } else {
  583. _this.getList(_this.listState.pageNum)
  584. // if (per && this.follow) {
  585. // this.follow = false
  586. // } else {
  587. // this.follow = true
  588. // }
  589. // if (per && this.claim) {
  590. // this.claim = false
  591. // } else {
  592. // this.claim = true
  593. // }
  594. }
  595. }.bind(this)
  596. })
  597. },
  598. arrDefault(array1, array2) {//比较的两个数组
  599. var tempArray1 = []
  600. var tempArray2 = []
  601. for(var i=0;i<array2.length;i++){
  602. if (!tempArray1.hasOwnProperty(array1[i])) {
  603. tempArray1[array2[i]]=true;
  604. }
  605. }
  606. for(var i=0;i<array1.length;i++){
  607. if(!tempArray1[array1[i]]){
  608. tempArray2.push(array1[i])
  609. }
  610. }
  611. return tempArray2
  612. },
  613. allGuanren (type) {
  614. if (this.selectName.length == 0) {
  615. toastFn('至少选择一项', 1500)
  616. } else {
  617. var tempArray1 = this.arrDefault(this.selectName, this.attentionName)
  618. var tempArray2 = this.arrDefault(this.selectName, this.claimcheckName)
  619. if (type == 0) {
  620. if (tempArray1.length == 0) {// 批量取关
  621. this.follow = true
  622. this.attention(String(this.selectName), type, true, 'pi')
  623. } else if (tempArray1.length == this.selectName.length) {// 批量关注
  624. this.follow = false
  625. this.attention(String(this.selectName), type, false, 'pi')
  626. } else {
  627. toastFn('关注和取消不能同时进行!', 2000)
  628. }
  629. } else {
  630. if (tempArray2.length == 0) {// 批量取认领
  631. this.claim = true
  632. this.attention(String(this.selectName), type, true, 'pi')
  633. } else if (tempArray2.length == this.selectName.length) {// 批量认领
  634. this.claim = false
  635. this.attention(String(this.selectName), type, false, 'pi')
  636. } else {
  637. toastFn('认领和取消不能同时进行!', 2000)
  638. }
  639. }
  640. }
  641. },
  642. guanAndren(item, type, index) {
  643. if (type == 1) {
  644. if (!item.claim1) {
  645. var top = 91 * (index + 1) + 'px'
  646. this.datas = item.Buyer
  647. $('.tags-box').slideToggle(function () {
  648. window.activeTags = []
  649. $('.tag-labels').empty()
  650. $('.clear-input').val('')
  651. $('.tags-list').find('.tags-item').removeClass('tags-active')
  652. $('.tag-placeholder').show()
  653. }).css({
  654. top: top,
  655. right: 0
  656. })
  657. } else {
  658. this.attention(item, type, '')
  659. }
  660. } else {
  661. this.attention(item, type, '')
  662. }
  663. },
  664. caiIndus(val, index) {
  665. let arrIndex = this.caiIndex.indexOf(index);
  666. if(arrIndex>-1){
  667. this.caiIndex.splice(arrIndex,1);
  668. this.indusList.splice(arrIndex,1);
  669. }else{
  670. this.caiIndex.push(index);
  671. this.indusList.push(val);
  672. }
  673. if (this.caiIndex.length < this.indusData.length) {
  674. this.qutive = false;
  675. }
  676. if (this.indusList.length == 0) {
  677. this.qutive = true;
  678. }
  679. if (this.caiIndex.length == this.indusData.length) {
  680. this.qutive = true;
  681. this.caiIndex = ["-2"];
  682. }
  683. this.searchContent = ''
  684. this.doSearch()
  685. },
  686. quanBu() {
  687. this.caiIndex = [];
  688. this.qutive = true;
  689. this.indusList = [];
  690. this.doSearch()
  691. },
  692. caiIndus1(val, index) {
  693. let arrIndex = this.caiIndex1.indexOf(index);
  694. if(arrIndex>-1){
  695. this.caiIndex1.splice(arrIndex,1);
  696. this.indusList1.splice(arrIndex,1);
  697. }else{
  698. this.caiIndex1.push(index);
  699. this.indusList1 = this.indusList1.concat(val);
  700. }
  701. if (this.caiIndex1.length < this.jobData.length) {
  702. this.qutive1 = false;
  703. }
  704. if (this.indusList1.length == 0) {
  705. this.qutive1 = true;
  706. }
  707. if (this.caiIndex1.length == this.jobData.length) {
  708. this.qutive1 = true;
  709. this.caiIndex1 = ["-2"];
  710. }
  711. this.searchContent = ''
  712. this.doSearch()
  713. },
  714. quanBu1() {
  715. this.caiIndex1 = [];
  716. this.qutive1 = true;
  717. this.indusList1 = [];
  718. this.doSearch()
  719. },
  720. cusMore() {
  721. console.log('1212')
  722. },
  723. qyCustmer() {
  724. $.ajax({
  725. url: '/entnicheNew/customer/history',
  726. method: 'GET',
  727. success: function (res) {
  728. if (res.error_code == 0 && $.isArray(res.data.list)) {
  729. this.qyData = res.data.list
  730. }
  731. }.bind(this)
  732. })
  733. },
  734. qyChange() {
  735. this.searchContent = ''
  736. this.doSearch()
  737. },
  738. jobRange() {
  739. const decide = window.localStorage.getItem('bus-key-group-SCOPE')
  740. if (decide) {
  741. this.jobData = JSON.parse(decide)
  742. } else {
  743. $.ajax({
  744. url: '/entnicheNew/subscribe/key/get',
  745. method: 'POST',
  746. success: function (res) {
  747. if ($.isArray(res.data.data) && res.error_code == 0) {
  748. res.data.data.forEach(v => {
  749. v.a_key.forEach(t => {
  750. this.jobData.push(t)
  751. })
  752. })
  753. }
  754. }.bind(this)
  755. })
  756. }
  757. },
  758. keyChange(appendkey, key, notkey) {
  759. let str = String(appendkey.concat(key).concat(notkey)).replace(/,/g, ' ')
  760. return str
  761. },
  762. initDOMEvents: function () {
  763. setTimeout(function () {
  764. // tabHover()
  765. }, 300)
  766. },
  767. areaCityChange: function (area) {
  768. var city = []
  769. for (var key in area) {
  770. city = city.concat(area[key])
  771. }
  772. this.entArea = area
  773. this.searchContent = ''
  774. this.doSearch()
  775. },
  776. isFilterShow: function () {
  777. if (this.filterShow) {
  778. $('.search-filters').slideUp()
  779. } else {
  780. $('.search-filters').slideDown()
  781. }
  782. this.filterShow = !this.filterShow
  783. },
  784. moneyUnit (m, type = 'string', lv = 0) {
  785. const mUnit = {
  786. levelArr: ['元', '万元', '亿元', '万亿元'],
  787. test (num, type, lv) {
  788. if (num === 0) {
  789. if (type === 'string') {
  790. return '0元'
  791. }
  792. if (type === 'lv') {
  793. return this.levelArr[lv]
  794. }
  795. if (type === 'number') {
  796. return 0
  797. }
  798. if (type === 'index') {
  799. return lv
  800. }
  801. }
  802. var result = num / Math.pow(10000, lv)
  803. if (result > 10000 && lv < 2) {
  804. return this.test(num, type, lv + 1)
  805. } else {
  806. if (type === 'string') {
  807. return String(Math.floor(result * 100) / 100).replace('.00', '') + this.levelArr[lv]
  808. }
  809. if (type === 'lv') {
  810. return this.levelArr[lv]
  811. }
  812. if (type === 'number') {
  813. return String(Math.floor(result * 100) / 100).replace('.00', '')
  814. }
  815. if (type === 'index') {
  816. return lv
  817. }
  818. }
  819. }
  820. }
  821. if (m === undefined || m === null) {
  822. return ''
  823. } else {
  824. return mUnit.test(m, type, lv)
  825. }
  826. },
  827. initCollectEvent () {
  828. const _this = this
  829. // 自定义标签
  830. // 标签输入框事件
  831. $('.tags-box').click(function (e) {
  832. e.stopPropagation()
  833. })
  834. $('.tag-input').click(function (e) {
  835. e.stopPropagation()
  836. $(this).children('.tag-placeholder').hide()
  837. $(this).children('input').focus()
  838. })
  839. // 标签输入框回车事件
  840. $('.tag-input .clear-input').keydown(function (event) {
  841. event.stopPropagation()
  842. if (event.keyCode == 13) {
  843. if (!$('.tags-box').is(':hidden')) {
  844. $('.tags-inputs .add-tag-button').trigger('click')
  845. }
  846. }
  847. })
  848. // 标签输入框失去焦点事件
  849. $('.tag-input .clear-input').blur(function () {
  850. if ($('.tag-labels').children().length == 0 && $(this).val() == '') {
  851. $('.tag-placeholder').show()
  852. }
  853. })
  854. // 添加标签按钮事件
  855. $('.tags-inputs .add-tag-button').on('click', function () {
  856. var input = $('.tag-input .clear-input')
  857. if (input.val().length >= 2 && input.val().length < 6) {
  858. // ajax提交自定义标签
  859. addTagsAjax(input.val())
  860. }
  861. })
  862. // 点击确定按钮,绑定标签
  863. $('.tags-footer .button-confirm').on('click', function () {
  864. if (!$('.tags-box').is(':hidden')) {
  865. var lids = ''
  866. var lname = ''
  867. $('.tags-item.tags-active').each(function () {
  868. if ($(this).attr('data-id')) {
  869. if (lids != '') {
  870. lids += ','
  871. }
  872. if (lname != '') {
  873. lname += ','
  874. }
  875. lids += $(this).attr('data-id')
  876. lname += $(this).text()
  877. }
  878. })
  879. var params = {
  880. name: _this.datas,
  881. mold: 1,
  882. D: false,
  883. label: lids
  884. }
  885. // 执行保存绑定标签操作
  886. // if (params.label !== '') {
  887. saveChooseTags(params, function () {
  888. $('.tags-footer .button-cancel').trigger('click')
  889. })
  890. // }
  891. }
  892. })
  893. $('.tags-footer .button-cancel').on('click', function () {
  894. $('.tags-box').slideToggle(function () {
  895. // 标签弹框消失时 清除上次选择的标签分类
  896. activeTags = []
  897. $('.tag-labels').empty()
  898. $('.clear-input').val('')
  899. $('.tags-list').find('.tags-item').removeClass('tags-active')
  900. $('.tag-placeholder').show()
  901. })
  902. })
  903. window.activeTags = [] // 选中的自定义标签 作为全局变量使用
  904. // 解绑自定义标签
  905. function deleteInputTag (item) {
  906. var index = $(item).parent().attr('data-index')
  907. var id = $(item).parent().attr('data-id')
  908. activeTags.splice(index, 1)
  909. inputTagList()
  910. $('.tags-item[data-id="' + id + '"]').removeClass('tags-active')
  911. }
  912. window.deleteInputTag = deleteInputTag
  913. function inputTagList () {
  914. var ht = ''
  915. $('.tag-labels').html(ht)
  916. activeTags.forEach(function (v, i) {
  917. ht += '<span class="tag-label" data-index=' + i + ' data-id="' + v.lid + '">'
  918. ht += '<em>' + v.lname + '</em>'
  919. ht += '<i class="tag-close" onclick="deleteInputTag(this)"></i>'
  920. ht += '</span>'
  921. })
  922. $('.tag-labels').html(ht)
  923. if ($('.tag-labels').children('.tag-label').length > 0) {
  924. $('.tag-placeholder').hide()
  925. }
  926. checkTagDisabled()
  927. }
  928. // 渲染标签列表数据
  929. function renderTagsList (data) {
  930. if (data && data.length > 0) {
  931. var ht = ''
  932. data.forEach(function (v, i) {
  933. ht += '<span class="tags-item" data-count=' + v.count + ' data-id=' + v.lid + '>' + v.lanme + '</span>'
  934. })
  935. $('.tags-list').html(ht)
  936. activeTags.forEach(function (s, j) {
  937. $('.tags-list .tags-item[data-id="' + s.lid + '"]').addClass('tags-active')
  938. })
  939. $('.tags-item').click(function (e) {
  940. e.stopPropagation()
  941. if ($(this).hasClass('disabled')) return
  942. var id = $(this).attr('data-id')
  943. var name = $(this).text()
  944. $(this).toggleClass('tags-active')
  945. if ($(this).hasClass('tags-active')) {
  946. activeTags.push({
  947. lid: id,
  948. lname: name
  949. })
  950. inputTagList()
  951. } else {
  952. var newArr = activeTags.filter(function (item) {
  953. return item.lid != id
  954. })
  955. activeTags = newArr
  956. inputTagList()
  957. }
  958. })
  959. }
  960. inputTagList()
  961. }
  962. // 获取用户自定义标签
  963. function getUserTags () {
  964. $.ajax({
  965. type: 'post',
  966. url: '/entnicheNew/customer/getLabel?t=' + Date.now(),
  967. success: function (r) {
  968. if (r.error_code == 0 && $.isArray(r.data)) {
  969. renderTagsList(r.data.reverse())
  970. }
  971. }
  972. })
  973. }
  974. window.getUserTags = getUserTags
  975. // 添加标签后认领接口
  976. function saveChooseTags (params, callback) {
  977. $.ajax({
  978. type: 'post',
  979. url: '/entnicheNew/customer/attention',
  980. contentType: 'application/json',
  981. data: JSON.stringify(params),
  982. dataType: 'json',
  983. success: function (r) {
  984. if (r.error_code == 0 && r.data) {
  985. $('.tags-box').slideToggle()
  986. _this.getList(_this.listState.pageNum)
  987. _this.$toast('认领成功!')
  988. _this.$emit('updatelist', true)
  989. callback && callback()
  990. } else {
  991. if (r.error_msg) {
  992. toastFn(r.error_msg, 2000)
  993. }
  994. }
  995. }
  996. })
  997. }
  998. // 新增标签
  999. function addTagsAjax (name) {
  1000. $.ajax({
  1001. type: 'post',
  1002. url: '/entnicheNew/customer/addLabel',
  1003. data: {
  1004. name: name
  1005. },
  1006. dataType: 'json',
  1007. success: function (r) {
  1008. if (r.data) {
  1009. $('.tag-input .clear-input').val('')
  1010. // 添加标签成功后 绑定标签
  1011. if (activeTags.length < 3) {
  1012. activeTags.push({
  1013. lid: r.data,
  1014. lname: name
  1015. })
  1016. }
  1017. getUserTags()
  1018. } else {
  1019. toastFn('标签已经存在,无需添加', 1000)
  1020. }
  1021. }
  1022. })
  1023. }
  1024. function checkTagDisabled () {
  1025. if (activeTags.length >= 3) {
  1026. // 禁用标签
  1027. $('.tags-list').find('.tags-item:not(.tags-active)').addClass('disabled')
  1028. } else {
  1029. // 解除禁用
  1030. $('.tags-list').find('.disabled').removeClass('disabled')
  1031. }
  1032. }
  1033. function baiduEvent (str) {
  1034. try {
  1035. // eslint-disable-next-line no-undef
  1036. _hmt.push(['_trackEvent', '大会员-pc', 'click', str])
  1037. } catch (e) {
  1038. console.log('未初始化百度统计')
  1039. }
  1040. }
  1041. getUserTags()
  1042. }
  1043. }
  1044. })