index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. <template>
  2. <view :class="[AppTheme,className]" :style="wrapper_style">
  3. <!-- style -->
  4. <view v-html="css"></view>
  5. <view v-if="datas.show_title" class="morebox">
  6. <view :style="title_style" class="title">{{ title }}</view>
  7. <view class="title2" @click="more">查看更多
  8. <u-icon :style="img_style2" color="#949494" name="arrow-right" size="14"></u-icon>
  9. </view>
  10. </view>
  11. <!-- 列表 -->
  12. <view class="wrap">
  13. <waterfall :datas="datas" :status="waterfall.status" :list="waterfall.list" :reset="waterfall.reset"
  14. @click="onClick" @done="onDone"></waterfall>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. // 自定义样式
  20. const css = function() {
  21. const {
  22. margin_top,
  23. margin_bottom,
  24. bg_color,
  25. shop_price_color,
  26. market_price_color,
  27. text_bg_color,
  28. text_color,
  29. time_text_bg_color,
  30. time_text_color,
  31. bar_text_color,
  32. buynow_bg_color,
  33. buynow_text_color
  34. } = this.datas;
  35. return `
  36. .component-${this.id} {
  37. background-color: ${bg_color || '#f8f8f8'};
  38. font-size: 24rpx;
  39. }
  40. .component-${this.id} .item-shop .shop-price {
  41. color: ${shop_price_color};
  42. }
  43. .component-${this.id} .item-market {
  44. color: ${market_price_color};
  45. }
  46. .component-${this.id} .item-claimed {
  47. color: ${bar_text_color};
  48. }
  49. .component-${this.id} .geshop-button-buynow {
  50. background-color: ${buynow_bg_color};
  51. color: ${buynow_text_color};
  52. }
  53. `;
  54. };
  55. /**
  56. * 返回剩余秒数,正整值
  57. * @param {timestamp} timestamp 时间戳
  58. */
  59. const get_second = (timestamp) => {
  60. const now = new Date().getTime();
  61. let left = timestamp - now;
  62. left = Math.abs(left);
  63. const second = parseInt((left / 1000));
  64. return second;
  65. };
  66. /**
  67. * 判断当前的倒计时状态
  68. * @param {timestamp} start 开始的时间
  69. * @param {timestamp} end 结束的时间
  70. * @return {Number} 0=未开始,1=正在开始,2=已经结束
  71. */
  72. const get_status = (start, end) => {
  73. const now = new Date().getTime();
  74. if (now < start) {
  75. return 0;
  76. }
  77. if (now >= start && now < end) {
  78. return 1;
  79. }
  80. if (now >= end) {
  81. return 2;
  82. }
  83. };
  84. /**
  85. * 秒数转换成日期
  86. * @param {Number} s 秒数
  87. * @returns {Array}
  88. */
  89. const second_to_date = (s) => {
  90. let t = ['00', '00', '00', '00'];
  91. if (s > -1) {
  92. t = [];
  93. const day = Math.floor(s / 3600 / 24);
  94. const hour = Math.floor(s / 3600) % 24;
  95. const min = Math.floor(s / 60) % 60;
  96. const sec = s % 60;
  97. t.push(`${day}D`);
  98. if (hour < 10) {
  99. t.push('0' + hour);
  100. } else {
  101. t.push(hour);
  102. }
  103. if (min < 10) {
  104. t.push('0' + min);
  105. } else {
  106. t.push(min);
  107. }
  108. if (sec < 10) {
  109. t.push('0' + sec);
  110. } else {
  111. t.push(sec);
  112. }
  113. };
  114. return t;
  115. };
  116. import homeApi from '@/api/home/index.js'
  117. import waterfall from "@/components/waterfall/waterfall-list"
  118. export default {
  119. props: ['isdiy', 'datas', 'styles'],
  120. components: {
  121. "waterfall": waterfall
  122. },
  123. data() {
  124. let siteinfo = getApp().globalData.siteinfo;
  125. const img = siteinfo.root_img + '/static/app/imgs/default-goods.png';
  126. return {
  127. // 加载状态
  128. loading: true,
  129. // 定时器钩子
  130. timer_id: null,
  131. // 倒计时秒数
  132. spiner: ['00', '00', '00', '00'],
  133. // 倒计时文案
  134. spiner_text: '倒计时文案',
  135. // 当前状态
  136. status: 0,
  137. default_img: img,
  138. // 瀑布流组件相关
  139. waterfall: {
  140. status: "",
  141. reset: false,
  142. list: null
  143. },
  144. total: 0,
  145. last_page: 0,
  146. current_page: 1
  147. };
  148. },
  149. computed: {
  150. /** 副标题内容 */
  151. title() {
  152. return this.datas.title || '';
  153. },
  154. img_style2() {
  155. return `
  156. width:15px;
  157. height:15px;
  158. margin:auto;
  159. `;
  160. },
  161. // 副标题栏样式
  162. title_style() {
  163. const {
  164. text_size,
  165. text_color,
  166. } = this.datas;
  167. return `
  168. font-size: ${text_size}px;
  169. color: ${text_color};
  170. `;
  171. },
  172. // 副标题栏样式
  173. title_style1() {
  174. const {
  175. text_size,
  176. } = this.datas;
  177. return `
  178. color:rgb(96, 98, 102);
  179. font-size: ${text_size}px;
  180. `;
  181. },
  182. /** 样式 */
  183. wrapper_style() {
  184. const {
  185. padding_top,
  186. padding_bottom,
  187. padding_left,
  188. padding_right,
  189. margin_top,
  190. margin_bottom,
  191. bg_color,
  192. } = this.datas;
  193. return `
  194. width: 100%;
  195. background-color:${bg_color};
  196. padding-top: ${margin_top}px;
  197. padding-bottom: ${margin_bottom}px;
  198. padding-left: ${padding_left}px;
  199. padding-right: ${padding_right}px;
  200. `;
  201. },
  202. className() {
  203. const name = ['component-wrapper', `component-${this.id}`];
  204. return name;
  205. },
  206. css() {
  207. return '<style>' + css.call(this) + '</style>';
  208. },
  209. env() {
  210. return this.$store.state.page.env;
  211. },
  212. // 开始时间
  213. start_time() {
  214. try {
  215. const timestamp = parseInt(this.datas.goods[0].tsk_info.tsk_begin_time);
  216. return timestamp * 1000;
  217. } catch (err) {
  218. return 1577265;
  219. }
  220. },
  221. // 结束时间
  222. end_time() {
  223. try {
  224. const timestamp = parseInt(this.datas.goods[0].tsk_info.tsk_end_time);
  225. return timestamp * 1000;
  226. } catch (err) {
  227. return 1577265;
  228. }
  229. },
  230. // 是否展示删除线
  231. del() {
  232. let visible = true;
  233. visible = (this.datas.market_price_del === undefined || this.datas.market_price_del === null) ? true :
  234. Number(
  235. this.datas.market_price_del) >= 1;
  236. return visible;
  237. }
  238. },
  239. methods: {
  240. // 监听瀑布流点击
  241. onClick(data, index, tag) {
  242. this.$until.u_gopage('U_goods2', data)
  243. },
  244. // 瀑布流渲染完成
  245. onDone() {
  246. // 设置组件为 非重置,这行代码保留不删即可
  247. this.waterfall.reset = false;
  248. // 恢复 getList 方法的调用
  249. // 设置组件状态为 等待加载
  250. // this.waterfall.status = '';
  251. },
  252. more() {
  253. uni.navigateTo({
  254. url: '/pagesE/pages/mall/list'
  255. })
  256. },
  257. getlist(type) {
  258. let that = this;
  259. that.waterfall.status = 'loading';
  260. if (that.isdiy && !that.isdiy) {
  261. that.waterfall.status = 'success';
  262. that.waterfall.list = that.datas.goods;
  263. } else {
  264. homeApi.getgoods({
  265. page: that.current_page,
  266. lable: that.datas.title,
  267. show_num: that.datas.show_num
  268. }).then(res => {
  269. if (type == 1) {
  270. that.waterfall.list = null;
  271. }
  272. uni.stopPullDownRefresh()
  273. that.last_page = res.data.last_page;
  274. that.total = res.data.total;
  275. if (res.data.data && res.data.data.length > 0) {
  276. that.waterfall.list = res.data.data
  277. }
  278. if (that.datas.show_num && that.datas.show_num > 0) {
  279. that.waterfall.status = 'showline';
  280. } else {
  281. if (that.total <= 0) {
  282. that.waterfall.status = 'finish';
  283. } else {
  284. let flag = parseInt(that.last_page) == parseInt(res.data.current_page);
  285. if (flag) {
  286. if (that.last_page == 1 && that.current_page == 1) {
  287. that.waterfall.status = 'showline';
  288. } else {
  289. if (res.data.data && res.data.data.length > 0) {
  290. that.waterfall.status = 'success';
  291. } else {
  292. that.waterfall.status = 'finish';
  293. }
  294. }
  295. } else {
  296. if (that.current_page < that.last_page) {
  297. that.waterfall.status = 'await';
  298. } else {
  299. that.waterfall.status = 'success';
  300. }
  301. }
  302. }
  303. }
  304. });
  305. }
  306. },
  307. toBottom(type) {
  308. if (type == 1) {
  309. this.current_page = 0;
  310. this.waterfall.reset = true;
  311. }
  312. this.current_page++;
  313. console.log('this.datas.show_num', this.datas.show_num)
  314. if (this.datas.show_num <= 0 || this.datas.show_num == undefined || this.current_page == 1) {
  315. this.getlist(type);
  316. }
  317. },
  318. // 剩余库存文案
  319. filter_only_left(count = 0) {
  320. return '剩余:' + count;
  321. }
  322. },
  323. watch: {
  324. // 监听商品列表是否有变化
  325. goods_list() {
  326. // this.$store.dispatch('global/async_goods_init_2', this);
  327. },
  328. },
  329. mounted() {
  330. this.getlist()
  331. this.$emit('loaded');
  332. }
  333. };
  334. </script>
  335. <style lang="scss" scoped>
  336. // 默认
  337. .component-wrapper {
  338. width: 750rpx;
  339. .morebox {
  340. display: flex;
  341. justify-content: space-between;
  342. align-items: center;
  343. padding: 10px 12px 10px 12px;
  344. .title2 {
  345. font-size: 28rpx;
  346. display: flex;
  347. color: #949494;
  348. align-items: center;
  349. }
  350. }
  351. }
  352. </style>