scanInPage.vue 9.6 KB

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