instrument.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. <template>
  2. <div class="instrument scrollbar-box">
  3. <div class="title-box">
  4. <p></p>
  5. <p class="reset-button-one" @click="backPage">返回</p>
  6. </div>
  7. <div class="for-max-box" v-for="(item,index) in instrumentList" :key="index">
  8. <p class="for-name-p">{{item.equipmentName}}</p>
  9. <div class="for-big-box">
  10. <p class="for-img el-icon-data-line"></p>
  11. <div class="for-right-box">
  12. <div class="for-text-box">
  13. <p>负责人:</p>
  14. <p>{{item.userName}}</p>
  15. </div>
  16. <div class="for-text-box">
  17. <p>仪器编号:</p>
  18. <p>{{item.equipmentNum}}</p>
  19. </div>
  20. <div class="for-text-box">
  21. <p>仪器型号:</p>
  22. <p>{{item.modelNumber}}</p>
  23. </div>
  24. </div>
  25. </div>
  26. <div class="for-button-box">
  27. <p @click="clickButton(2,item,index)">编辑</p>
  28. <p @click="clickButton(3,item,index)">查看</p>
  29. <p @click="clickButton(4,item,index)">删除</p>
  30. </div>
  31. </div>
  32. <div class="add-max-box" @click="clickButton(1)">
  33. <i class="el-icon-plus"></i> 添加仪器
  34. </div>
  35. <el-dialog :title="dialogTitle" v-if="dialogType" :visible.sync="dialogType" @close="cancel" width="600px"
  36. append-to-body class="instrument-dialog-box">
  37. <el-form :model="dialogForm" ref="dialogForm" :inline="true" :rules="rules" label-width="120px">
  38. <el-form-item label="仪器名称:" prop="equipmentName">
  39. <el-input
  40. :disabled="dialogLook"
  41. maxlength="20"
  42. style="width:400px;"
  43. v-model="dialogForm.equipmentName"
  44. placeholder="请输入仪器名称"/>
  45. </el-form-item>
  46. <el-form-item label="负责人:" prop="userName">
  47. <el-input
  48. :disabled="dialogLook"
  49. maxlength="10"
  50. style="width:400px;"
  51. v-model="dialogForm.userName"
  52. placeholder="请输入设备名称"/>
  53. </el-form-item>
  54. <el-form-item label="仪器类型:" prop="instrumentClass">
  55. <el-select v-model="dialogForm.instrumentClass"
  56. :disabled="dialogLook"
  57. placeholder="请选择仪器类型"
  58. style="width:400px;">
  59. <el-option
  60. v-for="dict in instrumentClassOptions"
  61. :key="dict.id"
  62. :label="dict.name"
  63. :value="dict.id"
  64. ></el-option>
  65. </el-select>
  66. </el-form-item>
  67. <el-form-item label="仪器编号:" prop="equipmentNum">
  68. <el-input
  69. :disabled="dialogLook"
  70. maxlength="20"
  71. style="width:400px;"
  72. v-model="dialogForm.equipmentNum"
  73. placeholder="请输入仪器编号"/>
  74. </el-form-item>
  75. <el-form-item label="仪器型号:" prop="modelNumber">
  76. <el-input
  77. :disabled="dialogLook"
  78. maxlength="20"
  79. style="width:400px;"
  80. v-model="dialogForm.modelNumber"
  81. placeholder="请输入仪器型号"/>
  82. </el-form-item>
  83. </el-form>
  84. <div slot="footer" class="dialog-footer" >
  85. <el-button @click="cancel">{{dialogLook?'关 闭':'取 消'}}</el-button>
  86. <el-button v-if="!dialogLook" type="primary" @click="submitForm">确定</el-button>
  87. </div>
  88. </el-dialog>
  89. </div>
  90. </template>
  91. <script>
  92. export default {
  93. name: 'instrument',
  94. props:{
  95. newData:{},
  96. },
  97. data(){
  98. return{
  99. // 仪器类型
  100. instrumentClassOptions:[
  101. { id:1, name:"化学分析仪器" },
  102. { id:2, name:"电子显微镜" },
  103. { id:3, name:"扫描电镜" },
  104. { id:4, name:"光学仪器及设备" },
  105. { id:5, name:"光学显微镜及成像系统" },
  106. { id:6, name:"激光共聚焦显微镜" },
  107. { id:7, name:"物理性能测试仪器" },
  108. { id:8, name:"试验仪器及环境试验箱" },
  109. { id:9, name:"其它试验仪器及环境试验箱" },
  110. { id:10, name:"光学仪器及设备" },
  111. { id:11, name:"其他设备" },
  112. ],
  113. //数据
  114. instrumentList:[
  115. {
  116. equipmentName:"激光共聚焦显微镜",
  117. userName:"赵晨博",
  118. equipmentNum:"jggz003513211",
  119. modelNumber:"LSM700",
  120. instrumentClass:6,
  121. },
  122. {
  123. equipmentName:"扫描电镜",
  124. userName:"梁建成",
  125. equipmentNum:"smdj004687231",
  126. modelNumber:"Helios Nanolab 600i",
  127. instrumentClass:3,
  128. },
  129. ],
  130. //弹窗
  131. dialogType:false,
  132. dialogForm:{},
  133. dialogLook:false,
  134. dialogIndex:null,
  135. dialogTitle:"",
  136. // 表单校验
  137. rules: {
  138. equipmentName: [
  139. { required: true, message: "请输入仪器名称", trigger: "blur" },
  140. { required: true, message: "请输入仪器名称", validator: this.spaceJudgment, trigger: "blur" }
  141. ],
  142. userName: [
  143. { required: true, message: "请选择负责人", trigger: "blur" },
  144. { required: true, message: "请选择负责人", validator: this.spaceJudgment, trigger: "blur" }
  145. ],
  146. equipmentNum: [
  147. { required: true, message: "请输入仪器编号", trigger: "blur" },
  148. { required: true, message: "请输入仪器编号", validator: this.spaceJudgment, trigger: "blur" }
  149. ],
  150. modelNumber: [
  151. { required: true, message: "请输入仪器型号", trigger: "blur" },
  152. { required: true, message: "请输入仪器型号", validator: this.spaceJudgment, trigger: "blur" }
  153. ],
  154. instrumentClass: [
  155. { required: true, message: "请选择仪器类型", trigger: "blur" },
  156. { required: true, message: "请选择仪器类型", validator: this.spaceJudgment, trigger: "blur" }
  157. ],
  158. },
  159. //vuex数据
  160. dataVUEX:[],
  161. }
  162. },
  163. created(){
  164. },
  165. mounted(){
  166. this.getVUEX();
  167. },
  168. methods:{
  169. clickButton(type,item,index){
  170. let self = this;
  171. if(type == 1){
  172. this.$set(this,'dialogLook',false);
  173. this.$set(this,'dialogIndex',null);
  174. this.$set(this,'dialogTitle','添加仪器');
  175. this.$set(this,'dialogForm',{
  176. equipmentName:"",
  177. userName:"",
  178. equipmentNum:"",
  179. modelNumber:"",
  180. instrumentClass:"",
  181. });
  182. this.$set(this,'dialogType',true);
  183. }else if (type == 2){
  184. this.$set(this,'dialogTitle','编辑仪器');
  185. this.$set(this,'dialogLook',false);
  186. this.$set(this,'dialogIndex',index);
  187. this.$set(this,'dialogForm',JSON.parse(JSON.stringify(item)));
  188. this.$set(this,'dialogType',true);
  189. }else if(type == 3){
  190. this.$set(this,'dialogTitle','查看仪器');
  191. this.$set(this,'dialogLook',true);
  192. this.$set(this,'dialogIndex',null);
  193. this.$set(this,'dialogForm',item);
  194. this.$set(this,'dialogType',true);
  195. }else if(type == 4){
  196. this.$confirm('确认要删除该设备?', "警告", {
  197. confirmButtonText: "确定",
  198. cancelButtonText: "取消",
  199. type: "warning"
  200. }).then(() => {
  201. self.instrumentList.splice(index, 1);
  202. self.setVUEX();
  203. }).catch(function() {
  204. // 取消
  205. });
  206. }
  207. },
  208. //本地数据存储
  209. setVUEX(){
  210. let self = this;
  211. let num = 0;
  212. for(let i=0;i<self.dataVUEX.length;i++){
  213. if(self.newData.id == self.dataVUEX[i].id){
  214. self.dataVUEX[i] = {
  215. id:self.newData.id,
  216. list:self.instrumentList
  217. }
  218. num++
  219. }
  220. }
  221. if(num == 0){
  222. this.dataVUEX.push({
  223. id:self.newData.id,
  224. list:self.instrumentList
  225. })
  226. }
  227. this.$store.dispatch("setInstrument", this.dataVUEX);
  228. },
  229. //本地数据读取
  230. getVUEX(){
  231. let self = this;
  232. let list = this.$store.getters.instrument;
  233. for(let i=0;i<list.length;i++){
  234. this.$set(self,'instrumentList',this.instrumentList.concat(list[i].list));
  235. }
  236. this.$set(this,'dataVUEX',list);
  237. },
  238. //返回上一页
  239. backPage(){
  240. this.$parent.clickPage(1);
  241. },
  242. //关闭
  243. cancel(){
  244. this.$set(this,'dialogType',false);
  245. },
  246. //提交
  247. submitForm(){
  248. this.$refs["dialogForm"].validate(valid => {
  249. if (valid) {
  250. if(this.dialogIndex){
  251. this.instrumentList[this.dialogIndex] = this.dialogForm;
  252. }else{
  253. this.instrumentList.push(this.dialogForm);
  254. }
  255. this.setVUEX();
  256. this.msgSuccess('操作成功')
  257. this.$set(this,'dialogType',false);
  258. }
  259. })
  260. },
  261. },
  262. }
  263. </script>
  264. <style scoped lang="scss">
  265. .instrument{
  266. flex:1;
  267. border-radius:10px!important;
  268. margin:5px 20px 20px 10px!important;
  269. box-shadow: 0 0 8px 1px rgba(0, 0, 0, 0.1) !important;
  270. padding:20px;
  271. font-weight:500;
  272. .title-box{
  273. display: flex;
  274. p:nth-child(1){
  275. flex:1;
  276. }
  277. p:nth-child(2){
  278. margin:0 0 20px 0;
  279. }
  280. }
  281. .for-max-box{
  282. width:350px;
  283. height:190px;
  284. border:1px solid #dedede;
  285. border-radius:4px;
  286. margin:0 20px 20px 0;
  287. display: inline-block;
  288. overflow: hidden;
  289. .for-name-p{
  290. font-size:16px;
  291. padding:0 20px;
  292. height:40px;
  293. line-height:40px;
  294. display:block;
  295. overflow:hidden;
  296. text-overflow:ellipsis;
  297. white-space:nowrap;
  298. border-bottom:1px solid #dedede;
  299. }
  300. .for-big-box{
  301. display: flex;
  302. .for-img{
  303. width:70px;
  304. height:70px;
  305. line-height:70px;
  306. text-align: center;
  307. font-size:60px;
  308. color:#666;
  309. margin:20px 30px;
  310. }
  311. .for-right-box{
  312. padding-top:15px;
  313. .for-text-box{
  314. display: flex;
  315. p{
  316. font-size:14px;
  317. line-height:25px;
  318. }
  319. p:nth-child(1){
  320. width:80px;
  321. text-align: right;
  322. }
  323. p:nth-child(2){
  324. width:130px;
  325. display:block;
  326. overflow:hidden;
  327. text-overflow:ellipsis;
  328. white-space:nowrap;
  329. }
  330. }
  331. }
  332. }
  333. .for-button-box{
  334. border-top:1px solid #dedede;
  335. display: flex;
  336. p{
  337. line-height:37px;
  338. font-size:14px;
  339. flex:1;
  340. text-align: center;
  341. cursor: pointer;
  342. }
  343. p:hover{
  344. color:#fff;
  345. background-color: #00a0e9;
  346. }
  347. }
  348. }
  349. .add-max-box{
  350. display: inline-block;
  351. overflow: hidden;
  352. margin:0 20px 20px 0;
  353. width:350px;
  354. height:190px;
  355. line-height: 190px;
  356. text-align: center;
  357. border:1px solid #dedede;
  358. cursor: pointer;
  359. border-radius:4px;
  360. }
  361. }
  362. </style>