selectOrder.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. <template>
  2. <view class="content-box">
  3. <uni-nav-bar
  4. fixed="true"
  5. statusBar="true"
  6. left-icon="back"
  7. title="选择工单"
  8. background-color="#157A2C"
  9. color="#fff"
  10. @clickLeft="back"
  11. ></uni-nav-bar>
  12. <view class="top-wrapper">
  13. <uni-section>
  14. <uni-easyinput
  15. prefixIcon="search"
  16. v-model="searchForm.code"
  17. placeholder="生产工单号"
  18. ></uni-easyinput>
  19. </uni-section>
  20. <image
  21. class="menu_icon"
  22. src="~@/static/pda/menu.svg"
  23. @click="showFilter = true"
  24. ></image>
  25. <button class="search_btn" @click="handleSearch">搜索</button>
  26. </view>
  27. <scroll-view scroll-y class="list_box">
  28. <u-list @scrolltolower="loadMore">
  29. <u-list-item v-for="item in orderList" :key="item.id">
  30. <view class="order-item" :class="{ selected: isSelected(item) }">
  31. <view class="order-checkbox">
  32. <checkbox
  33. :checked="isSelected(item)"
  34. @click.stop="toggleSelect(item)"
  35. color="#157A2C"
  36. />
  37. </view>
  38. <view class="order-content" @click="toggleSelect(item)">
  39. <view class="order-header">
  40. <text class="order-code">{{ item.code }}</text>
  41. </view>
  42. <view class="order-row">
  43. <text class="label">计划编号:</text>
  44. <text class="value">{{ item.productionPlanCode }}</text>
  45. </view>
  46. <view class="order-row">
  47. <text class="label">产品名称:</text>
  48. <text class="value">{{ item.productName }}</text>
  49. </view>
  50. <view class="order-row">
  51. <text class="label">产品编码:</text>
  52. <text class="value">{{ item.productCode }}</text>
  53. </view>
  54. <view class="order-row">
  55. <text class="label">牌号:</text>
  56. <text class="value">{{ item.brandNo }}</text>
  57. </view>
  58. <view class="order-row">
  59. <text class="label">批次号:</text>
  60. <text class="value">{{ item.batchNo }}</text>
  61. </view>
  62. <view class="order-row">
  63. <text class="label">规格:</text>
  64. <text class="value">{{ item.specification }}</text>
  65. </view>
  66. <view class="order-row">
  67. <text class="label">型号:</text>
  68. <text class="value">{{ item.model }}</text>
  69. </view>
  70. <view class="order-row">
  71. <text class="label">要求生产数量:</text>
  72. <text class="value">{{ item.formingNum }}{{ item.unit }}</text>
  73. </view>
  74. <view class="order-row">
  75. <text class="label">计划开始时间:</text>
  76. <text class="value">{{ item.planStartTime }}</text>
  77. </view>
  78. </view>
  79. </view>
  80. </u-list-item>
  81. <u-list-item v-if="orderList.length === 0">
  82. <view class="empty-wrapper">
  83. <u-empty iconSize="150" textSize="32" text="暂无工单数据"></u-empty>
  84. </view>
  85. </u-list-item>
  86. <u-list-item>
  87. <view style="height: 120rpx"></view>
  88. </u-list-item>
  89. </u-list>
  90. </scroll-view>
  91. <view class="footer-btns">
  92. <view class="footer-left">
  93. <checkbox
  94. :checked="isAllSelected"
  95. @click="toggleSelectAll"
  96. color="#157A2C"
  97. />
  98. <text class="select-all-text">全选</text>
  99. </view>
  100. <view class="footer-right">
  101. <u-button class="btn-cancel" @click="handleCancel">取消</u-button>
  102. <u-button type="success" class="btn-confirm" @click="handleConfirm"
  103. >确定({{ selectedList.length }})</u-button
  104. >
  105. </view>
  106. </view>
  107. <SearchPopup mode="top" v-if="showFilter">
  108. <template v-slot:list>
  109. <view class="search_list">
  110. <u-form
  111. labelPosition="left"
  112. :model="searchForm"
  113. labelWidth="180"
  114. labelAlign="left"
  115. >
  116. <u-form-item label="产品名称:" borderBottom>
  117. <input
  118. v-model="searchForm.productName"
  119. placeholder="请输入产品名称"
  120. class="order-input"
  121. />
  122. </u-form-item>
  123. </u-form>
  124. </view>
  125. </template>
  126. <template v-slot:operate>
  127. <view class="operate_box">
  128. <u-button
  129. size="small"
  130. class="u-reset-button reset-btn"
  131. @click="filterCancel"
  132. >重置</u-button
  133. >
  134. <u-button
  135. type="success"
  136. size="small"
  137. class="u-reset-button confirm-btn"
  138. @click="filterConfirm"
  139. >确定</u-button
  140. >
  141. </view>
  142. </template>
  143. </SearchPopup>
  144. </view>
  145. </template>
  146. <script>
  147. import { produceOrder } from "@/api/entrust/index";
  148. import SearchPopup from "../../components/searchPopup.vue";
  149. let isEnd = false;
  150. export default {
  151. components: {
  152. SearchPopup,
  153. },
  154. data() {
  155. return {
  156. searchForm: {
  157. code: "",
  158. productName: "",
  159. statusList: ["4", "5"],
  160. },
  161. orderList: [],
  162. selectedList: [],
  163. preSelectedIds: [],
  164. pageNum: 1,
  165. pageSize: 20,
  166. total: 0,
  167. loading: false,
  168. hasMore: true,
  169. showFilter: false,
  170. };
  171. },
  172. computed: {
  173. isAllSelected() {
  174. return (
  175. this.orderList.length > 0 &&
  176. this.selectedList.length === this.orderList.length
  177. );
  178. },
  179. },
  180. onLoad(options) {
  181. if (options.selectedIds) {
  182. this.preSelectedIds = options.selectedIds.split(",");
  183. }
  184. this.loadData();
  185. },
  186. methods: {
  187. async loadData(isRefresh = false) {
  188. if (this.loading) return;
  189. if (isRefresh) {
  190. this.pageNum = 1;
  191. this.orderList = [];
  192. this.hasMore = true;
  193. }
  194. if (!this.hasMore) return;
  195. this.loading = true;
  196. isEnd = false;
  197. try {
  198. const res = await produceOrder({
  199. pageNum: this.pageNum,
  200. size: this.pageSize,
  201. ...this.searchForm,
  202. });
  203. if (this.pageNum === 1) {
  204. this.orderList = [];
  205. }
  206. if (res.list && res.list.length > 0) {
  207. this.orderList.push(...res.list);
  208. this.total = res.total;
  209. isEnd = this.orderList.length >= this.total;
  210. this.hasMore = !isEnd;
  211. // Auto-select pre-selected items
  212. if (this.preSelectedIds.length > 0) {
  213. this.orderList.forEach((item) => {
  214. if (
  215. this.preSelectedIds.includes(String(item.id)) &&
  216. !this.isSelected(item)
  217. ) {
  218. this.selectedList.push(item);
  219. }
  220. });
  221. }
  222. } else {
  223. isEnd = true;
  224. this.hasMore = false;
  225. }
  226. } catch (error) {
  227. uni.showToast({
  228. title: "加载失败",
  229. icon: "none",
  230. });
  231. } finally {
  232. this.loading = false;
  233. }
  234. },
  235. loadMore() {
  236. if (isEnd) return;
  237. this.pageNum++;
  238. this.loadData();
  239. },
  240. handleSearch() {
  241. this.loadData(true);
  242. },
  243. filterConfirm() {
  244. this.showFilter = false;
  245. this.loadData(true);
  246. },
  247. filterCancel() {
  248. this.searchForm.productName = "";
  249. this.showFilter = false;
  250. this.loadData(true);
  251. },
  252. isSelected(item) {
  253. return this.selectedList.some((selected) => selected.id === item.id);
  254. },
  255. toggleSelect(item) {
  256. const index = this.selectedList.findIndex(
  257. (selected) => selected.id === item.id,
  258. );
  259. if (index > -1) {
  260. this.selectedList.splice(index, 1);
  261. } else {
  262. this.selectedList.push(item);
  263. }
  264. },
  265. toggleSelectAll() {
  266. if (this.isAllSelected) {
  267. this.selectedList = [];
  268. } else {
  269. this.selectedList = [...this.orderList];
  270. }
  271. },
  272. handleCancel() {
  273. uni.navigateBack();
  274. },
  275. handleConfirm() {
  276. if (this.selectedList.length === 0) {
  277. uni.showToast({
  278. title: "请选择工单",
  279. icon: "none",
  280. });
  281. return;
  282. }
  283. // 通过事件总线或页面栈传递数据
  284. const pages = getCurrentPages();
  285. const prevPage = pages[pages.length - 2];
  286. if (prevPage) {
  287. prevPage.$vm.receiveOrder(this.selectedList);
  288. }
  289. uni.navigateBack();
  290. },
  291. },
  292. };
  293. </script>
  294. <style lang="scss" scoped>
  295. .content-box {
  296. height: 100vh;
  297. display: flex;
  298. flex-direction: column;
  299. background-color: $page-bg;
  300. }
  301. .top-wrapper {
  302. background-color: #fff;
  303. display: flex;
  304. width: 750rpx;
  305. padding: 16rpx 32rpx;
  306. align-items: center;
  307. gap: 16rpx;
  308. flex-shrink: 0;
  309. /deep/.uni-section {
  310. margin-top: 0px;
  311. }
  312. /deep/.uni-section-header {
  313. padding: 0px;
  314. }
  315. .search_btn {
  316. width: 120rpx;
  317. height: 70rpx;
  318. line-height: 70rpx;
  319. padding: 0 24rpx;
  320. background: $theme-color;
  321. font-size: 32rpx;
  322. color: #fff;
  323. margin: 0;
  324. }
  325. .menu_icon {
  326. width: 44rpx;
  327. height: 44rpx;
  328. }
  329. }
  330. .list_box {
  331. flex: 1;
  332. height: 0;
  333. .u-list {
  334. height: 100% !important;
  335. }
  336. }
  337. .order-item {
  338. background-color: #fff;
  339. border-radius: 12rpx;
  340. padding: 24rpx;
  341. margin: 16rpx 24rpx 20rpx;
  342. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.08);
  343. border: 2rpx solid transparent;
  344. transition: all 0.3s;
  345. display: flex;
  346. gap: 16rpx;
  347. &.selected {
  348. border-color: $theme-color;
  349. background-color: rgba(21, 122, 44, 0.06);
  350. }
  351. .order-checkbox {
  352. display: flex;
  353. align-items: flex-start;
  354. padding-top: 4rpx;
  355. }
  356. .order-content {
  357. flex: 1;
  358. }
  359. .order-header {
  360. display: flex;
  361. justify-content: space-between;
  362. align-items: center;
  363. margin-bottom: 20rpx;
  364. padding-bottom: 20rpx;
  365. border-bottom: 1rpx solid #f0f0f0;
  366. .order-code {
  367. font-size: 32rpx;
  368. font-weight: bold;
  369. color: $theme-color;
  370. }
  371. }
  372. .order-row {
  373. display: flex;
  374. margin-bottom: 16rpx;
  375. font-size: 28rpx;
  376. .label {
  377. color: #999;
  378. min-width: 220rpx;
  379. }
  380. .value {
  381. flex: 1;
  382. color: #333;
  383. word-break: break-all;
  384. }
  385. }
  386. }
  387. .empty-wrapper {
  388. display: flex;
  389. align-items: center;
  390. justify-content: center;
  391. padding-top: 25vh;
  392. }
  393. .footer-btns {
  394. display: flex;
  395. justify-content: space-between;
  396. align-items: center;
  397. gap: 20rpx;
  398. padding: 20rpx 32rpx;
  399. background-color: #fff;
  400. box-shadow: 0 -2rpx 8rpx rgba(0, 0, 0, 0.08);
  401. padding-bottom: constant(safe-area-inset-bottom);
  402. padding-bottom: env(safe-area-inset-bottom);
  403. position: fixed;
  404. bottom: 0;
  405. left: 0;
  406. right: 0;
  407. z-index: 100;
  408. .footer-left {
  409. display: flex;
  410. align-items: center;
  411. gap: 12rpx;
  412. .select-all-text {
  413. font-size: 28rpx;
  414. color: #333;
  415. }
  416. }
  417. .footer-right {
  418. display: flex;
  419. gap: 20rpx;
  420. }
  421. /deep/ .u-button {
  422. height: 80rpx;
  423. border-radius: 40rpx;
  424. font-size: 30rpx;
  425. min-width: 160rpx;
  426. white-space: nowrap;
  427. }
  428. .btn-cancel {
  429. background-color: #fff;
  430. color: #666;
  431. border: 1rpx solid #e0e0e0;
  432. }
  433. }
  434. .search_list {
  435. min-height: 100rpx;
  436. padding: 24rpx 32rpx;
  437. .form-input {
  438. padding: 12rpx 16rpx;
  439. border: 1rpx solid #e0e0e0;
  440. border-radius: 6rpx;
  441. font-size: 28rpx;
  442. }
  443. }
  444. .operate_box {
  445. display: flex;
  446. flex-direction: row;
  447. align-items: center;
  448. justify-content: space-between;
  449. padding: 24rpx 32rpx 32rpx;
  450. gap: 24rpx;
  451. .reset-btn {
  452. flex: 1;
  453. height: 72rpx;
  454. border-radius: 36rpx;
  455. font-size: $uni-font-size-sm;
  456. }
  457. .confirm-btn {
  458. flex: 1;
  459. height: 72rpx;
  460. border-radius: 36rpx;
  461. font-size: $uni-font-size-sm;
  462. }
  463. }
  464. .order-input {
  465. flex: 1;
  466. padding: 20rpx 16rpx;
  467. border: 1rpx solid #e0e0e0;
  468. border-radius: 8rpx;
  469. font-size: 28rpx;
  470. min-height: 80rpx;
  471. background-color: #fff;
  472. }
  473. </style>