index.uvue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. <template>
  2. <uni-navbar-lite @rightClick="handleRight" :show-right="showRight" title="采购订单"></uni-navbar-lite>
  3. <view class="list-page">
  4. <view class="search-block">
  5. <view class="search-bar">
  6. <view class="search-box">
  7. <image class="search-icon" src="/static/images/workbench/list/1.png" mode="aspectFit"></image>
  8. <input class="search-input" type="text" placeholder="请输入供应商名称" v-model="keyword" @input="handleSearch" />
  9. <view v-if="keyword.length > 0" class="clear-btn" @tap="clearKeyword">
  10. <text class="clear-btn-text">×</text>
  11. </view>
  12. <view class="search-btn" @tap="handleSearch">
  13. <text class="search-btn-text">搜索</text>
  14. </view>
  15. </view>
  16. </view>
  17. <scroll-view class="status-tabs" scroll-x="true">
  18. <view class="status-tab" :class="{ 'active': currentStatus === '' }" @tap="handleStatusChange('')">
  19. <text class="status-tab-text" :class="{ 'active-text': currentStatus === '' }">全部</text>
  20. </view>
  21. <view class="status-tab" :class="{ 'active': currentStatus === 'PREPARE' }" @tap="handleStatusChange('PREPARE')">
  22. <text class="status-tab-text" :class="{ 'active-text': currentStatus === 'PREPARE' }">草稿</text>
  23. </view>
  24. <view class="status-tab" :class="{ 'active': currentStatus === 'CONFIRMED' }" @tap="handleStatusChange('CONFIRMED')">
  25. <text class="status-tab-text" :class="{ 'active-text': currentStatus === 'CONFIRMED' }">已确认</text>
  26. </view>
  27. <view class="status-tab" :class="{ 'active': currentStatus === 'FINISHED' }" @tap="handleStatusChange('FINISHED')">
  28. <text class="status-tab-text" :class="{ 'active-text': currentStatus === 'FINISHED' }">已完成</text>
  29. </view>
  30. <view class="status-tab" :class="{ 'active': currentStatus === 'CANCEL' }" @tap="handleStatusChange('CANCEL')">
  31. <text class="status-tab-text" :class="{ 'active-text': currentStatus === 'CANCEL' }">已取消</text>
  32. </view>
  33. </scroll-view>
  34. </view>
  35. <common-list
  36. :dataList="dataList"
  37. :loading="loading"
  38. :refreshing="refreshing"
  39. :hasMore="hasMore"
  40. @refresh="handleRefresh"
  41. @loadMore="loadMore"
  42. >
  43. <template #default="{ item, index }">
  44. <view class="list-item" @tap="handleItemClick(item, index)">
  45. <view class="item-container">
  46. <view class="item-header">
  47. <text class="item-title">{{ getPurchaseCode(item) }}</text>
  48. <text class="item-status" :class="'status-' + getStatus(item)">{{ getStatusText(item) }}</text>
  49. </view>
  50. <view class="item-info">
  51. <view class="info-row">
  52. <view class="info-item">
  53. <text class="info-label">供应商</text>
  54. <text class="info-value">{{ getVendorName(item) }}</text>
  55. </view>
  56. </view>
  57. <view class="info-row">
  58. <view class="info-item">
  59. <text class="info-label">创建人</text>
  60. <text class="info-value">{{ getNickName(item) }}</text>
  61. </view>
  62. <view class="info-item">
  63. <text class="info-label">创建时间</text>
  64. <text class="info-value">{{ getCreateTime(item) }}</text>
  65. </view>
  66. </view>
  67. <view class="info-row">
  68. <view class="info-item">
  69. <text class="info-label">金额</text>
  70. <text class="info-value warning">{{ getTotalAmount(item) }}</text>
  71. </view>
  72. <view class="info-item">
  73. <text class="info-label">合同</text>
  74. <text class="info-value">{{ getContractNumber(item) || '-' }}</text>
  75. </view>
  76. </view>
  77. </view>
  78. <view class="item-footer">
  79. <text class="item-name">{{ getPurchaseName(item) }}</text>
  80. <text class="arrow">›</text>
  81. </view>
  82. </view>
  83. </view>
  84. </template>
  85. </common-list>
  86. </view>
  87. </template>
  88. <script setup lang="uts">
  89. import { ref, onMounted } from 'vue'
  90. import { onShow } from '@dcloudio/uni-app'
  91. import { listPurchase } from '../../api/purchase/index'
  92. const dataList = ref<any[]>([])
  93. const keyword = ref<string>("")
  94. let searchTimer: number | null = null
  95. const currentStatus = ref<string>("")
  96. const page = ref<number>(1)
  97. const pageSize: number = 20
  98. const hasMore = ref<boolean>(true)
  99. const loading = ref<boolean>(false)
  100. const refreshing = ref<boolean>(false)
  101. const showRight = ref<boolean>(false)
  102. const getPurchaseCode = (item: any | null): string => {
  103. if (item == null) return ''
  104. const jsonItem = item as UTSJSONObject
  105. const val = jsonItem['purchaseCode']
  106. return val != null ? val.toString() : ''
  107. }
  108. const getPurchaseName = (item: any | null): string => {
  109. if (item == null) return ''
  110. const jsonItem = item as UTSJSONObject
  111. const val = jsonItem['purchaseName']
  112. return val != null ? val.toString() : ''
  113. }
  114. const getStatus = (item: any | null): string => {
  115. if (item == null) return ''
  116. const jsonItem = item as UTSJSONObject
  117. const val = jsonItem['status']
  118. return val != null ? val.toString() : ''
  119. }
  120. const getStatusText = (item: any | null): string => {
  121. if (item == null) return ''
  122. const jsonItem = item as UTSJSONObject
  123. const val = jsonItem['status']
  124. const status = val != null ? val.toString() : ''
  125. switch (status) {
  126. case 'PREPARE': return '草稿'
  127. case 'CONFIRMED': return '已确认'
  128. case 'FINISHED': return '已完成'
  129. case 'CANCEL': return '已取消'
  130. default: return status
  131. }
  132. }
  133. const getVendorName = (item: any | null): string => {
  134. if (item == null) return ''
  135. const jsonItem = item as UTSJSONObject
  136. const val = jsonItem['vendorName']
  137. return val != null ? val.toString() : '-'
  138. }
  139. const getTotalAmount = (item: any | null): string => {
  140. if (item == null) return '0.00'
  141. const jsonItem = item as UTSJSONObject
  142. const val = jsonItem['totalAmount']
  143. if (val == null) return '0.00'
  144. const num = Number(val)
  145. if (isNaN(num)) return '0.00'
  146. return num.toFixed(2)
  147. }
  148. const getNickName = (item: any | null): string => {
  149. if (item == null) return ''
  150. const jsonItem = item as UTSJSONObject
  151. const val = jsonItem['nickName']
  152. return val != null ? val.toString() : '-'
  153. }
  154. const getCreateTime = (item: any | null): string => {
  155. if (item == null) return ''
  156. const jsonItem = item as UTSJSONObject
  157. const val = jsonItem['createTime']
  158. if (val == null) return '-'
  159. const dateStr = val.toString()
  160. if (dateStr.length >= 16) {
  161. return dateStr.substring(0, 16)
  162. }
  163. return dateStr
  164. }
  165. const getContractNumber = (item: any | null): string => {
  166. if (item == null) return ''
  167. const jsonItem = item as UTSJSONObject
  168. const val = jsonItem['contractNumber']
  169. return val != null ? val.toString() : ''
  170. }
  171. const getFromSys = (item: any | null): string => {
  172. if (item == null) return ''
  173. const jsonItem = item as UTSJSONObject
  174. const val = jsonItem['fromSys']
  175. const sys = val != null ? val.toString() : ''
  176. switch (sys) {
  177. case 'oa': return 'OA'
  178. case 'self': return '本系统'
  179. default: return sys
  180. }
  181. }
  182. const loadData = async (isRefresh: boolean): Promise<void> => {
  183. if (loading.value) return
  184. try {
  185. loading.value = true
  186. if (isRefresh) {
  187. page.value = 1
  188. }
  189. const searchKeyword = keyword.value != null ? keyword.value : ''
  190. const statusParam = currentStatus.value != null ? currentStatus.value : ''
  191. const query = new UTSJSONObject()
  192. query['pageNum'] = page.value
  193. query['pageSize'] = pageSize
  194. if (searchKeyword.length > 0) {
  195. query['vendorName'] = searchKeyword
  196. }
  197. if (statusParam.length > 0) {
  198. query['status'] = statusParam
  199. }
  200. const result = await listPurchase(query)
  201. const resultObj = result as UTSJSONObject
  202. const rows = resultObj['rows']
  203. const total = resultObj['total'] as number
  204. if (rows != null) {
  205. const newData = rows as any[]
  206. if (isRefresh) {
  207. dataList.value = newData
  208. } else {
  209. dataList.value = [...dataList.value, ...newData]
  210. }
  211. hasMore.value = dataList.value.length < total
  212. } else {
  213. if (isRefresh) {
  214. dataList.value = []
  215. }
  216. hasMore.value = false
  217. }
  218. } catch (e) {
  219. console.error('加载失败:', e)
  220. } finally {
  221. loading.value = false
  222. refreshing.value = false
  223. }
  224. }
  225. const handleRefresh = (): void => {
  226. refreshing.value = true
  227. loadData(true)
  228. }
  229. const loadMore = (): void => {
  230. if (!hasMore.value || loading.value) return
  231. page.value++
  232. loadData(false)
  233. }
  234. const handleSearch = (): void => {
  235. const timer = searchTimer
  236. if (timer != null) {
  237. clearTimeout(timer)
  238. }
  239. searchTimer = setTimeout(() => {
  240. loadData(true)
  241. }, 300)
  242. }
  243. const clearKeyword = (): void => {
  244. keyword.value = ''
  245. loadData(true)
  246. }
  247. const handleStatusChange = (status: string): void => {
  248. currentStatus.value = status
  249. loadData(true)
  250. }
  251. const handleRight = (): void => {
  252. uni.navigateTo({
  253. url: `/pages/purchase/createByApply`
  254. })
  255. }
  256. const handleItemClick = (item: any | null, index: number): void => {
  257. if (item == null) return
  258. const jsonItem = item as UTSJSONObject
  259. const purchaseId = jsonItem['purchaseId']
  260. if (purchaseId == null) return
  261. const status = getStatus(item)
  262. uni.navigateTo({
  263. url: `/pages/purchase/detail?id=${purchaseId}`
  264. })
  265. }
  266. onMounted(() => {
  267. loadData(true)
  268. })
  269. onShow(() => {
  270. const needRefresh = uni.getStorageSync('needRefresh')
  271. if (needRefresh === 'true') {
  272. uni.removeStorageSync('needRefresh')
  273. loadData(true)
  274. }
  275. })
  276. </script>
  277. <style lang="scss">
  278. .list-page {
  279. flex: 1;
  280. background-color: #e8f0f9;
  281. }
  282. .search-block {
  283. background-color: #ffffff;
  284. }
  285. .search-bar {
  286. padding: 20rpx 30rpx;
  287. }
  288. .search-box {
  289. flex-direction: row;
  290. align-items: center;
  291. height: 72rpx;
  292. padding: 0 24rpx;
  293. background-color: #f5f5f5;
  294. border-radius: 36rpx;
  295. .search-icon {
  296. width: 32rpx;
  297. height: 32rpx;
  298. margin-right: 12rpx;
  299. }
  300. .search-input {
  301. flex: 1;
  302. font-size: 28rpx;
  303. color: #333333;
  304. }
  305. .search-btn {
  306. padding: 10rpx 20rpx;
  307. background-color: #007aff;
  308. border-radius: 8rpx;
  309. margin-left: 10rpx;
  310. }
  311. .search-btn-text {
  312. color: #ffffff;
  313. font-size: 24rpx;
  314. }
  315. .clear-btn {
  316. width: 36rpx;
  317. height: 36rpx;
  318. border-radius: 18rpx;
  319. background-color: #cccccc;
  320. align-items: center;
  321. justify-content: center;
  322. margin-left: 10rpx;
  323. }
  324. .clear-btn-text {
  325. color: #ffffff;
  326. font-size: 24rpx;
  327. font-weight: bold;
  328. }
  329. }
  330. .status-tabs {
  331. display: flex;
  332. flex-direction: row;
  333. padding: 0rpx 30rpx 20rpx;
  334. background-color: #ffffff;
  335. white-space: nowrap;
  336. width: 100%;
  337. }
  338. .status-tab {
  339. display: inline-flex;
  340. flex-direction: row;
  341. align-items: center;
  342. padding: 16rpx 24rpx;
  343. text-align: center;
  344. position: relative;
  345. margin-right: 16rpx;
  346. border-radius: 8rpx;
  347. background-color: #f5f5f5;
  348. justify-content: center;
  349. align-items: center;
  350. &.active {
  351. background-color: #007aff;
  352. }
  353. .status-tab-text {
  354. font-size: 26rpx;
  355. color: #666666;
  356. text-align: center;
  357. &.active-text {
  358. color: #ffffff;
  359. font-weight: bold;
  360. }
  361. }
  362. }
  363. .list-item {
  364. margin: 10rpx 20rpx;
  365. background-color: #ffffff;
  366. border-radius: 16rpx;
  367. }
  368. .item-container {
  369. padding: 30rpx;
  370. }
  371. .item-header {
  372. flex-direction: row;
  373. align-items: center;
  374. margin-bottom: 20rpx;
  375. .item-title {
  376. flex: 1;
  377. font-size: 32rpx;
  378. color: #333333;
  379. font-weight: bold;
  380. }
  381. .item-status {
  382. font-size: 26rpx;
  383. padding: 6rpx 16rpx;
  384. border-radius: 6rpx;
  385. &.status-PREPARE {
  386. background-color: #f0f0f0;
  387. color: #666666;
  388. }
  389. &.status-CONFIRMED {
  390. background-color: #e6f7ff;
  391. color: #1890ff;
  392. }
  393. &.status-FINISHED {
  394. background-color: #f6ffed;
  395. color: #52c41a;
  396. }
  397. &.status-CANCEL {
  398. background-color: #fff1f0;
  399. color: #ff4d4f;
  400. }
  401. }
  402. }
  403. .item-info {
  404. padding: 20rpx;
  405. background-color: #f8f9fa;
  406. border-radius: 8rpx;
  407. .info-row {
  408. flex-direction: row;
  409. justify-content: space-between;
  410. margin-bottom: 16rpx;
  411. &:last-child {
  412. margin-bottom: 0;
  413. }
  414. .info-item {
  415. flex-direction: row;
  416. align-items: center;
  417. flex: 1;
  418. &:last-child {
  419. flex: 1;
  420. justify-content: flex-end;
  421. }
  422. .info-label {
  423. font-size: 26rpx;
  424. color: #666666;
  425. margin-right: 8rpx;
  426. white-space: nowrap;
  427. }
  428. .info-value {
  429. font-size: 26rpx;
  430. color: #333333;
  431. flex: 1;
  432. &.warning {
  433. color: #faad14;
  434. }
  435. }
  436. }
  437. }
  438. }
  439. .item-footer {
  440. flex-direction: row;
  441. justify-content: space-between;
  442. align-items: center;
  443. margin-top: 20rpx;
  444. .item-name {
  445. font-size: 26rpx;
  446. color: #999999;
  447. flex: 1;
  448. }
  449. .arrow {
  450. font-size: 36rpx;
  451. color: #cccccc;
  452. }
  453. }
  454. </style>