scanInPage.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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. // // 过滤掉 status 为 1 的数据
  128. if (Number(dataList[i].status) === 1) continue;
  129. businessTypeList.value.push({
  130. text: dataList[i].label,
  131. value: dataList[i].value,
  132. })
  133. }
  134. })
  135. uni.$reqGet('getDictDataPage', {
  136. dictType: 'in_out_status',// 后端给的字典编码
  137. pageNo: 1,
  138. pageSize: 100
  139. }).then(({ data }) => {
  140. data?.list.forEach(item => {
  141. statusMap.value[item.value] = item.label// 例如 0→待出库 1→已出库
  142. })
  143. })
  144. })
  145. const goHome = function() {
  146. uni.$goHome()
  147. }
  148. const goBack = function() {
  149. uni.removeStorageSync('masterId')
  150. // 返回到扫码类型选择页面
  151. uni.$goBack('/pages/workbranch/warehouse/scanInOut/scanInOutType')
  152. }
  153. const handleToScanMaterials = function(params) {
  154. // 存储数据,使用abc页面需要的键名
  155. uni.setStorageSync('masterId', JSON.stringify({
  156. id: params?.id,
  157. businessType: params?.businessType
  158. }))
  159. // 根据 businessType 判断跳转页面:3=退料,其他=普通入库
  160. const isReturnMaterial = String(params?.businessType).trim() == '3'
  161. const targetUrl = isReturnMaterial
  162. ? '/pages/workbranch/warehouse/scanInOut/In/businessType3/returnMaterial'
  163. : '/pages/workbranch/warehouse/scanInOut/In/scannedMaterials'
  164. // 跳转到对应页面
  165. uni.navigateTo({
  166. url: targetUrl
  167. })
  168. }
  169. // 同步搜索条件到queryParams
  170. const syncQueryParams = () => {
  171. queryParams.value.businessType = selectedBusinessType.value;
  172. queryParams.value.requestNo = requestNo.value;
  173. };
  174. // 业务类型选择变化
  175. const onBusinessTypeChange = function(e) {
  176. businessTypeIndex.value = e.detail.value
  177. selectedBusinessType.value = businessTypeList.value[e.detail.value]?.value || ''
  178. }
  179. // 搜索
  180. const handleSearch = function() {
  181. queryParams.value.pageNo = 1
  182. syncQueryParams(); // 保证条件写进去
  183. search(1)
  184. }
  185. // 扫码获取申请单号
  186. const scanCode = function() {
  187. uni.scanCode({
  188. success: function(res) {
  189. // 将扫码结果填入申请单号输入框
  190. requestNo.value = res.result
  191. // 自动执行搜索
  192. handleSearch()
  193. },
  194. fail: function(err) {
  195. console.log('扫码失败', err)
  196. uni.showToast({
  197. title: '扫码失败',
  198. icon: 'none'
  199. })
  200. }
  201. })
  202. }
  203. // uniapp移动端触底事件
  204. onReachBottom(() => {
  205. queryParams.value.pageNo += 1
  206. syncQueryParams(); // 关键:把条件重新合并
  207. uni.$reqGet('getScanInList', queryParams.value)
  208. .then(({data,msg}) => {
  209. Array.prototype.push.call(cardList.value, ...data?.list ?? [])
  210. })
  211. })
  212. // 计算业务类型的中文标签
  213. const computedState = function (value, type = 'businessType') {
  214. if (value === '' || value == null) return '未知'
  215. // 业务类型
  216. if (type === 'businessType') {
  217. const hit = businessTypeList.value.find(i => String(i.value).trim() === String(value).trim())
  218. return hit ? hit.text : '未知'
  219. }
  220. // 单据状态
  221. if (type === 'status') {
  222. return statusMap.value[value] || '未知'
  223. }
  224. return '未知'
  225. }
  226. return {
  227. goHome,
  228. goBack,
  229. cardList,
  230. handleToScanMaterials,
  231. businessTypeList,
  232. computedState,
  233. businessTypeIndex,
  234. onBusinessTypeChange,
  235. handleSearch,
  236. requestNo,
  237. scanCode
  238. }
  239. }
  240. })
  241. </script>
  242. <style lang="scss" scoped>
  243. .gui-header-leader-btns {
  244. color: black;
  245. font-size: 24px !important;
  246. margin-left: 24rpx;
  247. }
  248. .list-content {
  249. margin-top: 50px;
  250. min-height: calc(100vh - 80px);
  251. background-color: #edeeee;
  252. }
  253. .search-bar {
  254. position: fixed;
  255. top: 72px;
  256. left: 0;
  257. width: 100%;
  258. background-color: #fff;
  259. padding: 12px;
  260. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  261. display: flex;
  262. flex-wrap: wrap;
  263. gap: 12px;
  264. z-index: 9;
  265. box-sizing: border-box;
  266. }
  267. .search-item {
  268. flex: 1 1 200px; // 原来只有 flex:1
  269. min-width: 200px;
  270. display: flex;
  271. align-items: center;
  272. gap: 8px;
  273. margin-bottom: 8px;
  274. }
  275. .search-input-wrapper {
  276. flex: 1;
  277. }
  278. .search-input {
  279. width: 90%;
  280. height: 36px;
  281. line-height: 36px;
  282. background-color: #f5f5f5;
  283. border-radius: 4px;
  284. padding: 0 12px;
  285. font-size: 12px;
  286. border: none;
  287. }
  288. .search-input-wrapper {
  289. flex: 1;
  290. position: relative;
  291. }
  292. .scan-icon {
  293. position: absolute;
  294. right: 10px;
  295. top: 50%;
  296. transform: translateY(-50%);
  297. font-size: 20px;
  298. color: #00a0e9;
  299. cursor: pointer;
  300. }
  301. .search-input:focus {
  302. outline: none;
  303. background-color: #fff;
  304. border: 1px solid #00a0e9;
  305. }
  306. .search-label {
  307. font-size: 12px;
  308. color: #666;
  309. }
  310. .search-select {
  311. flex: 1;
  312. position: relative;
  313. }
  314. .search-select picker {
  315. display: flex; // 关键:让内部文本撑开
  316. align-items: center;
  317. height: 36px;
  318. line-height: 36px;
  319. min-width: 120px; // 防止被 flex 挤没
  320. background-color: #f5f5f5;
  321. border-radius: 4px;
  322. padding: 0 28px 0 12px; // 右侧留图标位置
  323. }
  324. .picker-text {
  325. font-size: 12px;
  326. color: #333;
  327. display: flex;
  328. justify-content: space-between;
  329. align-items: center;
  330. }
  331. .picker-text::after {
  332. position: absolute;
  333. right: 8px;
  334. top: 50%;
  335. transform: translateY(-50%);
  336. }
  337. .search-btn {
  338. width: 80px;
  339. height: 36px;
  340. line-height: 36px;
  341. background-color: #00a0e9;
  342. color: #fff;
  343. border-radius: 4px;
  344. text-align: center;
  345. font-size: 12px;
  346. }
  347. .search-btn .font-icons {
  348. color: #fff;
  349. margin-right: 4px;
  350. }
  351. span,
  352. text {
  353. font-size: 12px;
  354. }
  355. .list-panel {
  356. padding: 12px;
  357. }
  358. .panel {
  359. background-color: white;
  360. border-radius: 8px;
  361. padding: 12px;
  362. margin-bottom: 12px;
  363. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  364. }
  365. .panel-row {
  366. display: flex;
  367. justify-content: space-between;
  368. align-items: center;
  369. margin-bottom: 8px;
  370. &:last-child {
  371. margin-bottom: 0;
  372. }
  373. span:first-child {
  374. color: #666;
  375. }
  376. span:last-child {
  377. font-weight: bold;
  378. }
  379. .font-icons {
  380. color: #00a0e9;
  381. display: flex;
  382. align-items: center;
  383. }
  384. }
  385. .bg-image {
  386. display: flex;
  387. flex-direction: column;
  388. align-items: center;
  389. justify-content: center;
  390. padding: 60px 0;
  391. image {
  392. width: 120px;
  393. height: 120px;
  394. margin-bottom: 16px;
  395. }
  396. text {
  397. color: #999;
  398. font-size: 14px;
  399. }
  400. }
  401. </style>