confirm.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  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. address: {
  15. id: '',
  16. townId: '',
  17. cityId: '',
  18. provinceId: '',
  19. name: '',
  20. mobile: '',
  21. desc: '',
  22. town: '',
  23. city: '',
  24. province: '',
  25. default: '',
  26. selectedId: ''
  27. },
  28. addressList: [],
  29. isShowAddressList: false,
  30. isShowAddressForm: false,
  31. addressForm: {
  32. id: '',
  33. name: '',
  34. mobile: '',
  35. townId: '',
  36. cityId: '',
  37. provinceId: '',
  38. desc: '',
  39. default: ''
  40. },
  41. provinceOptions:[],
  42. cityOptions:[],
  43. townOptions:[],
  44. saveLoading: false,
  45. rule:{
  46. name: '^[a-zA-Z\\u4e00-\\u9fa5]{2,}$',
  47. mobile: '^\\d{6,12}$'
  48. },
  49. balance: {
  50. flag: false, //使用余额抵扣
  51. originUserMoney: 0, //初始化后不能改变,用于还原余额抵扣
  52. userMoney: 0, //显示可使用余额
  53. deductMoney: 0, //显示已使用的余额
  54. surplusMoney: 0 //显示勾选后的剩余抵扣
  55. },
  56. payInfo: {
  57. clauseId: 0, //条款(暂时保留)
  58. orderShouldPayFee: 0.00,//提交的总价
  59. balancePayFlag: 0, //余额抵扣的状态 0不使用,1使用
  60. freight: 0.00, //邮费
  61. freePostFlag:-1 // 0包邮 -1到付 1 有运费
  62. },
  63. invoice: {
  64. type: 0,
  65. invoiceTitleType: 0, //发票抬头类型 1企业 0个人
  66. invoiceTitle: '', //单位名称
  67. corporationTaxNum:'',//纳税人识别号
  68. registeredAddress: '',//单位地址
  69. registeredPhone:'', //注册电话
  70. openBank:'', //开户银行
  71. bankAccountNo: '' //银行账号
  72. },
  73. submitLoading: false
  74. },
  75. computed: {
  76. },
  77. filters: {
  78. NumFormat:function(num) {
  79. var temp = String(num).split('.');
  80. if (temp.length === 1 || temp[1].length < 2) {
  81. return Number(num).toFixed(2);
  82. }else{
  83. return Number(num);
  84. }
  85. }
  86. },
  87. methods: {
  88. blurHandle: function(event) {
  89. var el = event.currentTarget;
  90. verifyHandle(el);
  91. },
  92. getConfirmList: function (productCount) {
  93. var _self = this;
  94. if(this.userId ===0){return;}
  95. OrderApi.GetOrderConfirmInfo({
  96. userId: _self.userId,
  97. count: productCount,
  98. productIds: this.productIds
  99. },function(r){
  100. if (r.code === 0 && r.data) {
  101. _self.listData = r.data.list;
  102. _self.totalPrice = r.data.totalPrice;
  103. _self.reducedPrice = r.data.reducedPrice;
  104. _self.totalCount = r.data.totalCount;
  105. _self.kindCount = r.data.kindCount;
  106. _self.balance.userMoney = r.data.userMoney;
  107. _self.balance.originUserMoney = r.data.userMoney;
  108. _self.payInfo.orderShouldPayFee = r.data.totalPrice;
  109. _self.getAddressList(_self.userId,20);
  110. }else{
  111. CAIMEI.Alert(r.msg, '确定', false);
  112. }
  113. });
  114. },
  115. // 获取邮费
  116. getFreight: function(townId){
  117. var _self = this;
  118. OrderApi.GetOrderPostage({
  119. userId: this.userId,
  120. productIds: this.productIds,
  121. totalPrice: this.totalPrice,
  122. townId: townId
  123. },function (r) {
  124. if(r.code === 0 && r.data){
  125. _self.payInfo.freePostFlag = r.data.freePostFlag;
  126. _self.payInfo.freight = (r.data.freePostFlag===1 ? r.data.freight : 0);
  127. _self.payInfo.orderShouldPayFee = _self.totalPrice + _self.payInfo.freight;
  128. }else{
  129. CAIMEI.Alert(response.msg, '确定', false);
  130. }
  131. })
  132. },
  133. // 获取收货地址
  134. getAddressList: function(userId,pageSize){
  135. var _self = this;
  136. OrderApi.GetAddressList({
  137. userID:userId,
  138. pageNum:1,
  139. pageSize:pageSize
  140. },function (r) {
  141. if(r.code === 0 && r.data){
  142. if(r.data.results){
  143. _self.addressList = r.data.results;
  144. _self.address.id = r.data.results[0].addressID;
  145. _self.address.townId = r.data.results[0].townID;
  146. _self.address.cityId = r.data.results[0].cityID;
  147. _self.address.provinceId = r.data.results[0].provinceID;
  148. _self.address.name = r.data.results[0].shouHuoRen;
  149. _self.address.mobile = r.data.results[0].mobile;
  150. _self.address.desc = r.data.results[0].address;
  151. _self.address.town = r.data.results[0].town;
  152. _self.address.city = r.data.results[0].city;
  153. _self.address.province = r.data.results[0].province;
  154. _self.address.default = true;
  155. _self.address.selectedId = r.data.results[0].addressID;
  156. _self.getFreight(_self.address.townId);
  157. }else{
  158. _self.createAddress();
  159. }
  160. _self.getProvinceOptions();
  161. }else {
  162. CAIMEI.Alert(r.msg, '确定', false);
  163. _self.createAddress();
  164. }
  165. })
  166. },
  167. // 获取全部省份
  168. getProvinceOptions: function(){
  169. var _self = this;
  170. PublicApi.GetProvince({},function(r){
  171. if(r.code === 0 && r.data){
  172. _self.provinceOptions =r.data;
  173. }else{
  174. CAIMEI.Alert(r.msg,'确定',false);
  175. }
  176. });
  177. },
  178. getCityOptions: function(provinceId,callback){
  179. var _self = this;
  180. if(provinceId && provinceId>0){
  181. _self.cityOptions = [];
  182. _self.townOptions = [];
  183. _self.addressForm.cityId = '';
  184. _self.addressForm.townId = '';
  185. PublicApi.GetCity({ provinceId: provinceId },function(r){
  186. if(r.code === 0 && r.data){
  187. _self.cityOptions = r.data;
  188. if(callback){callback();}
  189. }else{
  190. CAIMEI.Alert(r.msg,'确定',false);
  191. }
  192. });
  193. }
  194. },
  195. getTownOptions: function(cityId, callback){
  196. var _self = this;
  197. if(cityId && cityId>0){
  198. _self.townOptions = [];
  199. _self.addressForm.townId = '';
  200. PublicApi.GetTown({cityId: cityId},function(r){
  201. if(r.code === 0 && r.data){
  202. _self.townOptions = r.data;
  203. if(callback){callback();}
  204. }else{
  205. CAIMEI.Alert(r.msg,'确定',false);
  206. }
  207. })
  208. }
  209. },
  210. showAddressBox: function(){
  211. this.isShowAddressList = true;
  212. if(!isPC){fixedBody();}
  213. },
  214. closeAddressBox: function(){
  215. this.isShowAddressList = false;
  216. if(!isPC){looseBody();}
  217. },
  218. hideAddressForm: function(){
  219. this.isShowAddressForm = false;
  220. if(!isPC){looseBody();}
  221. },
  222. createAddress: function(){
  223. this.isShowAddressForm = true;
  224. if(!isPC){fixedBody();}
  225. },
  226. updateAddress: function(){
  227. this.isShowAddressForm = true;
  228. this.addressForm.id = this.address.id;
  229. this.addressForm.name = this.address.name;
  230. this.addressForm.mobile = this.address.mobile;
  231. this.addressForm.default = this.address.default;
  232. this.addressForm.desc = this.address.desc;
  233. this.addressForm.provinceId = this.address.provinceId;
  234. var _self = this;
  235. this.getCityOptions(this.address.provinceId, function(){
  236. _self.addressForm.cityId = _self.address.cityId;
  237. _self.getTownOptions(_self.address.cityId,function(){
  238. _self.addressForm.townId = _self.address.townId;
  239. });
  240. });
  241. if(!isPC){fixedBody();}
  242. },
  243. saveAddressForm: function(){
  244. var _self = this;
  245. var pass = verifyForm();
  246. if (_self.saveLoading) { return false; }
  247. this.$nextTick(function() {
  248. if (!pass) {return false;}
  249. if(!_self.addressForm.townId){
  250. CAIMEI.dialog('请选择所在地区');
  251. return false;
  252. };
  253. _self.saveLoading = true;
  254. var params = {
  255. userID:_self.userId, //用户id ,只在新增收货地址时传
  256. shouHuoRen:_self.addressForm.name, //收货人
  257. mobile:_self.addressForm.mobile, //手机
  258. townID:_self.addressForm.townId, //区ID
  259. address:_self.addressForm.desc, //地址
  260. defaultFlag:_self.addressForm.default?1:0 //是否默认收货地址(0 不是默认,1 默认)
  261. };
  262. if(_self.addressForm.id){
  263. // 编辑
  264. params.addressID = _self.addressForm.id;//编辑保存地址ID
  265. }
  266. _self.saveAddress(params);
  267. });
  268. },
  269. saveAddress: function(params){
  270. var _self = this;
  271. OrderApi.AddSaveAddress(params,function(r){
  272. if(r.code === 0){
  273. CAIMEI.dialog('保存成功');
  274. _self.saveLoading = false;
  275. this.isShowAddressForm = false;
  276. // 重新获取地址列表
  277. _self.getAddressList(_self.userId,20);
  278. }else{
  279. CAIMEI.Alert(r.msg,'确定',false);
  280. }
  281. });
  282. },
  283. // 列表直接设为默认地址
  284. setDefaultAddress: function(addressId){
  285. var _self = this;
  286. OrderApi.DefaultAddress({addressId:addressId,userId:_self.userId},function (r) {
  287. if(r.code === 0 ){
  288. // 重新获取地址列表
  289. _self.getAddressList(_self.userId,20);
  290. }else{
  291. CAIMEI.Alert(r.msg,'确定',false);
  292. }
  293. });
  294. },
  295. // 列表删除单个地址
  296. deleteAddress: function(addressId){
  297. var _self = this;
  298. CAIMEI.Modal('确定要删除该地址?','取消','确定',function () {
  299. OrderApi.DeleteAddress({addressID:addressId,userID:_self.userId},function (r) {
  300. if(r.code === 0 ){
  301. CAIMEI.dialog('删除成功');
  302. // 重新获取地址列表
  303. _self.getAddressList(_self.userId,20);
  304. }else{
  305. CAIMEI.Alert(r.msg,'确定',false);
  306. }
  307. })
  308. });
  309. },
  310. chooseAddress: function(selectedId){
  311. this.address.selectedId = selectedId;
  312. },
  313. confirmAddress: function(){
  314. var _self = this;
  315. this.addressList.forEach(function(item){
  316. if (_self.address.selectedId==item.addressID){
  317. _self.address.id = item.addressID;
  318. _self.address.townId = item.townID;
  319. _self.address.cityId = item.cityID;
  320. _self.address.provinceId = item.provinceID;
  321. _self.address.name = item.shouHuoRen;
  322. _self.address.mobile = item.mobile;
  323. _self.address.desc = item.address;
  324. _self.address.town = item.town;
  325. _self.address.city = item.city;
  326. _self.address.province = item.province;
  327. _self.address.default = (item.defaultFlag > 0);
  328. _self.getFreight(_self.address.townId);
  329. }
  330. });
  331. this.closeAddressBox();
  332. },
  333. toggleThisLadder: function(event){
  334. var el = event.currentTarget;
  335. if($(el).hasClass("on")){
  336. $(el).removeClass("on").siblings('.mFixed').hide();
  337. if(!isPC){looseBody();}
  338. }else{
  339. $(el).addClass("on").siblings('.mFixed').show();
  340. if(!isPC){fixedBody();}
  341. }
  342. },
  343. hideThisLadder: function(event){
  344. var el = event.currentTarget;
  345. $(el).parents('.priceTag').find('.tag').removeClass("on").siblings('.mFixed').hide();
  346. if(!isPC){looseBody();}
  347. },
  348. useUserMoney: function(){
  349. var _self = this;
  350. if(this.balance.userMoney>0){
  351. this.$nextTick(function() {
  352. var total = _self.totalPrice + _self.payInfo.freight;
  353. if(_self.balance.flag){
  354. _self.payInfo.balancePayFlag = 1;
  355. if(_self.balance.userMoney>=total){
  356. // 全部抵扣
  357. _self.payInfo.orderShouldPayFee = 0;
  358. _self.balance.deductMoney = total;
  359. _self.balance.surplusMoney = _self.balance.userMoney-total;
  360. }else{
  361. // 部分抵扣
  362. _self.payInfo.orderShouldPayFee = total - _self.balance.userMoney;
  363. _self.balance.deductMoney = _self.balance.userMoney;
  364. _self.balance.surplusMoney = 0;
  365. }
  366. }else{
  367. // 取消抵扣
  368. _self.payInfo.balancePayFlag = 0;
  369. _self.payInfo.orderShouldPayFee = total;
  370. _self.balance.userMoney = _self.balance.originUserMoney;
  371. _self.balance.deductMoney = 0;
  372. _self.balance.surplusMoney = _self.balance.originUserMoney;
  373. }
  374. });
  375. }
  376. },
  377. submitOrder: function(){
  378. var _self = this;
  379. if(this.submitLoading){return false;}
  380. if(!this.address.id){
  381. CAIMEI.dialog('请先添加收货地址~');
  382. return false;
  383. }
  384. if(this.invoice.type*1 === 1){
  385. // 普通发票
  386. if(!this.invoice.invoiceTitle){
  387. CAIMEI.dialog('请输入个人抬头');return false;
  388. }
  389. if(this.invoice.invoiceTitleType===1 && !this.invoice.corporationTaxNum){
  390. CAIMEI.dialog('请输入纳税人识别号');return false;
  391. }
  392. }else if(this.invoice.type*1 === 2){
  393. // 增值税发票
  394. if(!this.invoice.invoiceTitle){
  395. CAIMEI.dialog('请输入个人抬头');return false;
  396. }
  397. if(!this.invoice.corporationTaxNum){
  398. CAIMEI.dialog('请输入纳税人识别号');return false;
  399. }
  400. if(!this.invoice.registeredAddress){
  401. CAIMEI.dialog('请输入单位地址');return false;
  402. }
  403. if(!this.invoice.registeredPhone){
  404. CAIMEI.dialog('请输入注册电话');return false;
  405. }
  406. if(!this.invoice.openBank){
  407. CAIMEI.dialog('请输入开户银行');return false;
  408. }
  409. if(!this.invoice.bankAccountNo){
  410. CAIMEI.dialog('请输入银行账号');return false;
  411. }
  412. }
  413. var params = {
  414. cartType: this.type,
  415. orderSource: 1, // 购买类型:(1购物车提交[对应表cm_cart],2直接购买提交, 3协销下单)
  416. serviceProviderId: '', // 协销ID(小程序忽略)
  417. clubUserId: this.userId, // 机构用户ID
  418. addressId: this.address.id,// 地址ID
  419. orderInfo: [], // 商品信息
  420. payInfo: {}, // 订单信息
  421. orderInvoice: {} // 发票信息
  422. };
  423. // 发票信息
  424. if(this.invoice.type*1 === 0){
  425. params.orderInvoice = {type: 0};
  426. }else if(this.invoice.type*1 === 1){
  427. params.orderInvoice = {
  428. type: 1, // 普通发票
  429. invoiceContent: '商品明细',
  430. invoiceTitleType: this.invoice.invoiceTitleType, //发票抬头类型 1企业 0个人
  431. invoiceTitle: this.invoice.invoiceTitle, //发票抬头
  432. corporationTaxNum: this.invoice.corporationTaxNum//纳税人识别号
  433. }
  434. }else if(this.invoice.type*1 === 2){
  435. params.orderInvoice = {
  436. type: 2, // 增值税发票
  437. invoiceTitle: this.invoice.invoiceTitle, //单位名称
  438. corporationTaxNum: this.invoice.corporationTaxNum,//纳税人识别号
  439. registeredAddress: this.invoice.registeredAddress,//单位地址
  440. registeredPhone: this.invoice.registeredPhone, //注册电话
  441. openBank: this.invoice.openBank, //开户银行
  442. bankAccountNo: this.invoice.bankAccountNo //银行账号
  443. }
  444. }
  445. //商品信息
  446. params.orderInfo = this.listData.map(function(supplier){
  447. var productInfo = [];
  448. supplier.cartList.forEach(function(item){
  449. productInfo.push({
  450. productId:item.productId,
  451. productNum:item.number,
  452. presentNum:0,
  453. productType:item.productType
  454. })
  455. });
  456. return {
  457. shopId: supplier.id,
  458. note: supplier.note ? supplier.note : '',
  459. productInfo: productInfo
  460. }
  461. });
  462. params.payInfo = {
  463. clauseId: 0,
  464. orderShouldPayFee: toFloat(this.payInfo.orderShouldPayFee),
  465. balancePayFlag: this.payInfo.balancePayFlag,
  466. freight: toFloat(this.payInfo.freight),
  467. freePostFlag: this.payInfo.freePostFlag
  468. };
  469. console.log(params);
  470. this.submitLoading = true;
  471. OrderApi.ConfirmOrder({'params':JSON.stringify(params)},function (r) {
  472. if(r.code === 0){
  473. var _data = r.data;
  474. if(Number(_data.code) === 1){//余额抵扣全部订单金额
  475. var data = { payableAmount: _self.deductMoney };
  476. CAIMEI.Storage.removeItem('confirmOrderInfo');
  477. CAIMEI.Storage.setItem('confirmOrderInfo',JSON.stringify({data:data}));
  478. window.location.href = '/pay/success.html?pageType=www&type=success&payAmount='+_data.payTotalFee;
  479. }else{//余额抵扣部分订单金额或者未支付的
  480. var data = {
  481. orderID:_data.orderID,
  482. orderNo:_data.orderNo,
  483. orderMark:_data.orderMark,
  484. payableAmount:_data.payableAmount
  485. };
  486. CAIMEI.Storage.removeItem('confirmOrderInfo');
  487. CAIMEI.Storage.setItem('confirmOrderInfo',JSON.stringify({data:data}));
  488. window.location.href = '/pay/caimei-paycash.html?type=confirm&orderID='+_data.orderID;
  489. _self.submitLoading = false;
  490. }
  491. }else{
  492. CAIMEI.Alert(r.msg,'确定',true, function(){
  493. _self.submitLoading = false;
  494. });
  495. }
  496. });
  497. }
  498. },
  499. created: function () {
  500. this.type = getUrlParam("type") ? getUrlParam("type")*1 : "";
  501. if(globalUserData){
  502. this.userId = globalUserData.userId;
  503. this.userIdentity = globalUserData.identity;
  504. this.userToken = globalUserData.token;
  505. // type:(1购物车提交[对应表cm_cart],2直接购买提交, 3协销下单)
  506. if(this.type === 1) {
  507. this.productIds = window.localStorage.getItem("shoppingProductIds");
  508. // 获取列表数据
  509. this.getConfirmList(null);
  510. }else if(this.type === 2){
  511. this.productIds = getUrlParam("id");
  512. var count = getUrlParam("count");
  513. if(this.productIds && count) {
  514. // 获取列表数据
  515. this.getConfirmList(count);
  516. }else{
  517. alertInfo("参数错误,请重新提交订单!");
  518. }
  519. }
  520. }
  521. },
  522. mounted: function () {
  523. var _self = this;
  524. var minAwayBtm = $("footer").height();
  525. //处理滚动条控制底部提交fixed
  526. $(window).scroll(function() {
  527. var awayBtm = $(document).height() - $(window).scrollTop() - $(window).height();
  528. if(minAwayBtm <= awayBtm){
  529. $(".summaryWrap").addClass('fixed');
  530. }else{
  531. $(".summaryWrap").removeClass("fixed");
  532. }
  533. });
  534. }
  535. });