freight.js 8.8 KB

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