starter.factory('ErpBx', function ($resource, $cordovaFileTransfer, $q, cfg, formatFilter, global, $timeout) { var erpbx = {}; erpbx.taxrto = null; erpbx.recordlist = []; erpbx.tfitem = {}; erpbx.chkdd_tv_arr = ['不限制', '当日', '本周', '上周', '本月', '上月', '本季', '上季', '本年', '去年']; erpbx.query = function (type) { return $resource(formatFilter('{0}ext_erp/Query/{1}/', cfg.api, type)); } erpbx.linkerBX = function (type) { return $resource(formatFilter('{0}ext_erp/LinkerBX/{1}/', cfg.api, type)); } erpbx.MFBX = function (type) { return $resource(formatFilter('{0}ext_erp/MFBX/{1}/', cfg.api, type)); } erpbx.image = function (type) { return $resource(formatFilter('{0}ext_erp/File/{1}/', cfg.api, type)); } erpbx.uploadImage = function (fileurls, table, key) { uploadUrl = formatFilter('{0}{1}ext_erp/File/PostUpload/?table={2}&key={3}', global.api, cfg.api, table, key); var promises = []; _.each(_.isArray(fileurls) ? fileurls : [fileurls], function (itemfile) { var defer_up = $q.defer(); var options = new FileUploadOptions(); options.headers = { cid: {"linkid": global.user.compno, "langid": "TW", "phone": global.user.cellphone}, authorization: 'Token ' + global.user.token } $cordovaFileTransfer.upload(uploadUrl, itemfile, options, true).then(function (res) { defer_up.resolve(res); }, function (err) { console.log(JSON.stringify(err)); defer_up.reject(err); }); promises.push(defer_up.promise); }); return $q.all(promises); } return erpbx; });