assetsRegister.vue 18 KB

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