scanInPage.vue 10 KB

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