index.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <template>
  2. <page title="选择商品" ref="pageRef" nav-color="#fff">
  3. <tabbar2 custom-class="marginX14 marginT10" :tabs="tabs" @change="clickTab" />
  4. <scroll-view
  5. class="scroll"
  6. :style="{ top: top + 'px' }"
  7. scroll-y
  8. refresher-enabled
  9. refresher-default-style="white"
  10. @refresherrefresh="pullRefresh"
  11. :refresher-triggered="refreshing"
  12. @scrolltolower="loadMore"
  13. >
  14. <view v-if="tableData && tableData.length > 0" class="paddingX14">
  15. <view
  16. v-for="item in tableData"
  17. :key="item.id"
  18. class="cell flex-align"
  19. @click="choose(item)"
  20. >
  21. <image
  22. class="icon flex-shrink0"
  23. :src="item.spu.cover"
  24. @click.stop="showGoodsDetail(item)"
  25. mode="aspectFit"
  26. />
  27. <view class="flex1 marginL12 flex-column-around self-stretch">
  28. <view
  29. class="font4 bold"
  30. style="-webkit-line-clamp: 2;word-break: break-all;text-overflow:ellipsis"
  31. >
  32. {{ item.spu.name }}
  33. </view>
  34. <image class="icon-title" :src="LEVEL_MAP[item.level].titleText" />
  35. <view class="flex-align">
  36. <view class="font4 radius2">
  37. 可兑换
  38. <text :style="{ color: LEVEL_MAP[item.level].bgColor }">
  39. {{ item.magicAmount }}
  40. </text>
  41. 源石
  42. </view>
  43. </view>
  44. </view>
  45. <image
  46. class="check"
  47. v-if="!!goodsMap[item.id]"
  48. :src="resource.icon_check"
  49. mode="scaleToFill"
  50. />
  51. <view class="un-check" v-else></view>
  52. </view>
  53. </view>
  54. <empty v-if="isEmpty" :top="200" />
  55. </scroll-view>
  56. <image
  57. v-if="!single"
  58. :src="ossurl.mine.checkAll"
  59. webp
  60. class="check-all"
  61. @click="chooseAll"
  62. />
  63. <view class="bottom-wrapper flex-align-center">
  64. <view class="btn-create relative" @click="submit">
  65. <view class="btn">
  66. {{ single || type == 1 ? '确定' : '确认选择放入赠品池' }}
  67. </view>
  68. <view v-if="!(single || type == 1)" class="text">{{ tip }}</view>
  69. </view>
  70. </view>
  71. </page>
  72. </template>
  73. <script>
  74. import resource from '@/utils/resource'
  75. import ossurl from '@/utils/ossurl'
  76. import pageMixin from '@/mixin/page'
  77. import empty from '@/components/empty'
  78. import { LEVEL_MAP } from '@/utils/config'
  79. import goodsDetail from './../store/goods_detail'
  80. import tabbar2 from '@/components/tabbar2'
  81. const Tabs = [
  82. { title: '全部', value: '' },
  83. { title: '普通', value: 'D' },
  84. { title: '隐藏', value: 'C' },
  85. { title: '欧皇', value: 'B' },
  86. { title: '超神', value: 'A' },
  87. { title: '其他', value: 'OTHER' }
  88. ]
  89. export default {
  90. mixins: [pageMixin],
  91. components: { empty, goodsDetail, tabbar2 },
  92. data() {
  93. return {
  94. resource,
  95. ossurl,
  96. LEVEL_MAP,
  97. refreshing: false,
  98. goodsMap: {},
  99. tip: '',
  100. tab: Tabs[0],
  101. tabs: Tabs,
  102. single: false,
  103. type: 0
  104. }
  105. },
  106. computed: {
  107. top() {
  108. let height = this.$store.state.systemInfo.statusBarHeight + 36 + 45
  109. return height
  110. }
  111. },
  112. onLoad(options) {
  113. this.single = !!options.single
  114. this.type = options.type || 0
  115. },
  116. mounted() {
  117. let map = this.$cache.get(this.$cache.key.STORE_CHOOSE, this.goodsMap) || {}
  118. this.goodsMap = map
  119. this.$cache.remove(this.$cache.key.STORE_CHOOSE)
  120. this.refresh(true)
  121. this.cacuTip()
  122. },
  123. methods: {
  124. clickTab(item) {
  125. this.tab = item
  126. this.refresh(true)
  127. },
  128. pullRefresh() {
  129. this.refreshing = true
  130. this.refresh()
  131. },
  132. async loadData(loading = false) {
  133. const res = await this.$service.award.store(
  134. this.pageNum,
  135. this.pageSize,
  136. 0,
  137. this.tab.value,
  138. loading
  139. )
  140. setTimeout(() => {
  141. this.refreshing = false
  142. }, 1000)
  143. return res
  144. },
  145. choose(item) {
  146. if (this.single) {
  147. this.goodsMap = { [item.id]: item }
  148. this.cacuTip()
  149. return
  150. }
  151. if (!!this.goodsMap[item.id]) {
  152. delete this.goodsMap[item.id]
  153. } else {
  154. this.goodsMap[item.id] = item
  155. }
  156. this.goodsMap = { ...this.goodsMap }
  157. this.cacuTip()
  158. },
  159. forceChoose(item, flag, refresh = true) {
  160. if (flag) {
  161. this.goodsMap[item.id] = item
  162. } else {
  163. delete this.goodsMap[item.id]
  164. }
  165. if (refresh) {
  166. this.goodsMap = { ...this.goodsMap }
  167. this.cacuTip()
  168. }
  169. },
  170. chooseAll() {
  171. let flag = this.tableData.every((item) => !!this.goodsMap[item.id])
  172. if (flag) {
  173. this.goodsMap = {}
  174. } else {
  175. this.tableData.forEach((item) => {
  176. this.forceChoose(item, true, false)
  177. })
  178. this.goodsMap = { ...this.goodsMap }
  179. }
  180. this.cacuTip()
  181. },
  182. cacuTip() {
  183. let list = Object.values(this.goodsMap)
  184. let total = 0
  185. list.forEach((item) => {
  186. total += item.magicAmount
  187. })
  188. if (!list || list.length === 0) return (this.tip = '')
  189. this.tip = `已选${list.length}件,价值${total}源石`
  190. },
  191. submit() {
  192. this.$event.emit(this.$event.key.STORE_CHOOSE, this.goodsMap)
  193. this.$router.back()
  194. }
  195. }
  196. }
  197. </script>
  198. <style></style>
  199. <style lang="scss" scoped>
  200. .bg {
  201. position: fixed;
  202. z-index: -1;
  203. left: 0;
  204. right: 0;
  205. top: 0;
  206. width: 100%;
  207. height: 100%;
  208. opacity: 0.3;
  209. }
  210. .scroll {
  211. position: absolute;
  212. left: 0;
  213. right: 0;
  214. bottom: 176rpx;
  215. padding-top: 10rpx;
  216. }
  217. .bottom-wrapper {
  218. position: fixed;
  219. bottom: 0;
  220. left: 0;
  221. right: 0;
  222. background-color: #fff;
  223. padding-bottom: 48rpx;
  224. padding-top: 20rpx;
  225. }
  226. .btn-create {
  227. width: 426rpx;
  228. height: 64rpx;
  229. background: #fec433;
  230. border-radius: 178rpx 178rpx 178rpx 178rpx;
  231. font-size: 28rpx;
  232. font-family: Source Han Sans, Source Han Sans;
  233. font-weight: 400;
  234. color: #000000;
  235. text-align: center;
  236. line-height: 64rpx;
  237. .text {
  238. text-align: center;
  239. color: #000;
  240. font-size: 24rpx;
  241. }
  242. }
  243. .check-all {
  244. width: 68rpx;
  245. height: 98rpx;
  246. position: fixed;
  247. bottom: 400rpx;
  248. right: 20rpx;
  249. }
  250. .cell {
  251. background: #fff;
  252. border-radius: 16rpx 4rpx 16rpx 16rpx;
  253. padding: 30rpx;
  254. margin-bottom: 20rpx;
  255. position: relative;
  256. overflow: hidden;
  257. .icon {
  258. width: 180rpx;
  259. height: 180rpx;
  260. border-radius: 10rpx;
  261. }
  262. .icon-title {
  263. width: 90rpx;
  264. height: 32rpx;
  265. }
  266. .un-check {
  267. width: 32rpx;
  268. height: 32rpx;
  269. background: rgba($color: #fff, $alpha: 0.5);
  270. position: absolute;
  271. right: 0;
  272. top: 0;
  273. }
  274. .check {
  275. width: 32rpx;
  276. height: 32rpx;
  277. position: absolute;
  278. right: 0;
  279. top: 0;
  280. }
  281. }
  282. .tabs {
  283. height: 32px;
  284. background: rgba(0, 0, 0, 0.4);
  285. box-shadow: 0px 0px 5px 0px rgba(167, 110, 244, 0.5);
  286. border-radius: 4px;
  287. border: 1px solid rgba(255, 255, 255, 0.2);
  288. }
  289. </style>