123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465 |
- 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',
- powerInfo: {},
- power: false,
- 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, // 采购单位联系方式
- bidPhone: 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: {}, // 当前要删除标签的信息
- }
- }
- },
- created: function () {
- var _this = this
- this.getPower(function () {
- if (_this.hasRestoreState()) {
- // 等TagList请求完成后在恢复数据
- _this.getTagList(function () {
- setTimeout(function () {
- var $data = _this.restorePageState()
- if (!$data) {
- _this.getList()
- }
- }, 0)
- })
- } else {
- _this.getTagList()
- _this.getList()
- }
- })
- },
- methods: {
- showToast: function (content, timer, callback) {
- 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
- this.checkPower()
- }
- }.bind(this),
- complete: function () {
- this.powerLoaded = true
- callback && callback()
- }.bind(this)
- })
- },
- checkPower: function () {
- this.power = this.powerInfo.entniche || this.powerInfo.member || this.powerInfo.vip !== 0
- if (!this.power) {
- this.listState.pageSize = 100
- }
- },
- getTagList: function (callback) {
- $.ajax({
- url: '/publicapply/bidcoll/getLabel',
- type: 'POST',
- success: function (res) {
- if (res.error_code === 0) {
- this.tagList = res.data || []
- this.initSelectTagList()
- 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(','),
- buyPhone: this.filterState.buyPhone ? this.filterState.buyPhone : 0,
- bidPhone: this.filterState.bidPhone ? this.filterState.bidPhone : 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
- item.star = true
- item.index = _this.calcListIndex(index)
- })
- this.listState.list = list || []
- }
- } else {
- this.listState.total = 0
- this.listState.list = []
- }
- }.bind(this),
- complete: function () {
- 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) {
- callback && callback()
- }
- }.bind(this)
- })
- },
- resetListState: function () {
- var state = {
- loaded: false,
- loading: false,
- pageNum: 1, // 当前页
- total: 0, // 一共多少条数据
- list: []
- }
- Object.assign(this.listState, state)
- },
- onPageChange: function (p) {
- this.listState.pageNum = p
- this.getList()
- },
- 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.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.doQuery()
- },
- buyerClassFilterChange: function (buyerclass) {
- var buyerclassArr = []
- this.filterState.buyerclassObj = buyerclass
- for (var key in buyerclass) {
- buyerclassArr = buyerclassArr.concat(buyerclass[key])
- }
- this.filterState.buyerclass = buyerclassArr
- this.doQuery()
- },
- otherFilterChange: function (t) {
- this.doQuery()
- },
- changeListType: function (type) {
- this.listState.listType = type
- },
- dataExport: function () {
- var info = this.getSelectedIdArr()
- var ids = info.ids
- var data = null
- if (ids.length === 0) {
- data = {
- label: this.filterState.tags.join(','),
- selectTime: this.filterState.selectTime,
- buyerclass: this.filterState.buyerclass.join(','),
- buyPhone: this.filterState.buyPhone ? this.filterState.buyPhone : 0,
- bidPhone: this.filterState.bidPhone ? this.filterState.bidPhone : 0
- }
- } else {
- data = {
- selectIds: ids.join(',')
- }
- }
- $.ajax({
- url: '/publicapply/dataexpoet/bycollection',
- type: 'POST',
- data: data,
- success: function (res) {
- if (res.error_code === 0) {
- if (res.data._id) {
- this.savePageState()
- location.href = '/front/dataExport/toCreateOrderPage/' + res.data._id
- }
- }
- }.bind(this)
- })
- },
- // 批量取消收藏
- unStarSelected: function () {
- baiduEvent('列表页标讯收藏-星标') // 收藏按钮百度统计
- var _this = this
- var info = this.getSelectedIdArr()
- var ids = info.ids
- var selectedArr = info.arr
- if (ids.length === 0) {
- return this.showToast('请选择收藏信息')
- }
- this.bidCollectAction(ids, function () {
- selectedArr.forEach(function (item) {
- item.star = false
- })
- _this.showToast('已取消收藏', null, function () {
- _this.getList()
- })
- })
- },
- unStarThis: function (item) {
- baiduEvent('列表页标讯收藏-星标') // 收藏按钮百度统计
- var _this = this
- this.bidCollectAction([item._id], function () {
- _this.showToast('已取消收藏', null, function () {
- item.star = false
- _this.getList()
- })
- })
- },
- 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) {
- 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) {
- this.listState.list.forEach(function (item) {
- item.selected = state
- })
- },
- listItemCheckboxChange: function () {
- var arr = []
- this.listState.list.forEach(function (item) {
- arr.push(item.selected)
- })
- this.currentPageAllChecked = arr.indexOf(false) === -1
- },
- openTagDrawer: function () {
- this.tagDrawer.show = true
- },
- drawerConfirm: function () {
- this.tagDrawer.show = false
- },
- drawerCancel: function () {
- this.tagDrawer.show = false
- },
- delThisTag: function (tag) {
- this.tagDrawer.dialogShow = true
- this.tagDrawer.currentDelTagInfo = tag
- },
- 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()
- }, 1500)
- }
- }
- }.bind(this)
- })
- },
- savePageState: function () {
- var data = {
- filterState: this.filterState,
- listState: this.listState,
- currentSelectItems: this.currentSelectItems,
- currentPageAllChecked: this.currentPageAllChecked
- }
- 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 || {})
- // 恢复页面状态
- this.currentPageAllChecked = $data.currentPageAllChecked
- sessionStorage.removeItem(this.sessKey)
- }
- return !!$data
- }
- }
- })
|