stock_in.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. <template>
  2. <view class="stock_conatiner">
  3. <view class="stock_select_container">
  4. <view class="stock_title">
  5. <text>选择材质</text>
  6. </view>
  7. <view class="stock_list">
  8. <view class="stock_item" :class="{active: currentStockType==1}" @click="currentStockType=1">
  9. <image class="stock_icon" src="/static/images/au_icon.png" mode="widthFix"></image>
  10. <text class="stock_name">黄金</text>
  11. <text class="stock_num_title">可用库存 </text>
  12. <text class="stock_num">{{auStock.useful}}g</text>
  13. </view>
  14. <view class="stock_item stock_middle" :class="{active: currentStockType==2}"
  15. @click="currentStockType=2">
  16. <image class="stock_icon" src="/static/images/pt_icon.png" mode="widthFix"></image>
  17. <text class="stock_name">铂金</text>
  18. <text class="stock_num_title">可用库存 </text>
  19. <text class="stock_num">{{ptStock.useful}}g</text>
  20. </view>
  21. <view class="stock_item" :class="{active: currentStockType==3}" @click="currentStockType=3">
  22. <image class="stock_icon" src="/static/images/ag_icon.png" mode="widthFix"></image>
  23. <text class="stock_name">白银</text>
  24. <text class="stock_num_title">可用库存 </text>
  25. <text class="stock_num">{{agStock.useful}}g</text>
  26. </view>
  27. </view>
  28. </view>
  29. <view class="stock_ipt_container">
  30. <view class="stock_ipt_title">
  31. <text>补货数量</text>
  32. </view>
  33. <input class="stock_ipt" type="digit" v-model="restockWeight" placeholder="请输入补货数量"
  34. @input="onInputChange" />
  35. </view>
  36. <view class="stock_img_upload">
  37. <view class="stock_img_title">
  38. <text>上传进货凭证</text>
  39. </view>
  40. <view class="upload-img">
  41. <view class="upload-box-contanier">
  42. <up-upload :fileList="imageList" uploadIcon="plus" @afterRead="afterRead" @delete="deletePic"
  43. name="1" multiple :maxCount="1">
  44. <template #trigger>
  45. <view class="upload-block">
  46. <uni-icons size="30" color="#ccc" type="plusempty"></uni-icons>
  47. </view>
  48. </template>
  49. </up-upload>
  50. </view>
  51. </view>
  52. <view class="stock_img_tips">
  53. <text>支持 JPG、PNG 等常用图片格式,最多可上传 1 张图片,大小不超过 10MB。</text>
  54. </view>
  55. </view>
  56. <view class="stock_bottom_btn">
  57. <view class="stock_btn" @click="submitClickHandle">确认补货</view>
  58. <view class="full_screen" v-if="isFullScreen">
  59. </view>
  60. </view>
  61. </view>
  62. </template>
  63. <script setup>
  64. import {
  65. ref,
  66. } from 'vue';
  67. import {
  68. onLoad,
  69. onShow,
  70. onReachBottom
  71. } from "@dcloudio/uni-app";
  72. import {
  73. restockSubmitAPI,
  74. fetchMerchantMetalBalanceAPI
  75. } from '@/api/merchant';
  76. import {
  77. useImageUpload
  78. } from "@/hooks/useImageUpload";
  79. import {
  80. useToast
  81. } from "@/hooks/useToast";
  82. import {
  83. Debounce
  84. } from '@/utils/validate';
  85. const {
  86. imageList,
  87. afterRead,
  88. deletePic,
  89. uploadLoading
  90. } = useImageUpload({
  91. pid: 14,
  92. model: "recyle",
  93. });
  94. console.log(imageList.value);
  95. const {
  96. Toast
  97. } = useToast();
  98. const isFullScreen = ref()
  99. const currentStockType = ref(1)
  100. const restockWeight = ref()
  101. const auStock = ref({
  102. total: 0,
  103. useful: 0,
  104. used: 0,
  105. })
  106. const ptStock = ref({
  107. total: 0,
  108. useful: 0,
  109. used: 0,
  110. })
  111. const agStock = ref({
  112. total: 0,
  113. useful: 0,
  114. used: 0,
  115. })
  116. function onInputChange() {}
  117. function countDecimalPlaces(num) {
  118. const stringNum = String(num);
  119. if (stringNum.includes('.')) {
  120. return stringNum.split('.')[1].length;
  121. } else {
  122. return 0;
  123. }
  124. }
  125. // 使用同步方法获取系统信息
  126. let systemInfo = uni.getSystemInfoSync();
  127. console.log(systemInfo);
  128. // 检查是否为全面屏
  129. function isFullScreenFn(systemInfo) {
  130. // 通常判断全面屏可以通过比较屏幕高度和窗口高度来决定
  131. // 如果屏幕高度大于窗口高度,则可能是刘海屏
  132. console.log(systemInfo.screenHeight, systemInfo.windowHeight)
  133. return systemInfo.screenHeight > systemInfo.windowHeight;
  134. }
  135. onLoad((params) => {
  136. // isFullScreen.value = isFullScreenFn(systemInfo)
  137. console.log(params);
  138. currentStockType.value = params.type || 1
  139. const systemInfo = uni.getSystemInfoSync();
  140. try{
  141. console.log("Loaded", systemInfo.safeAreaInsets)
  142. isFullScreen.value = systemInfo.safeAreaInsets.bottom>0
  143. }catch(error){
  144. }
  145. fetchBalance()
  146. // console.log("Loaded", systemInfo.safeAreaInsets)
  147. })
  148. let submitting = false
  149. function submitClickHandle() {
  150. if (!restockWeight.value || restockWeight.value <= 0) {
  151. return Toast({
  152. title: "请输入补货数量"
  153. })
  154. }
  155. // 小数点后有几位,输入数字只支持两位小数
  156. const counts = countDecimalPlaces(restockWeight.value);
  157. if (counts > 2) {
  158. return Toast({
  159. title: "补货数量仅支持输入两位小数"
  160. })
  161. }
  162. if (!imageList.value || imageList.value.length == 0) {
  163. return Toast({
  164. title: "请上传进货凭证"
  165. })
  166. }
  167. if (submitting) return
  168. submitting = true;
  169. try {
  170. restockSubmitAPI({
  171. imageUrl: imageList.value[0]?.info?.url || "",
  172. metalType: currentStockType.value,
  173. restockWeight: restockWeight.value
  174. }).then(res => {
  175. console.log(res);
  176. Toast({
  177. title: "补货申请条件成功,正在审核中"
  178. })
  179. setTimeout(() => {
  180. // uni.navigateBack()
  181. submitting = false;
  182. }, 500)
  183. }).catch(() => {
  184. submitting = false;
  185. })
  186. } catch (error) {
  187. submitting = false;
  188. //TODO handle the exception
  189. }
  190. }
  191. /**
  192. * 获取当前登录商户金属资产明细
  193. */
  194. function fetchBalance() {
  195. fetchMerchantMetalBalanceAPI().then(res => {
  196. console.log(res)
  197. const {
  198. data,
  199. code
  200. } = res
  201. console.log(data, code)
  202. if (code === 200 && data.length > 0) {
  203. data.forEach(item => {
  204. console.log(item);
  205. switch (item.metalType) {
  206. case 1:
  207. auStock.value = {
  208. total: item.totalIncreaseWeight,
  209. useful: item.availableStock,
  210. used: item.totalDecreaseWeight
  211. }
  212. break;
  213. case 2:
  214. ptStock.value = {
  215. total: item.totalIncreaseWeight,
  216. useful: item.availableStock,
  217. used: item.totalDecreaseWeight
  218. }
  219. break;
  220. case 3:
  221. agStock.value = {
  222. total: item.totalIncreaseWeight,
  223. useful: item.availableStock,
  224. used: item.totalDecreaseWeight
  225. }
  226. break;
  227. default:
  228. break;
  229. }
  230. })
  231. }
  232. }).catch(err => {
  233. console.log(err);
  234. })
  235. }
  236. </script>
  237. <style scoped lang="scss">
  238. uni-page-body {
  239. height: 100%;
  240. }
  241. .stock_conatiner {
  242. width: 100%;
  243. padding: 16rpx;
  244. background-color: #F9F7F0;
  245. }
  246. .stock_select_container {
  247. background-color: #fff;
  248. width: 100%;
  249. border-radius: 16rpx;
  250. .stock_title {
  251. font-size: 32rpx;
  252. font-weight: bold;
  253. padding: 20rpx;
  254. }
  255. .stock_list {
  256. display: flex;
  257. flex-wrap: nowrap;
  258. justify-content: space-between;
  259. align-items: flex-start;
  260. padding: 0 20rpx 20rpx;
  261. }
  262. .stock_item {
  263. display: flex;
  264. width: 100rpx;
  265. flex: 1;
  266. background-color: #F8F7F1;
  267. border-radius: 16rpx;
  268. border: 2rpx solid transparent;
  269. flex-direction: column;
  270. align-items: center;
  271. justify-content: center;
  272. padding-top: 16rpx;
  273. &.stock_middle {
  274. margin: 0 16rpx;
  275. }
  276. &.active {
  277. border-color: #F8C008;
  278. background-color: rgba(248, 192, 8, 0.10);
  279. }
  280. .stock_icon {
  281. width: 72rpx;
  282. height: 72rpx;
  283. }
  284. .stock_name {
  285. font-size: 28rpx;
  286. font-weight: bold;
  287. margin: 10rpx 0;
  288. }
  289. .stock_num_title {
  290. font-size: 24rpx;
  291. padding-bottom: 0;
  292. color: #666;
  293. }
  294. .stock_num {
  295. font-size: 24rpx;
  296. padding-bottom: 14rpx;
  297. color: #666;
  298. }
  299. }
  300. }
  301. .stock_ipt_container {
  302. width: 100%;
  303. height: 100rpx;
  304. background-color: #fff;
  305. border-radius: 16rpx;
  306. padding: 20rpx;
  307. display: flex;
  308. justify-content: space-between;
  309. align-items: center;
  310. flex-wrap: nowrap;
  311. margin: 16rpx 0;
  312. .stock_ipt_title {
  313. font-size: 28rpx;
  314. color: #333;
  315. margin-right: 40rpx;
  316. }
  317. .stock_ipt {
  318. width: 300rpx;
  319. flex: 1;
  320. text-align: right;
  321. height: 60rpx;
  322. line-height: 60rpx;
  323. font-size: 28rpx;
  324. }
  325. }
  326. .stock_img_upload {
  327. background-color: #fff;
  328. border-radius: 16rpx;
  329. width: 100%;
  330. padding: 20rpx;
  331. .stock_img_title {
  332. font-size: 28rpx;
  333. color: #333;
  334. margin-bottom: 20rpx;
  335. }
  336. .stock_img_tips {
  337. font-size: 24rpx;
  338. color: #999;
  339. line-height: 40rpx;
  340. margin-top: 10rpx;
  341. }
  342. }
  343. .stock_bottom_btn {
  344. position: fixed;
  345. bottom: 0;
  346. left: 0;
  347. right: 0;
  348. width: 100%;
  349. // min-height: 132rpx;
  350. padding: 22rpx 0;
  351. display: flex;
  352. flex-direction: column;
  353. align-items: center;
  354. justify-content: center;
  355. background-color: #fff;
  356. .stock_btn {
  357. width: 686rpx;
  358. display: block;
  359. height: 88rpx;
  360. line-height: 88rpx;
  361. text-align: center;
  362. background-color: #F8C008;
  363. border-radius: 16rpx;
  364. color: #333;
  365. font-size: 32rpx;
  366. }
  367. }
  368. .upload-box {
  369. width: 682rpx;
  370. height: auto;
  371. background-color: #ffffff;
  372. box-shadow: 0rpx 3rpx 13rpx 0rpx rgba(0, 0, 0, 0.13);
  373. border-radius: 20rpx;
  374. box-sizing: border-box;
  375. margin-top: 25rpx;
  376. padding: 40rpx 40rpx;
  377. .upload-tips {
  378. font-size: 26rpx;
  379. color: #000000;
  380. margin: 30rpx 0;
  381. }
  382. .upload-img {
  383. margin: 30rpx 0;
  384. }
  385. .pz-tips {
  386. text-align: center;
  387. font-size: 24rpx;
  388. color: #7c7c7c;
  389. margin: 40rpx 0;
  390. }
  391. .pz-img {
  392. display: flex;
  393. justify-content: space-between;
  394. flex-wrap: wrap;
  395. margin: 30rpx 0;
  396. image {
  397. width: 138rpx;
  398. height: 138rpx;
  399. background-color: #f3f3f3;
  400. border-radius: 10rpx;
  401. margin: 15rpx 0;
  402. }
  403. }
  404. }
  405. .upload-box-contanier {
  406. .upload-block {
  407. width: 160rpx;
  408. height: 160rpx;
  409. border: 1px dashed #ccc;
  410. border-radius: 10rpx;
  411. display: flex;
  412. flex-direction: column;
  413. justify-content: center;
  414. align-items: center;
  415. color: #ccc;
  416. background-color: #F9F7F0;
  417. font-weight: 700;
  418. font-size: 26rpx;
  419. }
  420. }
  421. .full_screen {
  422. width: 750rpx;
  423. height: 32rpx;
  424. background-color: #fff;
  425. }
  426. ::v-deep .u-upload__wrap__preview {
  427. margin: 0;
  428. }
  429. </style>