addPick.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  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. <scroll-view class="scroll-container" scroll-y="true" scroll-with-animation>
  15. <!-- 顶部表单 -->
  16. <view class="form-section">
  17. <view class="form-item">
  18. <text class="label">领料单编号</text>
  19. <uni-easyinput v-model="pickForm.pickCode" disabled />
  20. </view>
  21. <view class="form-item">
  22. <text class="label">领料单名称</text>
  23. <uni-easyinput
  24. v-model="pickForm.pickName"
  25. placeholder="请输入领料单名称"
  26. />
  27. </view>
  28. <view class="btn-add">
  29. <button type="primary" size="mini" @click="openPicking">
  30. 添加物料
  31. </button>
  32. </view>
  33. </view>
  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. console.log(this.objPick, "11111");
  166. this.$forceUpdate();
  167. });
  168. },
  169. methods: {
  170. async getOrderCode() {
  171. this.pickForm.pickCode = await getCode("pick_order_code");
  172. },
  173. deepCopy(obj, hash = new WeakMap()) {
  174. if (obj === null) return null;
  175. if (obj instanceof Date) return new Date(obj);
  176. if (obj instanceof RegExp) return new RegExp(obj);
  177. if (typeof obj !== "object" && typeof obj !== "function") return obj;
  178. if (hash.has(obj)) return hash.get(obj);
  179. const result = Array.isArray(obj) ? [] : {};
  180. hash.set(obj, result);
  181. return Object.keys(obj).reduce((acc, key) => {
  182. acc[key] = this.deepCopy(obj[key], hash);
  183. return acc;
  184. }, result);
  185. },
  186. openPicking() {
  187. // this.$refs.pickingRef.open(this.objPick);
  188. },
  189. checkItem(row) {
  190. row.checked = !row.checked;
  191. },
  192. limitNum(row) {
  193. if (row.demandQuantity > row.measureQuantity) {
  194. row.demandQuantity = row.measureQuantity;
  195. }
  196. },
  197. // batchDelete() {
  198. // const filter = this.objPick.pickList.filter((i) => !i.checked);
  199. // if (filter.length === this.objPick.pickList.length) {
  200. // return uni.showToast({ title: "请选择需要删除的数据", icon: "none" });
  201. // }
  202. // this.objPick.pickList = filter;
  203. // },
  204. removeItem(index) {
  205. this.objPick.pickList.splice(index, 1);
  206. },
  207. openPicking() {
  208. const storageKey = Date.now() + "";
  209. uni.setStorageSync(storageKey, this.objPick.pickList || []);
  210. uni.navigateTo({
  211. url: `/pages/pda/selfBuiltPickOrder/components/choosePickList?isType=pick&storageKey=${storageKey}`,
  212. });
  213. },
  214. // allSelection(id, list) {
  215. // list.forEach((i) => {
  216. // i.code = i.categoryCode;
  217. // i.name = i.categoryName;
  218. // i.measuringUnit = i.measuringUnit || i.measureUnit;
  219. // });
  220. // this.objPick.pickList = JSON.parse(JSON.stringify(list));
  221. // },
  222. save() {
  223. if (!this.pickForm.pickName) {
  224. return uni.showToast({ title: "请输入领料单名称", icon: "none" });
  225. }
  226. if (this.objPick.pickList.length == 0) {
  227. return uni.showToast({ title: "请选择物料", icon: "none" });
  228. }
  229. if (this.objPick.pickList.length > 0) {
  230. let name;
  231. let bol2;
  232. let _i;
  233. bol2 = this.objPick.pickList.every((e, i) => {
  234. _i = i;
  235. name = e.name;
  236. // e.categoryId = e.id;
  237. // e.id = e.categoryId
  238. return (
  239. Object.prototype.hasOwnProperty.call(e, "demandQuantity") &&
  240. Number(e.demandQuantity) > 0 &&
  241. e.warehouseId
  242. );
  243. });
  244. if (!bol2) {
  245. // this.$message.warning(
  246. // `${this.objPick.pickList[_i].code}的${name}数据不能为空`
  247. // );
  248. // return false;
  249. return uni.showToast({
  250. title: `${this.objPick.pickList[_i].code}的${name}数量不能为空`,
  251. icon: "none",
  252. });
  253. }
  254. }
  255. let param = {
  256. detailList: this.objPick.pickList,
  257. name: this.pickForm.pickName,
  258. code: this.pickForm.pickCode,
  259. };
  260. unproductive(param).then((res) => {
  261. uni.showToast({ title: "提交成功" });
  262. setTimeout(() => {
  263. uni.navigateBack();
  264. }, 500);
  265. });
  266. // if (!this.objPick.pickList.length) {
  267. // return uni.showToast({ title: "请选择物料", icon: "none" });
  268. // }
  269. // const valid = this.objPick.pickList.every(
  270. // (e) => e.demandQuantity > 0 && e.warehouseId
  271. // );
  272. // if (!valid) {
  273. // return uni.showToast({ title: "请完善物料信息", icon: "none" });
  274. // }
  275. // const param = {
  276. // detailList: this.objPick.pickList,
  277. // name: this.pickForm.pickName,
  278. // code: this.pickForm.pickCode,
  279. // };
  280. // unproductive(param).then(() => {
  281. // uni.showToast({ title: "提交成功" });
  282. // this.close(true);
  283. // });
  284. },
  285. close(refresh) {
  286. uni.$emit("closePick", refresh);
  287. uni.navigateBack();
  288. },
  289. },
  290. };
  291. </script>
  292. <style lang="scss" scoped>
  293. .page {
  294. display: flex;
  295. flex-direction: column;
  296. height: 100vh;
  297. background-color: #f7f7f7;
  298. }
  299. .scroll-container {
  300. flex: 1;
  301. padding: 10rpx 16rpx;
  302. overflow-y: auto;
  303. }
  304. /* 顶部表单 */
  305. .form-section {
  306. background: #fff;
  307. border-radius: 12rpx;
  308. padding: 16rpx;
  309. margin-bottom: 16rpx;
  310. .form-item {
  311. display: flex;
  312. flex-wrap: wrap;
  313. align-items: center;
  314. margin-bottom: 12rpx;
  315. .label {
  316. width: 30%;
  317. font-size: 28rpx;
  318. color: #666;
  319. margin-bottom: 4rpx;
  320. }
  321. uni-easyinput {
  322. flex: 1;
  323. }
  324. }
  325. .btn-add {
  326. display: flex;
  327. justify-content: flex-end;
  328. }
  329. }
  330. /* 物料列表卡片 */
  331. .material-list {
  332. display: flex;
  333. flex-direction: column;
  334. gap: 16rpx;
  335. .material-card {
  336. position: relative;
  337. background: #fff;
  338. border-radius: 12rpx;
  339. padding: 16rpx;
  340. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
  341. transition: background 0.2s;
  342. &:active {
  343. background: #f5f5f5;
  344. }
  345. .delete-btn {
  346. position: absolute;
  347. top: 8rpx;
  348. right: 8rpx;
  349. width: 40rpx;
  350. height: 40rpx;
  351. display: flex;
  352. justify-content: center;
  353. align-items: center;
  354. z-index: 10;
  355. background: rgba(255, 255, 255, 0.8);
  356. border-radius: 50%;
  357. box-shadow: 0 1rpx 3rpx rgba(0, 0, 0, 0.2);
  358. }
  359. .card-content {
  360. display: flex;
  361. flex-direction: column;
  362. gap: 8rpx;
  363. .card-row {
  364. display: flex;
  365. // flex-wrap: wrap;
  366. align-items: center;
  367. .label {
  368. width: 22%;
  369. flex-shrink: 0;
  370. font-size: 26rpx;
  371. color: #666;
  372. margin-bottom: 4rpx;
  373. }
  374. .input-row {
  375. display: flex;
  376. align-items: center;
  377. gap: 8rpx;
  378. uni-easyinput {
  379. flex: 1; // 占满剩余空间
  380. min-width: 0; // ✅允许收缩,防止换行
  381. }
  382. .unit {
  383. flex-shrink: 0; // 单位宽度固定
  384. font-size: 24rpx;
  385. color: #666;
  386. }
  387. }
  388. }
  389. }
  390. }
  391. }
  392. /* 底部固定按钮 */
  393. .footer-btn {
  394. position: fixed;
  395. bottom: 0;
  396. left: 0;
  397. width: 100%;
  398. background: #fff;
  399. padding: 16rpx;
  400. display: flex;
  401. justify-content: space-between;
  402. box-shadow: 0 -2rpx 6rpx rgba(0, 0, 0, 0.05);
  403. z-index: 20;
  404. }
  405. /deep/ .uni-easyinput__content-input {
  406. padding-left: 0;
  407. }
  408. </style>