my.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. (function (app) {
  2. app.controller('myCtrl', ["$scope", "$state", 'userService', 'msg','config','$timeout', function ($scope, $state, userService,msg,config,$timeout) {
  3. $scope.user = {};
  4. $scope.host = config.server +'/upload/avatar/';
  5. $scope.$on('$ionicView.beforeEnter', function (viewResult) {
  6. $scope.load(true);
  7. });
  8. $scope.load = function (init) {
  9. userService.getUser().then(function (result) {
  10. $timeout(function () {
  11. $scope.user = result.data.data;
  12. });
  13. }, function (erro) {
  14. msg.error(erro.data.message);
  15. });
  16. }
  17. $scope.toProfile = function () {
  18. $state.go('wl.my_profile');
  19. }
  20. }]);
  21. app.controller('mySettingCtrl', ['$scope', 'data', '$state', '$http','$ionicModal','myService', function ($scope, data, $state, $http,$ionicModal,myService) {
  22. myService.setting().then(function (result) {
  23. $scope.res = result.data;
  24. }, function (erro) {
  25. msg.error(erro);
  26. });
  27. $scope.logout = function () {
  28. data.remove('user');
  29. data.remove('token');
  30. $http.defaults.headers.common["Authorization"] =undefined;
  31. $state.go('login');
  32. }
  33. $ionicModal.fromTemplateUrl('low.html', {
  34. scope: $scope,
  35. animation: 'slide-in-up'
  36. }).then(function(modal) {
  37. $scope.modal1 = modal;
  38. });
  39. $ionicModal.fromTemplateUrl('compay.html', {
  40. scope: $scope,
  41. animation: 'slide-in-up'
  42. }).then(function(modal) {
  43. $scope.modal2 = modal;
  44. });
  45. $scope.openModal1 = function() {
  46. $scope.modal1.show();
  47. };
  48. $scope.closeModal1 = function() {
  49. $scope.modal1.hide();
  50. };
  51. $scope.openModal2 = function() {
  52. $scope.modal2.show();
  53. };
  54. $scope.closeModal2 = function() {
  55. $scope.modal2.hide();
  56. };
  57. // Cleanup the modal when we're done with it!
  58. $scope.$on('$destroy', function() {
  59. $scope.modal1.remove();
  60. $scope.modal2.remove();
  61. });
  62. }]);
  63. app.controller('mySetPasswordCtrl', ['$scope', '$state', 'myService', 'msg', function ($scope, $state, myService, msg) {
  64. $scope.$on('$ionicView.beforeEnter', function (viewResult) {
  65. $scope.vm = {
  66. oldpassword:'',
  67. password: '',
  68. password1: '',
  69. };
  70. });
  71. $scope.submit = function (vm) {
  72. msg.loading('保存中...');
  73. var model = { old_password: vm.oldpassword, password: vm.password, password_confirmation: vm.password1 };
  74. myService.resetPassword(model).then(function () {
  75. msg.hide();
  76. $scope.data = {
  77. oldpassword:'',
  78. password: '',
  79. password1: '',
  80. };
  81. msg.success('密码修改成功');
  82. }, function (erro) {
  83. msg.hide();
  84. msg.error(erro.message);
  85. });
  86. }
  87. }]);
  88. app.controller('myProfileCtrl', ['$scope', '$ionicActionSheet', '$ionicPopup', '$timeout', 'userService', 'msg', 'util', 'data', 'camera','config', function ($scope, $ionicActionSheet, $ionicPopup, $timeout, userService, msg, util, data, camera,config) {
  89. // $scope.user = data.getObject('user');
  90. $scope.$on('$ionicView.beforeEnter', function (viewResult) {
  91. $scope.load(true);
  92. });
  93. $scope.load = function (init) {
  94. userService.getUser().then(function (result) {
  95. $timeout(function () {
  96. $scope.user = result.data.data;
  97. });
  98. }, function (erro) {
  99. msg.error(erro.data.message);
  100. });
  101. }
  102. $scope.genderOpt = [
  103. { name: "男", value: "1" },
  104. { name: "女", value: "0" }
  105. ];
  106. $scope.host = config.server +'/upload/avatar/';
  107. $scope.setAvator = function () {
  108. camera.chooseImage().then(function (imageUri) {
  109. var uploadOptions = new FileUploadOptions();
  110. uploadOptions.fileKey = "photo";
  111. uploadOptions.fileName = "avatar.jpg";
  112. uploadOptions.mimeType = "image/jpeg";
  113. uploadOptions.httpMethod = 'post';
  114. uploadOptions.chunkedMode = true;
  115. var token = 'Bearer ' + localStorage['token'];
  116. uploadOptions.headers = { "Authorization": token };
  117. var ft = new FileTransfer();
  118. ft.upload(imageUri, encodeURI(config.server + "api/user"), function (sucess) {
  119. $timeout(function () {
  120. var res = JSON.parse(sucess.response);
  121. $scope.user.avatar = res.data.avatar;
  122. });
  123. console.log('上传成功'+JSON.stringify(sucess.response));
  124. //alert('上传成功'+JSON.stringify(sucess));
  125. }, function (fail) {
  126. console.log('上传失败'+JSON.stringify(fail));
  127. //alert('上传失败'+JSON.stringify(fail));
  128. }, uploadOptions);
  129. }, function (erro) {
  130. msg.error(erro);
  131. });
  132. }
  133. $scope.save = function () {
  134. data.updateObject('user', $scope.user);
  135. msg.loading('保存中...');
  136. userService.update($scope.user).then(function () {
  137. msg.hide();
  138. msg.success('保存成功');
  139. }, function (erro) {
  140. msg.hide();
  141. msg.error(erro.data.message);
  142. });
  143. }
  144. }]);
  145. app.controller('myTruckCtrl', ['$scope', '$state', 'myService', 'msg','config', function ($scope, $state, myService, msg,config) {
  146. $scope.filter = {
  147. hasMore: false,
  148. page: 0,
  149. pageSize: 10,
  150. }
  151. $scope.items = [];
  152. $scope.host = config.server +'/upload/photo/';
  153. $scope.load = function (init) {
  154. if (init) {
  155. $scope.filter.pageIndex = 1;
  156. $scope.items = [];
  157. }
  158. myService.listTrucks($scope.filter).then(function (result) {
  159. $scope.filter.pageIndex++;
  160. var more = (result.data.data.length >= $scope.filter.pageSize);
  161. $scope.filter.hasMore = more;
  162. $scope.items = $scope.items.concat(result.data.data);
  163. if (init) {
  164. $scope.$broadcast('scroll.refreshComplete');
  165. } else {
  166. $scope.$broadcast('scroll.infiniteScrollComplete');
  167. }
  168. }, function (erro) {
  169. msg.error(erro.data.message);
  170. });
  171. }
  172. $scope.add = function () {
  173. $state.go('wl.my_truck_add', { item: {}});
  174. }
  175. $scope.detail = function (item) {
  176. $state.go('wl.my_truck_add', {item:item});
  177. }
  178. $scope.delete = function (item, $event) {
  179. $event.stopPropagation();
  180. msg.confirm('删除提示', '确定删除?').then(function (res) {
  181. if (res) {
  182. msg.loading('删除中...');
  183. myService.deleteTruck(item.id).then(function (result) {
  184. msg.hide();
  185. $scope.load(true);
  186. }, function (erro) {
  187. msg.hide();
  188. msg.error(erro.data.message);
  189. })
  190. } else {
  191. }
  192. });
  193. }
  194. $scope.$on('$ionicView.beforeEnter', function (viewResult) {
  195. $scope.load(true);
  196. });
  197. }]);
  198. app.controller('myTruckAddCtrl', ['$scope', 'myService', 'msg', '$state', '$stateParams', 'camera', 'config', '$timeout', function ($scope, myService, msg, $state, $stateParams, camera, config, $timeout) {
  199. $scope.vm = {};
  200. if ($stateParams.item) {
  201. $scope.vm = $stateParams.item;
  202. $scope.vm.type = 1;
  203. $scope.vm.begin_use_date = new Date($scope.vm.begin_use_date);
  204. $scope.vm.expire_date = new Date($scope.vm.expire_date);
  205. }
  206. $scope.typeOpt = [
  207. { name: '厢式货车', value: 1 },
  208. { name: '面包车', value: 2 },
  209. { name: '金杯车', value: 3 },
  210. { name: '中巴货车', value: 4 },
  211. { name: '高栏车', value: 5 },
  212. { name: '低栏车', value: 6 },
  213. { name: '平板车', value: 7 },
  214. { name: '高低板车', value: 8 },
  215. { name: '半挂车', value: 9 },
  216. { name: '自卸车', value: 10 },
  217. { name: '冷藏车', value: 11 },
  218. { name: '保温车', value: 12 },
  219. { name: '罐式车', value: 13 },
  220. { name: '铁笼车', value: 14 },
  221. { name: '集装箱运输车', value: 15 },
  222. { name: '大件运输车', value: 16 },
  223. { name: '危险品车', value: 17 },
  224. { name: '全挂车', value: 18 },
  225. { name: '加长挂车', value: 19 },
  226. { name: '其他', value: 20 }];
  227. $scope.save = function () {
  228. msg.loading('保存中...');
  229. console.log('id '+$scope.vm.id);
  230. if ($scope.vm.id>0) {
  231. $scope.vm.photo = null;
  232. console.log('updateTruck '+ JSON.stringify($scope.vm));
  233. myService.updateTruck($scope.vm).then(function (result) {
  234. msg.hide();
  235. $state.go('wl.my_truck');
  236. }, function (erro) {
  237. msg.hide();
  238. msg.error(erro.data.message);
  239. });
  240. } else {
  241. myService.addTruck($scope.vm).then(function (result) {
  242. msg.hide();
  243. $state.go('wl.my_truck');
  244. }, function (erro) {
  245. msg.hide();
  246. msg.error(erro.data.message);
  247. });
  248. }
  249. }
  250. //上传图片
  251. $scope.host = config.server +'/upload/photo/';
  252. $scope.setPhoto = function () {
  253. camera.chooseImage().then(function (imageUri) {
  254. var uploadOptions = new FileUploadOptions();
  255. uploadOptions.fileKey = "photo";
  256. uploadOptions.fileName = "photo.jpg";
  257. uploadOptions.mimeType = "image/jpeg";
  258. uploadOptions.httpMethod = 'post';
  259. var id = '';
  260. if ($scope.vm.id>0) {
  261. id = '/'+$scope.vm.id;
  262. }
  263. uploadOptions.chunkedMode = true;
  264. var token = 'Bearer ' + localStorage['token'];
  265. uploadOptions.headers = { "Authorization": token };
  266. var ft = new FileTransfer();
  267. ft.upload(imageUri, encodeURI(config.server + "api/trucks" + id), function (sucess) {
  268. $timeout(function () {
  269. var res = JSON.parse(sucess.response);
  270. $scope.vm.id = res.data.id;
  271. $scope.vm.photo = res.data.photo;
  272. });
  273. console.log('上传成功'+JSON.stringify(sucess.response));
  274. //alert('上传成功'+JSON.stringify(sucess));
  275. }, function (fail) {
  276. console.log('上传失败'+JSON.stringify(fail));
  277. //alert('上传失败'+JSON.stringify(fail));
  278. }, uploadOptions);
  279. }, function (erro) {
  280. msg.error(erro);
  281. });
  282. }
  283. }]);
  284. app.controller('myTruckDetailCtrl', ['$scope', function ($scope) {
  285. }]);
  286. app.controller('myMessageCtrl', ['$scope', 'myService', 'msg', '$state','config', function ($scope, myService, msg, $state,config) {
  287. $scope.filter = {
  288. hasMore: false,
  289. page: 0,
  290. pageSize: 10,
  291. }
  292. $scope.shouldShowDelete = false;
  293. $scope.items = [];
  294. $scope.host = config.server +'/upload/photo/';
  295. $scope.load = function (init) {
  296. if (init) {
  297. $scope.filter.pageIndex = 1;
  298. $scope.items = [];
  299. }
  300. myService.listMessages($scope.filter).then(function (result) {
  301. $scope.filter.pageIndex++;
  302. var more = (result.data.data.length >= $scope.filter.pageSize);
  303. $scope.filter.hasMore = more;
  304. $scope.items = $scope.items.concat(result.data.data);
  305. if (init) {
  306. $scope.$broadcast('scroll.refreshComplete');
  307. } else {
  308. $scope.$broadcast('scroll.infiniteScrollComplete');
  309. }
  310. }, function (erro) {
  311. msg.error(erro.data.message);
  312. });
  313. }
  314. $scope.close = function () {
  315. if ($scope.shouldShowDelete) {
  316. $scope.shouldShowDelete = false;
  317. } else {
  318. $scope.shouldShowDelete = true;
  319. }
  320. }
  321. $scope.detail = function (item) {
  322. $state.go('wl.my_message_detail', { item: item });
  323. }
  324. $scope.closeItem = function (item, $index) {
  325. $scope.items.splice($index, 1);
  326. item.state = 10;
  327. myService.deleteMessage(item).then(function () {
  328. }, function (erro) {
  329. msg.error(erro.data.message);
  330. });
  331. }
  332. $scope.$on('$ionicView.beforeEnter', function (viewResult) {
  333. $scope.load(true);
  334. });
  335. }]);
  336. app.controller('myMessageDetailCtrl', ['$scope', '$stateParams', function ($scope, $stateParams) {
  337. $scope.vm = $stateParams.item;
  338. }]);
  339. app.controller('myOrderCtrl', ['$scope', 'myService', 'msg', '$state', function ($scope, myService, msg, $state) {
  340. $scope.filter = {
  341. hasMore: false,
  342. page: 0,
  343. pageSize: 10,
  344. }
  345. $scope.items = [];
  346. $scope.load = function (init) {
  347. if (init) {
  348. $scope.filter.pageIndex = 1;
  349. $scope.items = [];
  350. }
  351. myService.listOrders($scope.filter).then(function (result) {
  352. $scope.filter.pageIndex++;
  353. var more = (result.data.data.length >= $scope.filter.pageSize);
  354. $scope.filter.hasMore = more;
  355. $scope.items = $scope.items.concat(result.data.data);
  356. if (init) {
  357. $scope.$broadcast('scroll.refreshComplete');
  358. } else {
  359. $scope.$broadcast('scroll.infiniteScrollComplete');
  360. }
  361. }, function (erro) {
  362. msg.error(erro.data.message);
  363. });
  364. }
  365. $scope.pay = function (item,$event) {
  366. $event.stopPropagation();
  367. msg.text('支付尚未开通,敬请期待');
  368. //var price = item.message.data.price;
  369. //window.alipay.pay({
  370. // tradeNo: new Date().getTime(),
  371. // subject: "测试标题",
  372. // body: "我是测试内容",
  373. // price: price,
  374. // notifyUrl: "http://your.server.notify.url"
  375. //}, function (successResults) { alert(successResults) }, function (errorResults) { alert(errorResults) });
  376. //to do
  377. }
  378. $scope.delete = function (item,$event) {
  379. $event.stopPropagation();
  380. msg.confirm('删除提示', '确定删除?').then(function (res) {
  381. if (res) {
  382. msg.loading('删除中...');
  383. myService.deleteOrder(item.id).then(function (result) {
  384. msg.hide();
  385. $scope.load(true);
  386. }, function (erro) {
  387. msg.hide();
  388. msg.error(erro.data.message);
  389. })
  390. } else {
  391. }
  392. });
  393. }
  394. $scope.detail = function (item) {
  395. $state.go('wl.my_order_detail', { item: item });
  396. }
  397. $scope.$on('$ionicView.beforeEnter', function (viewResult) {
  398. $scope.load(true);
  399. });
  400. }]);
  401. app.controller('myOrderDetailCtrl', ['$scope', '$stateParams', function ($scope, $stateParams) {
  402. $scope.vm = $stateParams.item;
  403. }]);
  404. })(angular.module('app.controllers'));