storageList.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. var _this;
  2. var nowTime = new Date().getTime();
  3. var periodChart, typeChart;
  4. new Vue({
  5. el: '#app',
  6. filters: {
  7. getImgList(key){
  8. return [fileUrl+key];
  9. }
  10. },
  11. data: function() {
  12. return {
  13. queryParams: {
  14. pageNum: 1,
  15. pageSize: 10,
  16. createBy: "lyzh"
  17. },
  18. imgUrl: '',
  19. storageList: [],
  20. allTotal: 0,
  21. stockTypeList: [],
  22. title: "",
  23. drawerDolag: false,
  24. storageForm: {},
  25. rules: {
  26. sparePartNumber: [{
  27. required: true, message: "备件编号不能为空", trigger: "blur"
  28. }],
  29. sparePartName: [{
  30. required: true, message: "备件名称不能为空", trigger: "blur"
  31. }],
  32. sparePartSpecifications: [{
  33. required: true, message: "备件规格不能为空", trigger: "blur"
  34. }],
  35. sparePartBrand: [{
  36. required: true, message: "备件品牌不能为空", trigger: "blur"
  37. }],
  38. sparePartUnitPrice: [{
  39. required: true, message: "备件单价期不能为空", trigger: "blur"
  40. }],
  41. sparePartQuantity: [{
  42. required: true, message: "库存总量不能为空", trigger: "blur"
  43. }],
  44. sparePartStockType: [{
  45. required: true, message: "备件类型不能为空", trigger: "blur"
  46. }],
  47. sparePartAccessExplain: [{
  48. required: true, message: "出入库说明不能为空", trigger: "blur"
  49. }]
  50. },
  51. upHeaders: {},
  52. srorageQuantityOut: {},
  53. storageOutTotal: 0,
  54. srorageQuantityIn: {},
  55. storageInTotal: 0,
  56. drawerOutIn: false,
  57. sparePartAccessType: '10',
  58. submitForm: {}
  59. }
  60. },
  61. created() {
  62. _this = this;
  63. _this.imgUrl = fileUrl;
  64. _this.upHeaders = {
  65. "Authorization": "Bearer " + getCookie("tzToken")
  66. }
  67. let _obj = getUseDict("com_spare_part_stock_type")
  68. setTimeout(()=>{
  69. _this.stockTypeList = _obj["com_spare_part_stock_type"];
  70. this.getList();
  71. }, 500);
  72. },
  73. mounted:function(){
  74. },
  75. methods: {
  76. getList(){
  77. // setFileLogin()
  78. getStorageList(_this.queryParams).then((_res) => {
  79. _this.storageList = _res.rows;
  80. _this.allTotal = _res.total;
  81. });
  82. },
  83. handleQuery() {
  84. _this.queryParams.pageNum = 1;
  85. this.getList();
  86. },
  87. resetQuery() {
  88. _this.queryParams = {
  89. pageNum: 1,
  90. pageSize: 10
  91. }
  92. this.handleQuery();
  93. },
  94. handleCurrentChange(val) {
  95. if(val != _this.queryParams.pageNum){
  96. _this.queryParams.pageNum = val;
  97. this.getList();
  98. }
  99. },
  100. handleUpdate(row) {
  101. this.reset();
  102. var sparePartId = row.sparePartId;
  103. getStorageDetail(sparePartId).then(response => {
  104. _this.storageForm = response.data;
  105. _this.drawerDolag = true;
  106. _this.title = "修改备件";
  107. });
  108. },
  109. handleAdd(){
  110. this.reset();
  111. _this.drawerDolag = true;
  112. _this.title = "添加备件";
  113. },
  114. reset() {
  115. _this.storageForm = {
  116. sparePartId: null,
  117. sparePartNumber: "",
  118. sparePartName: "",
  119. sparePartSpecifications: "",
  120. sparePartBrand: "",
  121. sparePartStorageLocation: "",
  122. sparePartStockType: "",
  123. sparePartGoodsType: "",
  124. sparePartQuantity: "",
  125. createBy: "",
  126. createTime: "",
  127. updateBy: "",
  128. updateTime: "",
  129. remark: "",
  130. sparePartUnitPrice: "",
  131. impa: "",
  132. filePath: "",
  133. };
  134. },
  135. handleDelete(row) {
  136. this.$confirm('是否确认删除改条备件记录为"' + row.sparePartId + '"的数据项?').then(function () {
  137. return DelStorage(row.sparePartId)
  138. }).then(() => {
  139. this.getList();
  140. this.$message({
  141. showClose: true,
  142. message: "删除成功",
  143. type: 'success'
  144. });
  145. }).catch(() => { });
  146. },
  147. handleSubmitForm(){
  148. if(_this.storageForm.sparePartName.length&&_this.storageForm.sparePartNumber.length&&_this.storageForm.sparePartName.length&&_this.storageForm.sparePartSpecifications.length&&_this.storageForm.sparePartStockType.length){
  149. if (_this.storageForm.sparePartId != null) {
  150. updateStorage(_this.storageForm).then(response => {
  151. this.$message({
  152. showClose: true,
  153. message: "修改成功",
  154. type: 'success'
  155. });
  156. _this.drawerDolag = false;
  157. this.getList();
  158. });
  159. } else {
  160. addStorage(_this.storageForm).then(response => {
  161. this.$message({
  162. showClose: true,
  163. message: "新增成功",
  164. type: 'success'
  165. });
  166. _this.drawerDolag = false;
  167. this.getList();
  168. });
  169. }
  170. }else{
  171. this.$message.error('请先填写完信息!');
  172. }
  173. },
  174. handleAvatarSuccess(res, file) {
  175. _this.storageForm.filePath = res.fileName;
  176. },
  177. beforeAvatarUpload(file) {
  178. const fileType = ["png", "jpg", "jpeg"];
  179. const isLt2M = file.size / 1024 / 1024 < 5;
  180. let fileExtension = "";
  181. if (file.name.lastIndexOf(".") > -1) {
  182. fileExtension = file.name.slice(file.name.lastIndexOf(".") + 1);
  183. }
  184. isImg = fileType.some(type => {
  185. if (file.type.indexOf(type) > -1) return true;
  186. if (fileExtension && fileExtension.indexOf(type) > -1) return true;
  187. return false;
  188. });
  189. if (!isImg) {
  190. this.$message.error('上传头像图片只能是 "png", "jpg", "jpeg" 格式!');
  191. }
  192. if (!isLt2M) {
  193. this.$message.error('上传头像图片大小不能超过 5MB!');
  194. }
  195. return isImg && isLt2M;
  196. },
  197. handleStorageOrder(key){
  198. _this.drawerOutIn = true;
  199. _this.sparePartAccessType = key;
  200. _this.submitForm = {
  201. sparePartAccessExplain: "",
  202. sparePartAccessType: "",
  203. sparePartAccessDetailsList: []
  204. };
  205. },
  206. handleStorageOut(row){
  207. _this.storageOutTotal = this.addStorageTotal(_this.srorageQuantityOut, row);
  208. },
  209. handleStorageIn(row){
  210. _this.storageInTotal = this.addStorageTotal(_this.srorageQuantityIn, row);
  211. },
  212. updateStorageOut(row){
  213. _this.storageOutTotal = this.updateStorageTotal(_this.srorageQuantityOut, row);
  214. },
  215. updateStorageIn(row){
  216. _this.storageInTotal = this.updateStorageTotal(_this.srorageQuantityIn, row);
  217. },
  218. removeQuantityIn(row){
  219. _this.storageInTotal = this.removeStorageTotal(_this.srorageQuantityIn, row);
  220. },
  221. removeQuantityOut(row){
  222. _this.storageOutTotal = this.removeStorageTotal(_this.srorageQuantityOut, row);
  223. },
  224. clrearQuantityIn(msg){
  225. _this.srorageQuantityIn = {};
  226. _this.storageInTotal = 0;
  227. if(msg){
  228. this.$message.success('已清空')
  229. }
  230. },
  231. clrearQuantityOut(msg){
  232. _this.srorageQuantityOut = {};
  233. _this.storageOutTotal = 0;
  234. if(msg){
  235. this.$message.success('已清空')
  236. }
  237. },
  238. submitOrder(){
  239. if(_this.submitForm.sparePartAccessExplain.length){
  240. _this.submitForm.sparePartAccessDetailsList = Object.values(_this.sparePartAccessType == 10 ? _this.srorageQuantityIn : _this.srorageQuantityOut);
  241. _this.submitForm.sparePartAccessType = _this.sparePartAccessType;
  242. setInOutOrder(_this.submitForm).then((_res) =>{
  243. if(_res.code == 200){
  244. this.$message.success('提交成功!');
  245. this.getList();
  246. _this.submitForm = {};
  247. _this.drawerOutIn = false;
  248. _this.sparePartAccessType == 10 ? _this.clrearQuantityIn(false) : _this.clrearQuantityOut(false)
  249. }else{
  250. this.$message.success(_res.msg)
  251. }
  252. })
  253. }else{
  254. this.$message.error('请先填写完信息!');
  255. }
  256. },
  257. removeStorageTotal(_list, item){
  258. delete _list[item.sparePartId]
  259. let total = 0;
  260. Object.values(_list).map((item) => {
  261. total += item.sparePartRetrievalQuantity;
  262. });
  263. this.$message.success('已删除')
  264. return total;
  265. },
  266. updateStorageTotal(_list, item){
  267. if (_list[item.sparePartId] == undefined) {
  268. item.sparePartRetrievalQuantity = 1
  269. _list[item.sparePartId] = item;
  270. } else {
  271. _list[item.sparePartId].sparePartRetrievalQuantity = parseInt(item.sparePartRetrievalQuantity)
  272. }
  273. let total = 0;
  274. Object.values(_list).map((item) => {
  275. total += item.sparePartRetrievalQuantity;
  276. });
  277. this.$message.success('修改成功')
  278. return total;
  279. },
  280. addStorageTotal(_list, item){
  281. if (_list[item.sparePartId] == undefined) {
  282. item.sparePartRetrievalQuantity = 1
  283. _list[item.sparePartId] = item
  284. } else {
  285. _list[item.sparePartId].sparePartRetrievalQuantity++
  286. }
  287. let total = 0;
  288. Object.values(_list).map((item) => {
  289. total += item.sparePartRetrievalQuantity;
  290. });
  291. this.$message.success('添加成功')
  292. return total;
  293. }
  294. }
  295. })