You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

519 lines
20 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. //公共参数
  2. let tableTags = "part_plan_data";//表格的id
  3. let currentRow;//临时的参数行
  4. //初始化
  5. $(function () {
  6. storTableInit();
  7. addPartPlanInfoTable();
  8. selectPartPlan();
  9. });
  10. //初始化表格
  11. function storTableInit() {
  12. $('#' + tableTags).bootstrapTable({
  13. url: '/part/searchPartPlanInfoList', //请求后台的URL(*)
  14. method: 'post', //请求方式(*)
  15. //contentType:'application/x-www-form-urlencoded',
  16. contentType: 'application/json;charset=utf-8',
  17. toolbar: '#toolbar', //工具按钮用哪个容器
  18. striped: true, //是否显示行间隔色
  19. cache: false, //是否使用缓存,默认为true,所以一般情况下需要设置一下这个属性(*)
  20. pagination: false, //是否显示分页(*)
  21. sortable: false, //是否启用排序
  22. sortOrder: "asc", //排序方式
  23. queryParamsType: "undefined", //排序方式
  24. queryParams: function queryParams(params) { //设置查询参数
  25. var param = {
  26. site: $('#current_site').val(),
  27. active: $('#status').val(),
  28. partdescription: $('#partdescription').val(),
  29. warehousename: $('#warehousename').val(),
  30. operating: 0,
  31. wareHouseTypeDb: 'T',
  32. othergroup2: ''
  33. };
  34. return JSON.stringify(param);
  35. },
  36. sidePagination: "server", //分页方式:client客户端分页,server服务端分页(*)
  37. pageNumber: 1, //初始化加载第一页,默认第一页
  38. pageSize: 10, //每页的记录行数(*)
  39. pageList: [10, 25, 50, 100], //可供选择的每页的行数(*)
  40. search: false, //是否显示表格搜索,此搜索是客户端搜索,不会进服务端,所以,个人感觉意义不大
  41. searchTimeOut: 1000,
  42. // : true,
  43. showColumns: false, //是否显示所有的列
  44. showRefresh: false, //是否显示刷新按钮
  45. minimumCountColumns: 2, //最少允许的列数
  46. clickToSelect: false, //是否启用点击选中行
  47. singleSelect: false,
  48. height: 400, //行高,如果没有设置height属性,表格自动根据记录条数觉得表格高度
  49. uniqueId: "id", //每一行的唯一标识,一般为主键列
  50. // showToggle: true, //是否显示详细视图和列表视图的切换按钮
  51. cardView: false, //是否显示详细视图
  52. detailView: false, //是否显示父子表
  53. columns: [/*{
  54. checkbox: true
  55. },*/{
  56. field: 'wareHouseId',
  57. title: '店铺编号',
  58. width: 200
  59. }, {
  60. field: 'warehousename',
  61. title: '店铺名称',
  62. width: 200
  63. }, {
  64. field: 'partNo',
  65. title: '物料编号',
  66. width: 200
  67. }, {
  68. field: 'partdescription',
  69. title: '物料名称',
  70. width: 200
  71. }, {
  72. field: 'averageConsumeQty',
  73. title: '日消耗数量',
  74. align: 'right',
  75. }, {
  76. field: 'coverDays',
  77. title: '维持天数',
  78. align: 'right',
  79. }, {
  80. field: 'othergroup2',
  81. title: '运营',
  82. align: 'right',
  83. }],
  84. onClickRow: function (row, $element) {
  85. $('.check_back').removeClass('check_back');
  86. $($element).addClass('check_back');
  87. currentRow = row;
  88. //调用自定义按钮的控制类
  89. customerBtnControl(tableTags, row, null);
  90. },
  91. onLoadSuccess: function (data) {
  92. var height_param = $(window).height() - 92;
  93. $('#' + tableTags).parents('.fixed-table-container').css("height", height_param + "px");
  94. //调用自定义按钮的控制类
  95. customerBtnControl(tableTags, null, null)
  96. },
  97. //>>>>>>>>>>>>>>导出excel表格设置
  98. showExport: false, //是否显示导出按钮(此方法是自己写的目的是判断终端是电脑还是手机,电脑则返回true,手机返回falsee,手机不显示按钮)
  99. exportDataType: "basic", //basic', 'all', 'selected'.
  100. exportTypes: ['excel', 'xlsx'], //导出类型
  101. exportButton: $('#download_button'), //为按钮btn_export 绑定导出事件 自定义导出按钮(可以不用)
  102. exportOptions: {
  103. ignoreColumn: [8, 8], //忽略某一列的索引
  104. fileName: '库存信息' + generateTimeReqestNumber(), //文件名称设置
  105. worksheetName: '库存信息', //表格工作区名称
  106. tableName: '库存信息',
  107. excelstyles: ['background-color', 'color', 'font-size', 'font-weight'],
  108. onMsoNumberFormat: DoOnMsoNumberFormat
  109. }
  110. //导出excel表格设置<<<<<<<<<<<<<<<<
  111. });
  112. }
  113. //处理搜索,刷新table
  114. function searchPartPlanInfo() {
  115. $('#part_plan_data').bootstrapTable('refresh');
  116. }
  117. // 编辑 物料库存水平
  118. function editPartPlanDataModal() {
  119. $('#skuName').val(currentRow.partdescription)
  120. $('#editWareHouseName').val(currentRow.warehousename)
  121. $('#averageConsumeQty').val(currentRow.averageConsumeQty)
  122. $('#coverDays').val(currentRow.coverDays)
  123. $('#edit_modal').modal()
  124. }
  125. // 编辑物料库存水平
  126. function updatePartPlanInfo() {
  127. let partPlanInfo = {
  128. id: currentRow.id,
  129. averageConsumeQty: $('#averageConsumeQty').val(),
  130. coverDays: $('#coverDays').val()
  131. }
  132. $.ajax({
  133. url: '/part/updatePartPlanInfo',
  134. contentType: 'application/json',
  135. type: "POST",
  136. async: false,
  137. data: JSON.stringify(partPlanInfo),
  138. dataType: "json",
  139. success: function (data) {
  140. layer.msg(data.msg)
  141. if (data.success) {
  142. $('#editClose').click()
  143. $('#part_plan_data').bootstrapTable('refresh')
  144. }
  145. },
  146. error: function (data) {
  147. var responseText = data.responseText;
  148. var json_str = JSON.parse(responseText);
  149. var status = json_str.status;
  150. var message = json_str.message;
  151. //判断是否是session超时
  152. if (403 == status) {
  153. layer.alert(message, function () {
  154. window.location.href = "/login";
  155. });
  156. }
  157. layer.closeAll('loading');
  158. }
  159. })
  160. }
  161. // 删除提示
  162. function remove() {
  163. layer.confirm('确定要删除选中的信息!', {
  164. btn: ['确定', '取消']
  165. // 按钮
  166. }, function () {
  167. removePartPlanInfo()
  168. }, function () {
  169. });
  170. }
  171. // 确认删除
  172. function removePartPlanInfo() {
  173. let partPlanInfo = {
  174. id: currentRow.id
  175. }
  176. $.ajax({
  177. url: '/part/removePartPlanInfo',
  178. contentType: 'application/json',
  179. type: "POST",
  180. async: false,
  181. data: JSON.stringify(partPlanInfo),
  182. dataType: "json",
  183. success: function (data) {
  184. layer.msg(data.msg)
  185. if (data.success) {
  186. $('#part_plan_data').bootstrapTable('refresh')
  187. }
  188. },
  189. error: function (data) {
  190. var responseText = data.responseText;
  191. var json_str = JSON.parse(responseText);
  192. var status = json_str.status;
  193. var message = json_str.message;
  194. //判断是否是session超时
  195. if (403 == status) {
  196. layer.alert(message, function () {
  197. window.location.href = "/login";
  198. });
  199. }
  200. layer.closeAll('loading');
  201. }
  202. })
  203. }
  204. // 未设置安全水平的物料库存水平列表
  205. function addPartPlanInfoTable() {
  206. $('#partMainTenance').bootstrapTable({
  207. url: '/part/searchPartPlanInfoList', //请求后台的URL(*)
  208. method: 'post', //请求方式(*)
  209. //contentType:'application/x-www-form-urlencoded',
  210. contentType: 'application/json;charset=utf-8',
  211. striped: true, //是否显示行间隔色
  212. cache: false, //是否使用缓存,默认为true,所以一般情况下需要设置一下这个属性(*)
  213. pagination: false, //是否显示分页(*)
  214. sortable: false, //是否启用排序
  215. sortOrder: "asc", //排序方式
  216. queryParamsType: "undefined", //排序方式
  217. queryParams: function queryParams(params) { //设置查询参数
  218. var param = {
  219. site: $('#current_site').val(),
  220. active: $('#status').val(),
  221. partdescription: $('#addPartDescription').val(),
  222. warehousename: $('#addWarehouseName').val(),
  223. // operating: 1,
  224. othergroup2: $('#current_username').val()
  225. };
  226. return JSON.stringify(param);
  227. },
  228. sidePagination: "server", //分页方式:client客户端分页,server服务端分页(*)
  229. pageNumber: 1, //初始化加载第一页,默认第一页
  230. pageSize: 10, //每页的记录行数(*)
  231. pageList: [10, 25, 50, 100], //可供选择的每页的行数(*)
  232. search: false, //是否显示表格搜索,此搜索是客户端搜索,不会进服务端,所以,个人感觉意义不大
  233. searchTimeOut: 1000,
  234. // : true,
  235. showColumns: false, //是否显示所有的列
  236. showRefresh: false, //是否显示刷新按钮
  237. minimumCountColumns: 2, //最少允许的列数
  238. clickToSelect: true, //是否启用点击选中行
  239. singleSelect: false,
  240. // height: 400, //行高,如果没有设置height属性,表格自动根据记录条数觉得表格高度
  241. uniqueId: "id", //每一行的唯一标识,一般为主键列
  242. // showToggle: true, //是否显示详细视图和列表视图的切换按钮
  243. cardView: false, //是否显示详细视图
  244. detailView: false, //是否显示父子表
  245. columns: [{
  246. checkbox: true
  247. }, {
  248. field: 'wareHouseId',
  249. title: '店铺编号',
  250. width: 200
  251. }, {
  252. field: 'warehousename',
  253. title: '店铺名称',
  254. width: 200
  255. }, {
  256. field: 'partNo',
  257. title: '物料编号',
  258. width: 200
  259. }, {
  260. field: 'partdescription',
  261. title: '物料名称',
  262. width: 200
  263. }, {
  264. field: 'averageConsumeQty',
  265. title: '日消耗数量',
  266. align: 'right',
  267. }, {
  268. field: 'coverDays',
  269. title: '维持天数',
  270. align: 'right',
  271. }, {
  272. field: 'othergroup2',
  273. title: '运营',
  274. align: 'right',
  275. }],
  276. onLoadSuccess: function (data) {
  277. $('#partMainTenance').parents('.bootstrap-table').css("margin-left", "10px");
  278. $('#partMainTenance').parents('.fixed-table-container').css("width", 670 + "px");
  279. $('#partMainTenance').parents('.fixed-table-container').css("height", '300');
  280. }
  281. });
  282. }
  283. // 赛选 物料
  284. function searchPart() {
  285. $('#partMainTenance').bootstrapTable('refresh');
  286. }
  287. // 添加模态框
  288. function add() {
  289. $('#partMainTenance').bootstrapTable('refresh')
  290. $('#add_modal').modal()
  291. }
  292. // 初始化页面显示的列
  293. function selectPartPlan() {
  294. $('#partPlanList').bootstrapTable({
  295. // url: '/part/searchPartPlanInfoList', //请求后台的URL(*)
  296. // method: 'post', //请求方式(*)
  297. //contentType:'application/x-www-form-urlencoded',
  298. // contentType: 'application/json;charset=utf-8',
  299. striped: true, //是否显示行间隔色
  300. cache: false, //是否使用缓存,默认为true,所以一般情况下需要设置一下这个属性(*)
  301. pagination: false, //是否显示分页(*)
  302. sortable: false, //是否启用排序
  303. sortOrder: "asc", //排序方式
  304. queryParamsType: "undefined", //排序方式
  305. queryParams: function queryParams(params) { //设置查询参数
  306. var param = {
  307. site: $('#current_site').val(),
  308. active: $('#status').val(),
  309. partdescription: $('#partdescription').val(),
  310. warehousename: $('#warehousename').val(),
  311. operating: 1,
  312. othergroup2: ''
  313. };
  314. return JSON.stringify(param);
  315. },
  316. sidePagination: "server", //分页方式:client客户端分页,server服务端分页(*)
  317. pageNumber: 1, //初始化加载第一页,默认第一页
  318. pageSize: 10, //每页的记录行数(*)
  319. pageList: [10, 25, 50, 100], //可供选择的每页的行数(*)
  320. search: false, //是否显示表格搜索,此搜索是客户端搜索,不会进服务端,所以,个人感觉意义不大
  321. searchTimeOut: 1000,
  322. // : true,
  323. showColumns: false, //是否显示所有的列
  324. showRefresh: false, //是否显示刷新按钮
  325. minimumCountColumns: 2, //最少允许的列数
  326. clickToSelect: true, //是否启用点击选中行
  327. singleSelect: false,
  328. // height: 400, //行高,如果没有设置height属性,表格自动根据记录条数觉得表格高度
  329. uniqueId: "id", //每一行的唯一标识,一般为主键列
  330. // showToggle: true, //是否显示详细视图和列表视图的切换按钮
  331. cardView: false, //是否显示详细视图
  332. detailView: false, //是否显示父子表
  333. columns: [{
  334. field: 'wareHouseId',
  335. title: '店铺编号',
  336. width: 200
  337. }, {
  338. field: 'warehousename',
  339. title: '店铺名称',
  340. width: 200
  341. }, {
  342. field: 'partNo',
  343. title: '物料编号',
  344. width: 200
  345. }, {
  346. field: 'partdescription',
  347. title: '物料名称',
  348. width: 200
  349. }, {
  350. field: 'averageConsumeQty',
  351. title: '日消耗数量',
  352. align: 'right', cellStyle: function () {
  353. return {css: {"text-align": "center"}}
  354. },
  355. formatter: function (value, row, index) {
  356. if (value == null) {
  357. value = 0
  358. }
  359. let averageConsumeQty = ' <input type="text" class=".parentNumber" name="averageConsumeQty" value=' + value + ' style="width: 165px;border-style:none;" autocomplete="off" onkeyup="value=value.replace(/[^\\d]/g,\'\')">'
  360. return averageConsumeQty
  361. }
  362. }, {
  363. field: 'coverDays',
  364. title: '维持天数',
  365. align: 'right',
  366. formatter: function (value, row, index) {
  367. if (value == null) {
  368. value = 0
  369. }
  370. let coverDays = ' <input type="text" class=".parentNumber" name="coverDays" value=' + value + ' style="width: 165px;border-style:none;" autocomplete="off" onkeyup="value=value.replace(/[^\\d]/g,\'\')">'
  371. return coverDays
  372. }
  373. }, {
  374. field: 'othergroup2',
  375. title: '运营',
  376. align: 'right',
  377. }],
  378. onPostHeader: function (data) {
  379. $('#partPlanList').parents('.bootstrap-table').css("margin-left", "10px");
  380. $('#partPlanList').parents('.fixed-table-container').css("width", 670 + "px");
  381. $('#partPlanList').parents('.fixed-table-container').css("height", '260');
  382. }
  383. });
  384. }
  385. var inputs
  386. // 选择需要设置 库存水平的 物料
  387. function addPartPlanInfo() {
  388. let partPlanList = $("#partMainTenance").bootstrapTable('getSelections')
  389. console.log(partPlanList)
  390. $('#partPlanList').bootstrapTable('load', partPlanList);
  391. $("#select_modal").modal()
  392. inputs = document.getElementById("partPlanList").getElementsByTagName("input");
  393. $("input").keydown(function (event) {
  394. var thisinput = $(this)[0];
  395. getfocus(thisinput);
  396. });
  397. }
  398. //回车和小键盘切换input焦点
  399. function getfocus(thisinput) {
  400. inputs = document.getElementsByTagName("input");
  401. let code = event.keyCode
  402. switch (code){
  403. case 13:
  404. case 40:
  405. case 39:
  406. for (var i = 0; i < inputs.length; i++) {
  407. if (thisinput == inputs[i]) {
  408. if (i == (inputs.length - 1)) {
  409. inputs[0].focus();
  410. break;
  411. } else {
  412. inputs[i + 1].focus();
  413. break;
  414. }
  415. }
  416. }
  417. break;
  418. case 37:
  419. case 38:
  420. for (var i = 0; i < inputs.length; i++) {
  421. if (thisinput == inputs[i]) {
  422. if (i != 0) {
  423. inputs[i - 1].focus();
  424. break;
  425. } else {
  426. inputs[inputs.length - 1].focus();
  427. break;
  428. }
  429. }
  430. }
  431. break;
  432. }
  433. }
  434. // 保存选中的 物料信息
  435. function savePartPlanInfo() {
  436. let bool = false
  437. let bool1 = false
  438. let data = []
  439. let partPlanList = $("#partPlanList").bootstrapTable('getData')
  440. let averageConsumeQtyList = $("[name='averageConsumeQty']")
  441. let coverDaysList = $("[name='coverDays']")
  442. averageConsumeQtyList.each((index, item) => {
  443. if ($(item).val() == '' || $(item).val() == null) {
  444. bool = true
  445. }
  446. if ($(coverDaysList [index]).val() == '' || $(coverDaysList [index]).val() == null) {
  447. bool1 = true
  448. }
  449. let partPlan = {
  450. id: partPlanList[index].id,
  451. wareHouseType: 'T',
  452. averageConsumeQty: $(item).val(),
  453. coverDays: $(coverDaysList [index]).val(),
  454. partNo: partPlanList[index].partNo,
  455. site: partPlanList[index].site,
  456. wareHouseId: partPlanList[index].wareHouseId
  457. }
  458. data.push(partPlan)
  459. })
  460. if (bool) {
  461. layer.alert('日消耗数不能为空')
  462. return
  463. }
  464. if (bool1) {
  465. layer.alert('维持天数不能为空')
  466. return;
  467. }
  468. $.ajax({
  469. url: '/part/savePartPlanInfoList',
  470. contentType: 'application/json',
  471. type: "POST",
  472. async: false,
  473. data: JSON.stringify(data),
  474. dataType: "json",
  475. success: function (data) {
  476. layer.msg(data.msg)
  477. if (data.success) {
  478. $('#saveClose').click()
  479. $('#partMainTenance').bootstrapTable('refresh')
  480. }
  481. },
  482. error: function (data) {
  483. var responseText = data.responseText;
  484. var json_str = JSON.parse(responseText);
  485. var status = json_str.status;
  486. var message = json_str.message;
  487. //判断是否是session超时
  488. if (403 == status) {
  489. layer.alert(message, function () {
  490. window.location.href = "/login";
  491. });
  492. }
  493. layer.closeAll('loading');
  494. }
  495. })
  496. }