index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  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. materialCodeChange( rows, props){
  251. console.log(rows, props,'rows, props');
  252. },
  253. },
  254. created() {
  255. },
  256. mounted() {},
  257. destroyed() {},
  258. };
  259. </script>
  260. <template>
  261. <el-drawer
  262. v-bind="$attrs"
  263. v-on="$listeners"
  264. :size="width"
  265. :visible.sync="visible"
  266. destroy-on-close
  267. :show-close="false"
  268. @close="hide"
  269. @open="beforeOpen"
  270. v-loading="loading"
  271. >
  272. <div
  273. slot="title"
  274. style="display: flex;
  275. justify-content: space-between;
  276. align-items: center;"
  277. >
  278. <h3>{{title}}</h3>
  279. <div>
  280. <el-button
  281. type="primary"
  282. :size="$attrs.size"
  283. :loading="loading"
  284. @click="useSubmit('superForm')"
  285. >确 认</el-button
  286. >
  287. <el-button :size="$attrs.size" :loading="loading" @click="hide"
  288. >取 消</el-button
  289. >
  290. </div>
  291. </div>
  292. <el-super-form
  293. v-model="params"
  294. :dict="dict"
  295. :rules="rules"
  296. :size="$attrs.size"
  297. :columns="TableColumns"
  298. ref="superForm"
  299. label-width="auto"
  300. label-position="right"
  301. style="padding: 20px"
  302. >
  303. <template slot="puOrgName" slot-scope="scope">
  304. <component
  305. v-bind="scope.attr"
  306. v-model="scope.row[scope.item.key]"
  307. :size="$attrs.size"
  308. :source.sync="scope.row"
  309. >
  310. </component
  311. ></template>
  312. </el-super-form>
  313. <div style="position: relative;">
  314. <el-tabs v-model="tabName" style="padding: 0 20px 20px">
  315. <el-tab-pane
  316. v-for="({ item, TableColumns: columns }, index) in TabColumns"
  317. :key="index"
  318. :label="item.title"
  319. :name="item.key"
  320. lazy
  321. >
  322. <div style="height: 420px;display:flex">
  323. <el-super-table
  324. index
  325. v-model="materialInfo[item.key]"
  326. :dict="dict"
  327. :ref="tabName"
  328. :columns="columns"
  329. :size="$attrs.size"
  330. >
  331. <!-- <template slot="materialCode" slot-scope="scope">
  332. <component
  333. v-bind="scope.attr"
  334. v-model="scope.row[scope.item.key]"
  335. :size="$attrs.size"
  336. :source.sync="scope.row"
  337. copy
  338. @change="materialCodeChange"
  339. >
  340. </component>
  341. </template> -->
  342. <template slot="materialName" slot-scope="scope">
  343. <component
  344. v-bind="scope.attr"
  345. v-model="scope.row[scope.item.key]"
  346. :size="$attrs.size"
  347. :source.sync="scope.row"
  348. >
  349. </component>
  350. </template>
  351. <!-- 判断是否禁用 -->
  352. <template slot="drug" slot-scope="scope">
  353. <component
  354. v-bind="scope.attr"
  355. v-model="scope.row[scope.item.key]"
  356. :size="$attrs.size"
  357. :source.sync="scope.row"
  358. :disabled="!(scope.row.medicineMaterial ==='0') "
  359. >
  360. <el-option
  361. v-for="item in dict.type[scope.attr.dictName]"
  362. :key="item.value"
  363. :label="item.label"
  364. :value="item.value"
  365. >
  366. </el-option>
  367. </component>
  368. </template>
  369. <template slot="registrationNo" slot-scope="scope">
  370. <component
  371. v-bind="scope.attr"
  372. v-model="scope.row[scope.item.key]"
  373. :size="$attrs.size"
  374. :source.sync="scope.row"
  375. :disabled="!(scope.row.medicineMaterial ==='0') "
  376. >
  377. </component>
  378. </template>
  379. <template slot="medicalDevices" slot-scope="scope">
  380. <component
  381. v-bind="scope.attr"
  382. v-model="scope.row[scope.item.key]"
  383. :size="$attrs.size"
  384. :source.sync="scope.row"
  385. :disabled="!(scope.row.medicineMaterial ==='0') "
  386. >
  387. <el-option
  388. v-for="item in dict.type[scope.attr.dictName]"
  389. :key="item.value"
  390. :label="item.label"
  391. :value="item.value"
  392. >
  393. </el-option>
  394. </component>
  395. </template>
  396. <template slot="maintenanceType" slot-scope="scope">
  397. <component
  398. v-bind="scope.attr"
  399. v-model="scope.row[scope.item.key]"
  400. :size="$attrs.size"
  401. :source.sync="scope.row"
  402. :disabled="!(scope.row.medicineMaterial ==='0') "
  403. >
  404. <el-option
  405. v-for="item in dict.type[scope.attr.dictName]"
  406. :key="item.value"
  407. :label="item.label"
  408. :value="item.value"
  409. >
  410. </el-option>
  411. </component>
  412. </template>
  413. <!-- <template slot="dosageFromName" slot-scope="scope">
  414. <component
  415. v-bind="scope.attr"
  416. v-model="scope.row[scope.item.key]"
  417. :size="$attrs.size"
  418. :source.sync="scope.row"
  419. :disabled="!(scope.row.medicineMaterial ==='0') "
  420. >
  421. </component>
  422. </template> -->
  423. <!-- 批号及库存状态管理 -->
  424. <template slot="isInventoryStatus" slot-scope="scope">
  425. <component
  426. v-bind="scope.attr"
  427. v-model="scope.row[scope.item.key]"
  428. :size="$attrs.size"
  429. :source.sync="scope.row"
  430. @change="changeIsInventoryStatus(scope.row)"
  431. >
  432. <el-option
  433. v-for="item in dict.type[scope.attr.dictName]"
  434. :key="item.value"
  435. :label="item.label"
  436. :value="item.value"
  437. >
  438. </el-option>
  439. </component>
  440. </template>
  441. <!-- 效期管理 -->
  442. <template slot="expiryDateManagerment" slot-scope="scope">
  443. <component
  444. v-bind="scope.attr"
  445. v-model="scope.row[scope.item.key]"
  446. :size="$attrs.size"
  447. :source.sync="scope.row"
  448. :disabled="scope.row.isInventoryStatus !=='0' "
  449. @change="changeExpiryDateManagerment(scope.row)"
  450. >
  451. <el-option
  452. v-for="item in dict.type[scope.attr.dictName]"
  453. :key="item.value"
  454. :label="item.label"
  455. :value="item.value"
  456. >
  457. </el-option>
  458. </component>
  459. </template>
  460. <!-- 是否序列号管理 -->
  461. <template slot="serialNoManager" slot-scope="scope">
  462. <component
  463. v-bind="scope.attr"
  464. v-model="scope.row[scope.item.key]"
  465. :size="$attrs.size"
  466. :source.sync="scope.row"
  467. :disabled="scope.row.isInventoryStatus !=='0' "
  468. >
  469. <el-option
  470. v-for="item in dict.type[scope.attr.dictName]"
  471. :key="item.value"
  472. :label="item.label"
  473. :value="item.value"
  474. >
  475. </el-option>
  476. </component>
  477. </template>
  478. <!-- 有效期 -->
  479. <template slot="usefulLife" slot-scope="scope">
  480. <component
  481. v-bind="scope.attr"
  482. v-model="scope.row[scope.item.key]"
  483. :size="$attrs.size"
  484. :source.sync="scope.row"
  485. :disabled="scope.row.expiryDateManagerment !=='0'"
  486. >
  487. </component>
  488. </template>
  489. <el-table-column fixed="right" label="操作" width="120" align="center">
  490. <template slot="header" slot-scope="scope">
  491. <el-button
  492. type="text"
  493. :size="$attrs.size"
  494. @click="useRowAdd(tabName)"
  495. >
  496. 增行
  497. </el-button>
  498. </template>
  499. <template slot-scope="scope">
  500. <el-button
  501. type="text"
  502. :size="$attrs.size"
  503. @click.native.prevent="useRowRemove(tabName, scope)"
  504. >
  505. 删除
  506. </el-button>
  507. <AmendantRecord
  508. v-if=" tabName ==='materialBasic' && addType === 'edit' && scope.row.id"
  509. v-model="scope.row"
  510. ></AmendantRecord>
  511. </template>
  512. </el-table-column>
  513. </el-super-table>
  514. </div>
  515. </el-tab-pane>
  516. </el-tabs>
  517. <el-row style="position: absolute; top: 0px; right: 20px">
  518. <BatchImport
  519. ref="batchImport"
  520. @import="handelImport"
  521. @temDownload="handleTemDownload"
  522. ></BatchImport>
  523. </el-row>
  524. </div>
  525. </el-drawer>
  526. </template>
  527. <style scoped>
  528. ::v-deep .el-table__row.is-hidden {
  529. display: none;
  530. }
  531. </style>