confirm.js 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. var shoppingConfirm = new Vue({
  2. el: "#shoppingConfirm",
  3. data: {
  4. userId: 0,
  5. userIdentity: '',
  6. userToken: '',
  7. type: '',
  8. productIds: '',
  9. listData: [],
  10. kindCount: 0,
  11. totalCount: 0,
  12. totalPrice: 0,
  13. reducedPrice: 0, // 满减金额
  14. couponAmount:0, // 优惠券金额
  15. totalDiscountAmount:0, // 共减金额
  16. address: {
  17. id: '',
  18. townId: '',
  19. cityId: '',
  20. provinceId: '',
  21. name: '',
  22. mobile: '',
  23. desc: '',
  24. town: '',
  25. city: '',
  26. province: '',
  27. default: '',
  28. selectedId: ''
  29. },
  30. addressList: [],
  31. isShowAddressList: false,
  32. isShowAddressForm: false,
  33. addressForm: {
  34. id: '',
  35. name: '',
  36. mobile: '',
  37. townId: '',
  38. cityId: '',
  39. provinceId: '',
  40. desc: '',
  41. default: ''
  42. },
  43. provinceOptions:[],
  44. cityOptions:[],
  45. townOptions:[],
  46. saveLoading: false,
  47. rule:{
  48. name: '^[a-zA-Z\\u4e00-\\u9fa5]{2,}$',
  49. mobile: '^\\d{6,12}$'
  50. },
  51. balance: {
  52. isFreight:false, //使用采美豆抵扣运费
  53. flag: false, //使用余额抵扣
  54. originUserMoney: 0, //初始化后不能改变,用于还原余额抵扣
  55. userMoney: 0, //显示可使用余额
  56. deductMoney: 0, //显示已使用的余额
  57. surplusMoney: 0 //显示勾选后的剩余抵扣
  58. },
  59. payInfo: {
  60. clauseId: 0, //条款(暂时保留)
  61. orderShouldPayFee: 0.00,//提交的总价
  62. balancePayFlag: 0, //余额抵扣的状态 0不使用,1使用
  63. freight: 0.00, //邮费
  64. freePostFlag:-1 // 0包邮 -1到付 1 有运费
  65. },
  66. clubCouponId:0, // 用户关联优惠Id
  67. invoice: {
  68. id:'',
  69. type: 0,
  70. invoiceTitleType: 0, //发票抬头类型 1企业 0个人
  71. invoiceTitle: '', //单位名称
  72. corporationTaxNum:'',//纳税人识别号
  73. registeredAddress: '',//单位地址
  74. registeredPhone:'', //注册电话
  75. openBank:'', //开户银行
  76. bankAccountNo: '', //银行账号
  77. },
  78. isBeansShow:false,
  79. userBeans:0,
  80. freightBeansMoney:0,
  81. freightMoney:0,
  82. deductionBeans:0,
  83. hanldUserBeans:0,
  84. submitLoading: false,
  85. checkedIndex:null,
  86. couponList:[], // 可用优惠券列表
  87. isCouponShow:false,
  88. },
  89. computed: {
  90. },
  91. filters: {
  92. NumFormat:function(num) {
  93. var temp = String(num).split('.');
  94. if (temp.length === 1 || temp[1].length < 2) {
  95. return Number(num).toFixed(2);
  96. }else{
  97. return Number(num);
  98. }
  99. },
  100. TypeFormat:function(value) {
  101. switch (value) {
  102. case 0:
  103. return '活动券';
  104. break;
  105. case 1:
  106. return '品类券';
  107. break;
  108. case 2:
  109. return '用户专享券';
  110. break;
  111. case 3:
  112. return '店铺券';
  113. break;
  114. case 4:
  115. return '新用户券';
  116. break;
  117. }
  118. }
  119. },
  120. methods: {
  121. blurHandle: function(event) {
  122. var el = event.currentTarget;
  123. verifyHandle(el);
  124. },
  125. getConfirmList: function (productCount) {// 初始化确认订单信息
  126. var _self = this;
  127. if(this.userId ===0){return;}
  128. OrderApi.GetOrderConfirmInfo({
  129. userId: _self.userId,
  130. count: productCount,
  131. productIds: this.productIds
  132. },function(response){
  133. if (response.code === 0 ) {
  134. var data = response.data;
  135. _self.listData = data.list;
  136. _self.totalPrice = data.totalPrice;
  137. _self.reducedPrice = data.reducedPrice;
  138. _self.totalCount = data.totalCount;
  139. _self.kindCount = data.kindCount;
  140. _self.balance.userMoney = data.userMoney;
  141. _self.balance.originUserMoney = data.userMoney;
  142. _self.payInfo.orderShouldPayFee = data.totalPrice;
  143. _self.getAddressList(_self.userId,20);
  144. if( data.couponList && data.couponList.length>0){
  145. _self.isCouponShow = true;
  146. _self.couponAmount = data.couponList[0].couponAmount;
  147. _self.clubCouponId = data.couponList[0].clubCouponId;
  148. data.couponList.forEach((el) => {
  149. _self.couponList.push(Object.assign(el,{ischecked:false}))
  150. })
  151. _self.couponList[0].ischecked = true;
  152. _self.payInfo.orderShouldPayFee = data.totalPrice - _self.couponAmount;
  153. console.log('111111111',_self.payInfo.orderShouldPayFee)
  154. }
  155. _self.totalDiscountAmount = _self.reducedPrice + _self.couponAmount;
  156. if(data.invoice){
  157. data.invoice.type = 0;
  158. _self.invoice = data.invoice;
  159. }
  160. }else{
  161. CAIMEI.Alert(r.msg, '确定', false);
  162. }
  163. });
  164. },
  165. getFreight: function(townId){// 获取邮费
  166. var _self = this;
  167. OrderApi.GetOrderPostage({
  168. userId: this.userId,
  169. productIds: this.productIds,
  170. totalPrice: this.totalPrice,
  171. townId: townId
  172. },function (r) {
  173. if(r.code === 0 && r.data){
  174. _self.payInfo.freePostFlag = r.data.freePostFlag;
  175. _self.userBeans = r.data.userBeans;
  176. _self.payInfo.freight = (r.data.freePostFlag===1 ? r.data.freight : 0);
  177. _self.payInfo.orderShouldPayFee = _self.totalPrice + _self.payInfo.freight - _self.couponAmount;
  178. switch (_self.payInfo.freePostFlag) {
  179. case 1:
  180. if( _self.userBeans > 0 ){
  181. _self.freightBeansMoney = r.data.freight;
  182. _self.freightMoney = r.data.freight;
  183. _self.isBeansShow = true;
  184. }else{
  185. _self.freightBeansMoney = 0;
  186. _self.balance.isFreight = false;
  187. _self.isBeansShow = false;
  188. }
  189. if(r.data.userBeans >= _self.freightBeansMoney*100){
  190. _self.deductionBeans = _self.freightBeansMoney*100
  191. }else{
  192. _self.deductionBeans = _self.userBeans
  193. }
  194. _self.changeDeductibleFreight();
  195. break;
  196. case -1:
  197. if( _self.userBeans > 0 ){
  198. _self.freightMoney = '到付';
  199. _self.freightBeansMoney = 30;
  200. _self.isBeansShow = true;
  201. }else{
  202. _self.freightBeansMoney = 0;
  203. _self.balance.isFreight = false;
  204. _self.isBeansShow = false;
  205. }
  206. if(r.data.userBeans >= _self.freightBeansMoney*100){
  207. _self.deductionBeans = _self.freightBeansMoney*100
  208. }else{
  209. _self.deductionBeans = _self.userBeans
  210. }
  211. _self.changeDeductibleFreight();
  212. break;
  213. }
  214. }else{
  215. CAIMEI.Alert(r.msg, '确定', false);
  216. }
  217. })
  218. },
  219. getAddressList: function(userId,pageSize){ // 获取收货地址
  220. var _self = this;
  221. OrderApi.GetAddressList({
  222. userID:userId,
  223. pageNum:1,
  224. pageSize:pageSize
  225. },function (r) {
  226. if(r.code === 0 && r.data){
  227. if(r.data.results){
  228. _self.addressList = r.data.results;
  229. _self.address.id = r.data.results[0].addressID;
  230. _self.address.townId = r.data.results[0].townID;
  231. _self.address.cityId = r.data.results[0].cityID;
  232. _self.address.provinceId = r.data.results[0].provinceID;
  233. _self.address.name = r.data.results[0].shouHuoRen;
  234. _self.address.mobile = r.data.results[0].mobile;
  235. _self.address.desc = r.data.results[0].address;
  236. _self.address.town = r.data.results[0].town;
  237. _self.address.city = r.data.results[0].city;
  238. _self.address.province = r.data.results[0].province;
  239. _self.address.default = true;
  240. _self.address.selectedId = r.data.results[0].addressID;
  241. _self.getFreight(_self.address.townId);
  242. }else{
  243. _self.createAddress();
  244. }
  245. _self.getProvinceOptions();
  246. }else {
  247. CAIMEI.Alert(r.msg, '确定', false);
  248. _self.createAddress();
  249. }
  250. })
  251. },
  252. getProvinceOptions: function(){ // 获取全部省份
  253. var _self = this;
  254. PublicApi.GetProvince({},function(r){
  255. if(r.code === 0 && r.data){
  256. _self.provinceOptions =r.data;
  257. }else{
  258. CAIMEI.Alert(r.msg,'确定',false);
  259. }
  260. });
  261. },
  262. getCityOptions: function(provinceId,callback){// 获取地区
  263. var _self = this;
  264. if(provinceId && provinceId>0){
  265. _self.cityOptions = [];
  266. _self.townOptions = [];
  267. _self.addressForm.cityId = '';
  268. _self.addressForm.townId = '';
  269. PublicApi.GetCity({ provinceId: provinceId },function(r){
  270. if(r.code === 0 && r.data){
  271. _self.cityOptions = r.data;
  272. if(callback){callback();}
  273. }else{
  274. CAIMEI.Alert(r.msg,'确定',false);
  275. }
  276. });
  277. }
  278. },
  279. getTownOptions: function(cityId, callback){
  280. var _self = this;
  281. if(cityId && cityId>0){
  282. _self.townOptions = [];
  283. _self.addressForm.townId = '';
  284. PublicApi.GetTown({cityId: cityId},function(r){
  285. if(r.code === 0 && r.data){
  286. _self.townOptions = r.data;
  287. if(callback){callback();}
  288. }else{
  289. CAIMEI.Alert(r.msg,'确定',false);
  290. }
  291. })
  292. }
  293. },
  294. showAddressBox: function(){// 显示地址弹窗
  295. this.isShowAddressList = true;
  296. if(!isPC){fixedBody();}
  297. },
  298. closeAddressBox: function(){// 关闭地址弹窗
  299. this.isShowAddressList = false;
  300. if(!isPC){looseBody();}
  301. },
  302. hideAddressForm: function(){// 隐藏地址表单
  303. this.isShowAddressForm = false;
  304. if(!isPC){looseBody();}
  305. },
  306. createAddress: function(){// 新建地址
  307. this.isShowAddressForm = true;
  308. this.addressForm.name= '';
  309. this.addressForm.mobile= '';
  310. this.addressForm.townId= '';
  311. this.addressForm.cityId= '';
  312. this.addressForm.provinceId= '';
  313. this.addressForm.desc= '';
  314. this.addressForm.default= '';
  315. this.getProvinceOptions();
  316. if(!isPC){fixedBody();}
  317. },
  318. updateAddress: function(){// 更新选择地址
  319. this.isShowAddressForm = true;
  320. this.addressForm.id = this.address.id;
  321. this.addressForm.name = this.address.name;
  322. this.addressForm.mobile = this.address.mobile;
  323. this.addressForm.default = this.address.default;
  324. this.addressForm.desc = this.address.desc;
  325. this.addressForm.provinceId = this.address.provinceId;
  326. var _self = this;
  327. this.getCityOptions(this.address.provinceId, function(){
  328. _self.addressForm.cityId = _self.address.cityId;
  329. _self.getTownOptions(_self.address.cityId,function(){
  330. _self.addressForm.townId = _self.address.townId;
  331. });
  332. });
  333. if(!isPC){fixedBody();}
  334. },
  335. saveAddressForm: function(){// 更新保存地址
  336. var _self = this;
  337. var pass = verifyForm();
  338. if (_self.saveLoading) { return false; }
  339. this.$nextTick(function() {
  340. if (!pass) {return false;}
  341. if(!_self.addressForm.townId){
  342. CAIMEI.dialog('请选择所在地区');
  343. return false;
  344. };
  345. _self.saveLoading = true;
  346. var params = {
  347. userID:_self.userId, //用户id ,只在新增收货地址时传
  348. shouHuoRen:_self.addressForm.name, //收货人
  349. mobile:_self.addressForm.mobile, //手机
  350. townID:_self.addressForm.townId, //区ID
  351. address:_self.addressForm.desc, //地址
  352. defaultFlag:_self.addressForm.default?1:0 //是否默认收货地址(0 不是默认,1 默认)
  353. };
  354. if(_self.addressForm.id){
  355. // 编辑
  356. params.addressID = _self.addressForm.id;//编辑保存地址ID
  357. }
  358. _self.saveAddress(params);
  359. });
  360. },
  361. saveAddress: function(params){// 更新保存地址
  362. var _self = this;
  363. OrderApi.AddSaveAddress(params,function(r){
  364. if(r.code === 0){
  365. CAIMEI.dialog('保存成功');
  366. _self.saveLoading = false;
  367. _self.isShowAddressForm = false;
  368. // 重新获取地址列表
  369. _self.getAddressList(_self.userId,20);
  370. }else{
  371. CAIMEI.Alert(r.msg,'确定',false);
  372. }
  373. });
  374. },
  375. setDefaultAddress: function(addressId){// 列表直接设为默认地址
  376. var _self = this;
  377. OrderApi.DefaultAddress({addressId:addressId,userId:_self.userId},function (r) {
  378. if(r.code === 0 ){
  379. // 重新获取地址列表
  380. _self.getAddressList(_self.userId,20);
  381. }else{
  382. CAIMEI.Alert(r.msg,'确定',false);
  383. }
  384. });
  385. },
  386. deleteAddress: function(addressId){// 列表删除单个地址
  387. var _self = this;
  388. CAIMEI.Modal('确定要删除该地址?','取消','确定',function () {
  389. OrderApi.DeleteAddress({addressID:addressId,userID:_self.userId},function (r) {
  390. if(r.code === 0 ){
  391. CAIMEI.dialog('删除成功');
  392. // 重新获取地址列表
  393. _self.getAddressList(_self.userId,20);
  394. }else{
  395. CAIMEI.Alert(r.msg,'确定',false);
  396. }
  397. })
  398. });
  399. },
  400. chooseAddress: function(selectedId){
  401. this.address.selectedId = selectedId;
  402. },
  403. confirmAddress: function(){// 确认地址并查询邮费
  404. var _self = this;
  405. this.addressList.forEach(function(item){
  406. if (_self.address.selectedId==item.addressID){
  407. _self.address.id = item.addressID;
  408. _self.address.townId = item.townID;
  409. _self.address.cityId = item.cityID;
  410. _self.address.provinceId = item.provinceID;
  411. _self.address.name = item.shouHuoRen;
  412. _self.address.mobile = item.mobile;
  413. _self.address.desc = item.address;
  414. _self.address.town = item.town;
  415. _self.address.city = item.city;
  416. _self.address.province = item.province;
  417. _self.address.default = (item.defaultFlag > 0);
  418. _self.getFreight(_self.address.townId);
  419. }
  420. });
  421. this.closeAddressBox();
  422. },
  423. checkedCoupon:function(idx){// 选择优惠券
  424. var _self = this;
  425. var coupon = { couponAmount:0,clubCouponId:0 };
  426. _self.checkedIndex = idx;
  427. _self.couponList.forEach((el,index) => {
  428. if(_self.checkedIndex == index){
  429. el.ischecked = !el.ischecked;
  430. }else{
  431. el.ischecked = false;
  432. }
  433. if(el.ischecked){
  434. coupon.couponAmount = el.couponAmount;
  435. coupon.clubCouponId = el.clubCouponId;
  436. }
  437. })
  438. _self.couponAmount = coupon.couponAmount;
  439. _self.totalDiscountAmount = _self.reducedPrice + _self.couponAmount;
  440. _self.clubCouponId = coupon.clubCouponId;
  441. _self.changeDeductibleFreight();
  442. _self.useUserMoney();
  443. },
  444. toggleThisLadder: function(event){
  445. var el = event.currentTarget;
  446. if($(el).hasClass("on")){
  447. $(el).removeClass("on").siblings('.mFixed').hide();
  448. if(!isPC){looseBody();}
  449. }else{
  450. $(el).addClass("on").siblings('.mFixed').show();
  451. if(!isPC){fixedBody();}
  452. }
  453. },
  454. hideThisLadder: function(event){
  455. var el = event.currentTarget;
  456. $(el).parents('.priceTag').find('.tag').removeClass("on").siblings('.mFixed').hide();
  457. if(!isPC){looseBody();}
  458. },
  459. useUserMoney: function(){//勾选余额抵扣
  460. var _self = this;
  461. if(this.balance.userMoney>0){
  462. this.$nextTick(function() {
  463. var total = _self.totalPrice + _self.payInfo.freight - _self.couponAmount; // 订单总金额 + 邮费金额
  464. if(_self.balance.flag){
  465. _self.payInfo.balancePayFlag = 1;
  466. if(_self.balance.userMoney >= total){ // 全部抵扣
  467. _self.payInfo.orderShouldPayFee = 0;
  468. if(_self.balance.isFreight){// 勾选了采美豆丢运费
  469. _self.balance.deductMoney = _self.totalPrice - _self.couponAmount; // 抵扣使用金额 = 订单总金额
  470. _self.balance.surplusMoney = _self.repiceNumSub(_self.balance.userMoney,_self.totalPrice); // 抵扣后剩余余额 = 余额总额 - (订单总金额+邮费金额)
  471. console.log('余额全部抵扣勾选了采美豆运费',_self.balance.surplusMoney)
  472. }else{
  473. _self.balance.deductMoney = total; // 抵扣使用金额 = 订单总金额 + 邮费金额 - 优惠券金额
  474. _self.balance.surplusMoney = _self.repiceNumSub(_self.balance.userMoney,_self.balance.deductMoney); // 抵扣后剩余余额 = 余额总额 - 抵扣使用金额
  475. console.log('余额全部抵扣未勾选了采美豆运费',_self.balance.surplusMoney)
  476. }
  477. }else{ // 部分抵扣
  478. if(_self.balance.isFreight){// 勾选了采美豆丢运费
  479. _self.payInfo.orderShouldPayFee = _self.repiceNumSub(_self.totalPrice,_self.balance.userMoney) - _self.couponAmount; // 最终订单总价 = 订单总金额 - 余额总额
  480. _self.balance.deductMoney = _self.balance.userMoney; // 抵扣使用金额 = 余额总额
  481. _self.balance.surplusMoney = 0; // 抵扣后剩余余额 = 0
  482. console.log('部分抵扣勾选了采美豆运费',_self.payInfo.orderShouldPayFee)
  483. }else{
  484. _self.payInfo.orderShouldPayFee = _self.repiceNumSub(total,_self.balance.userMoney); // 最终订单总价 = 订单总金额 - 余额总额
  485. _self.balance.deductMoney = _self.balance.userMoney; // 抵扣使用金额 = 余额总额
  486. _self.balance.surplusMoney = 0; // 抵扣后剩余余额 = 0
  487. console.log('部分抵扣没有勾选了采美豆运费',_self.payInfo.orderShouldPayFee)
  488. }
  489. }
  490. }else{// 取消抵扣
  491. _self.payInfo.balancePayFlag = 0;
  492. _self.balance.userMoney = _self.balance.originUserMoney;
  493. _self.balance.deductMoney = 0;
  494. _self.balance.surplusMoney = _self.balance.originUserMoney;
  495. if(_self.balance.isFreight){//判断是否有采美豆抵扣运费
  496. _self.payInfo.orderShouldPayFee = _self.totalPrice - _self.couponAmount; // 最终订单总价 = 订单总金额
  497. }else{
  498. _self.payInfo.orderShouldPayFee = total; // 最终订单总价 = 订单总金额 + 邮费金额
  499. }
  500. console.log('取消余额抵扣',_self.payInfo.orderShouldPayFee)
  501. }
  502. });
  503. }
  504. },
  505. changeDeductibleFreight: function(){//选择采美豆抵扣邮费
  506. var _self = this;
  507. var total = _self.totalPrice + _self.payInfo.freight - _self.couponAmount;
  508. if(_self.balance.isFreight){//判断是否勾选运费
  509. if(_self.payInfo.freePostFlag == 1){//有邮费
  510. _self.hanldUserBeans = _self.freightBeansMoney*100;
  511. if( _self.userBeans > 0 ){// 判断采美豆大于0
  512. if(_self.balance.flag) {// 勾选了余额抵扣
  513. console.log('订单总额',total)
  514. if(_self.balance.userMoney>=total){ // 全部抵扣
  515. _self.payInfo.orderShouldPayFee = 0;
  516. _self.balance.deductMoney = _self.totalPrice; // 抵扣使用金额 = 订单总金额
  517. _self.balance.surplusMoney = _self.repiceNumSub(_self.balance.userMoney,_self.balance.deductMoney); // 抵扣后剩余余额 = 余额总额 - 抵扣使用金额
  518. console.log('有勾选余额抵扣全抵',_self.payInfo.orderShouldPayFee)
  519. }else{ // 部分抵扣
  520. _self.payInfo.orderShouldPayFee = _self.repiceNumSub(_self.totalPrice,_self.balance.userMoney) - _self.couponAmount;
  521. _self.balance.deductMoney = _self.balance.userMoney; // 抵扣使用金额 = 余额总额
  522. _self.balance.surplusMoney = _self.repiceNumSub(_self.balance.userMoney,_self.balance.deductMoney); // 抵扣后剩余余额 = 余额总额 - 抵扣使用金额
  523. console.log('有勾选余额抵扣部分抵',_self.payInfo.orderShouldPayFee)
  524. }
  525. }else{
  526. console.log('订单总额2222222',total)
  527. _self.payInfo.orderShouldPayFee = ((_self.totalPrice*100 + _self.payInfo.freight*100 - _self.freightBeansMoney*100)/100) - _self.couponAmount;
  528. console.log('无余额抵扣',_self.payInfo.orderShouldPayFee)
  529. }
  530. }
  531. }else if(_self.payInfo.freePostFlag == -1){// 到付
  532. _self.hanldUserBeans = _self.freightBeansMoney*100;
  533. if(_self.balance.flag) {// 勾选了余额抵扣
  534. if(_self.balance.userMoney>=total){ // 全部抵扣
  535. _self.payInfo.orderShouldPayFee = 0;
  536. _self.balance.deductMoney = _self.totalPrice; // 抵扣使用金额 = 订单总金额
  537. _self.balance.surplusMoney = _self.repiceNumSub(_self.balance.userMoney,_self.balance.deductMoney); // 抵扣后剩余余额 = 余额总额 - 抵扣使用金额
  538. console.log('到付有勾选余额抵扣全抵',_self.payInfo.orderShouldPayFee)
  539. }else{ // 部分抵扣
  540. _self.payInfo.orderShouldPayFee = _self.repiceNumSub(_self.totalPrice,_self.balance.userMoney) - _self.couponAmount;
  541. _self.balance.deductMoney = _self.balance.userMoney; // 抵扣使用金额 = 余额总额
  542. _self.balance.surplusMoney = _self.repiceNumSub(_self.balance.userMoney,_self.balance.deductMoney); // 抵扣后剩余余额 = 余额总额 - 抵扣使用金额
  543. console.log('到付有勾选余额抵扣部分抵',_self.payInfo.orderShouldPayFee)
  544. }
  545. }else{
  546. _self.payInfo.orderShouldPayFee = _self.totalPrice - _self.couponAmount ;
  547. console.log('到付未勾选余额抵扣',_self.payInfo.orderShouldPayFee)
  548. }
  549. }else{
  550. _self.hanldUserBeans = 0;
  551. _self.payInfo.orderShouldPayFee = _self.totalPrice - _self.couponAmount ;
  552. console.log('其他',_self.payInfo.orderShouldPayFee)
  553. }
  554. }else{
  555. console.log('未勾选采美豆抵扣')
  556. _self.hanldUserBeans = 0;
  557. if(_self.balance.flag) {//如果勾选了余额抵扣
  558. if(_self.balance.userMoney>=total) { // 全部抵扣
  559. console.log('勾选采美豆抵扣=========》',total)
  560. _self.payInfo.orderShouldPayFee = 0 ;
  561. _self.balance.deductMoney = total; // 抵扣使用金额 = (订单总金额+邮费金额-优惠券价格)
  562. _self.balance.surplusMoney = _self.repiceNumSub(_self.balance.userMoney,_self.balance.deductMoney); // 抵扣后剩余余额 = 余额总额 - 抵扣使用金额
  563. console.log('余额全抵抵未勾选采美豆抵扣',_self.payInfo.orderShouldPayFee)
  564. }else{
  565. console.log('未勾选采美豆抵扣=========》',total)
  566. _self.payInfo.orderShouldPayFee = _self.repiceNumSub(total,_self.balance.userMoney);
  567. _self.balance.deductMoney = _self.balance.userMoney; // 抵扣使用金额 = (订单总金额+邮费金额)
  568. _self.balance.surplusMoney = _self.repiceNumSub(_self.balance.userMoney,_self.balance.deductMoney); // 抵扣后剩余余额 = 余额总额 - 抵扣使用金额
  569. console.log('余额部分抵未勾选采美豆抵扣',_self.payInfo.orderShouldPayFee)
  570. }
  571. }else{
  572. _self.payInfo.orderShouldPayFee = (_self.totalPrice + _self.payInfo.freight) - _self.couponAmount;
  573. }
  574. }
  575. },
  576. repiceNumSub: function(arg1, arg2) {//减法精确,arg2:被减数,arg1:减数
  577. var r1,r2,m,n;
  578. try{
  579. r1=arg1.toString().split(".")[1].length
  580. }catch(e){
  581. r1=0
  582. }
  583. try{
  584. r2=arg2.toString().split(".")[1].length
  585. }catch(e){
  586. r2=0
  587. }
  588. m=Math.pow(10,Math.max(r1,r2));
  589. // last modify by deeka
  590. // 动态控制精度长度
  591. n=(r1>=r2)?r1:r2;
  592. return ((arg1*m-arg2*m)/m).toFixed(n);
  593. },
  594. submitOrder: function(){
  595. var _self = this;
  596. if(this.submitLoading){return false;}
  597. if(!this.address.id){
  598. CAIMEI.dialog('请先添加收货地址~');
  599. return false;
  600. }
  601. if(this.invoice.type*1 === 1){
  602. // 普通发票
  603. if(!this.invoice.invoiceTitle){
  604. CAIMEI.dialog('请输入个人抬头');return false;
  605. }
  606. if(this.invoice.invoiceTitleType===1 && !this.invoice.corporationTaxNum){
  607. CAIMEI.dialog('请输入纳税人识别号');return false;
  608. }
  609. }else if(this.invoice.type*1 === 2){
  610. // 增值税发票
  611. if(!this.invoice.invoiceTitle){
  612. CAIMEI.dialog('请输入个人抬头');return false;
  613. }
  614. if(!this.invoice.corporationTaxNum){
  615. CAIMEI.dialog('请输入纳税人识别号');return false;
  616. }
  617. if(!this.invoice.registeredAddress){
  618. CAIMEI.dialog('请输入单位地址');return false;
  619. }
  620. if(!this.invoice.registeredPhone){
  621. CAIMEI.dialog('请输入注册电话');return false;
  622. }
  623. if(!this.invoice.openBank){
  624. CAIMEI.dialog('请输入开户银行');return false;
  625. }
  626. if(!this.invoice.bankAccountNo){
  627. CAIMEI.dialog('请输入银行账号');return false;
  628. }
  629. }
  630. // 禁用按钮
  631. this.submitLoading = true;
  632. // 发票信息
  633. if(this.invoice.type*1 === 0){
  634. this.invoice = Object.assign(this.invoice,'',{type:0});
  635. }else if(this.invoice.type*1 === 1){
  636. this.invoice = Object.assign(this.invoice,'',{type:1, invoiceContent: '商品明细'});
  637. }else if(this.invoice.type*1 === 2){
  638. this.invoice = Object.assign(this.invoice,'',{type:2});
  639. }
  640. //商品信息
  641. var _orderInfo = this.listData.map(function(supplier){
  642. var productInfo = [];
  643. supplier.cartList.forEach(function(item){
  644. productInfo.push({
  645. productId:item.productId,
  646. productNum:item.number,
  647. presentNum:0,
  648. productType:item.productType
  649. })
  650. });
  651. return {
  652. shopId: supplier.id,
  653. note: supplier.note ? supplier.note : '',
  654. productInfo: productInfo
  655. }
  656. });
  657. var _payInfo = {
  658. clauseId: 0,
  659. orderShouldPayFee: toFloat(this.payInfo.orderShouldPayFee),
  660. balancePayFlag: this.payInfo.balancePayFlag,
  661. freight: toFloat(this.payInfo.freight),
  662. freePostFlag: this.payInfo.freePostFlag,
  663. userBeans:this.hanldUserBeans
  664. };
  665. var params = {
  666. clubCouponId:this.clubCouponId,
  667. cartType: this.type,
  668. orderSource: 1, // 购买类型:(1购物车提交[对应表cm_cart],2直接购买提交, 3协销下单)
  669. serviceProviderId: '', // 协销ID(小程序忽略)
  670. clubUserId: this.userId, // 机构用户ID
  671. addressId: this.address.id,// 地址ID
  672. orderInfo: _orderInfo, // 商品信息
  673. payInfo: _payInfo, // 订单信息
  674. orderInvoice: this.invoice // 发票信息
  675. };
  676. OrderApi.ConfirmOrder({'params':JSON.stringify(params)},function (r) {
  677. if(r.code === 0){
  678. var _data = r.data;
  679. if(Number(_data.code) === 1){//余额抵扣全部订单金额
  680. var data = { payableAmount: _self.deductMoney };
  681. CAIMEI.Storage.removeItem('confirmOrderInfo');
  682. CAIMEI.Storage.setItem('confirmOrderInfo',JSON.stringify({data:data}));
  683. window.location.href = '/pay/success.html?pageType=www&type=success&payAmount='+_data.payTotalFee;
  684. }else{//余额抵扣部分订单金额或者未支付的
  685. var data = {
  686. orderID:_data.orderID,
  687. orderNo:_data.orderNo,
  688. orderMark:_data.orderMark,
  689. payableAmount:_data.payableAmount
  690. };
  691. CAIMEI.Storage.removeItem('confirmOrderInfo');
  692. CAIMEI.Storage.setItem('confirmOrderInfo',JSON.stringify({data:data}));
  693. window.location.href = '/pay/caimei-paycash.html?type=confirm&orderID='+_data.orderID;
  694. }
  695. }else{
  696. CAIMEI.Alert(r.msg,'确定',true, function(){
  697. setTimeout(function(){
  698. _self.submitLoading = false;
  699. },500);
  700. });
  701. }
  702. });
  703. }
  704. },
  705. created: function () {
  706. this.type = getUrlParam("type") ? getUrlParam("type")*1 : "";
  707. if(globalUserData){
  708. this.userId = globalUserData.userId;
  709. this.userIdentity = globalUserData.identity;
  710. this.userToken = globalUserData.token;
  711. // type:(1购物车提交[对应表cm_cart],2直接购买提交, 3协销下单)
  712. if(this.type === 1) {
  713. this.productIds = window.localStorage.getItem("shoppingProductIds");
  714. // 获取列表数据
  715. this.getConfirmList(null);
  716. }else if(this.type === 2){
  717. this.productIds = getUrlParam("id");
  718. var count = getUrlParam("count");
  719. if(this.productIds && count) {
  720. // 获取列表数据
  721. this.getConfirmList(count);
  722. }else{
  723. alertInfo("参数错误,请重新提交订单!");
  724. }
  725. }
  726. }
  727. },
  728. mounted: function () {
  729. var _self = this;
  730. var minAwayBtm = $("footer").height();
  731. //处理滚动条控制底部提交fixed
  732. $(window).scroll(function() {
  733. var awayBtm = $(document).height() - $(window).scrollTop() - $(window).height();
  734. if(minAwayBtm <= awayBtm){
  735. $(".summaryWrap").addClass('fixed');
  736. }else{
  737. $(".summaryWrap").removeClass("fixed");
  738. }
  739. });
  740. }
  741. });