factory.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. starter.factory('ErpBx', function ($resource, $cordovaFileTransfer, $q, cfg, formatFilter, global, $timeout) {
  2. var erpbx = {};
  3. erpbx.taxrto = null;
  4. erpbx.recordlist = [];
  5. erpbx.tfitem = {};
  6. erpbx.chkdd_tv_arr = ['不限制', '当日', '本周', '上周', '本月', '上月', '本季', '上季', '本年', '去年'];
  7. erpbx.query = function (type) {
  8. return $resource(formatFilter('{0}ext_erp/Query/{1}/', cfg.api, type));
  9. }
  10. erpbx.linkerBX = function (type) {
  11. return $resource(formatFilter('{0}ext_erp/LinkerBX/{1}/', cfg.api, type));
  12. }
  13. erpbx.MFBX = function (type) {
  14. return $resource(formatFilter('{0}ext_erp/MFBX/{1}/', cfg.api, type));
  15. }
  16. erpbx.image = function (type) {
  17. return $resource(formatFilter('{0}ext_erp/File/{1}/', cfg.api, type));
  18. }
  19. erpbx.uploadImage = function (fileurls, table, key) {
  20. uploadUrl = formatFilter('{0}{1}ext_erp/File/PostUpload/?table={2}&key={3}', global.api, cfg.api, table, key);
  21. var promises = [];
  22. _.each(_.isArray(fileurls) ? fileurls : [fileurls], function (itemfile) {
  23. var defer_up = $q.defer();
  24. var options = new FileUploadOptions();
  25. options.headers = {
  26. cid: {"linkid": global.user.compno, "langid": "TW", "phone": global.user.cellphone},
  27. authorization: 'Token ' + global.user.token
  28. }
  29. $cordovaFileTransfer.upload(uploadUrl, itemfile, options, true).then(function (res) {
  30. defer_up.resolve(res);
  31. }, function (err) {
  32. console.log(JSON.stringify(err));
  33. defer_up.reject(err);
  34. });
  35. promises.push(defer_up.promise);
  36. });
  37. return $q.all(promises);
  38. }
  39. return erpbx;
  40. });