asset_info.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  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="HTTP_REQUEST_URL_IMG+'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. import { HTTP_REQUEST_URL_IMG } from "@/config/app";
  179. onLoad(() => {
  180. console.log("asset_list page =====> Loaded")
  181. })
  182. onShow(()=>{
  183. fetchBalance()
  184. })
  185. const auStock = ref({
  186. total: '-',
  187. useful: '-',
  188. used: '-',
  189. })
  190. const ptStock = ref({
  191. total: '-',
  192. useful: '-',
  193. used: '-',
  194. })
  195. const agStock = ref({
  196. total: '-',
  197. useful: '-',
  198. used: '-',
  199. })
  200. const refreshTime = ref()
  201. /**
  202. * 获取当前登录商户金属资产明细
  203. */
  204. function fetchBalance(isRefresh) {
  205. fetchMerchantMetalBalanceAPI().then(res => {
  206. console.log(res)
  207. const {
  208. data,
  209. code
  210. } = res
  211. console.log(data, code)
  212. if (isRefresh) {
  213. uni.showToast({
  214. title: '刷新成功',
  215. icon: 'none',
  216. duration: 1000
  217. })
  218. }
  219. if (code === 200 && data.length > 0) {
  220. refreshTime.value = fetchCurrentTime()
  221. data.forEach(item => {
  222. console.log(item);
  223. switch (item.metalType) {
  224. case 1:
  225. auStock.value = {
  226. total: item.totalIncreaseWeight,
  227. useful: item.availableStock,
  228. used: item.totalDecreaseWeight
  229. }
  230. break;
  231. case 2:
  232. ptStock.value = {
  233. total: item.totalIncreaseWeight,
  234. useful: item.availableStock,
  235. used: item.totalDecreaseWeight
  236. }
  237. break;
  238. case 3:
  239. agStock.value = {
  240. total: item.totalIncreaseWeight,
  241. useful: item.availableStock,
  242. used: item.totalDecreaseWeight
  243. }
  244. break;
  245. default:
  246. break;
  247. }
  248. })
  249. }
  250. }).catch(err => {
  251. console.log(err);
  252. })
  253. }
  254. function fetchCurrentTime() {
  255. const now = new Date();
  256. let year = now.getFullYear(),
  257. month = now.getMonth() + 1,
  258. day = now.getDate(),
  259. hour = now.getHours(),
  260. min = now.getMinutes(),
  261. sec = now.getSeconds();
  262. month = month < 10 ? ('0' + month) : (month)
  263. day = day < 10 ? ('0' + day) : (day)
  264. hour = hour < 10 ? ('0' + hour) : (hour)
  265. min = min < 10 ? ('0' + min) : (min)
  266. sec = sec < 10 ? ('0' + sec) : (sec)
  267. return `${year}-${month}-${day} ${hour}:${min}:${sec}`
  268. }
  269. function recordClickHandle(type) {
  270. uni.navigateTo({
  271. url: `/pages/users/user_asset/record_list/record_list?type=${type}`
  272. })
  273. }
  274. function stockInClickHandle(type) {
  275. uni.navigateTo({
  276. url: `/pages/users/user_asset/stock_in/stock_in?type=${type}`
  277. })
  278. }
  279. function refreshClickHandle() {
  280. throttle(() => {
  281. fetchBalance(1)
  282. }, 1000)
  283. }
  284. </script>
  285. <style scoped lang="scss">
  286. uni-page-body {
  287. height: 100%;
  288. }
  289. .asset_refresh_box {
  290. width: 750rpx;
  291. display: flex;
  292. justify-content: space-between;
  293. padding: 0 0 0 32rpx;
  294. height: 76rpx;
  295. align-items: center;
  296. // position: absolute;
  297. // top:0;
  298. // left: 0;
  299. background-color: #FEF8E6;
  300. .refresh_time {
  301. font-size: 28rpx;
  302. color: #333;
  303. }
  304. .refresh_btn {
  305. display: flex;
  306. align-items: center;
  307. padding: 20rpx 32rpx 20rpx 20rpx;
  308. font-size: 24rpx;
  309. line-height: 32rpx;
  310. color: #F8C008;
  311. .refresh_icon {
  312. // width: 32rpx;
  313. height: 32rpx;
  314. margin-right: 8rpx;
  315. }
  316. }
  317. }
  318. .asset_container {
  319. // padding-top: 92rpx;
  320. background-color: #F9F7F0;
  321. height: 100vh;
  322. display: flex;
  323. flex-direction: column;
  324. justify-content: flex-start;
  325. align-items: center;
  326. .asset_list {
  327. width: 100%;
  328. background-color: #F9F7F0;
  329. height: 400rpx;
  330. flex: 1;
  331. padding: 16rpx;
  332. .list_container {
  333. padding-bottom: 20rpx;
  334. }
  335. .asset_item {
  336. width: 100%;
  337. border-radius: 16rpx;
  338. background-color: #fff;
  339. min-height: 200rpx;
  340. padding: 20rpx;
  341. margin-bottom: 20rpx;
  342. .asset_title {
  343. width: 100%;
  344. display: flex;
  345. justify-content: flex-start;
  346. align-items: center;
  347. font-size: 32rpx;
  348. color: #333;
  349. font-weight: bold;
  350. .title_icon {
  351. width: 48rpx;
  352. height: 48rpx;
  353. margin-right: 8rpx;
  354. }
  355. }
  356. .asset_count {
  357. width: 100%;
  358. padding: 16rpx;
  359. border-radius: 16rpx;
  360. background-color: #F9F7F0;
  361. display: flex;
  362. justify-content: space-between;
  363. align-items: center;
  364. margin-top: 20rpx;
  365. .total_count {
  366. display: flex;
  367. flex: 1;
  368. flex-direction: column;
  369. align-items: center;
  370. justify-content: center;
  371. min-width: 160rpx;
  372. flex-shrink: 0;
  373. .count_title {
  374. font-size: 24rpx;
  375. color: #333;
  376. margin-bottom: 10rpx;
  377. }
  378. .count_num {
  379. font-size: 40rpx;
  380. color: #3D3D3D;
  381. font-weight: bold;
  382. max-width: 200rpx;
  383. overflow: hidden;
  384. text-overflow: ellipsis;
  385. white-space: nowrap;
  386. &.green {
  387. color: #2DAB6C;
  388. }
  389. }
  390. }
  391. }
  392. .asset_tips {
  393. width: 100%;
  394. height: 80rpx;
  395. display: flex;
  396. justify-content: flex-start;
  397. align-items: center;
  398. background-color: #FEEAEA;
  399. border-radius: 16rpx;
  400. padding: 18rpx;
  401. font-size: 28rpx;
  402. line-height: 32rpx;
  403. color: #F52929;
  404. margin: 20rpx 0;
  405. .warn_icon {
  406. // width: 32rpx;
  407. height: 32rpx;
  408. margin-right: 16rpx;
  409. }
  410. }
  411. .asset_btns {
  412. width: 100%;
  413. display: flex;
  414. justify-content: space-between;
  415. margin-top: 20rpx;
  416. .record_list {
  417. width: 330rpx;
  418. height: 60rpx;
  419. line-height: 60rpx;
  420. text-align: center;
  421. color: #333;
  422. font-size: 28rpx;
  423. border-radius: 18rpx;
  424. background-color: rgba(248, 192, 8, 0.10);
  425. }
  426. .stock_in {
  427. width: 330rpx;
  428. height: 60rpx;
  429. line-height: 60rpx;
  430. text-align: center;
  431. color: #333;
  432. font-size: 28rpx;
  433. border-radius: 18rpx;
  434. background-color: #F8C008;
  435. }
  436. }
  437. }
  438. }
  439. }
  440. </style>