assetsEdit.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  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. <mt-field label="物品名称" placeholder="请输入物品名称" v-model="assetsForm.name"></mt-field>
  11. <mt-field label="型号" placeholder="请输入物品型号" v-model="assetsForm.modelNumber"></mt-field>
  12. <mt-field label="数量" placeholder="请输入数量" type="number" v-model="assetsForm.number"></mt-field>
  13. <mt-field label="单位" placeholder="请输入单位" v-model="assetsForm.unit"></mt-field>
  14. <div class="upload">
  15. <div class="left">物品图片</div>
  16. <div class="right upload_add" v-on:click="choosePic()">
  17. <div v-if="assetsForm.pic == null || assetsForm.pic == ''" class="upload_add_image" align="center">
  18. <img src="../../assets/image/camera.png" class="camera">
  19. <p class="font13">添加图片</p>
  20. </div>
  21. <div v-else class="right">
  22. <img class="pic" :src="assetsForm.pic">
  23. </div>
  24. </div>
  25. <input @change="fileChange($event)" type="file" accept="image/*" id="upload_file" style="display: none"/>
  26. </div>
  27. <mt-field label="地址" placeholder="请输入地址" v-model="assetsForm.address"></mt-field>
  28. </div>
  29. <div class="detailBox">
  30. <mt-field label="生产厂家" placeholder="请输入生产厂家" v-model="assetsForm.factory"></mt-field>
  31. <mt-field label="服务期限" placeholder="请输入服务期限" type="number" v-model="assetsForm.serviceLife"></mt-field>
  32. <mt-field label="下次维护日期" placeholder="请选择下次维护日期" type="date" v-model="assetsForm.nextIndate"></mt-field>
  33. </div>
  34. <div class="detailBox">
  35. <div class="left_tag">所属分类</div>
  36. <div class="right">
  37. <ul class="address_first">
  38. <li v-for="(item,index) in labels" :id="'btn'+item.id" v-bind:class="{'active':item.id==tagId}" v-on:click="chooseTag(item.id)">
  39. {{item.name}}
  40. <img v-if="index > 7" v-on:click="delTag(item.id)" src="../../assets/image/del.png">
  41. </li>
  42. <li v-on:click="addNewTag()" class="add">+</li>
  43. </ul>
  44. </div>
  45. </div>
  46. <div class="btn">
  47. <mt-button class="allBtn" size="large" type="primary" v-on:click.native="submit()">确定</mt-button>
  48. <mt-button class="allBtn" size="large" v-on:click.native="jumpBack()">取消</mt-button>
  49. </div>
  50. </div>
  51. </div>
  52. </template>
  53. <script>
  54. import { MessageBox } from 'mint-ui';
  55. export default {
  56. data() {
  57. return {
  58. id: this.$route.params.id,
  59. user: JSON.parse(sessionStorage.getItem("user")),
  60. assetsForm: {
  61. id: '',
  62. name: '',
  63. modelNumber: '',
  64. number: '',
  65. unit: '',
  66. address: '',
  67. factory: '',
  68. serviceLife: '',
  69. nextIndate: '',
  70. pic: '',
  71. tagId: 0,
  72. },
  73. labels: [],
  74. tagId: 0,
  75. limit: 1,
  76. canClick: true,
  77. }
  78. },
  79. methods: {
  80. // 详情
  81. getDetail() {
  82. this.$indicator.open();
  83. this.http.post(this.port.assets.detail, {
  84. 'id': this.id
  85. } ,
  86. res => {
  87. this.$indicator.close();
  88. if (res.code == "ok") {
  89. this.assetsForm = {
  90. id: this.id,
  91. name: res.data.name,
  92. modelNumber: res.data.modelNumber,
  93. number: res.data.goodsNosVO==null?0:res.data.goodsNosVO.length,
  94. unit: res.data.unit,
  95. address: res.data.address,
  96. factory: res.data.factory,
  97. serviceLife: res.data.serviceLife,
  98. nextIndate: res.data.nextIndate,
  99. pic: res.data.pic,
  100. tagId: res.data.tagId,
  101. }
  102. this.tagId = res.data.tagId
  103. this.getLabels();
  104. } else {
  105. this.$toast({
  106. message: res.msg,
  107. duration: 2000
  108. });
  109. }
  110. }, error => {
  111. this.$indicator.close();
  112. this.$toast({
  113. message: error,
  114. duration: 2000
  115. });
  116. })
  117. },
  118. // 标签列表
  119. getLabels() {
  120. this.http.post(this.port.label.list, {} ,
  121. res => {
  122. if (res.code == "ok") {
  123. this.labels = res.data;
  124. } else {
  125. this.$toast({
  126. message: res.msg,
  127. duration: 2000
  128. });
  129. }
  130. }, error => {
  131. this.$toast({
  132. message: error,
  133. duration: 2000
  134. });
  135. })
  136. },
  137. addNewTag() {
  138. MessageBox({
  139. $type:'prompt',
  140. title:'',
  141. message:'请输入资产类型名称',
  142. closeOnClickModal:false,
  143. showCancelButton:true,
  144. inputValidator:function(v){
  145. if (v === null) {
  146.    return true;
  147. }
  148. if (v != ""){
  149. return true
  150. } else {
  151. return false
  152. }
  153. },
  154. inputErrorMessage:'请输入资产类型名称',
  155. showInput:true
  156. }).then(({ value, action }) => {
  157. if(value == null) {
  158. this.$toast({
  159. message: '创建失败',
  160. duration: 2000
  161. });
  162. return false;
  163. } else {
  164. this.$indicator.open();
  165. this.http.post(this.port.label.add, {
  166. 'name': value,
  167. } ,
  168. res => {
  169. this.$indicator.close();
  170. if (res.code == "ok") {
  171. this.$toast({
  172. message: '创建成功',
  173. duration: 2000
  174. });
  175. this.getLabels();
  176. } else {
  177. this.$toast({
  178. message: res.msg,
  179. duration: 2000
  180. });
  181. }
  182. }, error => {
  183. this.$indicator.close();
  184. this.$toast({
  185. message: error,
  186. duration: 2000
  187. });
  188. })
  189. }
  190. }).catch(() => {
  191. });
  192. },
  193. chooseTag(id) {
  194. $("#btn"+id).addClass("active").siblings().removeClass("active");
  195. this.assetsForm.tagId = id;
  196. },
  197. delTag(id) {
  198. MessageBox.confirm('', { 
  199. message: '是否删除该分类?', 
  200. title: '', 
  201. confirmButtonText: '确定', 
  202. cancelButtonText: '取消' 
  203.  }).then(action => { 
  204. if (action == 'confirm') {     //确认的回调
  205. this.http.post(this.port.label.del, {
  206. 'id': id
  207. } ,
  208. res => {
  209. if (res.code == "ok") {
  210. this.$toast({
  211. message: "删除成功",
  212. duration: 2000
  213. });
  214. this.getLabels();
  215. } else {
  216. this.$toast({
  217. message: res.msg,
  218. duration: 2000
  219. });
  220. }
  221. }, error => {
  222. this.$toast({
  223. message: error,
  224. duration: 2000
  225. });
  226. })
  227. }
  228.  }).catch(err => { 
  229.  });
  230. },
  231. // 图片上传
  232. choosePic() {
  233. document.getElementById('upload_file').click();
  234. },
  235. fileChange(el) {
  236. if (!el.target.files[0].size) return;
  237. this.fileAdd(el.target.files[0]);
  238. el.target.value = ''
  239. },
  240. fileAdd(file) {
  241. //判断是否为图片文件
  242. if (file.type.indexOf('image') == -1) {
  243. this.$toast({
  244. message: '请选择图片文件',
  245. duration: 2000
  246. });
  247. } else {
  248. var form = new FormData();
  249. form.append("file", file);
  250. this.$indicator.open();
  251. this.http.uploadFile( this.port.assets.upload, form,
  252. res => {
  253. this.$indicator.close();
  254. if (res.code == "ok") {
  255. this.$toast({
  256. message: '上传成功',
  257. duration: 2000
  258. });
  259. this.assetsForm.pic = res.data;
  260. document.getElementById('upload_file').value = "";
  261. } else {
  262. this.$toast({
  263. message: res.msg,
  264. duration: 2000
  265. });
  266. }
  267. },
  268. error => {
  269. this.$indicator.close();
  270. this.$toast({
  271. message: error,
  272. duration: 2000
  273. });
  274. });
  275. }
  276. },
  277. // 创建
  278. submit() {
  279. if(this.canClick) {
  280. this.canClick = false;
  281. if(this.assetsForm.name == null || this.assetsForm.name == "") {
  282. this.$toast({
  283. message: '请输入物品名称',
  284. duration: 2000
  285. });
  286. this.canClick = true;
  287. return false;
  288. } else if(this.assetsForm.number == null || this.assetsForm.number == "") {
  289. this.$toast({
  290. message: '请输入物品数量',
  291. duration: 2000
  292. });
  293. this.canClick = true;
  294. return false;
  295. } else if(this.assetsForm.unit == null || this.assetsForm.unit == "") {
  296. this.$toast({
  297. message: '请输入物品单位',
  298. duration: 2000
  299. });
  300. this.canClick = true;
  301. return false;
  302. } else {
  303. this.$indicator.open();
  304. var _this = this;
  305. this.http.post( this.port.assets.update, this.assetsForm,
  306. res => {
  307. this.$indicator.close();
  308. if (res.code == "ok") {
  309. this.$toast({
  310. message: '更新成功',
  311. duration: 2000
  312. });
  313. setTimeout(function(){
  314. _this.$router.go(-1);
  315. }, 1000);
  316. } else {
  317. this.canClick = true;
  318. this.$toast({
  319. message: res.msg,
  320. duration: 2000
  321. });
  322. }
  323. },
  324. error => {
  325. this.canClick = true;
  326. this.$indicator.close();
  327. this.$toast({
  328. message: error,
  329. duration: 2000
  330. });
  331. });
  332. }
  333. } else {
  334. this.$toast({
  335. message: '请勿重复提交',
  336. duration: 2000
  337. });
  338. }
  339. },
  340. jumpBack() {
  341. this.$router.go(-1);
  342. }
  343. },
  344. created() {
  345. this.getDetail();
  346. },
  347. mounted() {
  348. }
  349. }
  350. </script>
  351. <style scoped>
  352. .detail_head {
  353. background: #fff;
  354. color: #333;
  355. height: 0.4rem;
  356. }
  357. .detail_body {
  358. margin-top: 0.4rem;
  359. padding-bottom: 0.15rem;
  360. }
  361. .detail {
  362. background: #EFEFEF;
  363. }
  364. .detailBox {
  365. background: #fff;
  366. margin-bottom: 0.11rem;
  367. }
  368. .left{
  369. float:left;
  370. /* margin: 0.15rem; */
  371. padding: 0.15rem 0 0.1rem 0;
  372. }
  373. .left_tag {
  374. margin: 0;
  375. padding: 0.15rem 0.15rem 0.1rem 0.15rem;
  376. }
  377. .upload .left {
  378. margin: 0.1rem 0.11rem;
  379. }
  380. .right div{
  381. line-height: 0.21rem;
  382. white-space: nowrap;
  383. overflow: hidden;
  384. text-overflow: ellipsis;
  385. }
  386. .btn {
  387. width: 80%;
  388. margin: 0.2rem auto 80px;
  389. }
  390. .allocation {
  391. width: 100%;
  392. height: 100%;
  393. }
  394. .address_first .current{
  395. background:#eee;
  396. color: #6f83ff;
  397. border-left: 2px solid #6f83ff;
  398. }
  399. .right > ul {
  400. margin: 0;
  401. padding: 0;
  402. overflow: auto;
  403. -webkit-transition-duration: 0.4s;
  404. box-sizing:border-box;
  405. padding: 0.08rem 0.1rem;
  406. }
  407. .right > ul > li {
  408. display: inline-block;
  409. height: 0.2rem;
  410. line-height: 0.22rem;
  411. font-size: 0.14rem;
  412. color: #ccc;
  413. padding: 0.02rem 0.12rem;
  414. margin: 0.06rem 0.07rem;
  415. border: 1px solid #ccc;
  416. border-radius: 50px;
  417. min-width: 0.3rem;
  418. text-align: center;
  419. position: relative;
  420. }
  421. .right > ul > li img {
  422. position: absolute;
  423. top: -0.05rem;
  424. right: -0.08rem;
  425. width: 0.18rem;
  426. height: 0.18rem;
  427. }
  428. .right > ul > li.add {
  429. border: 1px solid #777;
  430. color: #777;
  431. }
  432. .right > ul > li.active {
  433. border: 1px solid #2680EB;
  434. color: #2680EB;
  435. }
  436. .upload_add {
  437. display: inline-block;
  438. margin-bottom: 0.2rem;
  439. }
  440. .upload_add_image {
  441. padding-top: 0.08rem;
  442. margin: 0.15rem 0 0 0.3rem ;
  443. width: 1rem;
  444. height: 0.9rem;
  445. border: 1px dashed rgba(0, 0, 0, .2);
  446. }
  447. .upload_add-image .camera {
  448. font-size: 24px;
  449. }
  450. .upload_add_image p {
  451. padding: 0;
  452. margin: 0;
  453. color: #8e8e8e;
  454. }
  455. .right div img.pic {
  456. width: 0.8rem;
  457. height: 0.8rem;
  458. margin: 0.15rem 0 0 0.3rem ;
  459. }
  460. .textColor {
  461. margin-top: 0.4rem;
  462. color: #8e8e8e;
  463. padding: 0.12rem;
  464. font-size: 0.12rem;
  465. }
  466. .example {
  467. color: #8e8e8e;
  468. padding: 0.02rem 0.12rem;
  469. font-size: 0.12rem;
  470. }
  471. .allBtn {
  472. width: 80%;
  473. margin: 0.18rem auto;
  474. }
  475. </style>
  476. <style>
  477. .detail_head .mint-header-title {
  478. font-weight: 600;
  479. font-size: 0.15rem;
  480. }
  481. .detail_head .mint-button-text {
  482. color: #26a2ff;
  483. }
  484. .detailBox .mint-cell {
  485. padding: 0 0 0 0.02rem;
  486. }
  487. .mint-popup.allocation {
  488. background: #efefef;
  489. }
  490. .mint-msgbox {
  491. width: 70%;
  492. }
  493. .mint-cell-wrapper {
  494. background-image: none;
  495. }
  496. </style>