pur-search-index-pc.js 43 KB

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