asset_info.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. <template>
  2. <view class="asset_container">
  3. <view class="asset_refresh_box">
  4. <view class="refresh_time">
  5. 更新于:{{refreshTime}}
  6. </view>
  7. <view class="refresh_btn" @click="refreshClickHandle">
  8. <image src="/static/images/refresh_icon.png" mode="heightFix" class="refresh_icon"></image>
  9. <text>刷新</text>
  10. </view>
  11. </view>
  12. <scroll-view class="asset_list" scroll-y="true">
  13. <view class="list_container">
  14. <view class="asset_item">
  15. <view class="asset_title">
  16. <image src="/static/images/au_icon.png" mode="widthFix" class="title_icon"></image>
  17. <view class="">
  18. 黄金资产
  19. </view>
  20. </view>
  21. <view class="asset_count">
  22. <view class="total_count">
  23. <view class="count_title">
  24. 累计进货
  25. </view>
  26. <view class="count_num">
  27. {{auStock.total || 0}}g
  28. </view>
  29. </view>
  30. <view class="total_count">
  31. <view class="count_title">
  32. 可用库存
  33. </view>
  34. <view class="count_num" :class="{green: Number(auStock.useful)<0}">
  35. {{auStock.useful || 0}}g
  36. </view>
  37. </view>
  38. <view class="total_count">
  39. <view class="count_title">
  40. 累计销售
  41. </view>
  42. <view class="count_num">
  43. {{auStock.used || 0}}g
  44. </view>
  45. </view>
  46. </view>
  47. <view class="asset_tips" v-if="Number(auStock.useful)<0">
  48. <image src="/static/images/warn_icon.png" mode="heightFix" class="warn_icon"></image>
  49. <text>库存过低,请及时补货</text>
  50. </view>
  51. <view class="asset_btns">
  52. <view class="record_list" @click="recordClickHandle(1)">
  53. 交易记录
  54. </view>
  55. <view class="stock_in" @click="stockInClickHandle(1)">
  56. 补仓
  57. </view>
  58. </view>
  59. </view>
  60. <view class="asset_item">
  61. <view class="asset_title">
  62. <image src="/static/images/pt_icon.png" mode="widthFix" class="title_icon"></image>
  63. <view class="">
  64. 铂金资产
  65. </view>
  66. </view>
  67. <view class="asset_count">
  68. <view class="total_count">
  69. <view class="count_title">
  70. 累计进货
  71. </view>
  72. <view class="count_num">
  73. {{ptStock.total || 0}}g
  74. </view>
  75. </view>
  76. <view class="total_count">
  77. <view class="count_title">
  78. 可用库存
  79. </view>
  80. <view class="count_num" :class="{green: Number(ptStock.useful)<0}">
  81. {{ptStock.useful || 0}}g
  82. </view>
  83. </view>
  84. <view class="total_count">
  85. <view class="count_title">
  86. 累计销售
  87. </view>
  88. <view class="count_num">
  89. {{ptStock.used || 0}}g
  90. </view>
  91. </view>
  92. </view>
  93. <view class="asset_tips" v-if="Number(ptStock.useful)<0">
  94. <image src="/static/images/warn_icon.png" mode="heightFix" class="warn_icon"></image>
  95. <text>库存过低,请及时补货</text>
  96. </view>
  97. <view class="asset_btns">
  98. <view class="record_list" @click="recordClickHandle(2)">
  99. 交易记录
  100. </view>
  101. <view class="stock_in" @click="stockInClickHandle(2)">
  102. 补仓
  103. </view>
  104. </view>
  105. </view>
  106. <view class="asset_item">
  107. <view class="asset_title">
  108. <image src="/static/images/ag_icon.png" mode="widthFix" class="title_icon"></image>
  109. <view class="">
  110. 白银资产
  111. </view>
  112. </view>
  113. <view class="asset_count">
  114. <view class="total_count">
  115. <view class="count_title">
  116. 累计进货
  117. </view>
  118. <view class="count_num">
  119. {{agStock.total || 0}}g
  120. </view>
  121. </view>
  122. <view class="total_count">
  123. <view class="count_title">
  124. 可用库存
  125. </view>
  126. <view class="count_num" :class="{green: Number(agStock.useful)<0}">
  127. {{agStock.useful || 0}}g
  128. </view>
  129. </view>
  130. <view class="total_count">
  131. <view class="count_title">
  132. 累计销售
  133. </view>
  134. <view class="count_num">
  135. {{agStock.used || 0}}g
  136. </view>
  137. </view>
  138. </view>
  139. <view class="asset_tips" v-if="Number(agStock.useful)<0">
  140. <image src="/static/images/warn_icon.png" mode="heightFix" class="warn_icon"></image>
  141. <text>库存过低,请及时补货</text>
  142. </view>
  143. <view class="asset_btns">
  144. <view class="record_list" @click="recordClickHandle(3)">
  145. 交易记录
  146. </view>
  147. <view class="stock_in" @click="stockInClickHandle(3)">
  148. 补仓
  149. </view>
  150. </view>
  151. </view>
  152. </view>
  153. </scroll-view>
  154. </view>
  155. </template>
  156. <script setup>
  157. import {
  158. ref,
  159. } from 'vue';
  160. import {
  161. onLoad,
  162. onShow,
  163. onReachBottom
  164. } from "@dcloudio/uni-app";
  165. import {
  166. restockSubmitAPI,
  167. fetchMerchantMetalBalanceAPI
  168. } from '@/api/merchant';
  169. import {
  170. useImageUpload
  171. } from "@/hooks/useImageUpload";
  172. import {
  173. useToast
  174. } from "@/hooks/useToast";
  175. import {
  176. throttle
  177. } from '@/uni_modules/uview-plus';
  178. onLoad(() => {
  179. console.log("asset_list page =====> Loaded")
  180. })
  181. onShow(()=>{
  182. fetchBalance()
  183. })
  184. const auStock = ref({
  185. total: '-',
  186. useful: '-',
  187. used: '-',
  188. })
  189. const ptStock = ref({
  190. total: '-',
  191. useful: '-',
  192. used: '-',
  193. })
  194. const agStock = ref({
  195. total: '-',
  196. useful: '-',
  197. used: '-',
  198. })
  199. const refreshTime = ref()
  200. /**
  201. * 获取当前登录商户金属资产明细
  202. */
  203. function fetchBalance(isRefresh) {
  204. fetchMerchantMetalBalanceAPI().then(res => {
  205. console.log(res)
  206. const {
  207. data,
  208. code
  209. } = res
  210. console.log(data, code)
  211. if (isRefresh) {
  212. uni.showToast({
  213. title: '刷新成功',
  214. icon: 'none',
  215. duration: 1000
  216. })
  217. }
  218. if (code === 200 && data.length > 0) {
  219. refreshTime.value = fetchCurrentTime()
  220. data.forEach(item => {
  221. console.log(item);
  222. switch (item.metalType) {
  223. case 1:
  224. auStock.value = {
  225. total: item.totalIncreaseWeight,
  226. useful: item.availableStock,
  227. used: item.totalDecreaseWeight
  228. }
  229. break;
  230. case 2:
  231. ptStock.value = {
  232. total: item.totalIncreaseWeight,
  233. useful: item.availableStock,
  234. used: item.totalDecreaseWeight
  235. }
  236. break;
  237. case 3:
  238. agStock.value = {
  239. total: item.totalIncreaseWeight,
  240. useful: item.availableStock,
  241. used: item.totalDecreaseWeight
  242. }
  243. break;
  244. default:
  245. break;
  246. }
  247. })
  248. }
  249. }).catch(err => {
  250. console.log(err);
  251. })
  252. }
  253. function fetchCurrentTime() {
  254. const now = new Date();
  255. let year = now.getFullYear(),
  256. month = now.getMonth() + 1,
  257. day = now.getDate(),
  258. hour = now.getHours(),
  259. min = now.getMinutes(),
  260. sec = now.getSeconds();
  261. month = month < 10 ? ('0' + month) : (month)
  262. day = day < 10 ? ('0' + day) : (day)
  263. hour = hour < 10 ? ('0' + hour) : (hour)
  264. min = min < 10 ? ('0' + min) : (min)
  265. sec = sec < 10 ? ('0' + sec) : (sec)
  266. return `${year}-${month}-${day} ${hour}:${min}:${sec}`
  267. }
  268. function recordClickHandle(type) {
  269. uni.navigateTo({
  270. url: `/pages/users/user_asset/record_list/record_list?type=${type}`
  271. })
  272. }
  273. function stockInClickHandle(type) {
  274. uni.navigateTo({
  275. url: `/pages/users/user_asset/stock_in/stock_in?type=${type}`
  276. })
  277. }
  278. function refreshClickHandle() {
  279. throttle(() => {
  280. fetchBalance(1)
  281. }, 1000)
  282. }
  283. </script>
  284. <style scoped lang="scss">
  285. uni-page-body {
  286. height: 100%;
  287. }
  288. .asset_refresh_box {
  289. width: 750rpx;
  290. display: flex;
  291. justify-content: space-between;
  292. padding: 0 0 0 32rpx;
  293. height: 76rpx;
  294. align-items: center;
  295. // position: absolute;
  296. // top:0;
  297. // left: 0;
  298. background-color: #FEF8E6;
  299. .refresh_time {
  300. font-size: 28rpx;
  301. color: #333;
  302. }
  303. .refresh_btn {
  304. display: flex;
  305. align-items: center;
  306. padding: 20rpx 32rpx 20rpx 20rpx;
  307. font-size: 24rpx;
  308. line-height: 32rpx;
  309. color: #F8C008;
  310. .refresh_icon {
  311. // width: 32rpx;
  312. height: 32rpx;
  313. margin-right: 8rpx;
  314. }
  315. }
  316. }
  317. .asset_container {
  318. // padding-top: 92rpx;
  319. background-color: #F9F7F0;
  320. height: 100%;
  321. display: flex;
  322. flex-direction: column;
  323. justify-content: flex-start;
  324. align-items: center;
  325. .asset_list {
  326. width: 100%;
  327. background-color: #F9F7F0;
  328. height: 400rpx;
  329. flex: 1;
  330. padding: 16rpx;
  331. .list_container {
  332. padding-bottom: 20rpx;
  333. }
  334. .asset_item {
  335. width: 100%;
  336. border-radius: 16rpx;
  337. background-color: #fff;
  338. min-height: 200rpx;
  339. padding: 20rpx;
  340. margin-bottom: 20rpx;
  341. .asset_title {
  342. width: 100%;
  343. display: flex;
  344. justify-content: flex-start;
  345. align-items: center;
  346. font-size: 32rpx;
  347. color: #333;
  348. font-weight: bold;
  349. .title_icon {
  350. width: 48rpx;
  351. height: 48rpx;
  352. margin-right: 8rpx;
  353. }
  354. }
  355. .asset_count {
  356. width: 100%;
  357. padding: 16rpx;
  358. border-radius: 16rpx;
  359. background-color: #F9F7F0;
  360. display: flex;
  361. justify-content: space-between;
  362. align-items: center;
  363. margin-top: 20rpx;
  364. .total_count {
  365. display: flex;
  366. flex: 1;
  367. flex-direction: column;
  368. align-items: center;
  369. justify-content: center;
  370. min-width: 160rpx;
  371. flex-shrink: 0;
  372. .count_title {
  373. font-size: 24rpx;
  374. color: #333;
  375. margin-bottom: 10rpx;
  376. }
  377. .count_num {
  378. font-size: 40rpx;
  379. color: #3D3D3D;
  380. font-weight: bold;
  381. max-width: 200rpx;
  382. overflow: hidden;
  383. text-overflow: ellipsis;
  384. white-space: nowrap;
  385. &.green {
  386. color: #2DAB6C;
  387. }
  388. }
  389. }
  390. }
  391. .asset_tips {
  392. width: 100%;
  393. height: 80rpx;
  394. display: flex;
  395. justify-content: flex-start;
  396. align-items: center;
  397. background-color: #FEEAEA;
  398. border-radius: 16rpx;
  399. padding: 18rpx;
  400. font-size: 28rpx;
  401. line-height: 32rpx;
  402. color: #F52929;
  403. margin: 20rpx 0;
  404. .warn_icon {
  405. // width: 32rpx;
  406. height: 32rpx;
  407. margin-right: 16rpx;
  408. }
  409. }
  410. .asset_btns {
  411. width: 100%;
  412. display: flex;
  413. justify-content: space-between;
  414. margin-top: 20rpx;
  415. .record_list {
  416. width: 330rpx;
  417. height: 60rpx;
  418. line-height: 60rpx;
  419. text-align: center;
  420. color: #333;
  421. font-size: 28rpx;
  422. border-radius: 18rpx;
  423. background-color: rgba(248, 192, 8, 0.10);
  424. }
  425. .stock_in {
  426. width: 330rpx;
  427. height: 60rpx;
  428. line-height: 60rpx;
  429. text-align: center;
  430. color: #333;
  431. font-size: 28rpx;
  432. border-radius: 18rpx;
  433. background-color: #F8C008;
  434. }
  435. }
  436. }
  437. }
  438. }
  439. </style>