ArticleItem.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <template>
  2. <div class="article-item" :class="{'style-for-gray': config.gray, 'style-for-table': config.table }">
  3. <input v-if="config.collect" @change="changeCheck($event)" @click.stop class="custom-checkbox title-text-checkbox" name="bid-list" type="checkbox" :dataid="article._id">
  4. <div v-if="article.site === '剑鱼信息发布平台' || article.spidercode === 'a_jyxxfbpt_gg'" class="yhfb">用户发布</div>
  5. <div class="a-i-con">
  6. <div class="content-item" @click="onClick">
  7. <div v-html="calcTitle" class="a-i-left ellipsis visited-hd"></div>
  8. <span v-if="config.gray&&article.ca_fileExists" class="haveFile">有附件</span>
  9. </div>
  10. </div>
  11. <div class="a-i-right">
  12. <div class="tags">
  13. <span class="tag" v-if="article.area">{{ article.area }}</span>
  14. <span class="tag orange" v-if="article.type">{{ article.type }}</span>
  15. <span class="tag green" v-if="article.buyerclass">{{ article.buyerclass }}</span>
  16. <span class="tag dpink" v-if="calcBudget">{{ calcBudget }}</span>
  17. </div>
  18. <div class="time-container">
  19. <span class="el-icon-jy-time" v-if="!config.gray"></span>
  20. <span class="time-text">
  21. <slot name="right-time">{{ dateFromNow(article.publishtime * 1000) }}</slot>
  22. </span>
  23. </div>
  24. <i class="icon-collect" @click.stop="collectChange($event)" v-if="config.collect" :class="{'checked': article.collection}" :dataid="article._id"></i>
  25. </div>
  26. </div>
  27. </template>
  28. <script>
  29. import { Tag } from 'element-ui'
  30. import { moneyUnit, dateFromNow, replaceKeyword } from '@/utils/'
  31. export default {
  32. name: 'article-item',
  33. components: {
  34. [Tag.name]: Tag
  35. },
  36. props: {
  37. index: {
  38. type: [String, Number],
  39. default: '1'
  40. },
  41. config: {
  42. type: Object,
  43. default () {
  44. return {
  45. gray: false,
  46. table: false,
  47. collect: false
  48. }
  49. }
  50. },
  51. article: {
  52. type: Object,
  53. default () {
  54. return {
  55. title: '', // 标题
  56. area: '', // 区域
  57. type: '', // 类型
  58. buyerclass: '', // 行业
  59. budget: '', // 金额
  60. publishtime: 0, // 时间
  61. matchkeys: [], // 高亮的关键词
  62. ca_fileExists: false
  63. }
  64. }
  65. }
  66. },
  67. computed: {
  68. calcBudget () {
  69. if (this.article.budget) {
  70. return moneyUnit(this.article.budget)
  71. } else {
  72. return this.article.budget
  73. }
  74. },
  75. calcTitle () {
  76. const hightLightedTitle = replaceKeyword(this.article.title, this.article.matchkeys, ['<span class="highlight-text">', '</span>'])
  77. return `${this.index}. ${hightLightedTitle}`
  78. }
  79. },
  80. methods: {
  81. dateFromNow,
  82. onClick () {
  83. this.$emit('onClick')
  84. },
  85. changeCheck (e) {
  86. const { _id } = this.article
  87. const payload = {
  88. id: _id,
  89. check: this.$querySelector(e.target).prop('checked')
  90. }
  91. this.$emit('changeCheck', payload)
  92. },
  93. collectChange (e) {
  94. this.$emit('onCollect', {
  95. item: this.article,
  96. event: e
  97. })
  98. }
  99. }
  100. }
  101. </script>
  102. <style>
  103. .custom-toast .toast-container{
  104. /* display: none; */
  105. position: fixed;
  106. top: 50%;
  107. left: 50%;
  108. width: auto;
  109. padding: 16px 32px;
  110. font-size: 16px;
  111. background: rgba(0, 0, 0, 0.65);
  112. border-radius: 8px;
  113. color: #fff;
  114. transform: translateX(-50%) translateY(-50%);
  115. z-index: 99;
  116. }
  117. /* 附件标识样式 */
  118. .haveFile{
  119. display: inline-block;
  120. padding:0 8px;
  121. margin-left: 15px;
  122. height: 20px;
  123. border-radius: 4px;
  124. border: 1px solid #2CB7CA;
  125. font-size: 12px;
  126. font-weight: 400;
  127. color: #2CB7CA;
  128. line-height: 18px;
  129. }
  130. </style>
  131. <style lang="scss" scoped>
  132. $border-color: #ECECEC;
  133. @include diy-icon('time', 20, 20);
  134. .article-item {
  135. display: flex;
  136. align-items: center;
  137. justify-content: space-between;
  138. padding: 22px 16px;
  139. border-bottom: 1px solid $border-color;
  140. cursor: pointer;
  141. &:first-of-type,
  142. &:border-top {
  143. border-top: 1px solid $border-color;
  144. }
  145. &.style-for-gray {
  146. .custom-checkbox {
  147. margin-top: 0;
  148. }
  149. .icon-collect{
  150. display: inline-block;
  151. width: 20px;
  152. height: 20px;
  153. margin-left: 6px;
  154. background: transparent url(https://cdn-ali.jianyu360.com/images/collect.png) center no-repeat;
  155. background-size: contain;
  156. cursor: pointer;
  157. vertical-align: sub;
  158. ::before{
  159. content: ''
  160. }
  161. }
  162. .icon-collect.checked{
  163. background: transparent url(https://cdn-ali.jianyu360.com/images/collected.png) center no-repeat;
  164. background-size: contain;
  165. ::before{
  166. content: ''
  167. }
  168. }
  169. .tag,
  170. .orange.tag,
  171. .green.tag,
  172. .dpink.tag {
  173. background: #f5f5fb;
  174. border: 1px solid #ececec;
  175. border-radius: 4px;
  176. font-size: 12px;
  177. font-family: Microsoft YaHei, Microsoft YaHei-Regular;
  178. font-weight: 400;
  179. text-align: center;
  180. color: #686868;
  181. line-height: 20px;
  182. height: 22px;
  183. padding: 0 8px;
  184. }
  185. }
  186. &.style-for-table {
  187. }
  188. .a-i-con{
  189. flex: 1;
  190. }
  191. .content-item {
  192. display: flex;
  193. flex-direction: row;
  194. align-items: center;
  195. }
  196. .a-i-left {
  197. display: inline-block;
  198. max-width: 650px;
  199. }
  200. .a-i-right,
  201. .tags,
  202. .time-container {
  203. display: flex;
  204. align-items: center;
  205. justify-content: space-between;
  206. }
  207. .tag {
  208. display: flex;
  209. align-items: center;
  210. padding: 1px 6px;
  211. margin-right: 14px;
  212. color: #fff;
  213. font-size: 13px;
  214. line-height: 20px;
  215. background-color: #2CB7CA;
  216. border-radius: 3px;
  217. &:not(:last-of-type) {
  218. margin-right: 8px;
  219. }
  220. &.orange {
  221. background-color: #FFBA00;
  222. }
  223. &.green {
  224. background-color: #25C78C;
  225. }
  226. &.dpink {
  227. background-color: #FF878D;
  228. }
  229. }
  230. .time-text {
  231. margin-left: 6px;
  232. font-size: 14px;
  233. color: #797a7e;
  234. line-height: 24px;
  235. }
  236. .yhfb{
  237. background-color: rgba(255, 58, 32, 0.1);
  238. padding: 2px 12px;
  239. border-radius: 4px;
  240. line-height: 22px;
  241. font-size: 14px;
  242. color: #FF3A20;
  243. margin-right: 10px;
  244. }
  245. }
  246. </style>