confirm.js 35 KB

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