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.

257 lines
8.8 KiB

  1. //公共参数
  2. let tableTags = "stor_data";//表格的id
  3. let currentRow;//临时的参数行
  4. //初始化
  5. $(function () {
  6. storTableInit();
  7. });
  8. //初始化表格
  9. function storTableInit() {
  10. $('#' + tableTags).bootstrapTable({
  11. url: '/ware/searchWareHouseList', //请求后台的URL(*)
  12. method: 'post', //请求方式(*)
  13. //contentType:'application/x-www-form-urlencoded',
  14. contentType: 'application/json;charset=utf-8',
  15. toolbar: '#toolbar', //工具按钮用哪个容器
  16. striped: true, //是否显示行间隔色
  17. cache: false, //是否使用缓存,默认为true,所以一般情况下需要设置一下这个属性(*)
  18. pagination: false, //是否显示分页(*)
  19. sortable: false, //是否启用排序
  20. sortOrder: "asc", //排序方式
  21. queryParamsType: "undefined", //排序方式
  22. queryParams: function queryParams(params) { //设置查询参数
  23. var param = {
  24. 'site': $('#current_site').val(),
  25. 'warehousetypeDb': 'T',
  26. 'active': $('#status').val(),
  27. 'warehouseid': $('#warehouseid').val(),
  28. 'warehousename': $('#warehousename').val()
  29. };
  30. return JSON.stringify(param);
  31. },
  32. sidePagination: "server", //分页方式:client客户端分页,server服务端分页(*)
  33. pageNumber: 1, //初始化加载第一页,默认第一页
  34. pageSize: 10, //每页的记录行数(*)
  35. pageList: [10, 25, 50, 100], //可供选择的每页的行数(*)
  36. search: false, //是否显示表格搜索,此搜索是客户端搜索,不会进服务端,所以,个人感觉意义不大
  37. searchTimeOut: 1000,
  38. // : true,
  39. showColumns: false, //是否显示所有的列
  40. showRefresh: false, //是否显示刷新按钮
  41. minimumCountColumns: 2, //最少允许的列数
  42. clickToSelect: true, //是否启用点击选中行
  43. singleSelect: false,
  44. height: 400, //行高,如果没有设置height属性,表格自动根据记录条数觉得表格高度
  45. uniqueId: "id", //每一行的唯一标识,一般为主键列
  46. // showToggle: true, //是否显示详细视图和列表视图的切换按钮
  47. cardView: false, //是否显示详细视图
  48. detailView: false, //是否显示父子表
  49. columns: [/*{
  50. checkbox: true
  51. },*/{
  52. field: 'warehouseid',
  53. title: '店铺编号'
  54. }, {
  55. field: 'warehousename',
  56. title: '店铺名称'
  57. }, {
  58. field: 'active',
  59. title: '状态',
  60. formatter: function (value) {
  61. if (value == 'Y') {
  62. return '启用'
  63. }
  64. return '未启用'
  65. }
  66. }, {
  67. field: '-',
  68. title: '-',
  69. width: 200
  70. }, {
  71. field: '-',
  72. title: '-',
  73. width: 200
  74. }],
  75. onClickRow: function (row, $element) {
  76. $('.check_back').removeClass('check_back');
  77. $($element).addClass('check_back');
  78. currentRow = row;
  79. //调用自定义按钮的控制类
  80. customerBtnControl(tableTags, row, null);
  81. },
  82. onLoadSuccess: function (data) {
  83. //调用自定义按钮的控制类
  84. customerBtnControl(tableTags, null, null)
  85. },
  86. //>>>>>>>>>>>>>>导出excel表格设置
  87. showExport: false, //是否显示导出按钮(此方法是自己写的目的是判断终端是电脑还是手机,电脑则返回true,手机返回falsee,手机不显示按钮)
  88. exportDataType: "basic", //basic', 'all', 'selected'.
  89. exportTypes: ['excel', 'xlsx'], //导出类型
  90. exportButton: $('#download_button'), //为按钮btn_export 绑定导出事件 自定义导出按钮(可以不用)
  91. exportOptions: {
  92. ignoreColumn: [8, 8], //忽略某一列的索引
  93. fileName: '库存信息' + generateTimeReqestNumber(), //文件名称设置
  94. worksheetName: '库存信息', //表格工作区名称
  95. tableName: '库存信息',
  96. excelstyles: ['background-color', 'color', 'font-size', 'font-weight'],
  97. onMsoNumberFormat: DoOnMsoNumberFormat
  98. }
  99. //导出excel表格设置<<<<<<<<<<<<<<<<
  100. });
  101. }
  102. //处理搜索,刷新table
  103. function searchStor() {
  104. $('#stor_data').bootstrapTable('refresh');
  105. }
  106. // 添加店铺
  107. function addStorModal() {
  108. $('#stor_modal').modal()
  109. }
  110. // 保存店铺信息 (店铺 = 仓库)
  111. function saveStor() {
  112. let wareHouse = {
  113. 'site': $('#current_site').val(),
  114. 'warehouseid': $('#wareHouseID').val(),
  115. 'warehousename': $('#wareHouseName').val(),
  116. 'active': $('#active').val(),
  117. 'warehousetypeDb': 'T',
  118. 'wareHousetype': '店仓'
  119. }
  120. $.ajax({
  121. url: '/ware/addWareHouse',
  122. contentType: 'application/json',
  123. type: "POST",
  124. async: false,
  125. data: JSON.stringify(wareHouse),
  126. dataType: "json"
  127. }).done(function (data) {
  128. // 请求成功
  129. layer.msg(data.msg)
  130. if (data.success) {
  131. $('#storClose').click()
  132. $('#stor_data').bootstrapTable('refresh')
  133. cleanStor()
  134. }
  135. }).fail(function (jqXHR, textStatus, errorThrown) {
  136. // net::ERR_CONNECTION_REFUSED 发生时,也能进入
  137. // alert("请求超时,网络出现问题")
  138. if (jqXHR.status == 0) {
  139. layer.alert("网络连接异常: "+jqXHR.statusText);
  140. console.info("网络出错");
  141. }
  142. if (jqXHR.status == 403) {
  143. //判断是否是session超时
  144. layer.alert("用户登录信息过期,请重新登陆", function () {
  145. window.location.href = "/login";
  146. });
  147. }
  148. });
  149. }
  150. $('#storClose').click(function () {
  151. cleanStor()
  152. })
  153. function cleanStor() {
  154. $('#editWareHouseID').val('')
  155. $('#editWareHouseName').val('')
  156. $('#editActive').val('Y')
  157. }
  158. // 编辑店铺 modal
  159. function editStorModal() {
  160. $('#editWareHouseID').val(currentRow.warehouseid)
  161. $('#editWareHouseName').val(currentRow.warehousename)
  162. $('#editActive').val(currentRow.active)
  163. $('#edit_stor_modal').modal()
  164. }
  165. // 编辑店铺
  166. function updateStor() {
  167. let wareHouse = {
  168. warehouseid: $('#editWareHouseID').val(),
  169. warehousename: $('#editWareHouseName').val(),
  170. active: $('#active').val(),
  171. site: $('#current_site').val()
  172. }
  173. updateWare(wareHouse)
  174. }
  175. // 删除店铺
  176. function removerWare() {
  177. layer.confirm('确定要删除选中店铺信息!', {
  178. btn: ['确定', '取消']
  179. // 按钮
  180. }, function () {
  181. let wareHouse = {
  182. site: currentRow.site,
  183. active: 'N',
  184. warehouseid: currentRow.warehouseid,
  185. }
  186. updateWare(wareHouse)
  187. }, function () {
  188. });
  189. }
  190. // 修改
  191. function updateWare(data) {
  192. $.ajax({
  193. url: '/ware/updateWareHouse',
  194. contentType: 'application/json',
  195. type: "POST",
  196. async: false,
  197. data: JSON.stringify(data),
  198. dataType: "json",
  199. success: function (data) {
  200. layer.msg(data.msg)
  201. if (data.success) {
  202. $('#editStorClose').click()
  203. $('#stor_data').bootstrapTable('refresh')
  204. cleanStor()
  205. }
  206. },
  207. error: function (data) {
  208. var responseText = data.responseText;
  209. var json_str = JSON.parse(responseText);
  210. var status = json_str.status;
  211. var message = json_str.message;
  212. //判断是否是session超时
  213. if (403 == status) {
  214. layer.alert(message, function () {
  215. window.location.href = "/login";
  216. });
  217. }
  218. layer.closeAll('loading');
  219. }
  220. })
  221. }
  222. //格式化数字
  223. function DoOnMsoNumberFormat(cell, row, col) {
  224. var result = "";
  225. if (row > 0 && col == 0)
  226. debugger;
  227. result = "\\@";
  228. return result;
  229. }
  230. // 日期数字格式化
  231. function generateTimeReqestNumber() {
  232. var date = new Date();
  233. return date.getFullYear().toString() + pad2(date.getMonth() + 1) + pad2(date.getDate()) + pad2(date.getHours()) + pad2(date.getMinutes()) + pad2(date.getSeconds());
  234. }
  235. function pad2(n) {
  236. return n < 10 ? '0' + n : n
  237. }