materal.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <template>
  2. <view>
  3. <view class="change-container">
  4. <view class="relative width100 height100">
  5. <image
  6. class="width100 height100"
  7. :src="resource.ex_material_bg"
  8. mode="aspectFill"
  9. />
  10. <view class="contain">
  11. <view class="con_item" v-for="data in materialList" :key="data.id">
  12. <view class="item_img">
  13. <image class="width100 height100" :src="data.cover" mode="aspectFill" />
  14. <view class="item_intro flex-align-between">
  15. <view class="">
  16. {{ data.name }}
  17. </view>
  18. <view class="flex" style="font-size: 28rpx">
  19. <view style="color: #0694fe">
  20. {{ data.inventoryQuantity - data.soldQuantity }}
  21. </view>
  22. <view style="color: #fff">/{{ data.inventoryQuantity }}</view>
  23. </view>
  24. </view>
  25. </view>
  26. <view
  27. class="item_btn"
  28. :style="{
  29. backgroundColor: data.userSynthesisNum == 0 ? '#EFE8C0' : '#FBFAF0'
  30. }"
  31. >
  32. <view
  33. v-if="data.userSynthesisNum == 0"
  34. class="flex-align-between"
  35. style="color: #558dfe; height: 98%"
  36. @click.stop="preGetCake(data)"
  37. >
  38. <image
  39. style="width: 32rpx; height: 32rpx"
  40. :src="resource.m_molibi"
  41. mode="aspectFill"
  42. />
  43. <view class="">{{ data.price }}</view>
  44. <view class="">购买</view>
  45. </view>
  46. <view
  47. v-else
  48. class=""
  49. style="
  50. color: #bfc9f2;
  51. height: 98%;
  52. text-align: center;
  53. line-height: 46rpx;
  54. "
  55. >
  56. 已购买
  57. </view>
  58. </view>
  59. </view>
  60. </view>
  61. <view class="molibi">
  62. <image :src="resource.molibi" class="molibi_img" />
  63. {{ ownMolib }}
  64. </view>
  65. <view class="footer flex-align-between">
  66. <image
  67. class="height100"
  68. style="width: 240rpx"
  69. :src="resource.ex_to_getMlib"
  70. mode="aspectFill"
  71. @click.stop="$router.switchTab('award')"
  72. />
  73. <image
  74. v-if="synthesisFlag"
  75. class="height100"
  76. style="width: 240rpx"
  77. :src="resource.ex_cake"
  78. mode="aspectFill"
  79. @click="preGetCake(0)"
  80. />
  81. <image
  82. v-else
  83. class="height100"
  84. style="width: 240rpx"
  85. :src="resource.ex_uncake"
  86. mode="aspectFill"
  87. />
  88. </view>
  89. </view>
  90. </view>
  91. <confirm ref="confirmRef" @submit="getCake" />
  92. <lack-molib ref="lackMolibRef" />
  93. </view>
  94. </template>
  95. <script>
  96. import resource from '@/utils/resource'
  97. import { throttle } from '@/utils'
  98. import confirm from './buy_confirm.vue'
  99. import lackMolib from '../weal/lackMolib.vue'
  100. export default {
  101. components: { confirm, lackMolib },
  102. props: {
  103. caketType: {
  104. type: Number,
  105. default: 1
  106. }
  107. },
  108. data() {
  109. return {
  110. resource,
  111. materialList: [],
  112. synthesisFlag: false,
  113. ownMolib: 0
  114. }
  115. },
  116. mounted() {
  117. this.init()
  118. this.getMolibi()
  119. },
  120. methods: {
  121. async init() {
  122. if (this.caketType === 0) return
  123. await this.$service.weal.materialList().then((res) => {
  124. if (res.code === '0') {
  125. this.materialList = res.data
  126. } else {
  127. // this.$message.error(res.msg)
  128. }
  129. this.synthesisFlag = res.data && res.data.every((res) => res.userSynthesisNum === 1)
  130. })
  131. },
  132. async getMolibi() {
  133. const res = await this.$service.wallet.info('MAGIC_POWER_COIN')
  134. res && (this.ownMolib = res.balance)
  135. },
  136. refresh() {
  137. throttle.call(this.realRefresh)
  138. },
  139. realRefresh() {
  140. this.$emit('refresh')
  141. },
  142. preGetCake(data) {
  143. if (data !== 0 && data.price > this.ownMolib) {
  144. this.$refs.lackMolibRef.show()
  145. } else {
  146. this.$refs.confirmRef.show(data)
  147. }
  148. },
  149. async getCake(id) {
  150. await this.$service.weal.materialSubmit(id).then((res) => {
  151. if (res.code === '0') {
  152. this.init()
  153. this.getMolibi()
  154. if (id === 0) this.$emit('open')
  155. } else {
  156. this.$message.error(res.msg)
  157. }
  158. })
  159. }
  160. }
  161. }
  162. </script>
  163. <style lang="scss" scoped>
  164. .change-container {
  165. position: fixed;
  166. bottom: 48rpx;
  167. left: 30rpx;
  168. width: 694rpx;
  169. height: 734rpx;
  170. .contain {
  171. position: absolute;
  172. left: 37rpx;
  173. bottom: 171rpx;
  174. width: 618rpx;
  175. height: 481rpx;
  176. display: flex;
  177. flex-direction: row;
  178. flex-wrap: wrap;
  179. justify-content: center;
  180. .con_item {
  181. width: 164rpx;
  182. height: 222rpx;
  183. margin-right: 63rpx;
  184. margin-top: 37rpx;
  185. .item_img {
  186. position: relative;
  187. width: 100%;
  188. height: 164rpx;
  189. border-radius: 10rpx;
  190. overflow: hidden;
  191. background-color: #fff;
  192. .item_intro {
  193. position: absolute;
  194. bottom: 0;
  195. width: 100%;
  196. height: 36rpx;
  197. background-color: rgba(0, 0, 0, 0.3);
  198. padding: 0 10rpx;
  199. color: #fff;
  200. }
  201. }
  202. .item_btn {
  203. width: 100%;
  204. height: 46rpx;
  205. margin-top: 12rpx;
  206. border-radius: 23rpx;
  207. padding: 0 13rpx;
  208. }
  209. }
  210. .con_item:nth-child(3) {
  211. margin-right: 0;
  212. }
  213. .con_item:last-child {
  214. margin-right: 0;
  215. }
  216. }
  217. .molibi {
  218. position: absolute;
  219. top: 32rpx;
  220. right: 37rpx;
  221. padding-left: 50rpx;
  222. padding-right: 20rpx;
  223. height: 50rpx;
  224. border-radius: 25rpx;
  225. background-color: rgba(0, 0, 0, 0.4);
  226. color: #fff;
  227. font-size: 30rpx;
  228. text-align: center;
  229. line-height: 50rpx;
  230. z-index: 5;
  231. display: flex;
  232. justify-content: flex-end;
  233. align-items: center;
  234. .molibi_img {
  235. position: absolute;
  236. left: -10%;
  237. width: 50rpx;
  238. height: 50rpx;
  239. }
  240. }
  241. .footer {
  242. position: absolute;
  243. left: 90rpx;
  244. bottom: 33rpx;
  245. width: 514rpx;
  246. height: 76rpx;
  247. }
  248. }
  249. </style>