create.vue 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188
  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. <scroll-view scroll-y class="form-container">
  13. <!-- 基本信息 -->
  14. <view class="section">
  15. <view class="section-title">基本信息</view>
  16. <view class="form-item">
  17. <text class="label required">类型</text>
  18. <picker
  19. mode="selector"
  20. :range="typeList"
  21. range-key="label"
  22. @change="typeChange"
  23. class="picker-full"
  24. >
  25. <view class="picker-value">
  26. {{ form.typeName || "请选择类型" }}
  27. </view>
  28. </picker>
  29. </view>
  30. <view class="form-item">
  31. <text class="label required">紧急程度</text>
  32. <picker
  33. mode="selector"
  34. :range="priorityList"
  35. range-key="name"
  36. @change="priorityChange"
  37. class="picker-full"
  38. >
  39. <view class="picker-value">
  40. {{ form.priorityName || "请选择紧急程度" }}
  41. </view>
  42. </picker>
  43. </view>
  44. <view class="form-item">
  45. <text class="label required">名称</text>
  46. <input v-model="form.name" placeholder="请输入名称" class="input" />
  47. </view>
  48. <view class="form-item">
  49. <text class="label">请托部门</text>
  50. <input
  51. v-model="form.pleaseEntrustDeptName"
  52. disabled
  53. class="input disabled"
  54. />
  55. </view>
  56. <view class="form-item">
  57. <text class="label">请托人</text>
  58. <input
  59. v-model="form.pleaseEntrustUserName"
  60. disabled
  61. class="input disabled"
  62. />
  63. </view>
  64. <view class="form-item">
  65. <text class="label">所属工厂</text>
  66. <input v-model="form.factoriesName" disabled class="input disabled" />
  67. </view>
  68. <view class="form-item">
  69. <text class="label">受托工厂</text>
  70. <picker
  71. mode="selector"
  72. :range="factoryList"
  73. range-key="name"
  74. @change="factoryChange"
  75. class="picker-full"
  76. >
  77. <view class="picker-value">
  78. {{ form.beEntrustedFactoriesName || "请选择受托工厂" }}
  79. </view>
  80. </picker>
  81. </view>
  82. <view class="form-item">
  83. <text class="label required">受托部门</text>
  84. <view class="picker-full" @click="openDeptPopup">
  85. <view class="picker-value">
  86. {{ form.beEntrustedDeptName || "请选择受托部门" }}
  87. </view>
  88. </view>
  89. </view>
  90. <view class="form-item">
  91. <text class="label">执行人</text>
  92. <picker
  93. mode="selector"
  94. :range="userList"
  95. range-key="name"
  96. @change="userChange"
  97. class="picker-full"
  98. >
  99. <view class="picker-value">
  100. {{ form.executeUserName || "请选择执行人" }}
  101. </view>
  102. </picker>
  103. </view>
  104. <view class="form-item">
  105. <text class="label required">是否尾工序</text>
  106. <radio-group @change="isLastChange">
  107. <label class="radio-item">
  108. <radio value="1" :checked="form.isLast == 1" />是
  109. </label>
  110. <label class="radio-item">
  111. <radio value="0" :checked="form.isLast == 0" />否
  112. </label>
  113. </radio-group>
  114. </view>
  115. </view>
  116. <!-- 产品信息 -->
  117. <view class="section">
  118. <view class="section-title">产品信息</view>
  119. <view class="btn-group">
  120. <button class="btn-primary" size="mini" @click="addOrder">
  121. 新建
  122. </button>
  123. <button class="btn-danger" size="mini" @click="removeOrder">
  124. 删除
  125. </button>
  126. <button class="btn-select" size="mini" @click="selectAll">
  127. 全选
  128. </button>
  129. <button class="btn-deselect" size="mini" @click="deselectAll">
  130. 取消
  131. </button>
  132. </view>
  133. <view v-if="orderList.length > 0" class="order-list">
  134. <view
  135. v-for="(item, index) in orderList"
  136. :key="index"
  137. class="order-item"
  138. :class="{ active: selectedOrders.includes(index) }"
  139. >
  140. <view class="order-header">
  141. <checkbox
  142. :checked="selectedOrders.includes(index)"
  143. @click.stop="toggleSelect(index)"
  144. class="order-checkbox"
  145. />
  146. <text class="order-name">{{ item.categoryName }}</text>
  147. <text class="order-code">{{ item.workOrderCode }}</text>
  148. </view>
  149. <view class="order-row">
  150. <text class="label">计划编号:</text>
  151. <text class="value">{{ item.productionPlanCode }}</text>
  152. </view>
  153. <view class="order-row">
  154. <text class="label">牌号:</text>
  155. <text class="value">{{ item.brandNum }}</text>
  156. </view>
  157. <view class="order-row">
  158. <text class="label">批次号:</text>
  159. <text class="value">{{ item.batchNo }}</text>
  160. </view>
  161. <view class="order-row">
  162. <text class="label required">请托数量:</text>
  163. <input
  164. v-model="item.totalCount"
  165. type="digit"
  166. placeholder="请输入数量"
  167. class="order-input"
  168. />
  169. <text class="unit">{{ item.measuringUnit }}</text>
  170. </view>
  171. <view class="order-row">
  172. <text class="label">需求描述:</text>
  173. <textarea
  174. v-model="item.describes"
  175. placeholder="请输入需求描述"
  176. class="order-textarea"
  177. auto-height
  178. />
  179. </view>
  180. <view class="order-row">
  181. <text class="label required">工序:</text>
  182. <picker
  183. mode="selector"
  184. :range="item.taskList || []"
  185. range-key="name"
  186. @change="(e) => taskChange(e, index)"
  187. class="order-picker"
  188. >
  189. <view class="picker-value">
  190. {{ item.taskName || "请选择工序" }}
  191. </view>
  192. </picker>
  193. </view>
  194. <view class="order-row">
  195. <text class="label required">完成日期:</text>
  196. <uni-datetime-picker
  197. type="datetime"
  198. v-model="item.planDeliveryTime"
  199. @change="(e) => dateChange(e, index)"
  200. class="order-picker"
  201. :popup-style="{ zIndex: 1000 }"
  202. >
  203. <view class="picker-value">
  204. {{ item.planDeliveryTime || "请选择日期" }}
  205. </view>
  206. </uni-datetime-picker>
  207. </view>
  208. </view>
  209. </view>
  210. <view v-else class="empty-order">
  211. <text>暂无产品信息,请点击新建添加</text>
  212. </view>
  213. </view>
  214. </scroll-view>
  215. <!-- 底部按钮 -->
  216. <view class="footer-btns">
  217. <view class="btn-cancel" @click="handleCancel">取消</view>
  218. <view class="btn-save" @click="handleSave(1)">保存</view>
  219. <view v-if="type === 'add'" class="btn-submit" @click="handleSave(2)"
  220. >提交</view
  221. >
  222. </view>
  223. <!-- 部门树形选择器 -->
  224. <uni-popup ref="deptPopup" type="bottom" :safe-area="false">
  225. <view class="popup-content">
  226. <view class="popup-header">
  227. <text class="popup-title">选择受托部门</text>
  228. <text class="popup-close" @click="$refs.deptPopup.close()">关闭</text>
  229. </view>
  230. <scroll-view scroll-y class="dept-tree">
  231. <view
  232. v-for="dept in flatDeptList"
  233. :key="dept.id"
  234. v-show="dept.visible"
  235. class="dept-item"
  236. :style="{ paddingLeft: dept.level * 40 + 'rpx' }"
  237. >
  238. <text
  239. v-if="dept.hasChildren"
  240. class="dept-arrow"
  241. @click.stop="toggleDept(dept)"
  242. >{{ dept.expanded ? "▼" : "▶" }}</text
  243. >
  244. <text v-else class="dept-arrow-placeholder"></text>
  245. <text @click="selectDept(dept)">{{ dept.name }}</text>
  246. </view>
  247. </scroll-view>
  248. </view>
  249. </uni-popup>
  250. </view>
  251. </template>
  252. <script>
  253. import {
  254. save,
  255. addSubmit,
  256. pleaseEntrustDetail,
  257. update,
  258. getProduceTaskList,
  259. } from "@/api/entrust/index";
  260. import { getUserPage, listOrganizations, getDictByCode } from "@/api/common";
  261. import { getFactoryarea } from "@/api/inspectionWork/index";
  262. export default {
  263. data() {
  264. return {
  265. type: "add",
  266. form: {
  267. type: "",
  268. typeName: "",
  269. priority: "",
  270. priorityName: "",
  271. name: "",
  272. pleaseEntrustDeptName: "",
  273. pleaseEntrustDeptId: "",
  274. pleaseEntrustUserName: "",
  275. pleaseEntrustUserId: "",
  276. factoriesName: "",
  277. factoriesId: "",
  278. beEntrustedFactoriesId: "",
  279. beEntrustedFactoriesName: "",
  280. beEntrustedDeptId: "",
  281. beEntrustedDeptName: "",
  282. executeUserId: "",
  283. executeUserName: "",
  284. isLast: 0,
  285. },
  286. typeList: [],
  287. priorityList: [
  288. { name: "一般", value: 1 },
  289. { name: "紧急", value: 2 },
  290. ],
  291. factoryList: [],
  292. deptList: [],
  293. flatDeptList: [],
  294. userList: [],
  295. orderList: [],
  296. selectedOrders: [],
  297. selectedOrder: [],
  298. };
  299. },
  300. onShow() {
  301. if (this.selectedOrder && this.selectedOrder.length > 0) {
  302. this.receiveOrder(this.selectedOrder);
  303. this.selectedOrder = [];
  304. }
  305. },
  306. async onLoad(options) {
  307. this.type = options.type || "add";
  308. // 获取工厂列表
  309. await this.getFactoryList();
  310. this.initData();
  311. if (options.id) {
  312. this.getDetail(options.id);
  313. }
  314. },
  315. methods: {
  316. initData() {
  317. // 初始化用户信息
  318. const userInfo = uni.getStorageSync("userInfo");
  319. if (userInfo) {
  320. this.form.pleaseEntrustDeptName = userInfo.groupName;
  321. this.form.pleaseEntrustDeptId = userInfo.groupId;
  322. this.form.pleaseEntrustUserName = userInfo.name;
  323. this.form.pleaseEntrustUserId = userInfo.userId;
  324. const data = this.factoryList.filter(
  325. (it) => it.factoryId == userInfo.factoryId,
  326. );
  327. if (data.length != 0) {
  328. this.form.factoriesId = data[0].factoryId;
  329. this.form.factoriesName = data[0].factoryName;
  330. }
  331. }
  332. // 获取类型列表
  333. this.getTypeList();
  334. },
  335. async getTypeList() {
  336. // 从字典获取类型列表
  337. // this.typeList = [
  338. // { label: "加工", value: "1" },
  339. // { label: "装配", value: "2" },
  340. // ];
  341. try {
  342. const res = await getDictByCode("entrust_type");
  343. if (res?.length != 0) {
  344. let list = res.map((item) => {
  345. let key = Object.keys(item)[0];
  346. return { value: Number(key), label: item[key] };
  347. });
  348. this.typeList = list;
  349. }
  350. } catch (error) {
  351. console.error("获取类型列表失败", error);
  352. }
  353. },
  354. async getFactoryList() {
  355. try {
  356. const res = await getFactoryarea({
  357. pageNum: 1,
  358. size: 999,
  359. type: 1,
  360. });
  361. this.factoryList = res.list || [];
  362. } catch (error) {
  363. console.error("获取工厂列表失败", error);
  364. }
  365. },
  366. async getDeptList(factoryId) {
  367. try {
  368. const res = await listOrganizations();
  369. this.deptList = res || [];
  370. this.flatDeptList = this.buildFlatDeptList(this.deptList);
  371. } catch (error) {
  372. console.error("获取部门列表失败", error);
  373. }
  374. },
  375. buildFlatDeptList(list) {
  376. const map = {};
  377. const roots = [];
  378. list.forEach((item) => {
  379. map[item.id] = {
  380. ...item,
  381. children: [],
  382. expanded: false,
  383. visible: true,
  384. level: 0,
  385. hasChildren: false,
  386. };
  387. });
  388. list.forEach((item) => {
  389. const node = map[item.id];
  390. if (item.parentId === "0" || !map[item.parentId]) {
  391. roots.push(node);
  392. } else {
  393. map[item.parentId].children.push(node);
  394. map[item.parentId].hasChildren = true;
  395. }
  396. });
  397. const result = [];
  398. const traverse = (nodes, level) => {
  399. nodes.forEach((node) => {
  400. node.level = level;
  401. result.push(node);
  402. if (node.children.length > 0) {
  403. node.children.forEach((child) => (child.visible = false));
  404. traverse(node.children, level + 1);
  405. }
  406. });
  407. };
  408. traverse(roots, 0);
  409. return result;
  410. },
  411. toggleDept(dept) {
  412. dept.expanded = !dept.expanded;
  413. const index = this.flatDeptList.findIndex((d) => d.id === dept.id);
  414. if (index !== -1) {
  415. this.updateChildrenVisibility(dept, index + 1);
  416. }
  417. },
  418. updateChildrenVisibility(parent, startIndex) {
  419. const parentLevel = parent.level;
  420. for (let i = startIndex; i < this.flatDeptList.length; i++) {
  421. const item = this.flatDeptList[i];
  422. if (item.level <= parentLevel) break;
  423. if (item.level === parentLevel + 1) {
  424. item.visible = parent.expanded;
  425. if (!parent.expanded) item.expanded = false;
  426. }
  427. if (item.level > parentLevel + 1) {
  428. item.visible = false;
  429. item.expanded = false;
  430. }
  431. }
  432. this.$forceUpdate();
  433. },
  434. selectDept(dept) {
  435. this.form.beEntrustedDeptId = dept.id;
  436. this.form.beEntrustedDeptName = dept.name;
  437. this.form.executeUserId = "";
  438. this.form.executeUserName = "";
  439. this.getUserList(dept.id);
  440. this.$refs.deptPopup.close();
  441. },
  442. async getUserList(deptId) {
  443. try {
  444. const res = await getUserPage({
  445. pageNum: 1,
  446. size: -1,
  447. groupId: deptId,
  448. });
  449. this.userList = res.list || [];
  450. } catch (error) {
  451. console.error("获取用户列表失败", error);
  452. }
  453. },
  454. async getDetail(id) {
  455. try {
  456. const res = await pleaseEntrustDetail(id);
  457. const data = res;
  458. this.form = {
  459. ...this.form,
  460. pleaseEntrustDeptName: data.applyDeptName,
  461. pleaseEntrustDeptId: data.applyDeptId,
  462. pleaseEntrustUserName: data.createUserName,
  463. pleaseEntrustUserId: data.createUserId,
  464. factoriesId: data.applyFactoriesId,
  465. factoriesName: data.applyFactoriesName,
  466. beEntrustedDeptId: data.beEntrustedDeptId,
  467. beEntrustedDeptName: data.beEntrustedDeptName,
  468. beEntrustedFactoriesName: data.beEntrustedFactoriesName,
  469. beEntrustedFactoriesId: data.beEntrustedFactoriesId,
  470. executeUserId: data.executeUserId,
  471. executeUserName: data.executeUserName,
  472. name: data.name,
  473. type: data.type,
  474. typeName:
  475. (this.typeList.find((t) => t.value == data.type) || {}).label || "",
  476. priority: data.priority,
  477. priorityName:
  478. (this.priorityList.find((p) => p.value == data.priority) || {})
  479. .name || "",
  480. id: data.id,
  481. };
  482. if (data.beEntrustedFactoriesId) {
  483. this.getDeptList(data.beEntrustedFactoriesId);
  484. }
  485. if (data.beEntrustedDeptId) {
  486. this.getUserList(data.beEntrustedDeptId);
  487. }
  488. this.orderList = [{ ...data, taskList: [] }];
  489. await this.getOrderTaskList();
  490. } catch (error) {
  491. uni.showToast({
  492. title: "加载失败",
  493. icon: "none",
  494. });
  495. }
  496. },
  497. typeChange(e) {
  498. const index = e.detail.value;
  499. this.form.type = this.typeList[index].value;
  500. this.form.typeName = this.typeList[index].label;
  501. },
  502. priorityChange(e) {
  503. const index = e.detail.value;
  504. this.form.priority = this.priorityList[index].value;
  505. this.form.priorityName = this.priorityList[index].name;
  506. },
  507. factoryChange(e) {
  508. const index = e.detail.value;
  509. this.form.beEntrustedFactoriesId = this.factoryList[index].id;
  510. this.form.beEntrustedFactoriesName = this.factoryList[index].name;
  511. this.form.beEntrustedDeptId = "";
  512. this.form.beEntrustedDeptName = "";
  513. this.form.executeUserId = "";
  514. this.form.executeUserName = "";
  515. this.userList = [];
  516. this.getDeptList(this.factoryList[index].id);
  517. },
  518. openDeptPopup() {
  519. if (!this.form.beEntrustedFactoriesId) {
  520. uni.showToast({ title: "请先选择受托工厂", icon: "none" });
  521. return;
  522. }
  523. this.$refs.deptPopup.open();
  524. },
  525. deptChange(e) {
  526. const index = e.detail.value;
  527. this.form.beEntrustedDeptId = this.deptList[index].id;
  528. this.form.beEntrustedDeptName = this.deptList[index].name;
  529. this.getUserList(this.deptList[index].id);
  530. },
  531. userChange(e) {
  532. const index = e.detail.value;
  533. this.form.executeUserId = this.userList[index].id;
  534. this.form.executeUserName = this.userList[index].name;
  535. },
  536. isLastChange(e) {
  537. this.form.isLast = Number(e.detail.value);
  538. },
  539. addOrder() {
  540. const selectedIds = this.orderList
  541. .map((item) => item.workOrderId || item.id)
  542. .join(",");
  543. uni.navigateTo({
  544. url: `/pages/pda/entrust/selectOrder/selectOrder?selectedIds=${selectedIds}`,
  545. });
  546. },
  547. receiveOrder(list) {
  548. if (!list || list.length === 0) {
  549. this.orderList = [];
  550. return;
  551. }
  552. const getKey = (item) => item.id;
  553. const newKeys = new Set(list.map(getKey));
  554. const oldKeys = new Set(this.orderList.map(getKey));
  555. const keptOldList = this.orderList.filter((old) =>
  556. newKeys.has(getKey(old)),
  557. );
  558. const addedItems = list.filter((item) => !oldKeys.has(getKey(item)));
  559. const newList = addedItems.map((item) => ({
  560. ...item,
  561. describes: "",
  562. totalCount: item.formingNum,
  563. taskList: [],
  564. measuringUnit: item.unit,
  565. categoryName: item.productName,
  566. categoryCode: item.productCode,
  567. workOrderId: item.id,
  568. workOrderCode: item.code,
  569. brandNum: item.brandNo,
  570. modelType: item.model,
  571. planDeliveryTime: item.startTime,
  572. applyDeptId: this.form.pleaseEntrustDeptId,
  573. applyDeptName: this.form.pleaseEntrustDeptName,
  574. applyFactoriesId: this.form.factoriesId,
  575. applyFactoriesName: this.form.factoriesName,
  576. }));
  577. this.orderList = [...keptOldList, ...newList];
  578. this.getOrderTaskList();
  579. },
  580. removeOrder() {
  581. if (this.selectedOrders.length === 0) {
  582. uni.showToast({
  583. title: "请选择要删除的产品",
  584. icon: "none",
  585. });
  586. return;
  587. }
  588. uni.showModal({
  589. title: "提示",
  590. content: `确定要删除选中的${this.selectedOrders.length}个产品吗?`,
  591. success: (res) => {
  592. if (res.confirm) {
  593. this.orderList = this.orderList.filter(
  594. (_, index) => !this.selectedOrders.includes(index),
  595. );
  596. this.selectedOrders = [];
  597. }
  598. },
  599. });
  600. },
  601. toggleSelect(index) {
  602. const idx = this.selectedOrders.indexOf(index);
  603. if (idx > -1) {
  604. this.selectedOrders.splice(idx, 1);
  605. } else {
  606. this.selectedOrders.push(index);
  607. }
  608. },
  609. selectAll() {
  610. this.selectedOrders = this.orderList.map((_, index) => index);
  611. },
  612. deselectAll() {
  613. this.selectedOrders = [];
  614. },
  615. taskChange(e, index) {
  616. const taskIndex = e.detail.value;
  617. const task = this.orderList[index].taskList[taskIndex];
  618. this.orderList[index].taskId = task.id;
  619. this.orderList[index].taskName = task.name;
  620. },
  621. dateChange(e, index) {
  622. this.orderList[index].planDeliveryTime = e?.detail?.value || e;
  623. },
  624. async getOrderTaskList() {
  625. for (const item of this.orderList) {
  626. try {
  627. const res = await getProduceTaskList({
  628. isDetail: true,
  629. pageNum: 1,
  630. routingId: item.produceRoutingId,
  631. size: -1,
  632. });
  633. let list = res.list || [];
  634. if (list.length) {
  635. list = list.filter((it) => it.taskId != -2);
  636. const arr = list.findIndex((it) => it.id == item.taskId);
  637. if (arr != -1) {
  638. list.splice(0, arr);
  639. }
  640. item.taskList = list;
  641. }
  642. } catch (error) {
  643. console.error("获取工序列表失败", error);
  644. }
  645. }
  646. },
  647. validate() {
  648. if (!this.form.type) {
  649. uni.showToast({ title: "请选择类型", icon: "none" });
  650. return false;
  651. }
  652. if (!this.form.name) {
  653. uni.showToast({ title: "请输入名称", icon: "none" });
  654. return false;
  655. }
  656. if (!this.form.beEntrustedDeptId) {
  657. uni.showToast({ title: "请选择受托部门", icon: "none" });
  658. return false;
  659. }
  660. if (this.orderList.length === 0) {
  661. uni.showToast({ title: "请添加产品信息", icon: "none" });
  662. return false;
  663. }
  664. for (const item of this.orderList) {
  665. if (!item.totalCount) {
  666. uni.showToast({ title: "请托数量不能为空", icon: "none" });
  667. return false;
  668. }
  669. if (!item.taskId) {
  670. uni.showToast({ title: "工序不能为空", icon: "none" });
  671. return false;
  672. }
  673. if (!item.planDeliveryTime) {
  674. uni.showToast({ title: "完成日期不能为空", icon: "none" });
  675. return false;
  676. }
  677. }
  678. return true;
  679. },
  680. async handleSave(saveType) {
  681. if (!this.validate()) return;
  682. const user = this.userList.find((it) => it.id == this.form.executeUserId);
  683. const status = saveType == 1 ? 0 : 1;
  684. this.orderList.forEach((item) => {
  685. item.beEntrustedFactoriesId = this.form.beEntrustedFactoriesId;
  686. item.beEntrustedFactoriesName = this.form.beEntrustedFactoriesName;
  687. item.beEntrustedDeptName = this.form.beEntrustedDeptName;
  688. item.beEntrustedDeptId = this.form.beEntrustedDeptId;
  689. item.executeUserId = user?.id || "";
  690. item.executeUserName = user?.name || "";
  691. item.isLast = this.form.isLast;
  692. item.name = this.form.name;
  693. item.type = this.form.type;
  694. item.status = status;
  695. item.approvalStatus = saveType == 1 ? 0 : 1;
  696. });
  697. let apiFunc;
  698. if (saveType === 1) {
  699. apiFunc = this.type === "edit" ? update : save;
  700. } else {
  701. apiFunc = addSubmit;
  702. }
  703. if (this.type === "add") {
  704. this.orderList.forEach((it) => (it.id = ""));
  705. }
  706. uni.showLoading({ title: "保存中..." });
  707. try {
  708. await apiFunc(this.orderList);
  709. uni.hideLoading();
  710. uni.showToast({
  711. title: "保存成功",
  712. icon: "success",
  713. });
  714. setTimeout(() => {
  715. uni.navigateBack();
  716. }, 1500);
  717. } catch (error) {
  718. uni.hideLoading();
  719. uni.showToast({
  720. title: "保存失败",
  721. icon: "none",
  722. });
  723. }
  724. },
  725. handleCancel() {
  726. uni.navigateBack();
  727. },
  728. },
  729. };
  730. </script>
  731. <style lang="scss" scoped>
  732. .content-box {
  733. display: flex;
  734. flex-direction: column;
  735. height: 100vh;
  736. background-color: $page-bg;
  737. }
  738. .form-container {
  739. flex: 1;
  740. padding: 20rpx;
  741. padding-bottom: 140rpx;
  742. background-color: #f5f5f5;
  743. }
  744. .section {
  745. background-color: transparent;
  746. border-radius: 0;
  747. padding: 0;
  748. margin-bottom: 20rpx;
  749. .section-title {
  750. font-size: 28rpx;
  751. font-weight: normal;
  752. color: #999;
  753. margin-bottom: 16rpx;
  754. padding: 0 24rpx;
  755. }
  756. }
  757. .form-item {
  758. display: flex;
  759. align-items: center;
  760. padding: 24rpx;
  761. background-color: #fff;
  762. border-bottom: 1rpx solid #f0f0f0;
  763. &:first-child {
  764. border-radius: 12rpx 12rpx 0 0;
  765. }
  766. &:last-child {
  767. border-bottom: none;
  768. border-radius: 0 0 12rpx 12rpx;
  769. }
  770. .label {
  771. width: 180rpx;
  772. font-size: 30rpx;
  773. color: #333;
  774. flex-shrink: 0;
  775. &.required::before {
  776. content: "*";
  777. color: #ff4d4f;
  778. margin-right: 4rpx;
  779. }
  780. }
  781. .input {
  782. flex: 1;
  783. font-size: 30rpx;
  784. color: #333;
  785. text-align: right;
  786. &.disabled {
  787. color: #999;
  788. }
  789. }
  790. .picker-value {
  791. flex: 1;
  792. font-size: 30rpx;
  793. color: #333;
  794. text-align: right;
  795. }
  796. .picker-full {
  797. flex: 1;
  798. text-align: right;
  799. }
  800. .radio-item {
  801. margin-left: 40rpx;
  802. font-size: 28rpx;
  803. }
  804. }
  805. .btn-group {
  806. display: flex;
  807. justify-content: flex-end !important;
  808. gap: 20rpx;
  809. margin-bottom: 20rpx;
  810. padding: 24rpx;
  811. background-color: #fff;
  812. border-radius: 12rpx;
  813. button {
  814. height: 60rpx;
  815. line-height: 60rpx;
  816. font-size: 26rpx;
  817. border-radius: 30rpx;
  818. padding: 0 32rpx;
  819. }
  820. .btn-primary {
  821. background-color: #1890ff;
  822. color: #fff;
  823. }
  824. .btn-danger {
  825. background-color: #ff4d4f;
  826. color: #fff;
  827. }
  828. .btn-select {
  829. background-color: #52c41a;
  830. color: #fff;
  831. }
  832. .btn-deselect {
  833. background-color: #faad14;
  834. color: #fff;
  835. }
  836. }
  837. .order-list {
  838. // padding: 0 24rpx;
  839. .order-item {
  840. background-color: #fff;
  841. border-radius: 12rpx;
  842. padding: 24rpx;
  843. margin-bottom: 20rpx;
  844. border: 2rpx solid #e0e0e0;
  845. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.06);
  846. &.active {
  847. border-color: #1890ff;
  848. background-color: #f0f7ff;
  849. }
  850. .order-header {
  851. display: flex;
  852. align-items: center;
  853. gap: 12rpx;
  854. margin-bottom: 20rpx;
  855. padding-bottom: 16rpx;
  856. border-bottom: 1rpx solid #f0f0f0;
  857. .order-checkbox {
  858. transform: scale(1.2);
  859. flex-shrink: 0;
  860. }
  861. .order-name {
  862. flex: 1;
  863. font-size: 32rpx;
  864. font-weight: bold;
  865. color: #333;
  866. overflow: hidden;
  867. text-overflow: ellipsis;
  868. white-space: nowrap;
  869. }
  870. .order-code {
  871. font-size: 26rpx;
  872. color: #999;
  873. flex-shrink: 0;
  874. }
  875. }
  876. .order-row {
  877. display: flex;
  878. align-items: flex-start;
  879. margin-bottom: 20rpx;
  880. font-size: 28rpx;
  881. .label {
  882. min-width: 160rpx;
  883. padding-top: 20rpx;
  884. color: #666;
  885. flex-shrink: 0;
  886. &.required::before {
  887. content: "*";
  888. color: #ff4d4f;
  889. margin-right: 4rpx;
  890. }
  891. }
  892. .value {
  893. flex: 1;
  894. padding-top: 20rpx;
  895. color: #333;
  896. word-break: break-all;
  897. }
  898. .order-input {
  899. flex: 1;
  900. padding: 20rpx 16rpx;
  901. border: 1rpx solid #e0e0e0;
  902. border-radius: 8rpx;
  903. font-size: 28rpx;
  904. min-height: 80rpx;
  905. background-color: #fff;
  906. }
  907. .order-textarea {
  908. flex: 1;
  909. padding: 20rpx 16rpx;
  910. border: 1rpx solid #e0e0e0;
  911. border-radius: 8rpx;
  912. font-size: 28rpx;
  913. min-height: 100rpx;
  914. line-height: 1.6;
  915. background-color: #fff;
  916. }
  917. .order-picker {
  918. flex: 1;
  919. }
  920. .unit {
  921. margin-left: 12rpx;
  922. padding-top: 20rpx;
  923. color: #999;
  924. flex-shrink: 0;
  925. }
  926. .picker-value {
  927. flex: 1;
  928. padding: 20rpx 16rpx;
  929. border: 1rpx solid #e0e0e0;
  930. border-radius: 8rpx;
  931. font-size: 28rpx;
  932. min-height: 80rpx;
  933. display: flex;
  934. align-items: center;
  935. background-color: #fff;
  936. color: #333;
  937. }
  938. }
  939. }
  940. }
  941. .empty-order {
  942. display: flex;
  943. justify-content: center;
  944. align-items: center;
  945. padding: 80rpx 0;
  946. font-size: 28rpx;
  947. color: #999;
  948. background-color: #fff;
  949. border-radius: 12rpx;
  950. // margin: 0 24rpx;
  951. }
  952. .footer-btns {
  953. display: flex;
  954. flex-direction: row;
  955. align-items: center;
  956. gap: 20rpx;
  957. padding: 20rpx 32rpx;
  958. background-color: #fff;
  959. box-shadow: 0 -2rpx 8rpx rgba(0, 0, 0, 0.08);
  960. padding-bottom: constant(safe-area-inset-bottom);
  961. padding-bottom: env(safe-area-inset-bottom);
  962. position: fixed;
  963. bottom: 0;
  964. left: 0;
  965. right: 0;
  966. z-index: 1;
  967. box-sizing: border-box;
  968. .btn-cancel,
  969. .btn-save,
  970. .btn-submit {
  971. flex: 1;
  972. min-width: 0;
  973. height: 88rpx;
  974. line-height: 88rpx;
  975. font-size: 32rpx;
  976. border-radius: 44rpx;
  977. text-align: center;
  978. box-sizing: border-box;
  979. position: static !important;
  980. width: auto !important;
  981. margin: 0 !important;
  982. }
  983. .btn-cancel {
  984. background-color: #fff;
  985. color: #666;
  986. border: 1rpx solid #e0e0e0;
  987. }
  988. .btn-save {
  989. background-color: $theme-color;
  990. color: #fff;
  991. }
  992. .btn-submit {
  993. background-color: $theme-color;
  994. color: #fff;
  995. }
  996. }
  997. .popup-content {
  998. background-color: #fff;
  999. border-radius: 24rpx 24rpx 0 0;
  1000. max-height: 70vh;
  1001. display: flex;
  1002. flex-direction: column;
  1003. z-index: 999;
  1004. .popup-header {
  1005. display: flex;
  1006. justify-content: space-between;
  1007. align-items: center;
  1008. padding: 32rpx;
  1009. border-bottom: 1rpx solid #f0f0f0;
  1010. .popup-title {
  1011. font-size: 32rpx;
  1012. font-weight: bold;
  1013. color: #333;
  1014. }
  1015. .popup-close {
  1016. font-size: 28rpx;
  1017. color: $theme-color;
  1018. }
  1019. }
  1020. .dept-tree {
  1021. flex: 1;
  1022. padding: 24rpx;
  1023. .dept-item {
  1024. display: flex;
  1025. align-items: center;
  1026. padding: 24rpx;
  1027. border-bottom: 1rpx solid #f0f0f0;
  1028. font-size: 30rpx;
  1029. color: #333;
  1030. &:active {
  1031. background-color: #f5f5f5;
  1032. }
  1033. .dept-arrow {
  1034. width: 40rpx;
  1035. margin-right: 12rpx;
  1036. color: #999;
  1037. font-size: 24rpx;
  1038. }
  1039. .dept-arrow-placeholder {
  1040. width: 40rpx;
  1041. margin-right: 12rpx;
  1042. }
  1043. }
  1044. }
  1045. }
  1046. /* 确保日期选择器弹窗不被遮挡 */
  1047. ::v-deep .uni-datetime-picker-popup {
  1048. z-index: 1000 !important;
  1049. }
  1050. ::v-deep .uni-popup__wrapper {
  1051. z-index: 1000 !important;
  1052. }
  1053. </style>