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