material.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. <template>
  2. <div class="bgcolor">
  3. <div class="navBarTOP">
  4. <!-- 顶部条-->
  5. <van-nav-bar class="navBar" :title="title" left-arrow @click-left="onClickLeft">
  6. <template #right>
  7. <span style="color: #0057ba" @click="editorFn">保存</span>
  8. </template>
  9. </van-nav-bar>
  10. </div>
  11. <div class="lineGrey"></div>
  12. <div class="lineGrey"></div>
  13. <div class="lineGrey"></div>
  14. <div class="lineGrey"></div>
  15. <div class="lineGrey"></div>
  16. <!-- 主体内容-->
  17. <div class="container" style="width: 100%; margin: 0 auto">
  18. <el-table
  19. :data="list"
  20. border
  21. class="table-headermd table-headermdw"
  22. style="width: 100%"
  23. :span-method="objectSpanMethod">
  24. <el-table-column label="物料类型" prop="materialTypeName" align="center">
  25. <template slot-scope="scope">
  26. <span class="tipTitle" @click="tipTitle(scope.row.materialTypeName)">
  27. {{ scope.row.materialTypeName }}
  28. </span>
  29. </template>
  30. </el-table-column>
  31. <el-table-column label="物料名称" prop="materialDataName" align="center">
  32. <template slot-scope="scope">
  33. <span class="tipTitle" @click="tipTitle(scope.row.materialDataName)">
  34. {{ scope.row.materialDataName }}
  35. </span>
  36. </template>
  37. </el-table-column>
  38. <el-table-column prop="warehouseName" label="仓库名称" align="center" />
  39. <el-table-column prop="inventoryNum" label="总库存" align="center" />
  40. <el-table-column prop="myInventoryNum" label="我的库存" align="center" width="50px" />
  41. <el-table-column class="t-center" prop="inventoryNumArray" align="center" width="80px">
  42. <template slot="header">
  43. <span>{{ titles }}</span>
  44. <span class="xing">*</span>
  45. </template>
  46. <template slot-scope="scope">
  47. <van-field
  48. v-model="scope.row.inventoryNumArray"
  49. placeholder="请输入"
  50. type="number"
  51. @input="inputblurs(scope.row.inventoryNumArray, scope.$index, '1')" />
  52. </template>
  53. </el-table-column>
  54. </el-table>
  55. </div>
  56. </div>
  57. </template>
  58. <script>
  59. import { addMaterialInventory, getReceiveList } from '@/api/inventory';
  60. export default {
  61. data() {
  62. return {
  63. disabled: false,
  64. list: [],
  65. loading: false,
  66. finished: false,
  67. pageSize: 12,
  68. pageNum: 1,
  69. tabVal: '1',
  70. validFlag: '',
  71. titles: '领取量',
  72. title: '物料信息',
  73. fromValue: {
  74. pageSize: 12,
  75. pageNum: 1,
  76. },
  77. };
  78. },
  79. activated() {
  80. this.getReceiveList();
  81. },
  82. // watch: {
  83. // $route(to, from) {
  84. // if (to.path == '/material') {
  85. // this.getReceiveList();
  86. // }
  87. // },
  88. // },
  89. methods: {
  90. inputblurs(val, index, num) {
  91. if (this.$route.query.tabVal == 'B') {
  92. if ((val + '').trim() == '') {
  93. this.list[index].inventoryNumArray = '';
  94. } else {
  95. if (Number(val) > 10000 || Number(val) <= 0) {
  96. this.$toast('请输入大于0并且小于10000的整数');
  97. this.list[index].inventoryNumArray = '';
  98. } else if (this.list[index].inventoryNumArray == '') {
  99. this.list[index].inventoryNumArray = '';
  100. this.$toast('请输入使用量');
  101. } else if (Number(val) > Number(this.list[index].myInventoryNum)) {
  102. this.$toast('请输入小于等于我的存量');
  103. this.list[index].inventoryNumArray = '';
  104. } else {
  105. this.list[index].inventoryNumArray = val.replace(/[^\d.]/g, ''); //清除"数字"和"."以外的字符
  106. this.list[index].inventoryNumArray = val.replace(/^\./g, ''); //验证第一个字符是数字
  107. this.list[index].inventoryNumArray = val
  108. .replace('.', '$#$')
  109. .replace(/\./g, '')
  110. .replace('$#$', '');
  111. }
  112. }
  113. } else {
  114. if ((val + '').trim() == '') {
  115. this.list[index].inventoryNumArray = '';
  116. } else {
  117. if (Number(val) > 10000 || Number(val) <= 0) {
  118. this.$toast('请输入大于0并且小于10000的整数');
  119. this.list[index].inventoryNumArray = '';
  120. } else if (this.list[index].inventoryNumArray == '') {
  121. this.list[index].inventoryNumArray = '';
  122. this.$toast('请输入使用量');
  123. } else if (Number(val) > Number(this.list[index].inventoryNum)) {
  124. this.$toast('请输入小于等于销售部库存量');
  125. this.list[index].inventoryNumArray = '';
  126. } else {
  127. this.list[index].inventoryNumArray = val.replace(/[^\d.]/g, ''); //清除"数字"和"."以外的字符
  128. this.list[index].inventoryNumArray = val.replace(/^\./g, ''); //验证第一个字符是数字
  129. this.list[index].inventoryNumArray = val
  130. .replace('.', '$#$')
  131. .replace(/\./g, '')
  132. .replace('$#$', '');
  133. }
  134. }
  135. }
  136. },
  137. editorFn() {
  138. let loading1 = this.$toast.loading({
  139. duration: 0,
  140. message: '加载中...',
  141. forbidClick: true,
  142. });
  143. var inventoryIdArray = [];
  144. var inventoryNumArray = [];
  145. for (var i = 0; i < this.list.length; i++) {
  146. if (this.list[i].inventoryNumArray != '' && this.list[i].inventoryNumArray != null) {
  147. inventoryIdArray.push(this.list[i].inventoryId);
  148. inventoryNumArray.push(this.list[i].inventoryNumArray);
  149. }
  150. }
  151. var changeType = 2;
  152. if (this.$route.query.tabVal == 'B') {
  153. changeType = 5;
  154. }
  155. var formData = {
  156. inventoryIdArray: inventoryIdArray,
  157. changeType: changeType,
  158. inventoryNumArray: inventoryNumArray,
  159. userId: localStorage.getItem('userId'),
  160. };
  161. addMaterialInventory(formData).then((res) => {
  162. loading1.clear();
  163. if (res.code == 200) {
  164. this.$dialog
  165. .alert({
  166. title: '系统提示',
  167. message: '保存成功,返回我的库存',
  168. })
  169. .then((res) => {
  170. this.$router.go(-1);
  171. });
  172. } else {
  173. this.$toast(res.msg);
  174. }
  175. });
  176. },
  177. objectSpanMethod({ row, column, rowIndex, columnIndex }) {
  178. const cellValue = row[column.property];
  179. if (cellValue && ['materialTypeName'].includes(column.property)) {
  180. const prevRow = this.list[rowIndex - 1];
  181. let nextRow = this.list[rowIndex + 1];
  182. if (prevRow && prevRow[column.property] === cellValue) {
  183. return { rowspan: 0, colspan: 0 };
  184. } else {
  185. let countRowspan = 1;
  186. while (nextRow && nextRow[column.property] === cellValue) {
  187. nextRow = this.list[++countRowspan + rowIndex];
  188. }
  189. if (countRowspan > 1) {
  190. return { rowspan: countRowspan, colspan: 1 };
  191. }
  192. }
  193. }
  194. },
  195. getReceiveList() {
  196. this.title = '领取物料';
  197. this.titles = '领取量';
  198. if (this.$route.query.tabVal == 'B') {
  199. this.title = '退回物料';
  200. this.titles = '退回量';
  201. }
  202. if (this.refreshing) {
  203. this.list = [];
  204. this.refreshing = false;
  205. }
  206. let loading1 = this.$toast.loading({
  207. duration: 0,
  208. message: '加载中...',
  209. forbidClick: true,
  210. });
  211. var fromValue = this.fromValue;
  212. fromValue.pageNum = this.pageNum;
  213. fromValue.pageSize = this.pageSize;
  214. fromValue.inventoryLyUserId = localStorage.getItem('userId');
  215. fromValue.type = this.$route.query.tabVal == 'A' ? 'ly' : 'th';
  216. getReceiveList(fromValue).then((res) => {
  217. loading1.clear();
  218. this.disabled = false;
  219. if (res.code == 200) {
  220. this.loading = false;
  221. this.list = res.rows;
  222. } else {
  223. this.$toast.fail(res.msg);
  224. }
  225. });
  226. },
  227. storeDetailFn(id) {
  228. this.$router.push({
  229. path: '/storeDetail',
  230. query: { id: id },
  231. });
  232. },
  233. onClickRight() {
  234. this.$router.push('/storeAdd');
  235. },
  236. onClickLeft() {
  237. this.$router.go(-1);
  238. },
  239. onSearch() {
  240. window.scrollTo(0, 0);
  241. this.pageNum = 1;
  242. this.list = [];
  243. this.finished = true;
  244. this.onLoad();
  245. },
  246. },
  247. };
  248. </script>
  249. <style lang="scss" scoped>
  250. .bgcolor {
  251. background-color: #f5f5f5;
  252. }
  253. .container {
  254. padding-bottom: 50px;
  255. }
  256. </style>
  257. <style>
  258. .table-headermd {
  259. font-size: 12px;
  260. text-align: center;
  261. position: initial;
  262. width: 98% !important;
  263. margin: 0 auto;
  264. border-right: 0;
  265. }
  266. .table-headermd .el-table__header,
  267. .table-headermd .el-table__body {
  268. width: 100% !important;
  269. }
  270. .table-headermd col:nth-child(4) {
  271. width: 5.6rem;
  272. }
  273. .table-headermd col:nth-child(3) {
  274. width: 4.6rem;
  275. }
  276. .table-headermd .van-cell {
  277. padding: 0 4px;
  278. height: 100%;
  279. }
  280. .table-headermd th.el-table__cell > .cell {
  281. padding: 0 4px;
  282. text-align: center;
  283. }
  284. .table-headermd th.el-table__cell:first-child > .cell {
  285. text-align: left;
  286. }
  287. .table-headermd th.el-table__cell {
  288. background-color: #1989fa;
  289. color: #fff;
  290. }
  291. .table-headermd .el-table__cell {
  292. padding: 4px 0;
  293. }
  294. .table-headermd.el-table .cell {
  295. padding: 0;
  296. }
  297. .table-headermd .tipTitle {
  298. overflow: hidden;
  299. text-overflow: ellipsis;
  300. display: -webkit-box;
  301. -webkit-box-orient: vertical;
  302. -webkit-line-clamp: 2;
  303. }
  304. .table-headermd::before {
  305. height: 0;
  306. }
  307. .xing {
  308. color: red;
  309. padding-left: 4px;
  310. }
  311. .formLabel .van-radio__label,
  312. .formLabel .van-checkbox__label {
  313. font-size: 1.4rem;
  314. }
  315. .table-headermd .cell,
  316. .el-table--border .el-table__cell:first-child .cell {
  317. padding: 0 4px;
  318. }
  319. .van-dialog__confirm,
  320. .van-dialog__confirm:active {
  321. color: #1989fa;
  322. }
  323. .navBarTOP {
  324. position: fixed;
  325. width: 100%;
  326. z-index: 2;
  327. top: 0;
  328. }
  329. .isTableMust {
  330. padding: 4px;
  331. color: #999;
  332. margin: 0;
  333. margin-top: -10px;
  334. }
  335. .mobile-input .van-field__control {
  336. font-size: 12px;
  337. color: #999;
  338. border: 0;
  339. }
  340. .formLabel .mobile-input {
  341. border: 0 !important;
  342. }
  343. </style>