index.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. <!-- 批量新增 -->
  2. <script>
  3. import useColumns from "./column";
  4. import {
  5. addChangeList,
  6. getMaterialDetails,
  7. getChangeDetails,
  8. editChangeList,
  9. importInner,
  10. saveAndSubmit,
  11. } from "@/api/changeApply/basic";
  12. import { REFER } from "@/components/popover-select/api";
  13. export default {
  14. name: "AddChangeOrders",
  15. props: {
  16. dict: {
  17. type: Object,
  18. },
  19. addType: {
  20. type: String,
  21. default: "add",
  22. },
  23. },
  24. components: {
  25. AmendantRecord: () => import("../amendantRecord/index.vue"),
  26. ElSuperForm: () => import("@/components/super-form/index.vue"),
  27. ElSuperTable: () => import("@/components/super-table/index.vue"),
  28. ElPopoverSelectV2: () => import("@/components/popover-select-v2/index.vue"),
  29. ElPopoverTreeSelect: () =>
  30. import("@/components/popover-tree-select/index.vue"),
  31. BatchImport: () => import("@/components/BatchImport/index.vue"),
  32. ElSuperUxTable: () => import("@/components/super-ux-table/index.vue"),
  33. },
  34. data() {
  35. const {
  36. TabColumns,
  37. TableColumns,
  38. TabColumns: [
  39. {
  40. item: { key: tabName },
  41. },
  42. ],
  43. } = useColumns();
  44. const rules = this.$init.rules([...TabColumns, ...TableColumns]);
  45. const params = this.$init.params([...TabColumns, ...TableColumns]);
  46. return {
  47. width: "100%",
  48. visible: false,
  49. loading: false,
  50. rules,
  51. params,
  52. tabName: tabName,
  53. TabColumns: TabColumns,
  54. TableColumns: TableColumns,
  55. };
  56. },
  57. computed: {
  58. title: {
  59. get() {
  60. const { addType } = this;
  61. if (addType === "add") {
  62. return "新 增";
  63. }
  64. if (addType === "edit") {
  65. return "编 辑";
  66. }
  67. },
  68. set() {},
  69. },
  70. materialInfo: {
  71. get() {
  72. const { materialBasic } = this.params;
  73. this.params.materialBasic = materialBasic.map((item, index) => ({
  74. ...item,
  75. $index: index,
  76. }));
  77. return {
  78. materialBasic: this.params.materialBasic.filter(
  79. ({ delFlag }) => delFlag !== "2"
  80. ),
  81. };
  82. },
  83. set() {},
  84. },
  85. },
  86. watch: {},
  87. methods: {
  88. setVisible(prop) {
  89. this.visible = prop;
  90. },
  91. beforeOpen() {
  92. if (this.addType === "add") {
  93. let { name, nickName } = this.$store.state.user;
  94. this.params.createBy = name;
  95. this.params.createByName = nickName;
  96. this.params.createTime = new Date().Format("yyyy-MM-dd HH:mm:ss");
  97. this.params.updateBy = name;
  98. this.params.updateByName = nickName;
  99. this.params.updateTime = new Date().Format("yyyy-MM-dd HH:mm:ss");
  100. // this.params.approver = name;
  101. this.params.applicationTime = new Date().Format("yyyy-MM-dd HH:mm:ss");
  102. this.params.status = "0";
  103. console.log(this.$store.state.user, "user");
  104. this.params.orgName = "德荣集团";
  105. // this.useRowAdd(this.tabName);
  106. }
  107. },
  108. //
  109. async fetchItem(prop) {
  110. try {
  111. // try
  112. this.loading = true;
  113. let { code, data } = await getChangeDetails(prop.id);
  114. if (code == 200) {
  115. this.params = data;
  116. }
  117. } catch (err) {
  118. // catch
  119. console.error(err);
  120. } finally {
  121. // finally
  122. this.loading = false;
  123. }
  124. },
  125. //
  126. async hide() {
  127. const {
  128. TabColumns,
  129. TableColumns,
  130. TabColumns: [
  131. {
  132. item: { key: tabName },
  133. },
  134. ],
  135. } = useColumns();
  136. this.visible = false;
  137. this.$emit("success");
  138. this.tabName = tabName;
  139. this.params = this.$init.params([...TabColumns, ...TableColumns]);
  140. },
  141. //
  142. async useRowAdd(prop) {
  143. const { TableColumns } = this.TabColumns.find(
  144. ({ item: { key } }) => key === prop
  145. );
  146. this.params[prop].push({
  147. delFlag: "0",
  148. materialClassifyId: null,
  149. ...this.$init.params(TableColumns),
  150. });
  151. },
  152. //
  153. async useRowRemove(prop, scope) {
  154. const { addType } = this.$props;
  155. const {
  156. row: { $index },
  157. } = scope;
  158. if (addType === "add") {
  159. this.params[prop].splice($index, 1);
  160. }
  161. if (addType === "edit") {
  162. this.params[prop] = this.params[prop]
  163. .map((item, index) => ({
  164. ...item,
  165. delFlag: index === $index ? "2" : item.delFlag,
  166. }))
  167. .filter((item) => item.id || (!item.id && item.delFlag === "0"));
  168. }
  169. },
  170. handleSubmitValidate(prop, cb) {
  171. this.$refs[prop].$refs[prop].validate(async (valid) => {
  172. if (valid) {
  173. try {
  174. this.loading = true;
  175. let validList = this.params["materialBasic"].filter(
  176. (item) => item.delFlag === "0"
  177. );
  178. if (validList.length) {
  179. await cb();
  180. } else {
  181. this.$notify.error({
  182. message: "物料信息不能不为空!",
  183. });
  184. }
  185. } catch (err) {
  186. // catch
  187. console.error(err);
  188. } finally {
  189. // finally
  190. this.loading = false;
  191. }
  192. } else {
  193. return false;
  194. }
  195. });
  196. },
  197. //
  198. async useSave(prop) {
  199. let params = _.cloneDeep(this.params);
  200. this.handleSubmitValidate(prop, async () => {
  201. try {
  202. this.loading = true;
  203. const { code, msg } = await addChangeList(params);
  204. if (code == 200) {
  205. this.hide();
  206. this.$notify.success({
  207. title: msg,
  208. });
  209. }
  210. } catch (error) {
  211. } finally {
  212. this.loading = false;
  213. }
  214. // await;
  215. });
  216. },
  217. // 保存并提交
  218. async useSubmit(prop) {
  219. let params = _.cloneDeep(this.params);
  220. console.log(params, "params");
  221. this.handleSubmitValidate(prop, async () => {
  222. try {
  223. this.loading = true;
  224. const { code, msg } = await saveAndSubmit({
  225. ...params,
  226. isInventory: "Y",
  227. });
  228. if (code == 200) {
  229. this.hide();
  230. this.$notify.success({
  231. title: msg,
  232. });
  233. } else if (code == 10000) {
  234. this.$alert(
  235. "<div style='overflow: auto;overflow-x: hidden;max-height: 65vh;padding: 10px 20px 0;'>" +
  236. msg +
  237. "</div>",
  238. "提示",
  239. {
  240. showCancelButton: true,
  241. dangerouslyUseHTMLString: true,
  242. confirmButtonText: "确认",
  243. cancelButtonText: "取消",
  244. beforeClose: async (action, instance, done) => {
  245. if (action === "confirm") {
  246. instance.confirmButtonLoading = true;
  247. instance.confirmButtonText = "执行中...";
  248. try {
  249. const { code, msg } = await saveAndSubmit({
  250. ...params,
  251. isInventory: "N",
  252. });
  253. if (code == 200) {
  254. done();
  255. this.hide();
  256. this.$notify.success({
  257. message: msg,
  258. });
  259. }
  260. } catch (error) {
  261. instance.confirmButtonText = "确认";
  262. } finally {
  263. instance.confirmButtonLoading = false;
  264. }
  265. } else {
  266. done();
  267. this.$notify.warning({
  268. message:
  269. "不允许修改【批号及库存状态管理】或【是否序列号管理】",
  270. });
  271. }
  272. },
  273. }
  274. );
  275. }
  276. } catch (error) {
  277. } finally {
  278. this.loading = false;
  279. }
  280. });
  281. },
  282. async handelImport(fileList) {
  283. try {
  284. let formData = new FormData();
  285. formData.append("file", fileList[0].raw);
  286. this.$modal.loading("正在上传文件,请稍候...");
  287. let { code, data } = await importInner(formData);
  288. if (code == 200) {
  289. // let size = 20;
  290. // let num = 1;
  291. // let total = Math.ceil(data.length / size);
  292. // let resultData = [...data];
  293. // let intervalPush = setInterval(()=>{
  294. // if(num > total) clearInterval(intervalPush);
  295. // resultData.slice(size*(num-1), (size*num) ).forEach(item =>{
  296. // this.params['materialBasic'].push(item);
  297. this.params["materialBasic"].push(...data);
  298. // })
  299. // num++;
  300. // },200);
  301. let { setVisible } = this.$refs.batchImport;
  302. setVisible(false);
  303. }
  304. } catch (error) {
  305. } finally {
  306. this.$modal.closeLoading();
  307. }
  308. },
  309. async handleTemDownload() {
  310. this.download(
  311. "/material/change/downloadInner",
  312. {},
  313. `变更单物料信息模板${new Date().getTime()}.xlsx`
  314. );
  315. },
  316. // 批号及库存状态管理
  317. changeIsInventoryStatus(row) {
  318. if (row.isInventoryStatus === "2") {
  319. row.expiryDateManagerment = "2";
  320. row.serialNoManager = "2";
  321. }
  322. this.changeExpiryDateManagerment(row);
  323. },
  324. changeExpiryDateManagerment(row) {
  325. if (row.expiryDateManagerment === "2") {
  326. row.usefulLife = "";
  327. row.expiryUnitId = "";
  328. row.usefulLifeUnitId = "";
  329. row.nearOnsetManagerment = "2";
  330. row.recentWarningPeriod = "";
  331. }
  332. },
  333. // 物料编码
  334. async materialCodeChange(prop) {
  335. let { factory } = prop;
  336. try {
  337. // this.loading = true;
  338. let { code, rows } = await REFER(
  339. {
  340. type: "MANUFACTURER_PARAM",
  341. search: "",
  342. id: factory,
  343. isPage: true,
  344. },
  345. { pageNum: 1, pageSize: 10 }
  346. );
  347. if (rows[0]) {
  348. let { manufacturerOther } = rows[0];
  349. prop["brand"] = manufacturerOther.brand;
  350. }
  351. } catch (error) {
  352. } finally {
  353. // this.loading = false;
  354. }
  355. },
  356. },
  357. created() {},
  358. mounted() {},
  359. destroyed() {},
  360. };
  361. </script>
  362. <template>
  363. <el-drawer
  364. v-bind="$attrs"
  365. v-on="$listeners"
  366. :size="width"
  367. :visible.sync="visible"
  368. destroy-on-close
  369. :show-close="false"
  370. @close="hide"
  371. @open="beforeOpen"
  372. v-loading="loading"
  373. >
  374. <div
  375. slot="title"
  376. style="display: flex; justify-content: space-between; align-items: center"
  377. >
  378. <h3>{{ title }}</h3>
  379. <div>
  380. <el-button
  381. type="primary"
  382. :size="$attrs.size"
  383. :loading="loading"
  384. @click="useSave('superForm')"
  385. >保 存</el-button
  386. >
  387. <el-button
  388. type="primary"
  389. :size="$attrs.size"
  390. :loading="loading"
  391. @click="useSubmit('superForm')"
  392. >保存并提交</el-button
  393. >
  394. <el-button :size="$attrs.size" :loading="loading" @click="hide"
  395. >取 消</el-button
  396. >
  397. </div>
  398. </div>
  399. <el-super-form
  400. v-model="params"
  401. :dict="dict"
  402. :rules="rules"
  403. :size="$attrs.size"
  404. :columns="TableColumns"
  405. ref="superForm"
  406. label-width="auto"
  407. label-position="right"
  408. style="padding: 20px"
  409. >
  410. <template slot="puOrgName" slot-scope="scope">
  411. <component
  412. v-bind="scope.attr"
  413. v-model="scope.row[scope.item.key]"
  414. :size="$attrs.size"
  415. :source.sync="scope.row"
  416. >
  417. </component
  418. ></template>
  419. </el-super-form>
  420. <div style="position: relative">
  421. <el-tabs v-model="tabName" style="padding: 0 20px 20px">
  422. <el-tab-pane
  423. v-for="({ item, TableColumns: columns }, index) in TabColumns"
  424. :key="index"
  425. :label="item.title"
  426. :name="item.key"
  427. lazy
  428. >
  429. <el-super-ux-table
  430. index
  431. v-model="materialInfo[item.key]"
  432. :dict="dict"
  433. :ref="tabName"
  434. :columns="columns"
  435. :size="$attrs.size"
  436. :height="420"
  437. >
  438. <template slot="materialCode" slot-scope="scope">
  439. <component
  440. v-bind="scope.attr"
  441. v-model="scope.row[scope.item.key]"
  442. :size="$attrs.size"
  443. :source.sync="scope.row"
  444. @change="materialCodeChange(scope.row)"
  445. >
  446. </component>
  447. </template>
  448. <template slot="materialName" slot-scope="scope">
  449. <component
  450. v-bind="scope.attr"
  451. v-model="scope.row[scope.item.key]"
  452. :size="$attrs.size"
  453. :source.sync="scope.row"
  454. >
  455. </component>
  456. </template>
  457. <!-- 判断是否禁用 -->
  458. <template slot="drug" slot-scope="scope">
  459. <component
  460. v-bind="scope.attr"
  461. v-model="scope.row[scope.item.key]"
  462. :size="$attrs.size"
  463. :source.sync="scope.row"
  464. :disabled="!(scope.row.medicineMaterial === '0')"
  465. >
  466. <el-option
  467. v-for="item in dict.type[scope.attr.dictName]"
  468. :key="item.value"
  469. :label="item.label"
  470. :value="item.value"
  471. >
  472. </el-option>
  473. </component>
  474. </template>
  475. <template slot="registrationNo" slot-scope="scope">
  476. <component
  477. v-bind="scope.attr"
  478. v-model="scope.row[scope.item.key]"
  479. :size="$attrs.size"
  480. :source.sync="scope.row"
  481. :disabled="!(scope.row.medicineMaterial === '0')"
  482. >
  483. </component>
  484. </template>
  485. <template slot="medicalDevices" slot-scope="scope">
  486. <component
  487. v-bind="scope.attr"
  488. v-model="scope.row[scope.item.key]"
  489. :size="$attrs.size"
  490. :source.sync="scope.row"
  491. :disabled="!(scope.row.medicineMaterial === '0')"
  492. >
  493. <el-option
  494. v-for="item in dict.type[scope.attr.dictName]"
  495. :key="item.value"
  496. :label="item.label"
  497. :value="item.value"
  498. >
  499. </el-option>
  500. </component>
  501. </template>
  502. <template slot="maintenanceType" slot-scope="scope">
  503. <component
  504. v-bind="scope.attr"
  505. v-model="scope.row[scope.item.key]"
  506. :size="$attrs.size"
  507. :source.sync="scope.row"
  508. :disabled="!(scope.row.medicineMaterial === '0')"
  509. >
  510. <el-option
  511. v-for="item in dict.type[scope.attr.dictName]"
  512. :key="item.value"
  513. :label="item.label"
  514. :value="item.value"
  515. >
  516. </el-option>
  517. </component>
  518. </template>
  519. <!-- <template slot="dosageFromName" slot-scope="scope">
  520. <component
  521. v-bind="scope.attr"
  522. v-model="scope.row[scope.item.key]"
  523. :size="$attrs.size"
  524. :source.sync="scope.row"
  525. :disabled="!(scope.row.medicineMaterial ==='0') "
  526. >
  527. </component>
  528. </template> -->
  529. <!-- 批号及库存状态管理 -->
  530. <template slot="isInventoryStatus" slot-scope="scope">
  531. <component
  532. v-bind="scope.attr"
  533. v-model="scope.row[scope.item.key]"
  534. :size="$attrs.size"
  535. :source.sync="scope.row"
  536. @change="changeIsInventoryStatus(scope.row)"
  537. >
  538. <el-option
  539. v-for="item in dict.type[scope.attr.dictName]"
  540. :key="item.value"
  541. :label="item.label"
  542. :value="item.value"
  543. >
  544. </el-option>
  545. </component>
  546. </template>
  547. <!-- 效期管理 -->
  548. <template slot="expiryDateManagerment" slot-scope="scope">
  549. <component
  550. v-bind="scope.attr"
  551. v-model="scope.row[scope.item.key]"
  552. :size="$attrs.size"
  553. :source.sync="scope.row"
  554. :disabled="scope.row.isInventoryStatus !== '0'"
  555. @change="changeExpiryDateManagerment(scope.row)"
  556. >
  557. <el-option
  558. v-for="item in dict.type[scope.attr.dictName]"
  559. :key="item.value"
  560. :label="item.label"
  561. :value="item.value"
  562. >
  563. </el-option>
  564. </component>
  565. </template>
  566. <!-- 是否序列号管理 -->
  567. <template slot="serialNoManager" slot-scope="scope">
  568. <component
  569. v-bind="scope.attr"
  570. v-model="scope.row[scope.item.key]"
  571. :size="$attrs.size"
  572. :source.sync="scope.row"
  573. :disabled="scope.row.isInventoryStatus !== '0'"
  574. >
  575. <el-option
  576. v-for="item in dict.type[scope.attr.dictName]"
  577. :key="item.value"
  578. :label="item.label"
  579. :value="item.value"
  580. >
  581. </el-option>
  582. </component>
  583. </template>
  584. <!-- 有效期 -->
  585. <template slot="usefulLife" slot-scope="scope">
  586. <component
  587. v-bind="scope.attr"
  588. v-model="scope.row[scope.item.key]"
  589. :size="$attrs.size"
  590. :source.sync="scope.row"
  591. :disabled="scope.row.expiryDateManagerment !== '0'"
  592. >
  593. </component>
  594. </template>
  595. <!-- 效期单位 -->
  596. <template slot="expiryUnitId" slot-scope="scope">
  597. <component
  598. v-bind="scope.attr"
  599. v-model="scope.row[scope.item.key]"
  600. :size="$attrs.size"
  601. :source.sync="scope.row"
  602. :disabled="scope.row.expiryDateManagerment !== '0'"
  603. >
  604. <el-option
  605. v-for="item in dict.type[scope.attr.dictName]"
  606. :key="item.value"
  607. :label="item.label"
  608. :value="item.value"
  609. >
  610. </el-option>
  611. </component>
  612. </template>
  613. <!-- 有效期至单位 -->
  614. <template slot="usefulLifeUnitId" slot-scope="scope">
  615. <component
  616. v-bind="scope.attr"
  617. v-model="scope.row[scope.item.key]"
  618. :size="$attrs.size"
  619. :source.sync="scope.row"
  620. :disabled="scope.row.expiryDateManagerment !== '0'"
  621. >
  622. <el-option
  623. v-for="item in dict.type[scope.attr.dictName]"
  624. :key="item.value"
  625. :label="item.label"
  626. :value="item.value"
  627. >
  628. </el-option>
  629. </component>
  630. </template>
  631. <!-- 近效期预警天数 -->
  632. <template slot="recentWarningPeriod" slot-scope="scope">
  633. <component
  634. v-bind="scope.attr"
  635. v-model="scope.row[scope.item.key]"
  636. :size="$attrs.size"
  637. :source.sync="scope.row"
  638. :disabled="scope.row.expiryDateManagerment !== '0'"
  639. >
  640. </component>
  641. </template>
  642. <ux-table-column
  643. fixed="right"
  644. title="操作"
  645. width="120"
  646. align="center"
  647. >
  648. <template slot="header" slot-scope="scope">
  649. <el-button
  650. type="text"
  651. :size="$attrs.size"
  652. @click="useRowAdd(tabName)"
  653. >
  654. 增行
  655. </el-button>
  656. </template>
  657. <template slot-scope="scope">
  658. <el-button
  659. type="text"
  660. :size="$attrs.size"
  661. @click.native.prevent="useRowRemove(tabName, scope)"
  662. >
  663. 删除
  664. </el-button>
  665. <AmendantRecord
  666. v-if="
  667. tabName === 'materialBasic' &&
  668. addType === 'edit' &&
  669. scope.row.id
  670. "
  671. v-model="scope.row"
  672. ></AmendantRecord>
  673. </template>
  674. </ux-table-column>
  675. </el-super-ux-table>
  676. </el-tab-pane>
  677. </el-tabs>
  678. <el-row style="position: absolute; top: 0px; right: 20px">
  679. <BatchImport
  680. ref="batchImport"
  681. @import="handelImport"
  682. @temDownload="handleTemDownload"
  683. ></BatchImport>
  684. </el-row>
  685. </div>
  686. </el-drawer>
  687. </template>
  688. <style scoped>
  689. ::v-deep .el-table__row.is-hidden {
  690. display: none;
  691. }
  692. </style>