assetsEdit.vue 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  1. <template>
  2. <div class="detail">
  3. <mt-header class="detail_head" fixed title="编辑资产">
  4. <router-link to="" slot="left">
  5. <mt-button icon="back" v-on:click="jumpBack()"></mt-button>
  6. </router-link>
  7. </mt-header>
  8. <div class="detail_body">
  9. <div class="detailBox">
  10. <div class="left_tag">资产分类</div>
  11. <div class="right">
  12. <ul class="address_first">
  13. <li v-for="(item,index) in labels" :id="'btn'+item.id" v-bind:class="{'active':item.id==tagId}" v-on:click="chooseTag(item.id)">
  14. {{item.name}}
  15. <img v-if="index > 3" v-on:click="delTag(item.id)" src="../../assets/image/del.png">
  16. </li>
  17. <li v-on:click="addNewTag()" class="add">+</li>
  18. </ul>
  19. </div>
  20. </div>
  21. <div class="detailBox">
  22. <mt-field label="物品名称" placeholder="请输入物品名称" v-model="assetsForm.name"></mt-field>
  23. <mt-field label="型号" placeholder="请输入物品型号" v-model="assetsForm.modelNumber"></mt-field>
  24. <mt-field label="产品序列" placeholder="请输入产品序列" v-model="assetsForm.goodsSequence"></mt-field>
  25. <mt-field label="数量" placeholder="请输入数量" type="number" v-model="assetsForm.number"></mt-field>
  26. <mt-field label="单位" placeholder="请输入单位" v-model="assetsForm.unit"></mt-field>
  27. <div class="upload">
  28. <div class="left">物品图片</div>
  29. <div class="right upload_add" v-on:click="choosePic()">
  30. <div v-if="assetsForm.pic == null || assetsForm.pic == ''" class="upload_add_image" align="center">
  31. <img src="../../assets/image/camera.png" class="camera">
  32. <p class="font13">添加图片</p>
  33. </div>
  34. <div v-else class="right">
  35. <img class="pic" :src="assetsForm.pic">
  36. </div>
  37. </div>
  38. <input @change="fileChange($event)" type="file" accept="image/*" id="upload_file" style="display: none"/>
  39. </div>
  40. <mt-field label="地址" placeholder="请输入地址" v-model="assetsForm.address"></mt-field>
  41. </div>
  42. <div class="detailBox">
  43. <mt-field label="项目编号" placeholder="请输入项目编号" v-model="assetsForm.projectNo"></mt-field>
  44. <mt-field label="项目名称" placeholder="请输入项目名称" v-model="assetsForm.projectName"></mt-field>
  45. <mt-field label="采购日期" placeholder="请选择采购日期" type="date" v-model="assetsForm.purchaseDate"></mt-field>
  46. </div>
  47. <div class="detailBox">
  48. <mt-field label="设备厂家" placeholder="请输入设备厂家" v-model="assetsForm.deviceFactory"></mt-field>
  49. <mt-field label="设备联系人" placeholder="请输入设备联系人" v-model="assetsForm.deviceContact"></mt-field>
  50. <mt-field label="联系人电话" placeholder="请输入设备联系人电话" v-model="assetsForm.deviceContactPhone"></mt-field>
  51. <mt-field label="供应商" placeholder="请输入供应商" v-model="assetsForm.factory"></mt-field>
  52. <mt-field label="采购价格" placeholder="请输入采购价格" type="number" v-model="assetsForm.price"></mt-field>
  53. <mt-field label="质保期限" placeholder="请输入质保期限(单位:年)" type="number" v-model="assetsForm.warrantyPeriod"></mt-field>
  54. <mt-field label="服务期限" placeholder="请输入服务期限(单位:天)" type="number" v-model="assetsForm.serviceLife"></mt-field>
  55. <mt-field label="下次维护日期" placeholder="请选择下次维护日期" type="date" v-model="assetsForm.nextIndate"></mt-field>
  56. </div>
  57. <div class="detailBox">
  58. <mt-field label="备注" placeholder="请输入备注" type="textarea" class="content" rows="5" v-model="assetsForm.content"></mt-field>
  59. </div>
  60. <div class="btn">
  61. <mt-button class="allBtn" size="large" type="primary" v-on:click.native="submit()">确定</mt-button>
  62. <mt-button class="allBtn" size="large" v-on:click.native="jumpBack()">取消</mt-button>
  63. </div>
  64. </div>
  65. </div>
  66. </template>
  67. <script>
  68. import { MessageBox } from 'mint-ui';
  69. export default {
  70. data() {
  71. return {
  72. id: this.$route.params.id,
  73. user: JSON.parse(sessionStorage.getItem("user")),
  74. assetsForm: {
  75. id: '',
  76. name: '',
  77. modelNumber: '',
  78. number: '',
  79. unit: '',
  80. address: '',
  81. factory: '',
  82. serviceLife: '',
  83. nextIndate: '',
  84. pic: '',
  85. tagId: 0,
  86. projectNo: '',
  87. projectName: '',
  88. purchaseDate: '',
  89. price: '',
  90. warrantyPeriod: '',
  91. content: '',
  92. goodsSequence: '',
  93. deviceFactory: '',
  94. deviceContact: '',
  95. deviceContactPhone: '',
  96. },
  97. labels: [],
  98. tagId: 0,
  99. limit: 1,
  100. canClick: true,
  101. unit: [],
  102. project: [],
  103. projectNo: [],
  104. projectName: [],
  105. }
  106. },
  107. methods: {
  108. // 详情
  109. getDetail() {
  110. this.$indicator.open();
  111. this.http.post(this.port.assets.detail, {
  112. 'id': this.id
  113. } ,
  114. res => {
  115. this.$indicator.close();
  116. if (res.code == "ok") {
  117. this.assetsForm = {
  118. id: this.id,
  119. name: res.data.name,
  120. modelNumber: res.data.modelNumber,
  121. number: res.data.goodsNosVO==null?0:res.data.goodsNosVO.length,
  122. unit: res.data.unit,
  123. address: res.data.address,
  124. factory: res.data.factory,
  125. serviceLife: res.data.serviceLife,
  126. nextIndate: res.data.nextIndate,
  127. pic: res.data.pic,
  128. tagId: res.data.tagId,
  129. projectNo: res.data.projectNo,
  130. projectName: res.data.projectName,
  131. purchaseDate: res.data.purchaseDate,
  132. price: res.data.price,
  133. warrantyPeriod: res.data.warrantyPeriod,
  134. content: res.data.content,
  135. goodsSequence: res.data.goodsSequence,
  136. deviceFactory: res.data.deviceFactory,
  137. deviceContact: res.data.deviceContact,
  138. deviceContactPhone: res.data.deviceContactPhone,
  139. }
  140. this.tagId = res.data.tagId
  141. this.getLabels();
  142. } else {
  143. this.$toast({
  144. message: res.msg,
  145. duration: 2000
  146. });
  147. }
  148. }, error => {
  149. this.$indicator.close();
  150. this.$toast({
  151. message: error,
  152. duration: 2000
  153. });
  154. })
  155. },
  156. // 标签列表
  157. getLabels() {
  158. this.http.post(this.port.label.list, {} ,
  159. res => {
  160. if (res.code == "ok") {
  161. this.labels = res.data;
  162. } else {
  163. this.$toast({
  164. message: res.msg,
  165. duration: 2000
  166. });
  167. }
  168. }, error => {
  169. this.$toast({
  170. message: error,
  171. duration: 2000
  172. });
  173. })
  174. },
  175. getUnit() {
  176. this.http.post(this.port.assets.unit, {} ,
  177. res => {
  178. if (res.code == "ok") {
  179. var list = res.data;
  180. for(var i in list) {
  181. list[i].name = list[i].unit;
  182. }
  183. this.unit = list;
  184. } else {
  185. this.$toast({
  186. message: res.msg,
  187. duration: 2000
  188. });
  189. }
  190. }, error => {
  191. this.$toast({
  192. message: error,
  193. duration: 2000
  194. });
  195. })
  196. },
  197. getProject() {
  198. this.http.post(this.port.assets.project, {} ,
  199. res => {
  200. if (res.code == "ok") {
  201. this.project = res.data;
  202. var list = res.data;
  203. for(var i in list) {
  204. this.projectNo.push({
  205. id: list[i].id,
  206. name: list[i].projectNo
  207. });
  208. this.projectName.push({
  209. id: list[i].id,
  210. name: list[i].projectName
  211. })
  212. }
  213. } else {
  214. this.$toast({
  215. message: res.msg,
  216. duration: 2000
  217. });
  218. }
  219. }, error => {
  220. this.$toast({
  221. message: error,
  222. duration: 2000
  223. });
  224. })
  225. },
  226. addNewTag() {
  227. MessageBox({
  228. $type:'prompt',
  229. title:'',
  230. message:'请输入资产类型名称',
  231. closeOnClickModal:false,
  232. showCancelButton:true,
  233. inputValidator:function(v){
  234. if (v === null) {
  235.    return true;
  236. }
  237. if (v != ""){
  238. return true
  239. } else {
  240. return false
  241. }
  242. },
  243. inputErrorMessage:'请输入资产类型名称',
  244. showInput:true
  245. }).then(({ value, action }) => {
  246. if(value == null) {
  247. this.$toast({
  248. message: '创建失败',
  249. duration: 2000
  250. });
  251. return false;
  252. } else {
  253. this.$indicator.open();
  254. this.http.post(this.port.label.add, {
  255. 'name': value,
  256. } ,
  257. res => {
  258. this.$indicator.close();
  259. if (res.code == "ok") {
  260. this.$toast({
  261. message: '创建成功',
  262. duration: 2000
  263. });
  264. this.getLabels();
  265. } else {
  266. this.$toast({
  267. message: res.msg,
  268. duration: 2000
  269. });
  270. }
  271. }, error => {
  272. this.$indicator.close();
  273. this.$toast({
  274. message: error,
  275. duration: 2000
  276. });
  277. })
  278. }
  279. }).catch(() => {
  280. });
  281. },
  282. chooseTag(id) {
  283. $("#btn"+id).addClass("active").siblings().removeClass("active");
  284. this.assetsForm.tagId = id;
  285. },
  286. chooseUnit() {
  287. var _this = this;
  288. var dataShippingSpace = this.unit;
  289. var pickerDiv = document.getElementById("unit");
  290. var pickerView = new PickerView({
  291. bindElem: pickerDiv,
  292. data: dataShippingSpace,
  293. title: "单位",
  294. leftText: "取消",
  295. rightText: "确定",
  296. rightFn: function(selectArr) {
  297. _this.assetsForm.unit = selectArr[0].name;
  298. }
  299. });
  300. },
  301. chooseProject(i) {
  302. var _this = this;
  303. var dataShippingSpace = i==0?this.projectNo:this.projectName;
  304. var pickerDiv = i==0?document.getElementById("projectNo"):document.getElementById("projectName");
  305. var pickerView = new PickerView({
  306. bindElem: pickerDiv,
  307. data: dataShippingSpace,
  308. title: i==0?"项目编号":"项目名称",
  309. leftText: "取消",
  310. rightText: "确定",
  311. rightFn: function(selectArr) {
  312. var list = _this.project;
  313. for(var j in list) {
  314. if(list[j].id == selectArr[0].id) {
  315. _this.assetsForm.projectNo = list[j].projectNo;
  316. _this.assetsForm.projectName = list[j].projectName;
  317. }
  318. }
  319. }
  320. });
  321. },
  322. delTag(id) {
  323. MessageBox.confirm('', { 
  324. message: '是否删除该分类?', 
  325. title: '', 
  326. confirmButtonText: '确定', 
  327. cancelButtonText: '取消' 
  328.  }).then(action => { 
  329. if (action == 'confirm') {     //确认的回调
  330. this.http.post(this.port.label.del, {
  331. 'id': id
  332. } ,
  333. res => {
  334. if (res.code == "ok") {
  335. this.$toast({
  336. message: "删除成功",
  337. duration: 2000
  338. });
  339. this.getLabels();
  340. } else {
  341. this.$toast({
  342. message: res.msg,
  343. duration: 2000
  344. });
  345. }
  346. }, error => {
  347. this.$toast({
  348. message: error,
  349. duration: 2000
  350. });
  351. })
  352. }
  353.  }).catch(err => { 
  354.  });
  355. },
  356. // 图片上传
  357. choosePic() {
  358. document.getElementById('upload_file').click();
  359. },
  360. fileChange(el) {
  361. if (!el.target.files[0].size) return;
  362. this.fileAdd(el.target.files[0]);
  363. el.target.value = ''
  364. },
  365. fileAdd(file) {
  366. //判断是否为图片文件
  367. if (file.type.indexOf('image') == -1) {
  368. this.$toast({
  369. message: '请选择图片文件',
  370. duration: 2000
  371. });
  372. } else {
  373. var form = new FormData();
  374. form.append("file", file);
  375. this.$indicator.open();
  376. this.http.uploadFile( this.port.assets.upload, form,
  377. res => {
  378. this.$indicator.close();
  379. if (res.code == "ok") {
  380. this.$toast({
  381. message: '上传成功',
  382. duration: 2000
  383. });
  384. this.assetsForm.pic = res.data;
  385. document.getElementById('upload_file').value = "";
  386. } else {
  387. this.$toast({
  388. message: res.msg,
  389. duration: 2000
  390. });
  391. }
  392. },
  393. error => {
  394. this.$indicator.close();
  395. this.$toast({
  396. message: error,
  397. duration: 2000
  398. });
  399. });
  400. }
  401. },
  402. // 创建
  403. submit() {
  404. if(this.canClick) {
  405. this.canClick = false;
  406. if(this.assetsForm.name == null || this.assetsForm.name == "") {
  407. this.$toast({
  408. message: '请输入物品名称',
  409. duration: 2000
  410. });
  411. this.canClick = true;
  412. return false;
  413. } else if(this.assetsForm.modelNumber == null || this.assetsForm.modelNumber == "") {
  414. this.$toast({
  415. message: '请输入物品型号',
  416. duration: 2000
  417. });
  418. this.canClick = true;
  419. return false;
  420. } else if(this.assetsForm.number == null || this.assetsForm.number == "") {
  421. this.$toast({
  422. message: '请输入物品数量',
  423. duration: 2000
  424. });
  425. this.canClick = true;
  426. return false;
  427. } else if(this.assetsForm.unit == null || this.assetsForm.unit == "") {
  428. this.$toast({
  429. message: '请输入物品单位',
  430. duration: 2000
  431. });
  432. this.canClick = true;
  433. return false;
  434. } else if(this.assetsForm.address == null || this.assetsForm.address == "") {
  435. this.$toast({
  436. message: '请输入地址',
  437. duration: 2000
  438. });
  439. this.canClick = true;
  440. return false;
  441. } else if(this.assetsForm.projectNo == null || this.assetsForm.projectNo == "") {
  442. this.$toast({
  443. message: '请输入项目编号',
  444. duration: 2000
  445. });
  446. this.canClick = true;
  447. return false;
  448. } else if(this.assetsForm.projectName == null || this.assetsForm.projectName == "") {
  449. this.$toast({
  450. message: '请输入项目名称',
  451. duration: 2000
  452. });
  453. this.canClick = true;
  454. return false;
  455. } else if(this.assetsForm.purchaseDate == null || this.assetsForm.purchaseDate == "") {
  456. this.$toast({
  457. message: '请选择采购日期',
  458. duration: 2000
  459. });
  460. this.canClick = true;
  461. return false;
  462. } else if(this.assetsForm.factory == null || this.assetsForm.factory == "") {
  463. this.$toast({
  464. message: '请输入供应商',
  465. duration: 2000
  466. });
  467. this.canClick = true;
  468. return false;
  469. } else if(this.assetsForm.price == null || this.assetsForm.price == "") {
  470. this.$toast({
  471. message: '请输入采购价格',
  472. duration: 2000
  473. });
  474. this.canClick = true;
  475. return false;
  476. } else if(this.assetsForm.warrantyPeriod == null || this.assetsForm.warrantyPeriod == "") {
  477. this.$toast({
  478. message: '请输入质保期限(单位:年)',
  479. duration: 2000
  480. });
  481. this.canClick = true;
  482. return false;
  483. } else if(this.assetsForm.serviceLife == null || this.assetsForm.serviceLife == "") {
  484. this.$toast({
  485. message: '请输入服务期限',
  486. duration: 2000
  487. });
  488. this.canClick = true;
  489. return false;
  490. } else if(this.assetsForm.content.length >= 100) {
  491. this.$toast({
  492. message: '备注内容请控制在100字以内',
  493. duration: 2000
  494. });
  495. this.canClick = true;
  496. return false;
  497. } else {
  498. this.$indicator.open();
  499. var _this = this;
  500. this.http.post( this.port.assets.update, this.assetsForm,
  501. res => {
  502. this.$indicator.close();
  503. if (res.code == "ok") {
  504. this.$toast({
  505. message: '更新成功',
  506. duration: 2000
  507. });
  508. setTimeout(function(){
  509. _this.$router.go(-1);
  510. }, 1000);
  511. } else {
  512. this.canClick = true;
  513. this.$toast({
  514. message: res.msg,
  515. duration: 2000
  516. });
  517. }
  518. },
  519. error => {
  520. this.canClick = true;
  521. this.$indicator.close();
  522. this.$toast({
  523. message: error,
  524. duration: 2000
  525. });
  526. });
  527. }
  528. } else {
  529. this.$toast({
  530. message: '请勿重复提交',
  531. duration: 2000
  532. });
  533. }
  534. },
  535. jumpBack() {
  536. this.$router.go(-1);
  537. }
  538. },
  539. created() {
  540. this.getDetail();
  541. },
  542. mounted() {
  543. }
  544. }
  545. </script>
  546. <style scoped>
  547. .detail_head {
  548. background: #fff;
  549. color: #333;
  550. height: 0.4rem;
  551. }
  552. .detail_body {
  553. margin-top: 0.4rem;
  554. padding-bottom: 0.15rem;
  555. height: auto;
  556. background: #efefef;
  557. }
  558. .detail {
  559. background: #EFEFEF;
  560. }
  561. .detailBox {
  562. background: #fff;
  563. margin-bottom: 0.11rem;
  564. }
  565. .left{
  566. float:left;
  567. /* margin: 0.15rem; */
  568. padding: 0.15rem 0 0.1rem 0;
  569. }
  570. .left_tag {
  571. margin: 0;
  572. padding: 0.15rem 0.15rem 0.1rem 0.15rem;
  573. }
  574. .upload .left {
  575. margin: 0.1rem 0.11rem;
  576. }
  577. .right div{
  578. line-height: 0.21rem;
  579. white-space: nowrap;
  580. overflow: hidden;
  581. text-overflow: ellipsis;
  582. }
  583. .btn {
  584. width: 80%;
  585. margin: 0.2rem auto 80px;
  586. }
  587. .allocation {
  588. width: 100%;
  589. height: 100%;
  590. }
  591. .address_first .current{
  592. background:#eee;
  593. color: #6f83ff;
  594. border-left: 2px solid #6f83ff;
  595. }
  596. .right > ul {
  597. margin: 0;
  598. padding: 0;
  599. overflow: auto;
  600. -webkit-transition-duration: 0.4s;
  601. box-sizing:border-box;
  602. padding: 0.08rem 0.1rem;
  603. }
  604. .right > ul > li {
  605. display: inline-block;
  606. height: 0.2rem;
  607. line-height: 0.22rem;
  608. font-size: 0.14rem;
  609. color: #ccc;
  610. padding: 0.02rem 0.12rem;
  611. margin: 0.06rem 0.07rem;
  612. border: 1px solid #ccc;
  613. border-radius: 50px;
  614. min-width: 0.3rem;
  615. text-align: center;
  616. position: relative;
  617. }
  618. .right > ul > li img {
  619. position: absolute;
  620. top: -0.05rem;
  621. right: -0.08rem;
  622. width: 0.18rem;
  623. height: 0.18rem;
  624. }
  625. .right > ul > li.add {
  626. border: 1px solid #777;
  627. color: #777;
  628. }
  629. .right > ul > li.active {
  630. border: 1px solid #2680EB;
  631. color: #2680EB;
  632. }
  633. .upload_add {
  634. display: inline-block;
  635. margin-bottom: 0.2rem;
  636. }
  637. .upload_add_image {
  638. padding-top: 0.08rem;
  639. margin: 0.15rem 0 0 0.3rem ;
  640. width: 1rem;
  641. height: 0.9rem;
  642. border: 1px dashed rgba(0, 0, 0, .2);
  643. }
  644. .upload_add-image .camera {
  645. font-size: 24px;
  646. }
  647. .upload_add_image p {
  648. padding: 0;
  649. margin: 0;
  650. color: #8e8e8e;
  651. }
  652. .right div img.pic {
  653. width: 0.8rem;
  654. height: 0.8rem;
  655. margin: 0.15rem 0 0 0.3rem ;
  656. }
  657. .textColor {
  658. margin-top: 0.4rem;
  659. color: #8e8e8e;
  660. padding: 0.12rem;
  661. font-size: 0.12rem;
  662. }
  663. .example {
  664. color: #8e8e8e;
  665. padding: 0.02rem 0.12rem;
  666. font-size: 0.12rem;
  667. }
  668. .allBtn {
  669. width: 80%;
  670. margin: 0.18rem auto;
  671. }
  672. </style>
  673. <style>
  674. .detail_head .mint-header-title {
  675. font-weight: 600;
  676. font-size: 0.15rem;
  677. }
  678. .detail_head .mint-button-text {
  679. color: #26a2ff;
  680. }
  681. .detailBox .mint-cell {
  682. padding: 0 0 0 0.02rem;
  683. }
  684. .mint-popup.allocation {
  685. background: #efefef;
  686. }
  687. .mint-msgbox {
  688. width: 70%;
  689. }
  690. .mint-cell-wrapper {
  691. background-image: none;
  692. }
  693. .content .mint-cell-wrapper {
  694. position: relative;
  695. }
  696. .content .mint-cell-title {
  697. position: absolute;
  698. top: 0;
  699. }
  700. .content .mint-cell-value {
  701. margin-left: 105px;
  702. }
  703. </style>