editPage.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. <!--编辑-->
  2. <template>
  3. <div class="editPage">
  4. <div class="editPage-min" v-if="pageType == 1">
  5. <div class="title-box">
  6. <p>化学品申购</p>
  7. <p class="reset-button-one" @click="backPage(0)"><i class="el-icon-arrow-left"></i>返回</p>
  8. </div>
  9. <div class="page-max-box scrollbar-box">
  10. <el-form :model="formData" ref="form" :inline="true" :rules="rules">
  11. <el-form-item label="申购原因:" prop="applyReason" label-width="100px">
  12. <el-input
  13. type="textarea"
  14. resize="none"
  15. maxLength="50"
  16. :rows="4"
  17. style="width:1200px;"
  18. v-model="formData.applyReason"
  19. placeholder="请输入申购原因"
  20. clearable/>
  21. </el-form-item>
  22. <div class="two-form-flex">
  23. <div class="two-form-left">
  24. <el-form-item label="实验室:" prop="subId" label-width="100px">
  25. <el-select
  26. style="width:360px;"
  27. v-model="formData.subId"
  28. filterable
  29. remote
  30. clearable
  31. reserve-keyword
  32. @change="subChange"
  33. @focus="selectFocus"
  34. @clear="clearClick"
  35. placeholder="请选择实验室"
  36. :remote-method="getSelectList"
  37. :loading="loading">
  38. <el-option
  39. v-for="item in selectList"
  40. :key="item.id"
  41. :label="item.name"
  42. :value="item.id">
  43. </el-option>
  44. </el-select>
  45. </el-form-item>
  46. </div>
  47. <p class="two-form-right add-button-one-90" @click="pageToggle(2)">更换化学品</p>
  48. </div>
  49. <div class="form-list-max-box">
  50. <div class="form-list-title-box">
  51. <p>化学品名称</p>
  52. <p>化学品柜</p>
  53. <p>剩余可存放量</p>
  54. <p>本次申购量</p>
  55. </div>
  56. <div class="form-list-data-box" v-for="(item,index) in formData.maxList" :key="index">
  57. <div class="form-list-data-title">
  58. <p>{{item.chemicalName}}</p>
  59. </div>
  60. <div class="form-list-data-for-max-box">
  61. <div class="form-list-data-for" v-for="(minItem,minIndex) in item.list" :key="minIndex">
  62. <div class="form-list-one-box">
  63. <el-form-item label="" :prop="'maxList.'+ index +'.list.'+ minIndex +'.cabinetId'"
  64. :rules="rules.cabinetId">
  65. <el-select v-model="minItem.cabinetId" clearable placeholder="请选择化学品柜"
  66. @change="(val)=>selectCabinet(index,minIndex,val)">
  67. <el-option v-for="item in cabinetLit"
  68. :key="item.id" :value="item.id" :label="item.cabinetName"></el-option>
  69. </el-select>
  70. </el-form-item>
  71. </div>
  72. <p class="form-list-text-p">
  73. {{minItem.applyText?minItem.applyText+item.applyUnit:'请选择化学品柜'}}
  74. </p>
  75. <div class="form-list-two-box">
  76. <el-form-item label="" :prop="'maxList.'+ index +'.list.'+ minIndex +'.applyNum'"
  77. :rules="rules.applyNum">
  78. <el-input
  79. maxLength="6"
  80. v-model="minItem.applyNum"
  81. placeholder="请输入本次申购量"
  82. clearable
  83. style="width: 220px"
  84. ><i slot="append">{{item.applyUnit}}</i></el-input>
  85. </el-form-item>
  86. <p class="el-icon-delete button-icon-p" v-if="formData.maxList[index].list.length>1" @click="delObj(index,minIndex)"></p>
  87. <p class="el-icon-circle-plus-outline button-icon-p" v-if="minIndex ==formData.maxList[index].list.length-1" @click="addObj(index)"></p>
  88. </div>
  89. </div>
  90. </div>
  91. </div>
  92. </div>
  93. <div class="bottom-button-box">
  94. <p class="add-button-one-90 right-button" @click="upData(2)" v-hasPermi="['chemical:hxpapply:add']">保存草稿</p>
  95. <p class="inquire-button-one right-button" @click="upData(1)" v-hasPermi="['chemical:hxpapply:add']">提交</p>
  96. </div>
  97. </el-form>
  98. </div>
  99. </div>
  100. <edit-check-page :editCheckIds="editCheckIds" v-if="pageType == 2"></edit-check-page>
  101. </div>
  102. </template>
  103. <script>
  104. import editCheckPage from "./editCheckPage.vue"
  105. import { getNoAdminSubjectListNopage,getCabinetBySubId,getRestStock,addHxpapply,getHxpapply } from "@/api/medicUniversity-3_1/index";
  106. export default {
  107. name: "editPage",
  108. components: {
  109. editCheckPage
  110. },
  111. props:{
  112. editPagePropsData:{},
  113. },
  114. data(){
  115. const nonZero = (rule, value, callback) => {
  116. if(value<=0){
  117. callback(new Error("请输入本次申购量"));
  118. }else{
  119. callback();
  120. }
  121. };
  122. return{
  123. pageType:1,
  124. loading:false,
  125. formData:{
  126. subId:"",
  127. applyReason:"",
  128. maxList:[],
  129. },
  130. rules:{
  131. applyReason:[
  132. { required: true, message: '请输入申购原因', trigger: 'blur' },
  133. { required: true, message: "请输入申购原因", validator: this.spaceJudgment, trigger: "blur" }
  134. ],
  135. subId:[
  136. { required: true, message: '请选择实验室', trigger: 'blur' },
  137. { required: true, message: "请选择实验室", validator: this.spaceJudgment, trigger: "blur" }
  138. ],
  139. cabinetId:[
  140. { required: true, message: '请选择化学品柜', trigger: 'blur' },
  141. { required: true, message: "请选择化学品柜", validator: this.spaceJudgment, trigger: "blur" }
  142. ],
  143. applyNum:[
  144. { required: true, message: '请输入本次申购量', trigger: 'blur' },
  145. { required: true, message: "请输入本次申购量", validator: this.spaceJudgment, trigger: "blur" },
  146. { required: true, message: "请输入本次申购量", validator: nonZero, trigger: "blur" },
  147. { required: true, message: "只能输入数字", validator: this.isNum, trigger: "blur" },
  148. ],
  149. },
  150. //实验室列表
  151. selectList:[],
  152. //机柜列表
  153. cabinetLit:[],
  154. //当前选中化学品(用于下级页面)
  155. editCheckIds:{},
  156. }
  157. },
  158. created() {
  159. },
  160. mounted(){
  161. this.editData();
  162. },
  163. methods: {
  164. //去选择页面
  165. pageToggle(type,data){
  166. let self = this;
  167. if(type == 1){
  168. this.pageType = 1;
  169. }else if(type == 2){
  170. let text = "";
  171. for(let i=0;i<self.formData.maxList.length;i++){
  172. if(i == 0){
  173. text = self.formData.maxList[i].chemicalId
  174. }else{
  175. text = text + ',' +self.formData.maxList[i].chemicalId
  176. }
  177. }
  178. this.$set(this.editCheckIds,'ids',text);
  179. this.pageType = 2;
  180. }else if(type == 3){
  181. let newList = [];
  182. for(let i=0;i<self.formData.maxList.length;i++){
  183. for(let o=0;o<data.length;o++){
  184. if(self.formData.maxList[i].chemicalId == data[o].id){
  185. newList.push(self.formData.maxList[i]);
  186. }
  187. }
  188. }
  189. newList = JSON.parse(JSON.stringify(newList));
  190. this.$set(this.formData,'maxList',newList);
  191. for(let i=0;i<data.length;i++){
  192. let num = 0;
  193. for(let o=0;o<self.formData.maxList.length;o++){
  194. if(self.formData.maxList[o].chemicalId == data[i].id){
  195. num++
  196. }
  197. }
  198. if(num == 0){
  199. let obj = {
  200. chemicalId:data[i].id,
  201. chemicalName:data[i].chemicalName,
  202. list:[{cabinetId:"",applyNum:"",applyText:""}],
  203. }
  204. self.formData.maxList.push(obj);
  205. }
  206. }
  207. this.pageType = 1;
  208. }
  209. },
  210. //新增逻辑
  211. editData(){
  212. this.$set(this,'formData',this.editPagePropsData);
  213. this.getSubject();
  214. this.getCabinet(this.editPagePropsData.subId);
  215. },
  216. //删除子项
  217. delObj(index,minIndex){
  218. this.formData.maxList[index].list.splice(minIndex,1)
  219. },
  220. //增加子项
  221. addObj(index){
  222. let obj = {cabinetId:"",applyNum:"",applyText:""}
  223. this.formData.maxList[index].list.push(obj);
  224. },
  225. //提交
  226. upData(type){
  227. let self = this;
  228. this.$refs["form"].validate((valid) => {
  229. if (valid) {
  230. let text = type==1?'提交':'保存';
  231. this.$confirm('是否确认'+text+'?', "警告", {
  232. confirmButtonText: "确定",
  233. cancelButtonText: "取消",
  234. type: "warning"
  235. }).then(function() {
  236. let upObj = {
  237. id:self.formData.id,
  238. applyStatus:type,
  239. subId:self.formData.subId,
  240. applyReason:self.formData.applyReason,
  241. actHxpapplyDetailList:[],
  242. };
  243. for(let i=0;i<self.formData.maxList.length;i++){
  244. for(let o=0;o<self.formData.maxList[i].list.length;o++){
  245. let obj = {
  246. chemicalId: self.formData.maxList[i].chemicalId,
  247. chemicalName: self.formData.maxList[i].chemicalName,
  248. cabinetId: self.formData.maxList[i].list[o].cabinetId,
  249. applyNum: self.formData.maxList[i].list[o].applyNum,
  250. remainingStorage:self.formData.maxList[i].list[o].applyText
  251. }
  252. upObj.actHxpapplyDetailList.push(obj)
  253. }
  254. }
  255. addHxpapply(upObj).then(response => {
  256. self.msgSuccess(response.msg);
  257. self.backPage(1);
  258. });
  259. }).then(() => {
  260. }).catch(() => {});
  261. }
  262. })
  263. },
  264. //返回
  265. backPage(type){
  266. if(type == 0){
  267. this.$parent.pageToggle(0);
  268. }else if(type == 1){
  269. this.$parent.pageToggle(1);
  270. }
  271. },
  272. // 机柜选中
  273. selectCabinet(index,minIndex,val){
  274. let obj = {
  275. subId:this.formData.subId,
  276. chemicalId:this.formData.maxList[index].chemicalId,
  277. cabinetId:this.formData.maxList[index].list[minIndex].cabinetId,
  278. };
  279. getRestStock(obj).then(response => {
  280. this.$set(this.formData.maxList[index].list[minIndex],'applyText',response.data.restStock);
  281. });
  282. },
  283. // 实验室选中
  284. subChange(val){
  285. let self = this;
  286. getCabinetBySubId({subId:val}).then(response => {
  287. this.$set(this,'cabinetLit',response.data);
  288. for(let i=0;i<self.formData.maxList.length;i++){
  289. for(let o=0;o<self.formData.maxList[i].list.length;o++){
  290. console.log(self.formData.maxList[i].list[o])
  291. this.$set(this.formData.maxList[i].list[o],'cabinetId',"");
  292. this.$set(this.formData.maxList[i].list[o],'applyText',"");
  293. }
  294. }
  295. });
  296. },
  297. getSubject(){
  298. //查询院系下实验室
  299. getNoAdminSubjectListNopage().then(response => {
  300. //当前列表
  301. this.selectList = JSON.parse(JSON.stringify(response.data));
  302. //原始列表数据
  303. this.selectListData = JSON.parse(JSON.stringify(response.data));
  304. });
  305. },
  306. getCabinet(val){
  307. getCabinetBySubId({subId:val}).then(response => {
  308. this.$set(this,'cabinetLit',response.data);
  309. });
  310. },
  311. selectFocus(){
  312. this.selectList = JSON.parse(JSON.stringify(this.selectListData));
  313. },
  314. /** 实验室-本地懒加载 */
  315. getSelectList(val) {
  316. let self = this;
  317. let list = [];
  318. for(let i=0;i<self.selectListData.length;i++){
  319. if(self.selectListData[i].name.indexOf(val) != -1){
  320. list.push(self.selectListData[i]);
  321. }
  322. }
  323. this.selectList = JSON.parse(JSON.stringify(list))
  324. },
  325. //实验室选中清除
  326. clearClick(){
  327. this.selectList = JSON.parse(JSON.stringify(this.selectListData))
  328. },
  329. }
  330. }
  331. </script>
  332. <style scoped lang="scss">
  333. .editPage{
  334. flex:1;
  335. display: flex;
  336. flex-direction: column;
  337. overflow: hidden;
  338. .editPage-min{
  339. flex:1;
  340. display: flex;
  341. flex-direction: column;
  342. overflow: hidden;
  343. p{
  344. margin:0;
  345. padding:0;
  346. }
  347. .title-box{
  348. display: flex;
  349. height:90px;
  350. border-bottom: 1px solid #D8D8D8;
  351. p:nth-child(1){
  352. flex:1;
  353. font-size:16px;
  354. line-height:90px;
  355. margin-left:18px;
  356. color:#0045AF;
  357. }
  358. p:nth-child(2){
  359. margin:25px 25px 0 0;
  360. }
  361. }
  362. .page-max-box{
  363. flex:1;
  364. display: flex;
  365. flex-direction: column;
  366. padding:20px 80px;
  367. .two-form-flex{
  368. display: flex;
  369. .two-form-left{
  370. flex:1;
  371. }
  372. .two-form-right{
  373. width:130px;
  374. }
  375. }
  376. .form-list-max-box{
  377. .form-list-title-box{
  378. display: flex;
  379. background: #F5F5F5;
  380. border-bottom:1px solid #e0e0e0;
  381. p{
  382. line-height:60px;
  383. font-size:16px;
  384. color:#333;
  385. }
  386. p:nth-child(1){
  387. padding-left:58px;
  388. width:255px;
  389. }
  390. p:nth-child(2){
  391. width:469px;
  392. }
  393. p:nth-child(3){
  394. width:252px;
  395. }
  396. p:nth-child(4){
  397. flex:1;
  398. }
  399. }
  400. .form-list-data-box{
  401. display: flex;
  402. border:1px solid #e0e0e0;
  403. border-top:none;
  404. padding-top:20px;
  405. .form-list-data-title{
  406. vertical-align:middle;
  407. width:255px;
  408. display: flex;
  409. p{
  410. height:40px;
  411. line-height:40px;
  412. align-self: center;
  413. margin-top:-20px;
  414. margin-left:58px;
  415. }
  416. }
  417. .form-list-data-for-max-box{
  418. .form-list-data-for{
  419. display: flex;
  420. .form-list-one-box{
  421. width:469px;
  422. }
  423. .form-list-text-p{
  424. width:252px;
  425. line-height:40px;
  426. font-size:14px;
  427. }
  428. .form-list-two-box{
  429. flex:1;
  430. .button-icon-p:nth-child(2){
  431. margin-left:80px;
  432. }
  433. .button-icon-p{
  434. color:#A2A2A2;
  435. width:40px;
  436. height:40px;
  437. line-height:40px;
  438. text-align: center;
  439. cursor: pointer;
  440. margin-left:20px;
  441. }
  442. }
  443. }
  444. }
  445. }
  446. }
  447. .bottom-button-box{
  448. display: flex;
  449. width:260px;
  450. margin:55px auto;
  451. p:nth-child(1){
  452. width:120px;
  453. margin-right:20px;
  454. }
  455. p:nth-child(2){
  456. width:120px;
  457. }
  458. }
  459. }
  460. }
  461. }
  462. </style>