scanOutPage.vue 9.9 KB

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