scanOutPage.vue 10 KB

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