freight.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. $(function () {
  2. $("#jqGrid").jqGrid({
  3. url: '../freight/list',
  4. datatype: "json",
  5. colModel: [
  6. {label: 'ID', name: 'id', index: 'id', hidden: true, key: true},
  7. {label: '模版名称', name: 'name', index: 'name'},
  8. {
  9. label: '模版类型', name: 'templateType', index: 'template_type', width: 100,
  10. formatter: function (value) {
  11. return transTemplateType(value);
  12. }
  13. },
  14. {
  15. label: '计价方式', name: 'pricingManner', index: 'pricing_manner', width: 100,
  16. formatter: function (value) {
  17. return transPricingManner(value);
  18. }
  19. }],
  20. viewrecords: true,
  21. height: 675,
  22. rowNum: 10,
  23. rowList: [10, 30, 50],
  24. rownumbers: true,
  25. rownumWidth: 25,
  26. autowidth: true,
  27. multiselect: true,
  28. pager: "#jqGridPager",
  29. jsonReader: {
  30. root: "page.list",
  31. page: "page.currPage",
  32. total: "page.totalPage",
  33. records: "page.totalCount"
  34. },
  35. prmNames: {
  36. page: "page",
  37. rows: "limit",
  38. order: "order"
  39. },
  40. gridComplete: function () {
  41. $("#jqGrid").closest(".ui-jqgrid-bdiv").css({"overflow-x": "hidden"});
  42. }
  43. });
  44. });
  45. function transTemplateType(value) {
  46. if (value == 1) {
  47. return '卖家包邮';
  48. }
  49. return '买家承担运费';
  50. };
  51. function transPricingManner(value) {
  52. if (value == 1) {
  53. return '按重量';
  54. } else if (value == 2) {
  55. return '按体积';
  56. }
  57. return '按件数';
  58. };
  59. let vm = new Vue({
  60. el: '#rrapp',
  61. data: {
  62. showList: true,
  63. title: null,
  64. freight: {},
  65. ruleValidate: {
  66. name: [
  67. {required: true, message: '名称不能为空', trigger: 'blur'}
  68. ]
  69. },
  70. q: {
  71. name: ''
  72. },
  73. freightItemEntityList: [{
  74. id: '',
  75. freId: '',
  76. deliveryArea: true,
  77. firstPiece: '',
  78. freight: '',
  79. continuePiece: '',
  80. renew: '',
  81. isDelete: 0
  82. }],
  83. storeList: [],
  84. merchList: []
  85. },
  86. methods: {
  87. changeUnit: function(value) {
  88. if (value == '0') {
  89. $('#first').html('首件(个)');
  90. $('#continue').html('续件(个)');
  91. } else if (value == '1') {
  92. $('#first').html('首件(kg)');
  93. $('#continue').html('续件(kg)');
  94. } else if (value == '2') {
  95. $('#first').html('首件(m³)');
  96. $('#continue').html('续件(m³)');
  97. }
  98. },
  99. delItemRow: function (index) {
  100. //最后一行时禁止删除
  101. if (vm.freightItemEntityList.length == 1) {
  102. return;
  103. }
  104. vm.freightItemEntityList[index].isDelete = 1;
  105. },
  106. addItemRow: function () {
  107. let id = '';
  108. if (vm.freight) {
  109. id = vm.freight.id;
  110. }
  111. vm.freightItemEntityList.push({
  112. id: '',
  113. freId: '',
  114. firstPiece: '',
  115. freight: '',
  116. continuePiece: '',
  117. renew: '',
  118. isDelete: 0
  119. })
  120. },
  121. query: function () {
  122. vm.reload();
  123. },
  124. add: function () {
  125. vm.showList = false;
  126. vm.title = "新增";
  127. vm.freight = {
  128. name: '',
  129. templateType: 0,
  130. pricingManner: 0,
  131. isDefault: false
  132. };
  133. vm.freightItemEntityList = [{
  134. id: '',
  135. freId: '',
  136. deliveryArea: true,
  137. firstPiece: '',
  138. freight: '',
  139. continuePiece: '',
  140. renew: '',
  141. isDelete: 0
  142. }];
  143. vm.storeList = [];
  144. vm.merchList = [];
  145. vm.getMerchList();
  146. },
  147. getStoresByMerch: function (opt) {
  148. var value = opt.value;
  149. $.get("../store/getStoresByMerch?merchSn=" + value, function (r) {
  150. vm.storeList = r.list;
  151. });
  152. },
  153. getMerchList: function() {
  154. $.get("../merch/queryAll", function (r) {
  155. vm.merchList = r.list;
  156. });
  157. },
  158. update: function (event) {
  159. let id = getSelectedRow();
  160. if (id == null) {
  161. return;
  162. }
  163. vm.showList = false;
  164. vm.title = "修改";
  165. vm.getInfo(id)
  166. vm.getMerchList();
  167. vm.getStoresByMerch();
  168. },
  169. saveOrUpdate: function (event) {
  170. let url = vm.freight.id == null ? "../freight/save" : "../freight/update";
  171. vm.freight.freightItemEntityList = vm.freightItemEntityList;
  172. $.ajax({
  173. type: "POST",
  174. url: url,
  175. contentType: "application/json",
  176. data: JSON.stringify(vm.freight),
  177. success: function (r) {
  178. if (r.code === 0) {
  179. alert('操作成功', function (index) {
  180. vm.reload();
  181. });
  182. } else {
  183. alert(r.msg);
  184. }
  185. }
  186. });
  187. },
  188. del: function (event) {
  189. let ids = getSelectedRows();
  190. if (ids == null){
  191. return;
  192. }
  193. confirm('确定要删除选中的记录?', function () {
  194. $.ajax({
  195. type: "POST",
  196. url: "../freight/delete",
  197. contentType: "application/json",
  198. data: JSON.stringify(ids),
  199. success: function (r) {
  200. if (r.code == 0) {
  201. alert('操作成功', function (index) {
  202. $("#jqGrid").trigger("reloadGrid");
  203. });
  204. } else {
  205. alert(r.msg);
  206. }
  207. }
  208. });
  209. });
  210. },
  211. getInfo: function(id){
  212. $.get("../freight/info/"+id, function (r) {
  213. vm.freight = r.freight;
  214. if (vm.freight.isDefault == "1") {
  215. vm.freight.isDefault = true;
  216. }
  217. if (r.freight.freightItemEntityList.length > 0) {
  218. vm.freightItemEntityList = r.freight.freightItemEntityList;
  219. for (var item in vm.freightItemEntityList) {
  220. if (item.deliveryArea == "ALL") {
  221. item.deliveryArea = true;
  222. }
  223. }
  224. } else {
  225. vm.freightItemEntityList = [{
  226. id: '',
  227. freId: '',
  228. deliveryArea: true,
  229. firstPiece: '',
  230. freight: '',
  231. continuePiece: '',
  232. renew: '',
  233. isDelete: 0
  234. }];
  235. }
  236. });
  237. },
  238. reloadSearch: function() {
  239. vm.q = {
  240. name: ''
  241. }
  242. vm.reload();
  243. },
  244. reload: function (event) {
  245. vm.showList = true;
  246. let page = $("#jqGrid").jqGrid('getGridParam', 'page');
  247. $("#jqGrid").jqGrid('setGridParam', {
  248. postData: {'name': vm.q.name},
  249. page: page
  250. }).trigger("reloadGrid");
  251. vm.handleReset('formValidate');
  252. },
  253. handleSubmit: function (name) {
  254. handleSubmitValidate(this, name, function () {
  255. vm.saveOrUpdate()
  256. });
  257. },
  258. handleReset: function (name) {
  259. handleResetForm(this, name);
  260. }
  261. }
  262. });