freight.js 12 KB

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