stock_in.vue 9.9 KB

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