freight.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. $(function () {
  2. $("#jqGrid").jqGrid({
  3. url: '../freight/list',
  4. datatype: "json",
  5. colModel: [
  6. {label: 'ID', name: 'id', index: 'id', width: 80, align: 'center', key: true},
  7. {label: '所属商户', name: 'merchName', index: 'merchName', width: 140, align: 'center'},
  8. {label: '所属门店', name: 'storeName', index: 'storeName', width: 180, align: 'center'},
  9. {label: '模版名称', name: 'name', width: 180, index: 'name'},
  10. {
  11. label: '模版类型', name: 'templateType', index: 'template_type', width: 200,
  12. formatter: function (value) {
  13. return transTemplateType(value);
  14. }
  15. },
  16. {
  17. label: '计价方式', name: 'pricingManner', index: 'pricing_manner', width: 180,
  18. formatter: function (value) {
  19. return transPricingManner(value);
  20. }
  21. },
  22. {label: '操作', width: 190, align: 'center', sortable: false,
  23. formatter: function (value, col, row) {
  24. if(hasPermission('freight:saveCopyFreight')) {
  25. return "&nbsp;&nbsp;&nbsp;&nbsp;<button class='btn btn-primary' " +
  26. "onclick='vm.copyFreight(" + row.id + ")'>复制运费</button>";
  27. }else{
  28. return '-';
  29. }
  30. }
  31. }],
  32. viewrecords: true,
  33. height: 675,
  34. rowNum: 10,
  35. rowList: [10, 30, 50],
  36. rownumbers: true,
  37. rownumWidth: 25,
  38. autowidth: true,
  39. shrinkToFit: false,
  40. autoScroll: true, //开启水平滚动条
  41. width: 1500,
  42. multiselect: true,
  43. pager: "#jqGridPager",
  44. jsonReader: {
  45. root: "page.list",
  46. page: "page.currPage",
  47. total: "page.totalPage",
  48. records: "page.totalCount"
  49. },
  50. prmNames: {
  51. page: "page",
  52. rows: "limit",
  53. order: "order"
  54. },
  55. gridComplete: function () {
  56. $("#jqGrid").closest(".ui-jqgrid-bdiv").css({"overflow-x": "scroll"});
  57. }
  58. });
  59. });
  60. function transTemplateType(value) {
  61. if (value == 1) {
  62. return '卖家包邮';
  63. }
  64. return '买家承担运费';
  65. };
  66. function transPricingManner(value) {
  67. if (value == 1) {
  68. return '按重量';
  69. } else if (value == 2) {
  70. return '按体积';
  71. }
  72. return '按件数';
  73. };
  74. let vm = new Vue({
  75. el: '#rrapp',
  76. data: {
  77. showList: true,
  78. title: null,
  79. freight: {},
  80. ruleValidate: {
  81. name: [
  82. {required: true, message: '名称不能为空', trigger: 'blur'}
  83. ]
  84. },
  85. q: {
  86. name: ''
  87. },
  88. freightItemEntityList: [{
  89. id: '',
  90. freId: '',
  91. deliveryArea: true,
  92. firstPiece: '',
  93. freight: '',
  94. continuePiece: '',
  95. renew: '',
  96. isDelete: 0
  97. }],
  98. storeList: [],
  99. merchList: [],
  100. copyFreightDto:{
  101. freightId: '',
  102. storeList: ''
  103. },
  104. showCopyList: true,
  105. showViewList: false,
  106. },
  107. methods: {
  108. copyFreight: function(id){
  109. vm.copyFreightDto.freightId = id;
  110. vm.copyFreightDto.storeList = "";
  111. vm.showCopyList = false;
  112. vm.showList = true;
  113. vm.showViewList = true;
  114. vm.title = "复制运费";
  115. },
  116. handleSubmitCopyFreight: function () {
  117. if(vm.copyFreightDto.freightId == ""){
  118. alert('运费id不能为空');
  119. return;
  120. }
  121. if(vm.copyFreightDto.storeList == ""){
  122. alert('门店id批量上传数据没有上传或未上传成功');
  123. return;
  124. }
  125. var url = "../freight/saveCopyFreight";
  126. $.ajax({
  127. type: "POST",
  128. url: url,
  129. contentType: "application/json",
  130. data: JSON.stringify(vm.copyFreightDto),
  131. success: function (r) {
  132. if (r.code === 0) {
  133. alert('操作成功', function (index) {
  134. vm.showCopyList = true;
  135. vm.showList = true;
  136. vm.showViewList = false;
  137. vm.reload();
  138. });
  139. } else {
  140. alert(r.msg);
  141. }
  142. }
  143. });
  144. },
  145. uploadExcelSuccess: function (data) {
  146. if(data.code==0){
  147. alert(data.msg, function (index) {
  148. vm.copyFreightDto.storeList = data.storeIds;
  149. });
  150. }else{
  151. alert(data.msg);
  152. }
  153. },
  154. uploadExcelError: function (data) {
  155. console.log(data);
  156. alert('上传出现异常,请重试!');
  157. },
  158. uploadExcelFormatError: function (file) {
  159. this.$Notice.warning({
  160. title: '文件格式不正确',
  161. desc: '文件 ' + file.name + ' 格式不正确,请上传 xls 或 xlsx 格式的文件。'
  162. });
  163. },
  164. changeUnit: function(value) {
  165. if (value == '0') {
  166. $('#first').html('首件(个)');
  167. $('#continue').html('续件(个)');
  168. } else if (value == '1') {
  169. $('#first').html('首件(kg)');
  170. $('#continue').html('续件(kg)');
  171. } else if (value == '2') {
  172. $('#first').html('首件(m³)');
  173. $('#continue').html('续件(m³)');
  174. }
  175. },
  176. delItemRow: function (index) {
  177. //最后一行时禁止删除
  178. if (vm.freightItemEntityList.length == 1) {
  179. return;
  180. }
  181. vm.freightItemEntityList[index].isDelete = 1;
  182. },
  183. addItemRow: function () {
  184. let id = '';
  185. if (vm.freight) {
  186. id = vm.freight.id;
  187. }
  188. vm.freightItemEntityList.push({
  189. id: '',
  190. freId: '',
  191. firstPiece: '',
  192. freight: '',
  193. continuePiece: '',
  194. renew: '',
  195. isDelete: 0
  196. })
  197. },
  198. query: function () {
  199. vm.reload();
  200. },
  201. add: function () {
  202. vm.showList = false;
  203. vm.showCopyList = true;
  204. vm.showViewList = true;
  205. vm.title = "新增";
  206. vm.freight = {
  207. name: '',
  208. templateType: 0,
  209. pricingManner: 0,
  210. isDefault: false
  211. };
  212. vm.freightItemEntityList = [{
  213. id: '',
  214. freId: '',
  215. deliveryArea: true,
  216. firstPiece: '',
  217. freight: '',
  218. continuePiece: '',
  219. renew: '',
  220. isDelete: 0
  221. }];
  222. vm.storeList = [];
  223. vm.merchList = [];
  224. vm.getMerchList();
  225. },
  226. getStoresByMerch: function (opt) {
  227. var value = opt.value;
  228. $.get("../store/getStoresByMerch?merchSn=" + value, function (r) {
  229. vm.storeList = r.list;
  230. });
  231. },
  232. getMerchList: function() {
  233. $.get("../merch/queryAll", function (r) {
  234. vm.merchList = r.list;
  235. });
  236. },
  237. update: function (event) {
  238. let id = getSelectedRow();
  239. if (id == null) {
  240. return;
  241. }
  242. vm.showList = false;
  243. vm.showCopyList = true;
  244. vm.showViewList = true;
  245. vm.title = "修改";
  246. vm.freight = {
  247. name: '',
  248. templateType: 0,
  249. pricingManner: 0,
  250. isDefault: false
  251. };
  252. vm.freightItemEntityList = [{
  253. id: '',
  254. freId: '',
  255. deliveryArea: true,
  256. firstPiece: '',
  257. freight: '',
  258. continuePiece: '',
  259. renew: '',
  260. isDelete: 0
  261. }];
  262. vm.storeList = [];
  263. vm.merchList = [];
  264. vm.getInfo(id)
  265. vm.getMerchList();
  266. vm.getStoresByMerch();
  267. },
  268. saveOrUpdate: function (event) {
  269. let url = vm.freight.id == null ? "../freight/save" : "../freight/update";
  270. vm.freight.freightItemEntityList = vm.freightItemEntityList;
  271. $.ajax({
  272. type: "POST",
  273. url: url,
  274. contentType: "application/json",
  275. data: JSON.stringify(vm.freight),
  276. success: function (r) {
  277. if (r.code === 0) {
  278. alert('操作成功', function (index) {
  279. vm.reload();
  280. });
  281. } else {
  282. alert(r.msg);
  283. }
  284. }
  285. });
  286. },
  287. del: function (event) {
  288. let ids = getSelectedRows();
  289. if (ids == null){
  290. return;
  291. }
  292. confirm('确定要删除选中的记录?', function () {
  293. $.ajax({
  294. type: "POST",
  295. url: "../freight/delete",
  296. contentType: "application/json",
  297. data: JSON.stringify(ids),
  298. success: function (r) {
  299. if (r.code == 0) {
  300. alert('操作成功', function (index) {
  301. $("#jqGrid").trigger("reloadGrid");
  302. });
  303. } else {
  304. alert(r.msg);
  305. }
  306. }
  307. });
  308. });
  309. },
  310. getInfo: function(id){
  311. $.get("../freight/info/"+id, function (r) {
  312. vm.freight = r.freight;
  313. if (vm.freight.isDefault == "1") {
  314. vm.freight.isDefault = true;
  315. }
  316. if (r.freight.freightItemEntityList.length > 0) {
  317. vm.freightItemEntityList = r.freight.freightItemEntityList;
  318. for (var item in vm.freightItemEntityList) {
  319. if (item.deliveryArea == "ALL") {
  320. item.deliveryArea = true;
  321. }
  322. }
  323. } else {
  324. vm.freightItemEntityList = [{
  325. id: '',
  326. freId: '',
  327. deliveryArea: true,
  328. firstPiece: '',
  329. freight: '',
  330. continuePiece: '',
  331. renew: '',
  332. isDelete: 0
  333. }];
  334. }
  335. });
  336. },
  337. reloadSearch: function() {
  338. vm.q = {
  339. name: ''
  340. }
  341. vm.reload();
  342. },
  343. reload: function (event) {
  344. vm.showViewList = false;
  345. vm.showList = true;
  346. vm.showCopyList = true;
  347. let page = $("#jqGrid").jqGrid('getGridParam', 'page');
  348. $("#jqGrid").jqGrid('setGridParam', {
  349. postData: {'name': vm.q.name},
  350. page: page
  351. }).trigger("reloadGrid");
  352. vm.handleReset('formValidate');
  353. },
  354. handleSubmit: function (name) {
  355. handleSubmitValidate(this, name, function () {
  356. vm.saveOrUpdate()
  357. });
  358. },
  359. handleReset: function (name) {
  360. handleResetForm(this, name);
  361. }
  362. }
  363. });