index-pc.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. var vm = new Vue({
  2. el: '.search-content',
  3. delimiters: ['${', '}'],
  4. components: {
  5. selectListComponent: selectListComponent,
  6. dateTimeComponent: dateTimeComponent,
  7. selectLevel2Component: selectLevel2Component,
  8. articleItemComponent: articleItemComponent,
  9. noData: noDataComponent
  10. },
  11. data: function () {
  12. return {
  13. sessKey: '$data-collection-index',
  14. powerInfo: {},
  15. power: false,
  16. powerLoaded: false,
  17. toast: {
  18. show: false,
  19. content: '暂无数据'
  20. },
  21. buyclassMap: buyclassArr,
  22. tagList: [],
  23. tagSelectList: [],
  24. buyerPhoneOptions: [
  25. {
  26. label: '不限',
  27. value: 0
  28. },
  29. {
  30. label: '有联系方式',
  31. value: 1
  32. },
  33. {
  34. label: '无联系方式',
  35. value: -1
  36. }
  37. ],
  38. filterState: {
  39. tags: [],
  40. selectTime: '',
  41. timeSelectorObj: {
  42. start: '',
  43. end: '',
  44. exact: ''
  45. },
  46. buyerclass: [],
  47. buyerclassObj: {}, // buyerclass原始选中数据
  48. buyerPhone: 0, // 采购单位联系方式
  49. bidPhone: 0, // 中标企业联系方式
  50. },
  51. listState: {
  52. listType: 'line', // line/table
  53. loaded: false, // 是否已经搜索过
  54. loading: false,
  55. pageNum: 1, // 当前页
  56. pageSize: 50, // 每页多少条数据
  57. total: 0, // 一共多少条数据
  58. list: [] // 查询请求返回的数据
  59. },
  60. currentPageAllChecked: false,
  61. currentSelectItems: [],
  62. tagDrawer: {
  63. dialogShow: false,
  64. toastShow: false,
  65. show: false,
  66. currentDelTagInfo: {}, // 当前要删除标签的信息
  67. }
  68. }
  69. },
  70. created: function () {
  71. var _this = this
  72. this.getPower(function () {
  73. if (_this.hasRestoreState()) {
  74. // 等TagList请求完成后在恢复数据
  75. _this.getTagList(function () {
  76. setTimeout(function () {
  77. var $data = _this.restorePageState()
  78. if (!$data) {
  79. _this.getList()
  80. }
  81. }, 0)
  82. })
  83. } else {
  84. _this.getTagList()
  85. _this.getList()
  86. }
  87. })
  88. },
  89. methods: {
  90. showToast: function (content, timer, callback) {
  91. content = content || '暂无数据'
  92. timer = timer || 2000
  93. this.toast.content = content
  94. this.toast.show = true
  95. setTimeout(function () {
  96. this.toast.show = false
  97. callback && callback()
  98. }.bind(this), timer)
  99. },
  100. getPower: function (callback) {
  101. $.ajax({
  102. url: '/publicapply/bidcoll/power',
  103. type: 'POST',
  104. success: function (res) {
  105. if (res.error_code === 0 && res.data) {
  106. this.powerInfo = res.data
  107. this.checkPower()
  108. }
  109. }.bind(this),
  110. complete: function () {
  111. this.powerLoaded = true
  112. callback && callback()
  113. }.bind(this)
  114. })
  115. },
  116. checkPower: function () {
  117. this.power = this.powerInfo.entniche || this.powerInfo.member || this.powerInfo.vip !== 0
  118. if (!this.power) {
  119. this.listState.pageSize = 100
  120. }
  121. },
  122. getTagList: function (callback) {
  123. $.ajax({
  124. url: '/publicapply/bidcoll/getLabel',
  125. type: 'POST',
  126. success: function (res) {
  127. if (res.error_code === 0) {
  128. this.tagList = res.data || []
  129. this.initSelectTagList()
  130. callback && callback()
  131. }
  132. }.bind(this)
  133. })
  134. },
  135. getList: function () {
  136. var _this = this
  137. var data = {
  138. pagenum: this.listState.pageNum,
  139. pagesize: this.listState.pageSize,
  140. label: this.filterState.tags.join(','),
  141. selectTime: this.filterState.selectTime,
  142. buyerclass: this.filterState.buyerclass.join(','),
  143. buyPhone: this.filterState.buyPhone ? this.filterState.buyPhone : 0,
  144. bidPhone: this.filterState.bidPhone ? this.filterState.bidPhone : 0
  145. }
  146. this.listState.loading = true
  147. this.listState.loaded = false
  148. $.ajax({
  149. url: '/publicapply/bidcoll/list',
  150. type: 'POST',
  151. contentType: 'application/json',
  152. data: JSON.stringify(data),
  153. success: function (res) {
  154. if (res.error_code === 0 && res.data) {
  155. var list = res.data.res
  156. if (res.data.count) {
  157. this.listState.total = res.data.count
  158. }
  159. // 给list添加额外属性
  160. if (list) {
  161. list.forEach(function (item, index) {
  162. item.selected = false
  163. item.star = true
  164. item.index = _this.calcListIndex(index)
  165. })
  166. this.listState.list = list || []
  167. }
  168. } else {
  169. this.listState.total = 0
  170. this.listState.list = []
  171. }
  172. }.bind(this),
  173. complete: function () {
  174. this.listState.loading = false
  175. this.listState.loaded = true
  176. }.bind(this)
  177. })
  178. },
  179. bidCollectAction: function (ids, callback) {
  180. var binfo = []
  181. ids.forEach(function (item) {
  182. binfo.push({
  183. bid: item
  184. })
  185. })
  186. var data = {
  187. baction: 'R',
  188. binfo: binfo
  189. }
  190. $.ajax({
  191. url: '/publicapply/bidcoll/action',
  192. type: 'POST',
  193. contentType: 'application/json',
  194. data: JSON.stringify(data),
  195. success: function (res) {
  196. if (res.error_code === 0 && res.data) {
  197. callback && callback()
  198. }
  199. }.bind(this)
  200. })
  201. },
  202. resetListState: function () {
  203. var state = {
  204. loaded: false,
  205. loading: false,
  206. pageNum: 1, // 当前页
  207. total: 0, // 一共多少条数据
  208. list: []
  209. }
  210. Object.assign(this.listState, state)
  211. },
  212. onPageChange: function (p) {
  213. this.listState.pageNum = p
  214. this.getList()
  215. },
  216. doQuery: function () {
  217. this.resetListState()
  218. this.getList()
  219. },
  220. initSelectTagList: function () {
  221. var arr = []
  222. this.tagList.forEach(function (item) {
  223. arr.push({
  224. label: item.lanme,
  225. value: item.lid,
  226. count: item.count
  227. })
  228. })
  229. this.tagSelectList = arr
  230. },
  231. tagFilterChange: function (tagList) {
  232. this.filterState.tags = tagList
  233. this.doQuery()
  234. },
  235. dateTimeFilterChange: function (t) {
  236. this.filterState.timeSelectorObj = t
  237. var arr = []
  238. if (t.start) {
  239. arr.push(t.start / 1000)
  240. }
  241. if (t.end) {
  242. arr.push(t.end / 1000)
  243. }
  244. if (arr.length === 0) {
  245. this.filterState.selectTime = ''
  246. } else {
  247. this.filterState.selectTime = arr.join('_')
  248. }
  249. this.doQuery()
  250. },
  251. buyerClassFilterChange: function (buyerclass) {
  252. var buyerclassArr = []
  253. this.filterState.buyerclassObj = buyerclass
  254. for (var key in buyerclass) {
  255. buyerclassArr = buyerclassArr.concat(buyerclass[key])
  256. }
  257. this.filterState.buyerclass = buyerclassArr
  258. this.doQuery()
  259. },
  260. otherFilterChange: function (t) {
  261. this.doQuery()
  262. },
  263. changeListType: function (type) {
  264. this.listState.listType = type
  265. },
  266. dataExport: function () {
  267. var info = this.getSelectedIdArr()
  268. var ids = info.ids
  269. var data = null
  270. if (ids.length === 0) {
  271. data = {
  272. label: this.filterState.tags.join(','),
  273. selectTime: this.filterState.selectTime,
  274. buyerclass: this.filterState.buyerclass.join(','),
  275. buyPhone: this.filterState.buyPhone ? this.filterState.buyPhone : 0,
  276. bidPhone: this.filterState.bidPhone ? this.filterState.bidPhone : 0
  277. }
  278. } else {
  279. data = {
  280. selectIds: ids.join(',')
  281. }
  282. }
  283. $.ajax({
  284. url: '/publicapply/dataexpoet/bycollection',
  285. type: 'POST',
  286. data: data,
  287. success: function (res) {
  288. if (res.error_code === 0) {
  289. if (res.data._id) {
  290. this.savePageState()
  291. location.href = '/front/dataExport/toCreateOrderPage/' + res.data._id
  292. }
  293. }
  294. }.bind(this)
  295. })
  296. },
  297. // 批量取消收藏
  298. unStarSelected: function () {
  299. baiduEvent('列表页标讯收藏-星标') // 收藏按钮百度统计
  300. var _this = this
  301. var info = this.getSelectedIdArr()
  302. var ids = info.ids
  303. var selectedArr = info.arr
  304. if (ids.length === 0) {
  305. return this.showToast('请选择收藏信息')
  306. }
  307. this.bidCollectAction(ids, function () {
  308. selectedArr.forEach(function (item) {
  309. item.star = false
  310. })
  311. _this.showToast('已取消收藏', null, function () {
  312. _this.getList()
  313. })
  314. })
  315. },
  316. unStarThis: function (item) {
  317. baiduEvent('列表页标讯收藏-星标') // 收藏按钮百度统计
  318. var _this = this
  319. this.bidCollectAction([item._id], function () {
  320. _this.showToast('已取消收藏', null, function () {
  321. item.star = false
  322. _this.getList()
  323. })
  324. })
  325. },
  326. getSelectedIdArr: function () {
  327. var arr = []
  328. var ids = []
  329. this.listState.list.forEach(function (item) {
  330. if (item.selected) {
  331. arr.push(item)
  332. ids.push(item._id)
  333. }
  334. })
  335. this.currentSelectItems = ids
  336. return {
  337. ids: ids,
  338. arr: arr
  339. }
  340. },
  341. toListDetail: function (item) {
  342. window.open('/article/content/' + item._id + '.html')
  343. },
  344. calcArticleItemTags: function (article) {
  345. var arr = []
  346. if (article.area) {
  347. arr.push(article.area)
  348. }
  349. if (article.buyerclass) {
  350. arr.push(article.buyerclass)
  351. }
  352. if (article.type) {
  353. arr.push(article.type)
  354. }
  355. if (article.budget) {
  356. arr.push(utils.moneyUnit(article.budget))
  357. }
  358. return arr
  359. },
  360. calcListIndex: function (index) {
  361. return (this.listState.pageSize * (this.listState.pageNum - 1)) + index + 1
  362. },
  363. calcMoney: function (m) {
  364. if (m) {
  365. return parseInt(utils.moneyUnit(m))
  366. } else {
  367. return ''
  368. }
  369. },
  370. calcArticleType: function (type) {
  371. if (type) {
  372. return type + '公告'
  373. } else {
  374. return ''
  375. }
  376. },
  377. calcTime: function (time, pattern) {
  378. if (time) {
  379. var t = new Date(time)
  380. return t.pattern(pattern)
  381. } else {
  382. return ''
  383. }
  384. },
  385. allCheckboxChange: function (state) {
  386. this.listState.list.forEach(function (item) {
  387. item.selected = state
  388. })
  389. },
  390. listItemCheckboxChange: function () {
  391. var arr = []
  392. this.listState.list.forEach(function (item) {
  393. arr.push(item.selected)
  394. })
  395. this.currentPageAllChecked = arr.indexOf(false) === -1
  396. },
  397. openTagDrawer: function () {
  398. this.tagDrawer.show = true
  399. },
  400. drawerConfirm: function () {
  401. this.tagDrawer.show = false
  402. },
  403. drawerCancel: function () {
  404. this.tagDrawer.show = false
  405. },
  406. delThisTag: function (tag) {
  407. this.tagDrawer.dialogShow = true
  408. this.tagDrawer.currentDelTagInfo = tag
  409. },
  410. delThisTagConfirm: function () {
  411. var _this = this
  412. var data = {
  413. lids: this.tagDrawer.currentDelTagInfo.value,
  414. lname: this.tagDrawer.currentDelTagInfo.label,
  415. laction: 'D'
  416. }
  417. $.ajax({
  418. url: '/publicapply/bidcoll/label',
  419. type: 'POST',
  420. contentType: 'application/json',
  421. data: JSON.stringify(data),
  422. success: function (res) {
  423. if (res.error_code === 0) {
  424. _this.tagDrawer.dialogShow = false
  425. if (res.data) {
  426. _this.tagDrawer.toastShow = true
  427. setTimeout(function () {
  428. _this.tagDrawer.toastShow = false
  429. _this.getTagList()
  430. }, 1500)
  431. }
  432. }
  433. }.bind(this)
  434. })
  435. },
  436. savePageState: function () {
  437. var data = {
  438. filterState: this.filterState,
  439. listState: this.listState,
  440. currentSelectItems: this.currentSelectItems,
  441. currentPageAllChecked: this.currentPageAllChecked
  442. }
  443. sessionStorage.setItem(this.sessKey, JSON.stringify(data))
  444. },
  445. hasRestoreState: function () {
  446. return !!sessionStorage.getItem(this.sessKey)
  447. },
  448. restorePageState: function () {
  449. var $data = sessionStorage.getItem(this.sessKey)
  450. if ($data) {
  451. $data = JSON.parse($data)
  452. // 恢复数据
  453. Object.assign(this.filterState, $data.filterState || {})
  454. Object.assign(this.listState, $data.listState || {})
  455. Object.assign(this.currentSelectItems, $data.currentSelectItems || {})
  456. // 恢复页面状态
  457. this.currentPageAllChecked = $data.currentPageAllChecked
  458. sessionStorage.removeItem(this.sessKey)
  459. }
  460. return !!$data
  461. }
  462. }
  463. })