var selectDataIds = [] var inInjectBI = getParam('report') === 'bi' // 是否bi嵌入 if (inInjectBI) { $('body').addClass('in-bi') } var vm = new Vue({ el: '.search-content', delimiters: ['${', '}'], components: { selectListComponent: selectListComponent, dateTimeComponent: dateTimeComponent, selectLevel2Component: selectLevel2Component, articleItemComponent: articleItemComponent, noData: noDataComponent }, data: function () { return { sessKey: '$data-collection-index', inInjectBI: inInjectBI, bi: { loading: false, addedIds: [] }, powerInfo: {}, powerLoaded: false, toast: { show: false, content: '暂无数据' }, buyclassMap: buyclassArr, tagList: [], tagSelectList: [], buyerPhoneOptions: [ { label: '不限', value: 0 }, { label: '有联系方式', value: 1 }, { label: '无联系方式', value: -1 } ], filterState: { tags: [], selectTime: '', timeSelectorObj: { start: '', end: '', exact: '' }, buyerclass: [], buyerclassObj: {}, // buyerclass原始选中数据 buyerPhone: 0, // 采购单位联系方式 winnerPhone: 0, // 中标企业联系方式 }, listState: { listType: 'line', // line/table loaded: false, // 是否已经搜索过 loading: false, pageNum: 1, // 当前页 pageSize: 50, // 每页多少条数据 total: 0, // 一共多少条数据 list: [] // 查询请求返回的数据 }, currentPageAllChecked: false, currentSelectItems: [], tagDrawer: { dialogShow: false, toastShow: false, show: false, currentDelTagInfo: {}, // 当前要删除标签的信息 }, addTagInfo: { content: '' }, powerDialogShow: false, urlFilterTagId: [], tableShowData: [], tableFirst20: [], checkNum: 0, exportChecked: false } }, watch: { exportChecked (newval) { $.ajax({ type: 'POST', url: '/front/dataExport/setDontPromptAgain', contentType: 'application/x-www-form-urlencoded', data: { status: newval ? '1' : '0' } }) } }, computed: { biEnv: function () { return this.inInjectBI }, power: function () { return this.powerInfo.entniche || this.powerInfo.member || this.powerInfo.vip !== 0 } }, created: function () { var _this = this var tag = utils.getParam('tag') if (tag) { this.urlFilterTagId = tag.split(',') } if (this.biEnv) { this.getBiAddedProjects() } this.getPower(function () { if (_this.hasRestoreState()) { // 等TagList请求完成后在恢复数据 _this.getTagList(function () { setTimeout(function () { var $data = _this.restorePageState() if (!$data) { _this.getList() } }, 0) }) } else { _this.getTagList(function () { _this.getList() }) } }) var _this = this document.addEventListener('visibilitychange', function() { if (document.visibilityState === 'visible') { _this.getBidIsJoin() } }) }, methods: { showToast: function (content, timer, callback) { if (this.toast.show) return content = content || '暂无数据' timer = timer || 2000 this.toast.content = content this.toast.show = true setTimeout(function () { this.toast.show = false callback && callback() }.bind(this), timer) }, getPower: function (callback) { $.ajax({ url: '/publicapply/bidcoll/power', type: 'POST', success: function (res) { if (res.error_code === 0 && res.data) { this.powerInfo = res.data if (!this.power) { // this.listState.pageSize = 100 } } }.bind(this), complete: function () { this.powerLoaded = true callback && callback() }.bind(this) }) }, getTagList: function (callback) { $.ajax({ url: '/publicapply/bidcoll/getLabel', type: 'POST', success: function (res) { if (res.error_code === 0) { if (res.data) { this.tagList = res.data.reverse() } else { this.tagList = [] } this.initSelectTagList() if (this.urlFilterTagId.length) { this.filterState.tags = this.filterState.tags.concat(this.urlFilterTagId) } callback && callback() } }.bind(this) }) }, getList: function () { var _this = this var data = { pagenum: this.listState.pageNum, pagesize: this.listState.pageSize, label: this.filterState.tags.join(','), selectTime: this.filterState.selectTime, buyerclass: this.filterState.buyerclass.join(','), buyerPhone: this.filterState.buyerPhone ? this.filterState.buyerPhone : 0, winnerPhone: this.filterState.winnerPhone ? this.filterState.winnerPhone : 0 } this.listState.loading = true this.listState.loaded = false $.ajax({ url: '/publicapply/bidcoll/list', type: 'POST', contentType: 'application/json', data: JSON.stringify(data), success: function (res) { if (res.error_code === 0 && res.data) { var list = res.data.res if (res.data.count) { _this.listState.total = res.data.count } // 给list添加额外属性 if (list) { list.forEach(function (item, index) { item.selected = false selectDataIds.forEach((sum, i) => { if(item._id == sum) { item.selected = true } }) if(!item.selected) { _this.currentPageAllChecked = false } else { _this.currentPageAllChecked = true } item.joinBid = undefined item.star = true item.index = _this.calcListIndex(index) try { item.visited = visitedPath.pathVisited( new VisitedPathItem( '/article/content/*.html', 'id=' + item._id ) ) } catch (error) {} }) this.listState.list = list || [] if (_this.listState.pageNum === 1 && _this.listState.pageSize >= 50) { _this.tableShowData = list || [] _this.tableFirst20 = list.slice(0, 20) } // 获取参标数据 _this.getBidIsJoin() } } else { this.listState.total = 0 this.listState.list = [] } }.bind(this), complete: function () { this.checkAddedState() this.listState.loading = false this.listState.loaded = true }.bind(this) }) }, bidCollectAction: function (ids, callback) { var binfo = [] ids.forEach(function (item) { binfo.push({ bid: item }) }) var data = { baction: 'R', binfo: binfo } $.ajax({ url: '/publicapply/bidcoll/action', type: 'POST', contentType: 'application/json', data: JSON.stringify(data), success: function (res) { if (res.error_code === 0 && res.data) { selectDataIds = [] callback && callback() } }.bind(this) }) }, addTagConfirmed: function () { var name = this.addTagInfo.content if (!name) return $.ajax({ url: '/publicapply/bidcoll/addLabel', type: 'POST', data: { name: name }, success: function (res) { if (res.error_code === 0 && res.data) { this.addTagInfo.content = '' this.tagList.unshift({ count: 0, lanme: name, lid: res.data }) // 数组去重 this.tagList = utils.unique(this.tagList) this.initSelectTagList() // 重新请求数据 this.filterState.tags = [] this.doQuery() } else { // this.showToast(res.error_msg) this.showToast('标签已经存在,无需添加') } }.bind(this) }) }, resetListState: function () { var state = { loaded: false, loading: false, pageNum: 1, // 当前页 pageSize: 50, total: 0, // 一共多少条数据 list: [] } Object.assign(this.listState, state) }, onPageChange: function (p) { this.listState.pageNum = p var info = this.getSelectedIdArr() var ids = info.ids if(selectDataIds.length == 0) { selectDataIds = ids } else { ids.forEach((item, index) => { //避免重复添加(若存在元素时,不添加) if(!this.contains(selectDataIds, item)) { selectDataIds.push(item) } }) } this.getList() }, contains: function (arr, ele) { if(arr.length == 0){ return; } var i = arr.length; while (i--) { if (arr[i] == ele) { return true; } } return false; }, doQuery: function () { this.resetListState() this.getList() }, initSelectTagList: function () { var arr = [] this.tagList.forEach(function (item) { arr.push({ label: item.lanme, value: item.lid, count: item.count }) }) this.tagSelectList = arr }, tagFilterChange: function (tagList) { this.filterState.tags = tagList this.clearSelectState() this.doQuery() }, dateTimeFilterChange: function (t) { this.filterState.timeSelectorObj = t var arr = [] if (t.start) { arr.push(t.start / 1000) } if (t.end) { arr.push(t.end / 1000) } if (arr.length === 0) { this.filterState.selectTime = '' } else { this.filterState.selectTime = arr.join('_') } this.clearSelectState() this.doQuery() }, buyerClassFilterChange: function (buyerclass) { if (this.power) { var buyerclassArr = [] this.filterState.buyerclassObj = buyerclass for (var key in buyerclass) { buyerclassArr = buyerclassArr.concat(buyerclass[key]) } this.filterState.buyerclass = buyerclassArr this.clearSelectState() this.doQuery() } else { this.$refs.buyerClassFilter.setState() this.filterState.buyerclass = '' this.powerDialogShow = true } }, otherFilterChange: function (t) { if (this.power) { this.clearSelectState() this.doQuery() } else { this.filterState.buyerPhone = 0 this.filterState.winnerPhone = 0 this.powerDialogShow = true } }, changeListType: function (type) { this.listState.listType = type }, dataExport: function () { const _this = this //数据导出 $.ajax({ type: "POST", url: "/front/dataExport/getDontPromptAgain", contentType: "application/x-www-form-urlencoded", success: function (res) { if(res.error_code === 0) { // 数据导出-判断是否展示弹框 if(res.isPrompt && _this.listState.total >= 20000) { $('.have-thousand-dialog').show() // 获取微信客服二维码 if (window.customers && window.customers.length > 0) { const customerInfo = window.customers.filter(v => v.name === '高静') if (customerInfo) { const html = `` $('.custom-wx').html(html) } } } else { $('.have-thousand-dialog').hide() // _this.toDataExportEvent() } } else { $('.have-thousand-dialog').hide() // _this.toDataExportEvent() } }, error: function(err) { // _this.toDataExportEvent() } }) }, toDataExportEvent: function () { this.onPageChange(this.listState.pageNum) var info = this.getSelectedIdArr() var ids = info.ids var data = null if (ids.length === 0 && selectDataIds.length === 0) { data = { label: this.filterState.tags.join(','), selectTime: this.filterState.selectTime, buyerclass: this.filterState.buyerclass.join(','), buyerPhone: this.filterState.buyerPhone ? this.filterState.buyerPhone : 0, winnerPhone: this.filterState.winnerPhone ? this.filterState.winnerPhone : 0 } } else { data = { selectIds: selectDataIds.join(',') } } $.ajax({ url: '/publicapply/dataexpoet/bycollection', type: 'POST', data: data, success: function (res) { if (res.error_code === 0) { if (res.data._id) { this.savePageState() this.listState.loaded = true location.href = '/front/dataExport/toCreateOrderPage/' + res.data._id } } }.bind(this) }) }, setCloseDialog () { $('.have-thousand-dialog').hide() }, setCheckBox ($this, type) { $($this).hide() if (type === 'open') { $('.el-icon-check').show() } else { $('.bif-checkbox').show() } }, checkNotEnoughOnePage: function (unStarCount) { // 当前数据总共多少页数据 var totalPageCount = Math.ceil(this.listState.total / this.listState.pageSize) // 选中数量大于等于当前页数量 var lastCount = this.listState.list.length - unStarCount // 剩余几页数据 var lastPageCount = Math.ceil((this.listState.total - unStarCount) / this.listState.pageSize) // 取消了几页数据 var unStarPageCount = totalPageCount - lastPageCount console.log('剩余几页数据', lastPageCount) return { notEnoughOnePage: lastCount <= 0, lastPageCount: lastPageCount, unStarPageCount: unStarPageCount } }, getListAfterUnStar: function (unStarCount) { var unStarInfo = this.checkNotEnoughOnePage(unStarCount) if (unStarInfo.notEnoughOnePage) { var diff = this.listState.pageNum - unStarInfo.unStarPageCount if (diff <= 1) { this.doQuery() } else { this.onPageChange(diff) } } else { this.getList() } }, // 批量取消收藏 unStarSelected: function () { baiduEvent('列表页标讯收藏-星标') // 收藏按钮百度统计 var _this = this var info = this.getSelectedIdArr() var ids = info.ids var selectedArr = info.arr if (ids.length === 0 && selectDataIds.length == 0) { return this.showToast('请选择收藏信息') } if(selectDataIds.length !== 0) { ids = selectDataIds } this.bidCollectAction(ids, function () { _this.showToast('已取消收藏', null) _this.getListAfterUnStar(ids.length) }) }, clearSelectState: function () { selectDataIds = [] this.listState.list.forEach(function (item) { item.selected = selectDataIds.indexOf(item._id) !== -1 }) }, unStarThis: function (item) { baiduEvent('列表页标讯收藏-星标') // 收藏按钮百度统计 var _this = this this.bidCollectAction([item._id], function () { _this.showToast('已取消收藏', null, function () {}) _this.getListAfterUnStar(1) }) }, getSelectedIdArr: function () { var arr = [] var ids = [] this.listState.list.forEach(function (item) { if (item.selected) { arr.push(item) ids.push(item._id) } }) this.currentSelectItems = ids return { ids: ids, arr: arr } }, toListDetail: function (item) { try { item.visited = true visitedPath.pathVisiting( new VisitedPathItem( '/article/content/*.html', 'id=' + item._id ) ) } catch (error) {} window.open('/article/content/' + item._id + '.html') }, calcArticleItemTags: function (article) { var arr = [] if (article.area) { arr.push(article.area) } if (article.buyerclass) { arr.push(article.buyerclass) } if (article.type) { arr.push(article.type) } if (article.budget) { arr.push(utils.moneyUnit(article.budget)) } return arr }, calcListIndex: function (index) { return (this.listState.pageSize * (this.listState.pageNum - 1)) + index + 1 }, calcMoney: function (m) { if (m) { return parseInt(utils.moneyUnit(m)) } else { return '' } }, calcArticleType: function (type) { if (type) { return type + '公告' } else { return '' } }, calcTime: function (time, pattern) { if (time) { var t = new Date(time) return t.pattern(pattern) } else { return '' } }, allCheckboxChange: function (state) { let _this = this this.listState.list.forEach(function (item) { if(state) { if(!_this.contains(selectDataIds,item._id)) { selectDataIds.push(item._id) } } else { selectDataIds.forEach(function(v,index) { if (v == item._id) { selectDataIds.splice(index, 1) } }) } item.selected = state }) this.checkNum = selectDataIds? selectDataIds.length : 0 }, listItemCheckboxChange: function (data, check) { if (check) { if(!this.contains(selectDataIds, data)) { selectDataIds.push(data) } } else { selectDataIds.forEach(function(v,index) { if (v == data) { selectDataIds.splice(index, 1) } }) } var arr = [] this.listState.list.forEach(function (item) { arr.push(item.selected) }) this.currentPageAllChecked = arr.indexOf(false) === -1 this.checkNum = selectDataIds? selectDataIds.length : 0 }, openTagDrawer: function () { this.tagDrawer.show = true }, openVipPage: function () { window.open('/front/subscribe.html') }, drawerConfirm: function () { this.tagDrawer.show = false }, drawerCancel: function () { this.tagDrawer.show = false }, delThisTag: function (tag) { this.tagDrawer.dialogShow = true for (var key in tag) { this.$set(this.tagDrawer.currentDelTagInfo, key, tag[key]) } }, delThisTagConfirm: function () { var _this = this var data = { lids: this.tagDrawer.currentDelTagInfo.value, lname: this.tagDrawer.currentDelTagInfo.label, laction: 'D' } $.ajax({ url: '/publicapply/bidcoll/label', type: 'POST', contentType: 'application/json', data: JSON.stringify(data), success: function (res) { if (res.error_code === 0) { _this.tagDrawer.dialogShow = false if (res.data) { _this.tagDrawer.toastShow = true setTimeout(function () { _this.tagDrawer.toastShow = false _this.getTagList() // 重新请求数据 _this.filterState.tags = [] _this.doQuery() }, 1500) } } }.bind(this) }) }, savePageState: function () { var data = { filterState: this.filterState, listState: this.listState, currentSelectItems: this.currentSelectItems, currentPageAllChecked: this.currentPageAllChecked, selectDataIds: selectDataIds, tableShowData: this.tableShowData, tableFirst20: this.tableFirst20 } this.listState.loaded = true sessionStorage.setItem(this.sessKey, JSON.stringify(data)) }, hasRestoreState: function () { return !!sessionStorage.getItem(this.sessKey) }, restorePageState: function () { var $data = sessionStorage.getItem(this.sessKey) if ($data) { $data = JSON.parse($data) // 恢复数据 Object.assign(this.filterState, $data.filterState || {}) Object.assign(this.listState, $data.listState || {}) Object.assign(this.currentSelectItems, $data.currentSelectItems || {}) Object.assign(this.tableShowData, $data.tableShowData || []) Object.assign(this.tableFirst20, $data.tableFirst20 || []) selectDataIds = $data.selectDataIds this.listState.loading = false // 恢复页面状态 this.currentPageAllChecked = $data.currentPageAllChecked sessionStorage.removeItem(this.sessKey) } return !!$data }, onSizeChange: function (val) { this.listState.pageSize = val this.listState.pageNum = 1 this.onPageChange(this.listState.pageNum) }, getBiAddedProjects: function () { $.ajax({ url: '/jyapi/biService/getInfoId', type: 'POST', success: function (res) { if (res && res.error_code === 0 && $.isArray(res.data)) { this.bi.addedIds = res.data this.checkAddedState() } }.bind(this) }) }, checkAddedState: function () { var _this = this var addedIds = this.bi.addedIds || [] if (!$.isArray(addedIds)) return if (addedIds.length === 0) return this.listState.list.forEach(function (item) { var added = addedIds.indexOf(item._id) !== -1 _this.$set(item, 'added', added) }) }, // 单个添加 biAddProject: function (item) { if (item.added) return const id = item._id if (!id) return this.biBatchAddRequest([id]) }, // bi下批量操作 biBatchAddSelected: function () { var ids = selectDataIds if (!$.isArray(ids)) return if (ids.length === 0) { return this.showToast('请选择要添加的信息') } this.biBatchAddRequest(ids) }, biBatchAddRequest: function (ids) { if (this.bi.loading) return this.bi.loading = true var _this = this var data = { info_id: ids.join(','), source: 1 } $.ajax({ url: '/jyapi/biService/addProject', type: 'POST', contentType: 'application/json', data: JSON.stringify(data), success: function (res) { if (res) { if (res.error_code === 0) { if (res.data && res.data.status === 1) { _this.clearSelectState() _this.showToast('添加成功') } _this.getBiAddedProjects() } else { if (res.error_msg) { _this.showToast(res.error_msg) } } } }, complete: function () { _this.bi.loading = false } }) }, // 获取参标数据 getBidIsJoin: function () { var _this = this var paramsData = { ids: _this.listState.list.map(function(item){ return item._id }).join() } $.ajax({ type: 'post', contentType: "application/json", url: '/jyapi/jybx/core/participate/show?t=' + Date.now(), data: JSON.stringify(paramsData), dataType: 'json', success: function (r) { if (r.data && r.error_code == 0) { var data = r.data || [] if(data.length > 0) { Bidrenewal_Dialog.initBidrenewalDialog = true // 加载参标状态更新弹窗 } data.forEach(function(item) { _this.listState.list.forEach(function(temp) { if (item.id == temp._id) { temp.joinBid = Boolean(item.value) } }) }) } } }) }, /******参标********/ /** * 参标、终止参标 * @param action in:参标;out:终止参标;transfer:划转 * @param bidIds 招标信息id(加密) 必传 * @param projectIds 项目信息id ,多个,号隔开 划转和终止参标必传(bidIds和projectIds必传一个) * @param callback */ joinBidAction: function (item) { if(item.joinBid) { return this.showToast('如需终止参标,需要在详情页进行操作。') } var params = { bidIds: item._id } var _this = this $.ajax({ type:'post', contentType: "application/json", url:'/jyapi/jybx/core/participate/in/info', data: JSON.stringify(params), dataType: 'json', success: function(r){ if (r && r.data && r.error_code == 0) { item.joinBid = true // _this.showToast('已参标,请前往我的参标项目列表查看。') try{ Bidrenewal_Dialog.sendId(item._id) window.$BidrenewalDialog.open() }catch(e){ setTimeout(function() { Bidrenewal_Dialog.sendId(item._id) window.$BidrenewalDialog.open() } , 100) } } else if(r.error_code == -1) { var msg = r.error_msg || '参标错误,请稍后重试' _this.showToast(msg) } } }) }, goCollect: function () { window.open('/page_workDesktop/work-bench/page?link=' + encodeURIComponent(location.origin + '/jylab/supsearch/index.html')) } } })