addPick.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. <template>
  2. <view class="page">
  3. <!-- 顶部标题栏 -->
  4. <uni-nav-bar
  5. fixed
  6. statusBar
  7. left-icon="back"
  8. title="新建领料单"
  9. background-color="#157A2C"
  10. color="#fff"
  11. @clickLeft="back"
  12. />
  13. <!-- 顶部表单 -->
  14. <view class="form-section">
  15. <view class="form-item">
  16. <text class="label">领料单编号</text>
  17. <uni-easyinput v-model="pickForm.pickCode" disabled />
  18. </view>
  19. <view class="form-item">
  20. <text class="label">领料单名称</text>
  21. <uni-easyinput
  22. v-model="pickForm.pickName"
  23. placeholder="请输入领料单名称"
  24. />
  25. </view>
  26. <view class="btn-add">
  27. <button type="primary" size="mini" @click="openPicking">
  28. 添加物料
  29. </button>
  30. </view>
  31. </view>
  32. <!-- 页面主体滚动区域 -->
  33. <scroll-view class="scroll-container" scroll-y="true" scroll-with-animation>
  34. <!-- 物料列表 -->
  35. <view class="material-list">
  36. <view
  37. class="material-card"
  38. v-for="(mate, idx) in objPick.pickList"
  39. :key="idx"
  40. >
  41. <!-- 删除按钮 -->
  42. <view class="delete-btn" @click.stop="removeItem(idx)">
  43. <uni-icons
  44. custom-prefix="iconfont"
  45. type="icon-shanchu"
  46. size="28"
  47. color="#fa3534"
  48. />
  49. </view>
  50. <!-- 卡片内容 -->
  51. <view class="card-content">
  52. <view class="card-row">
  53. <text class="label">编码:</text>
  54. <text class="value">{{
  55. mate.rootCategoryLevelId == 4 ? mate.codeNumber : mate.code
  56. }}</text>
  57. </view>
  58. <view class="card-row">
  59. <text class="label">名称:</text>
  60. <text class="value">{{ mate.name }}</text>
  61. </view>
  62. <view class="card-row">
  63. <text class="label">类型:</text>
  64. <text class="value">{{
  65. typeName[Number(mate.rootCategoryLevelId)]
  66. }}</text>
  67. </view>
  68. <view class="card-row">
  69. <text class="label">库存数量:</text>
  70. <text class="value"
  71. >{{ mate.measureQuantity }} {{ mate.measuringUnit }}</text
  72. >
  73. </view>
  74. <view class="card-row">
  75. <text class="label">数量:</text>
  76. <view class="input-row">
  77. <uni-easyinput
  78. v-model="mate.demandQuantity"
  79. placeholder="请输入数量"
  80. type="text"
  81. />
  82. <text class="unit">{{ mate.measuringUnit }}</text>
  83. </view>
  84. </view>
  85. <view class="card-row">
  86. <text class="label">型号:</text>
  87. <text class="value">{{ mate.modelType }}</text>
  88. </view>
  89. <view class="card-row">
  90. <text class="label">规格:</text>
  91. <text class="value">{{ mate.specification }}</text>
  92. </view>
  93. <view class="card-row">
  94. <text class="label">批次号:</text>
  95. <text class="value">{{ mate.batchNo }}</text>
  96. </view>
  97. <view class="card-row">
  98. <text class="label">牌号:</text>
  99. <text class="value">{{ mate.brandNum }}</text>
  100. </view>
  101. <view class="card-row">
  102. <text class="label">领料仓库:</text>
  103. <zxz-uni-data-select
  104. :localdata="mate.warehouseList"
  105. v-model="mate.warehouseId"
  106. dataValue="warehouse_id"
  107. format="{warehouse_name}"
  108. dataKey="warehouse_name"
  109. filterable
  110. />
  111. </view>
  112. </view>
  113. </view>
  114. </view>
  115. </scroll-view>
  116. <!-- 底部操作按钮 -->
  117. <view class="footer-btn">
  118. <button @click="close" size="mini">取消</button>
  119. <button type="primary" @click="save" size="mini">提交</button>
  120. </view>
  121. </view>
  122. </template>
  123. <script>
  124. import { unproductive, getCode } from "@/api/pda/selfBuiltPickOrder.js";
  125. import { typeName } from "@/pages/pda/feeding/common.js";
  126. export default {
  127. data() {
  128. return {
  129. pickForm: {
  130. pickCode: "",
  131. pickName: "",
  132. },
  133. objPick: {
  134. pickList: [],
  135. },
  136. selectionData: [],
  137. typeName,
  138. };
  139. },
  140. onLoad() {
  141. this.getOrderCode();
  142. },
  143. onShow() {
  144. uni.$off("setSelectList");
  145. uni.$on("setSelectList", (selectList, id) => {
  146. selectList.forEach((item) => {
  147. item.code = item.categoryCode;
  148. item.name = item.categoryName;
  149. item.modelType = item.categoryModel;
  150. item.measuringUnit = item.measuringUnit
  151. ? item.measuringUnit
  152. : item.measureUnit;
  153. item.unit = item.unit ? item.unit : item.measureUnit;
  154. item.demandQuantity = "";
  155. });
  156. const newData = [];
  157. if (selectList.length != 0) {
  158. selectList.forEach((it) => {
  159. newData.push(this.deepCopy(it));
  160. });
  161. }
  162. this.objPick = {
  163. pickList: newData,
  164. };
  165. this.$forceUpdate();
  166. });
  167. },
  168. methods: {
  169. async getOrderCode() {
  170. this.pickForm.pickCode = await getCode("pick_order_code");
  171. },
  172. deepCopy(obj, hash = new WeakMap()) {
  173. if (obj === null) return null;
  174. if (obj instanceof Date) return new Date(obj);
  175. if (obj instanceof RegExp) return new RegExp(obj);
  176. if (typeof obj !== "object" && typeof obj !== "function") return obj;
  177. if (hash.has(obj)) return hash.get(obj);
  178. const result = Array.isArray(obj) ? [] : {};
  179. hash.set(obj, result);
  180. return Object.keys(obj).reduce((acc, key) => {
  181. acc[key] = this.deepCopy(obj[key], hash);
  182. return acc;
  183. }, result);
  184. },
  185. checkItem(row) {
  186. row.checked = !row.checked;
  187. },
  188. limitNum(row) {
  189. if (row.demandQuantity > row.measureQuantity) {
  190. row.demandQuantity = row.measureQuantity;
  191. }
  192. },
  193. // batchDelete() {
  194. // const filter = this.objPick.pickList.filter((i) => !i.checked);
  195. // if (filter.length === this.objPick.pickList.length) {
  196. // return uni.showToast({ title: "请选择需要删除的数据", icon: "none" });
  197. // }
  198. // this.objPick.pickList = filter;
  199. // },
  200. removeItem(index) {
  201. this.objPick.pickList.splice(index, 1);
  202. },
  203. openPicking() {
  204. const storageKey = Date.now() + "";
  205. uni.setStorageSync(storageKey, this.objPick.pickList || []);
  206. uni.navigateTo({
  207. url: `/pages/pda/selfBuiltPickOrder/components/choosePickList?isType=pick&storageKey=${storageKey}`,
  208. });
  209. },
  210. // allSelection(id, list) {
  211. // list.forEach((i) => {
  212. // i.code = i.categoryCode;
  213. // i.name = i.categoryName;
  214. // i.measuringUnit = i.measuringUnit || i.measureUnit;
  215. // });
  216. // this.objPick.pickList = JSON.parse(JSON.stringify(list));
  217. // },
  218. save() {
  219. if (!this.pickForm.pickName) {
  220. return uni.showToast({ title: "请输入领料单名称", icon: "none" });
  221. }
  222. if (this.objPick.pickList.length == 0) {
  223. return uni.showToast({ title: "请选择物料", icon: "none" });
  224. }
  225. if (this.objPick.pickList.length > 0) {
  226. let name;
  227. let bol2;
  228. let _i;
  229. bol2 = this.objPick.pickList.every((e, i) => {
  230. _i = i;
  231. name = e.name;
  232. // e.categoryId = e.id;
  233. // e.id = e.categoryId
  234. return (
  235. Object.prototype.hasOwnProperty.call(e, "demandQuantity") &&
  236. Number(e.demandQuantity) > 0 &&
  237. e.warehouseId
  238. );
  239. });
  240. if (!bol2) {
  241. // this.$message.warning(
  242. // `${this.objPick.pickList[_i].code}的${name}数据不能为空`
  243. // );
  244. // return false;
  245. return uni.showToast({
  246. title: `${this.objPick.pickList[_i].code}的${name}数量不能为空`,
  247. icon: "none",
  248. });
  249. }
  250. }
  251. let param = {
  252. detailList: this.objPick.pickList,
  253. name: this.pickForm.pickName,
  254. code: this.pickForm.pickCode,
  255. };
  256. unproductive(param).then((res) => {
  257. uni.showToast({ title: "提交成功" });
  258. setTimeout(() => {
  259. uni.navigateBack();
  260. }, 500);
  261. });
  262. // if (!this.objPick.pickList.length) {
  263. // return uni.showToast({ title: "请选择物料", icon: "none" });
  264. // }
  265. // const valid = this.objPick.pickList.every(
  266. // (e) => e.demandQuantity > 0 && e.warehouseId
  267. // );
  268. // if (!valid) {
  269. // return uni.showToast({ title: "请完善物料信息", icon: "none" });
  270. // }
  271. // const param = {
  272. // detailList: this.objPick.pickList,
  273. // name: this.pickForm.pickName,
  274. // code: this.pickForm.pickCode,
  275. // };
  276. // unproductive(param).then(() => {
  277. // uni.showToast({ title: "提交成功" });
  278. // this.close(true);
  279. // });
  280. },
  281. close(refresh) {
  282. uni.$emit("closePick", refresh);
  283. uni.navigateBack();
  284. },
  285. },
  286. };
  287. </script>
  288. <style lang="scss" scoped>
  289. .page {
  290. display: flex;
  291. flex-direction: column;
  292. height: 100vh;
  293. background-color: #f7f7f7;
  294. }
  295. .scroll-container {
  296. flex: 1;
  297. padding: 10rpx 16rpx;
  298. overflow-y: auto;
  299. padding-bottom: 115rpx;
  300. }
  301. /* 顶部表单 */
  302. .form-section {
  303. background: #fff;
  304. border-radius: 12rpx;
  305. padding: 16rpx;
  306. margin-bottom: 16rpx;
  307. .form-item {
  308. display: flex;
  309. flex-wrap: wrap;
  310. align-items: center;
  311. margin-bottom: 12rpx;
  312. .label {
  313. width: 30%;
  314. font-size: 28rpx;
  315. color: #666;
  316. margin-bottom: 4rpx;
  317. }
  318. uni-easyinput {
  319. flex: 1;
  320. }
  321. }
  322. .btn-add {
  323. display: flex;
  324. justify-content: flex-end;
  325. }
  326. }
  327. /* 物料列表卡片 */
  328. .material-list {
  329. display: flex;
  330. flex-direction: column;
  331. gap: 16rpx;
  332. .material-card {
  333. position: relative;
  334. background: #fff;
  335. border-radius: 12rpx;
  336. padding: 16rpx;
  337. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
  338. transition: background 0.2s;
  339. &:active {
  340. background: #f5f5f5;
  341. }
  342. .delete-btn {
  343. position: absolute;
  344. top: 8rpx;
  345. right: 8rpx;
  346. width: 40rpx;
  347. height: 40rpx;
  348. display: flex;
  349. justify-content: center;
  350. align-items: center;
  351. z-index: 10;
  352. background: rgba(255, 255, 255, 0.8);
  353. border-radius: 50%;
  354. box-shadow: 0 1rpx 3rpx rgba(0, 0, 0, 0.2);
  355. }
  356. .card-content {
  357. display: flex;
  358. flex-direction: column;
  359. gap: 8rpx;
  360. .card-row {
  361. display: flex;
  362. // flex-wrap: wrap;
  363. align-items: center;
  364. .label {
  365. width: 22%;
  366. flex-shrink: 0;
  367. font-size: 26rpx;
  368. color: #666;
  369. margin-bottom: 4rpx;
  370. }
  371. .input-row {
  372. display: flex;
  373. align-items: center;
  374. gap: 8rpx;
  375. uni-easyinput {
  376. flex: 1; // 占满剩余空间
  377. min-width: 0; // ✅允许收缩,防止换行
  378. }
  379. .unit {
  380. flex-shrink: 0; // 单位宽度固定
  381. font-size: 24rpx;
  382. color: #666;
  383. }
  384. }
  385. }
  386. }
  387. }
  388. }
  389. /* 底部固定按钮 */
  390. .footer-btn {
  391. position: fixed;
  392. bottom: 0;
  393. left: 0;
  394. width: 100%;
  395. background: #fff;
  396. padding: 16rpx;
  397. display: flex;
  398. justify-content: space-between;
  399. box-shadow: 0 -2rpx 6rpx rgba(0, 0, 0, 0.05);
  400. z-index: 20;
  401. }
  402. /deep/ .uni-easyinput__content-input {
  403. padding-left: 0;
  404. }
  405. </style>