index-wx.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. var vNode = {
  2. delimiters: ['${', '}'],
  3. el: '#myCollection',
  4. components: {
  5. tagsComponent: tagsComponent,
  6. dateComponent: dateComponent,
  7. cateComponent: cateComponent,
  8. phoneComponent: phoneComponent
  9. },
  10. data: {
  11. sessStorageKey: '$data-collection',
  12. listState: {
  13. value: '',
  14. loading: false,
  15. finished: false,
  16. pageSize: 10,
  17. offset: 80,
  18. scrollTop: 0,
  19. total: 0,
  20. list: []
  21. },
  22. listInfo: {
  23. scrollTop: 0
  24. },
  25. // 筛选参数
  26. limitlist: {
  27. pageNum: 1,
  28. label: '',
  29. selectTime: '',
  30. buyerclass: '',
  31. buyerPhone: 0,
  32. winnerPhone: 0
  33. },
  34. tagList: [], // 个人标签列表
  35. selectTagList: [], //选择标签列表
  36. selectCateList: [], // 选择的采购单位类型列表
  37. // 下拉菜单参数
  38. params: {
  39. value2: '',
  40. buyerData: {
  41. dataType: '1',
  42. option: [
  43. { text: '有联系方式', value: 1, type: false },
  44. { text: '无联系方式', value: -1, type: false },
  45. ],
  46. },
  47. winnerData: {
  48. dataType: '2',
  49. option: [
  50. { text: '有联系方式', value: 1, type: false },
  51. { text: '无联系方式', value: -1, type: false },
  52. ]
  53. }
  54. },
  55. // 收藏日期选择时间参数
  56. selectDate: {
  57. startDate: '',
  58. endDate: '',
  59. exact: ''
  60. },
  61. tagText: {
  62. timeText: '收藏时间',
  63. perText: '个人标签',
  64. cateText: '采购单位类型',
  65. },
  66. limitshow: false, // 筛选框显示
  67. condition: true, // 列表星星显示
  68. personTagactive:0, //个人标签选择按钮下标
  69. screenShow: false, // 筛选按钮是否显示
  70. },
  71. computed: {
  72. getParamsStatus () {
  73. return this.limitlist.label=='' && this.limitlist.selectTime=='' && this.limitlist.buyerclass=='' && this.limitlist.buyerPhone==0 && this.limitlist.winnerPhone==0 && this.limitlist.pageNum==1
  74. }
  75. },
  76. created () {
  77. var recover = this.recover()
  78. if (!recover) {
  79. this.getList()
  80. this.getUserRoot()
  81. this.getTagsList()
  82. }
  83. },
  84. mounted() {
  85. if(this.limitlist.label !=='' || this.limitlist.selectTime != '' || this.limitlist.buyerclass != '' || this.limitlist.buyerPhone != 0 || this.limitlist.winnerPhone != 0) {
  86. this.limitshow = true
  87. } else {
  88. this.limitshow = false
  89. }
  90. },
  91. mounted () {
  92. setTimeout(() => {
  93. $(this.$refs.jList).scrollTop(this.listState.scrollTop)
  94. }, 300)
  95. },
  96. methods: {
  97. recover: function () {
  98. let _this = this
  99. var excludeKey = ['sessStorageKey']
  100. var $data = sessionStorage.getItem(this.sessStorageKey)
  101. if ($data) {
  102. $data = JSON.parse($data)
  103. var listState = $data["listState"];
  104. var list = listState["list"];
  105. for (var i=0;i<list.length;i++){
  106. if (sessionStorage.getItem('listCollSessionId')&&sessionStorage.getItem('listCollSessionId')==list[i]["_id"]){
  107. if (sessionStorage.getItem('listCollSessionBool')=="0"){
  108. listState["list"].splice(i,1);
  109. }
  110. sessionStorage.removeItem('listCollSessionId')
  111. sessionStorage.removeItem('listCollSessionBool')
  112. }
  113. }
  114. for (var key in $data) {
  115. if (excludeKey.indexOf(key) !== -1) {
  116. continue
  117. }
  118. this.$data[key] = $data[key]
  119. }
  120. const res = _this.$data.limitlist
  121. // 标签
  122. if(res.label != '') {
  123. this.selectTagList = res.label.split(',')
  124. }
  125. // 时间
  126. if(res.selectTime != '') {
  127. this.selectDate.startDate = res.selectTime.split('_')[0] * 1000
  128. this.selectDate.endDate= res.selectTime.split('_')[1] * 1000
  129. }
  130. // 采购单位类型
  131. if(res.buyerclass != '') {
  132. this.selectCateList = res.buyerclass.split(',')
  133. }
  134. sessionStorage.removeItem(this.sessStorageKey)
  135. }
  136. return !!$data
  137. },
  138. setrecover: function() {
  139. var scrollTop = $(this.$refs.jList).scrollTop()
  140. // 如果滚动高度为0,或者entList长度为0,则不缓存数据(即返回刷新)
  141. this.listState.scrollTop = scrollTop
  142. sessionStorage.setItem(this.sessStorageKey, JSON.stringify(this.$data))
  143. },
  144. // 判断是否是有权限
  145. getUserRoot: function() {
  146. let _this = this
  147. $.ajax({
  148. url: '/publicapply/bidcoll/power',
  149. type: 'POST',
  150. success: function(res) {
  151. console.log(res)
  152. if(res.data.entniche || res.data.member || res.data.vip > 0) {
  153. _this.screenShow = true
  154. } else {
  155. _this.screenShow = false
  156. }
  157. }
  158. })
  159. },
  160. // 列表跳转
  161. linkRouter: function(id) {
  162. this.setrecover()
  163. location.href = '/article/content/' + id + '.html'
  164. },
  165. // 筛选按钮
  166. screenBtn() {
  167. this.limitshow = !this.limitshow
  168. setTimeout(()=>{
  169. this.setToggle()
  170. })
  171. },
  172. getContainer: function() {
  173. return this.$refs.searchContainer
  174. },
  175. // 获取列表数据
  176. getList: function(isScreen) {
  177. let _this = this
  178. _this.listState.loading = true
  179. let params = _this.limitlist
  180. $.ajax({
  181. url: '/publicapply/bidcoll/list',
  182. type: "POST",
  183. contentType: 'application/json;charset=utf-8',
  184. data: JSON.stringify(params),
  185. success: function(res){
  186. console.log(res)
  187. if (res.error_code == 0) {
  188. if (res.data && res.data.res && $.isArray(res.data.res)) {
  189. // 当数组为空时,且不为第一页,底部显示没有更多数据
  190. if(res.data.res.length == 0 && _this.limitlist.pageNum != 1){
  191. if(isScreen) {
  192. _this.listState.list = res.data.res
  193. } else {
  194. _this.listState.list = _this.listState.list.concat(res.data.res)
  195. }
  196. _this.listState.loading = false
  197. if(!res.data.haveNextPage){
  198. _this.listState.loading = true
  199. _this.listState.finished = true;
  200. }else{
  201. _this.listState.loading = false
  202. _this.limitlist.pageNum++
  203. }
  204. } else if(res.data.res.length == 0 && _this.limitlist.pageNum == 1){
  205. // 当数组为空时,且为第一页,页面为暂无数据页面
  206. _this.listState.loading = true
  207. _this.listState.finished = true;
  208. _this.listState.list = res.data.res
  209. } else {
  210. // 数据正常加载更多
  211. for (let i = 0; i < res.data.res.length; i++) {
  212. res.data.res[i].bidamount = utils.moneyUnit(res.data.res[i].bidamount)
  213. res.data.res[i].publishtime = utils.dateFromNow(res.data.res[i].publishtime * 1000)
  214. }
  215. if(isScreen) {
  216. _this.listState.list = res.data.res
  217. } else {
  218. _this.listState.list = _this.listState.list.concat(res.data.res)
  219. }
  220. _this.listState.loading = false
  221. if(!res.data.haveNextPage){
  222. _this.listState.loading = true
  223. _this.listState.finished = true;
  224. }else{
  225. _this.listState.loading = false
  226. _this.limitlist.pageNum++
  227. }
  228. }
  229. } else {
  230. _this.listState.loading = true
  231. _this.listState.finished = true;
  232. }
  233. } else {
  234. _this.$toast(res.error_msg)
  235. }
  236. },
  237. error: function(err){
  238. _this.listState.loading = true
  239. _this.listState.finished = true;
  240. }
  241. })
  242. },
  243. // 取消收藏
  244. collecClick: function(e,id) {
  245. e.stopPropagation()
  246. let _this = this
  247. let params = {
  248. baction: 'R',
  249. binfo: [
  250. {
  251. bid: id
  252. }
  253. ]
  254. }
  255. $.ajax({
  256. url: '/publicapply/bidcoll/action',
  257. type: "POST",
  258. contentType: 'application/json;charset=utf-8',
  259. data:JSON.stringify(params),
  260. success: function(res){
  261. console.log(res)
  262. if(res.error_code == 0) {
  263. if(res.data) {
  264. _this.$toast('取消收藏成功')
  265. if(_this.listState.list.length <= 1) {
  266. location.reload()
  267. }else {
  268. _this.reLoadList(true)
  269. }
  270. } else {
  271. _this.$toast('取消收藏失败')
  272. }
  273. }
  274. },
  275. error: function(err){
  276. _this.$toast('取消收藏失败')
  277. }
  278. })
  279. },
  280. // 确定按钮事件
  281. confirm: function(data) {
  282. console.log(data)
  283. if(data.name == 'dateItem'){
  284. const timeRange = {
  285. start: (data.data.start / 1000).toFixed(0),
  286. end: (data.data.end / 1000).toFixed(0)
  287. }
  288. // 开始时间未选择,则默认开始时间为2000年
  289. if (!timeRange.start || timeRange.start == 0) {
  290. timeRange.start = +new Date('2000') / 1000
  291. }
  292. // 结束时间未选择,则默认当天23点
  293. if (!timeRange.end || timeRange.end == 0) {
  294. var today = new Date().pattern('yyyy/MM/dd')
  295. var day1 = 24 * 60 * 60 * 1000
  296. var todayEnd = +new Date(today) + day1 - 1000
  297. timeRange.end = Math.round(todayEnd / 1000)
  298. }
  299. if (timeRange.start == 0 && timeRange.end == 0) {
  300. this.limitlist.selectTime = ''
  301. this.tagText.timeText = '收藏时间'
  302. } else if(timeRange.start == 0 && timeRange.end != 0) {
  303. this.limitlist.selectTime = '_' + timeRange.end
  304. } else if(timeRange.start != 0 && timeRange.end == 0) {
  305. this.limitlist.selectTime = timeRange.start + '_'
  306. } else {
  307. this.limitlist.selectTime = timeRange.start + '_' + timeRange.end
  308. }
  309. this.selectDate.exact = data.data.exact
  310. switch (data.data.exact) {
  311. case 'all': {
  312. this.tagText.timeText = '收藏时间'
  313. break
  314. }
  315. case 'lately7': {
  316. this.tagText.timeText = '最近7天'
  317. break
  318. }
  319. case 'lately30': {
  320. this.tagText.timeText = '最近30天'
  321. break
  322. }
  323. case 'lastYear': {
  324. this.tagText.timeText = '去年'
  325. break
  326. }
  327. case 'exact': {
  328. if(timeRange.start == 0 && timeRange.end == 0) {
  329. this.limitlist.selectTime = ''
  330. this.tagText.timeText = '收藏时间'
  331. this.setToggle()
  332. return
  333. } else {
  334. this.tagText.timeText = new Date(timeRange.start*1000).pattern('yyyy.MM.dd') + '~' + new Date(timeRange.end*1000).pattern('yyyy.MM.dd')
  335. }
  336. break
  337. }
  338. }
  339. } else if (data.name == 'cateItem') {
  340. this.tagText.cateText = '采购单位类型' + data.t
  341. this.limitlist.buyerclass = data.data.join(',')
  342. } else if (data.name == 'tagsItem') {
  343. this.tagText.perText = data.t
  344. this.limitlist.label = data.data
  345. } else if (data.name == 'buyerItem') {
  346. this.limitlist.buyerPhone = parseInt(data.data)
  347. } else if (data.name == 'winnerItem') {
  348. this.limitlist.winnerPhone = parseInt(data.data)
  349. }
  350. this.limitlist.pageNum = 1
  351. this.setToggle()
  352. this.reLoadList(true)
  353. },
  354. // 取消按钮事件
  355. cancel: function(data) {
  356. console.log(data)
  357. if(data.name == 'dateItem'){
  358. this.limitlist.selectTime = ''
  359. this.tagText.timeText = '收藏时间'
  360. this.selectDate.exact = 'all'
  361. this.$refs.datecom.setState()
  362. } else if (data.name == 'cateItem') {
  363. this.tagText.cateText = '采购单位类型'
  364. this.limitlist.buyerclass = ''
  365. this.selectCateList = []
  366. this.$refs.catecom.setState()
  367. } else if (data.name == 'tagsItem') {
  368. this.limitlist.label = ''
  369. this.tagText.perText = '个人标签'
  370. this.selectTagList = []
  371. this.$refs.tagcom.setState()
  372. } else if (data.name == 'buyerItem') {
  373. this.limitlist.buyerPhone = 0
  374. } else if (data.name == 'winnerItem') {
  375. this.limitlist.winnerPhone = 0
  376. }
  377. this.reLoadList(true)
  378. this.setToggle()
  379. },
  380. // 刷新列表
  381. reLoadList: function(isScreen) {
  382. this.getList(isScreen)
  383. },
  384. // 关闭菜单
  385. setToggle: function() {
  386. this.$refs.dateItem.toggle(false)
  387. this.$refs.cateItem.toggle(false)
  388. this.$refs.tagItem.toggle(false)
  389. this.$refs.buyerItem.toggle(false)
  390. this.$refs.winnerItem.toggle(false)
  391. },
  392. // 获取个人标签列表
  393. getTagsList: function() {
  394. let _this = this
  395. $.ajax({
  396. url: '/publicapply/bidcoll/getLabel',
  397. type: "POST",
  398. success: function(res){
  399. console.log(res)
  400. if(res.error_code == 0 && res.data) {
  401. res.data.forEach(function(item, index){
  402. item.type = false
  403. })
  404. _this.tagList = res.data
  405. } else {
  406. _this.tagList = []
  407. }
  408. },
  409. error: function(err){
  410. console.log(err)
  411. }
  412. })
  413. },
  414. // 数据导出
  415. dataReport: function() {
  416. if(this.listState.list.length == 0) {
  417. this.$toast('暂无数据')
  418. } else {
  419. $.ajax({
  420. url: '/publicapply/dataexpoet/bycollection',
  421. type: 'POST',
  422. data: {
  423. label: this.limitlist.label,
  424. selectTime: this.limitlist.selectTime,
  425. buyerclass: this.limitlist.buyerclass,
  426. buyerPhone: this.limitlist.buyerPhone,
  427. winnerPhone: this.limitlist.winnerPhone,
  428. },
  429. success: function(res) {
  430. if(res.error_code == 0 && res.data) {
  431. location.href = '/front/wx_dataExport/submitOrder?id=' + res.data._id + '&source=d&dataspec='
  432. }
  433. }
  434. })
  435. }
  436. }
  437. }
  438. }
  439. var myCollection = new Vue(vNode)