freight.js 12 KB

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