scanInPage.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. <template>
  2. <gui-page :custom-header="true" :header-class="['gui-theme-background-color']">
  3. <template #gHeader>
  4. <view style="height:44px;" class="gui-flex gui-nowrap gui-rows gui-align-items-center">
  5. <!-- 使用组件实现返回按钮及返回出入库选择页面按钮按钮 -->
  6. <!-- <text style="font-size:44rpx;" class="gui-header-leader-btns gui-color-white font-icons"
  7. @tap="goBack">&#xe6c5;</text> -->
  8. <text style="font-size:44rpx;" class="gui-header-leader-btns gui-color-white font-icons"
  9. @tap="goHome">&#xe6c5;</text>
  10. <!-- 导航文本此处也可以是其他自定义内容 -->
  11. <text class="gui-h4 gui-blod gui-flex1 gui-text-center gui-ellipsis gui-color-white gui-primary-text"
  12. style="font-size: 1rem;">扫码入库列表</text>
  13. <!-- 此处加一个右侧展位元素与左侧同宽,实现标题居中 -->
  14. <!-- 实际宽度请根据自己情况设置 -->
  15. <view style="width:40px;" />
  16. <!-- 如果右侧有其他内容可以利用条件编译和定位来实现-->
  17. </view>
  18. </template>
  19. <template #gBody>
  20. <view class="list-content">
  21. <!-- 搜索栏 -->
  22. <view class="search-bar">
  23. <view class="search-item">
  24. <text class="search-label">业务类型</text>
  25. <view class="search-select">
  26. <picker @change="onBusinessTypeChange" :range="businessTypeList" range-key="text" :value="businessTypeIndex">
  27. <view class="picker-text">{{ businessTypeList[businessTypeIndex]?.text || '请选择业务类型' }}</view>
  28. </picker>
  29. </view>
  30. </view>
  31. <view class="search-item">
  32. <text class="search-label">申请单号</text>
  33. <view class="search-input-wrapper">
  34. <!-- <input type="text" v-model="requestNo" placeholder="请输入申请单号" class="search-input" focus /> -->
  35. <input type="text" v-model="requestNo" placeholder="请输入申请单号" class="search-input" />
  36. <text class="scan-icon font-icons" @tap="scanCode">
  37. &#xe6b7;
  38. </text>
  39. </view>
  40. </view>
  41. <view class="search-btn" @tap="handleSearch">
  42. <text class="font-icons">搜索&#xe60c;</text>
  43. </view>
  44. </view>
  45. <view style="margin-top: 110px;">
  46. <view v-if="cardList?.length > 0" class="list-panel">
  47. <div v-for="(item, key) in cardList" :key="key" class="panel"
  48. @click="handleToScanMaterials(item)">
  49. <div class="panel-row">
  50. <span>{{ item.requestNo }}</span>
  51. <span class="font-icons">前往扫描&#xe66b;</span>
  52. </div>
  53. <div class="panel-row">
  54. <span>业务类型</span>
  55. <span>{{ computedState(item.businessType,'businessType') }}</span>
  56. </div>
  57. <div class="panel-row">
  58. <span>业务状态</span>
  59. <span>{{ computedState(item.status,'status') }}</span>
  60. </div>
  61. </div>
  62. </view>
  63. <view v-else>
  64. <view class="bg-image">
  65. <image src="@/static/empty.png" mode="heightFix" />
  66. <text>这里什么都没有...</text>
  67. </view>
  68. </view>
  69. </view>
  70. </view>
  71. </template>
  72. </gui-page>
  73. </template>
  74. <script>
  75. import {
  76. onReachBottom
  77. } from '@dcloudio/uni-app'
  78. import {
  79. ref,
  80. defineComponent,
  81. computed,
  82. onMounted
  83. } from 'vue'
  84. export default defineComponent({
  85. setup() {
  86. const queryParams = ref({
  87. pageSize: 10,
  88. pageNo: 1,
  89. keyWord: '',
  90. businessType: ''
  91. })
  92. const cardList = ref([])
  93. const businessTypeList = ref([])
  94. const statusMap = ref({})
  95. const businessTypeIndex = ref(0)
  96. const selectedBusinessType = ref('')
  97. const requestNo = ref('')
  98. const search = function(pageNo) {
  99. uni.$reqGet('getScanInList', {
  100. ...queryParams.value,
  101. businessType: selectedBusinessType.value,
  102. requestNo: requestNo.value,
  103. pageNo
  104. })
  105. .then(({
  106. data,
  107. msg
  108. }) => {
  109. cardList.value = data?.list ?? []
  110. // 如果是通过申请单号搜索且有结果,直接跳转到scannedMaterials页面
  111. if (requestNo.value && cardList.value.length === 1) {
  112. handleToScanMaterials(cardList.value[0])
  113. }
  114. })
  115. }
  116. onMounted(() => {
  117. search(1)
  118. // 获取业务类型字典数据
  119. uni.$reqGet('getDictDataPage', {
  120. dictType: 'in_business_type',
  121. pageNo: 1,
  122. pageSize: 100
  123. }).then(({ data }) => {
  124. businessTypeList.value = [{ text: '请选择业务类型', value: '' }]
  125. const dataList = data?.list || [];
  126. for (var i = 0; i < dataList.length; i++) {
  127. businessTypeList.value.push({
  128. text: dataList[i].label,
  129. value: dataList[i].value,
  130. })
  131. }
  132. })
  133. uni.$reqGet('getDictDataPage', {
  134. dictType: 'in_out_status',// 后端给的字典编码
  135. pageNo: 1,
  136. pageSize: 100
  137. }).then(({ data }) => {
  138. data?.list.forEach(item => {
  139. statusMap.value[item.value] = item.label// 例如 0→待出库 1→已出库
  140. })
  141. })
  142. })
  143. const goHome = function() {
  144. uni.$goHome()
  145. }
  146. const goBack = function() {
  147. uni.removeStorageSync('masterId')
  148. // 返回到扫码类型选择页面
  149. uni.$goBack('/pages/workbranch/warehouse/scanInOut/scanInOutType')
  150. }
  151. const handleToScanMaterials = function(params) {
  152. // 存储数据,使用abc页面需要的键名
  153. uni.setStorageSync('masterId', JSON.stringify({
  154. id: params?.id,
  155. businessType: params?.businessType
  156. }))
  157. // 根据 businessType 判断跳转页面:3=退料,其他=普通入库
  158. const isReturnMaterial = String(params?.businessType).trim() == '3'
  159. const targetUrl = isReturnMaterial
  160. ? '/pages/workbranch/warehouse/scanInOut/In/businessType3/returnMaterial'
  161. : '/pages/workbranch/warehouse/scanInOut/In/scannedMaterials'
  162. // 跳转到对应页面
  163. uni.navigateTo({
  164. url: targetUrl
  165. })
  166. }
  167. // 同步搜索条件到queryParams
  168. const syncQueryParams = () => {
  169. queryParams.value.businessType = selectedBusinessType.value;
  170. queryParams.value.requestNo = requestNo.value;
  171. };
  172. // 业务类型选择变化
  173. const onBusinessTypeChange = function(e) {
  174. businessTypeIndex.value = e.detail.value
  175. selectedBusinessType.value = businessTypeList.value[e.detail.value]?.value || ''
  176. }
  177. // 搜索
  178. const handleSearch = function() {
  179. queryParams.value.pageNo = 1
  180. syncQueryParams(); // 保证条件写进去
  181. search(1)
  182. }
  183. // 扫码获取申请单号
  184. const scanCode = function() {
  185. uni.scanCode({
  186. success: function(res) {
  187. // 将扫码结果填入申请单号输入框
  188. requestNo.value = res.result
  189. // 自动执行搜索
  190. handleSearch()
  191. },
  192. fail: function(err) {
  193. console.log('扫码失败', err)
  194. uni.showToast({
  195. title: '扫码失败',
  196. icon: 'none'
  197. })
  198. }
  199. })
  200. }
  201. // uniapp移动端触底事件
  202. onReachBottom(() => {
  203. queryParams.value.pageNo += 1
  204. syncQueryParams(); // 关键:把条件重新合并
  205. uni.$reqGet('getScanInList', queryParams.value)
  206. .then(({data,msg}) => {
  207. Array.prototype.push.call(cardList.value, ...data?.list ?? [])
  208. })
  209. })
  210. // 计算业务类型的中文标签
  211. const computedState = function (value, type = 'businessType') {
  212. if (value === '' || value == null) return '未知'
  213. // 业务类型
  214. if (type === 'businessType') {
  215. const hit = businessTypeList.value.find(i => String(i.value).trim() === String(value).trim())
  216. return hit ? hit.text : '未知'
  217. }
  218. // 单据状态
  219. if (type === 'status') {
  220. return statusMap.value[value] || '未知'
  221. }
  222. return '未知'
  223. }
  224. return {
  225. goHome,
  226. goBack,
  227. cardList,
  228. handleToScanMaterials,
  229. businessTypeList,
  230. computedState,
  231. businessTypeIndex,
  232. onBusinessTypeChange,
  233. handleSearch,
  234. requestNo,
  235. scanCode
  236. }
  237. }
  238. })
  239. </script>
  240. <style lang="scss" scoped>
  241. .gui-header-leader-btns {
  242. color: black;
  243. font-size: 24px !important;
  244. margin-left: 24rpx;
  245. }
  246. .list-content {
  247. margin-top: 50px;
  248. min-height: calc(100vh - 80px);
  249. background-color: #edeeee;
  250. }
  251. .search-bar {
  252. position: fixed;
  253. top: 72px;
  254. left: 0;
  255. width: 100%;
  256. background-color: #fff;
  257. padding: 12px;
  258. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  259. display: flex;
  260. flex-wrap: wrap;
  261. gap: 12px;
  262. z-index: 9;
  263. box-sizing: border-box;
  264. }
  265. .search-item {
  266. flex: 1 1 200px; // 原来只有 flex:1
  267. min-width: 200px;
  268. display: flex;
  269. align-items: center;
  270. gap: 8px;
  271. margin-bottom: 8px;
  272. }
  273. .search-input-wrapper {
  274. flex: 1;
  275. }
  276. .search-input {
  277. width: 90%;
  278. height: 36px;
  279. line-height: 36px;
  280. background-color: #f5f5f5;
  281. border-radius: 4px;
  282. padding: 0 12px;
  283. font-size: 12px;
  284. border: none;
  285. }
  286. .search-input-wrapper {
  287. flex: 1;
  288. position: relative;
  289. }
  290. .scan-icon {
  291. position: absolute;
  292. right: 10px;
  293. top: 50%;
  294. transform: translateY(-50%);
  295. font-size: 20px;
  296. color: #00a0e9;
  297. cursor: pointer;
  298. }
  299. .search-input:focus {
  300. outline: none;
  301. background-color: #fff;
  302. border: 1px solid #00a0e9;
  303. }
  304. .search-label {
  305. font-size: 12px;
  306. color: #666;
  307. }
  308. .search-select {
  309. flex: 1;
  310. position: relative;
  311. }
  312. .search-select picker {
  313. display: flex; // 关键:让内部文本撑开
  314. align-items: center;
  315. height: 36px;
  316. line-height: 36px;
  317. min-width: 120px; // 防止被 flex 挤没
  318. background-color: #f5f5f5;
  319. border-radius: 4px;
  320. padding: 0 28px 0 12px; // 右侧留图标位置
  321. }
  322. .picker-text {
  323. font-size: 12px;
  324. color: #333;
  325. display: flex;
  326. justify-content: space-between;
  327. align-items: center;
  328. }
  329. .picker-text::after {
  330. position: absolute;
  331. right: 8px;
  332. top: 50%;
  333. transform: translateY(-50%);
  334. }
  335. .search-btn {
  336. width: 80px;
  337. height: 36px;
  338. line-height: 36px;
  339. background-color: #00a0e9;
  340. color: #fff;
  341. border-radius: 4px;
  342. text-align: center;
  343. font-size: 12px;
  344. }
  345. .search-btn .font-icons {
  346. color: #fff;
  347. margin-right: 4px;
  348. }
  349. span,
  350. text {
  351. font-size: 12px;
  352. }
  353. .list-panel {
  354. padding: 12px;
  355. }
  356. .panel {
  357. background-color: white;
  358. border-radius: 8px;
  359. padding: 12px;
  360. margin-bottom: 12px;
  361. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  362. }
  363. .panel-row {
  364. display: flex;
  365. justify-content: space-between;
  366. align-items: center;
  367. margin-bottom: 8px;
  368. &:last-child {
  369. margin-bottom: 0;
  370. }
  371. span:first-child {
  372. color: #666;
  373. }
  374. span:last-child {
  375. font-weight: bold;
  376. }
  377. .font-icons {
  378. color: #00a0e9;
  379. display: flex;
  380. align-items: center;
  381. }
  382. }
  383. .bg-image {
  384. display: flex;
  385. flex-direction: column;
  386. align-items: center;
  387. justify-content: center;
  388. padding: 60px 0;
  389. image {
  390. width: 120px;
  391. height: 120px;
  392. margin-bottom: 16px;
  393. }
  394. text {
  395. color: #999;
  396. font-size: 14px;
  397. }
  398. }
  399. </style>