index.vue 16 KB

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