index.vue 16 KB

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