var vm = new Vue({ el: '.search-content', delimiters: ['${', '}'], components: { selectListComponent: selectListComponent, dateTimeComponent: dateTimeComponent, selectLevel2Component: selectLevel2Component, articleItemComponent: articleItemComponent, noData: noDataComponent }, data: function () { return { 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: [], timeStart: 0, timeEnd: 0, buyerclass: [], buyerPhone: 0, // 采购单位联系方式 bidPhone: 0, // 中标企业联系方式 }, listState: { listType: 'line', // line/table loaded: false, // 是否已经搜索过 loading: false, pageNum: 1, // 当前页 pageSize: 50, // 每页多少条数据 total: 0, // 一共多少条数据 list: [] // 查询请求返回的数据 }, currentPageAllChecked: false, tagDrawer: { dialogShow: false, toastShow: false, show: false, currentDelTagInfo: {}, // 当前要删除标签的信息 } } }, created: function () { this.getPower(function () { this.getTagList() this.getList() }.bind(this)) }, mounted: function () {}, 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 () { $.ajax({ url: '/publicapply/bidcoll/getLabel', type: 'POST', success: function (res) { if (res.error_code === 0 && res.data) { this.tagList = res.data this.initSelectTagList() } }.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.timeStart / 1000 + '_' + this.filterState.timeEnd / 1000, 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.timeStart = t.start this.filterState.timeEnd = t.end this.doQuery() }, buyerClassFilterChange: function (buyerclass) { var buyerclassArr = [] 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 if (ids.length !== 0) { return window.open('/front/dataExport/superSearchExport?selectIds=' + ids.join(',')) } }, // 批量取消收藏 unStarSelected: function () { 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) { 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) } }) 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) }) }, } })