confirmedList.js 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018
  1. // confirmedList.js
  2. var app = getApp()
  3. var MD5Util = require('../../utils/md5.js');
  4. var goosdListnew = [];
  5. var breakOrderList = [];
  6. Page({
  7. data: {
  8. orderState : 0,
  9. order_type : '0',
  10. goosdListnew: goosdListnew,
  11. orderTime : '',
  12. order_Consignee: '',
  13. order_phone: '',
  14. order_address: '',
  15. invoice_type_name : '',
  16. invoice_title : '',
  17. invoice_company_title : '',
  18. invoice_number: '',
  19. order_number: '', //订单编号
  20. orderr_Coupon : 0, //优惠劵
  21. hiddenmodal: true, //弹窗
  22. maskBg : false,//支付提示蒙层
  23. phone: '',
  24. order_check_sta : '',
  25. showCancelOrder: false,//待定制状态 - 取消订单
  26. showShouhou: false, //已完成状态 - 售后
  27. showCancelPay: false,//待付款 - 取消弹窗
  28. showSendFriendMsg: false,//送朋友弹窗
  29. breakOrderList: breakOrderList,//准备拆分的订单
  30. sendFlag: 0,//送朋友 - 0,送自己 - 1
  31. newTotal: 0,//拆分订单总价
  32. breakAllNum: 0,
  33. sendMsg: '',//赠送提示语
  34. },
  35. onLoad: function (options) {
  36. var that = this;
  37. var host = getApp().globalData.servsers;
  38. //转义&符
  39. var goosdListnew = options.goosdListnew;
  40. goosdListnew = goosdListnew.replace(/zss/g, "&");
  41. goosdListnew = JSON.parse(goosdListnew);
  42. var listLen = goosdListnew.list_order_aff_data.length;
  43. for (var i = 0; i < listLen ; i ++){
  44. var price = parseFloat(goosdListnew.list_order_aff_data[i].com_price);
  45. var boxPrice = parseFloat(goosdListnew.list_order_aff_data[i].box_price);//礼盒价格
  46. if (boxPrice == '' || boxPrice == null || boxPrice == undefined){
  47. boxPrice = 0;
  48. }
  49. var num = parseFloat(goosdListnew.list_order_aff_data[i].com_num);
  50. goosdListnew.list_order_aff_data[i].new_price = (price + boxPrice) * num;
  51. }
  52. console.log(goosdListnew);
  53. that.setData({
  54. goosdListnew: goosdListnew,
  55. orderTime : goosdListnew.list_order_aff_data[0].creat_time,
  56. order_Consignee: goosdListnew.list_order_aff_data[0].order_Consignee,
  57. order_phone: goosdListnew.list_order_aff_data[0].order_phone,
  58. order_address: goosdListnew.list_order_aff_data[0].order_address,
  59. invoice_type_name: goosdListnew.list_order_aff_data[0].invoice_type_name,
  60. invoice_title: goosdListnew.list_order_aff_data[0].invoice_title,
  61. invoice_company_name: goosdListnew.list_order_aff_data[0].invoice_company_name,
  62. invoice_number: goosdListnew.list_order_aff_data[0].invoice_number,
  63. orderState: goosdListnew.order_sta,
  64. order_number: goosdListnew.order_number,
  65. orderr_Coupon : goosdListnew.list_order_aff_data[0].orderr_Coupon,
  66. order_type: goosdListnew.list_order_aff_data[0].order_type,
  67. order_check_sta: goosdListnew.list_order_aff_data[0].order_check_sta
  68. })
  69. wx.request({
  70. url: host + "phoneapi/phoneall",
  71. data: {},
  72. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  73. header: {
  74. 'Accept': 'application/json'
  75. },
  76. success: function (res) {
  77. that.setData({
  78. phone: res.data.rows[0].phone,
  79. });
  80. if (res == null || res.data == null) {
  81. console.error('网络请求失败');
  82. return;
  83. }
  84. wx: wx.hideNavigationBarLoading(
  85. that.setData({
  86. hidden: ''
  87. })
  88. )
  89. }
  90. })
  91. },
  92. sendBtn: function (options) {
  93. var that = this;
  94. var id = options.currentTarget.dataset.id;//i
  95. if (that.data.goosdListnew.list_order_aff_data[0].img2 != '' && that.data.goosdListnew.list_order_aff_data[0].img2 != undefined) {
  96. var imgSrc = that.data.goosdListnew.list_order_aff_data[0].img2
  97. } else {
  98. var imgSrc = that.data.goosdListnew.list_order_aff_data[0].logo
  99. }
  100. wx.navigateTo({
  101. url: '/pages/share/share?src=' + imgSrc + "&id=" + that.data.goosdListnew.list_order_aff_data[0].order_aff_id + '&order_number=' + that.data.goosdListnew.order_number + '&order_userid=' + that.data.goosdListnew.list_order_aff_data[0].order_userid
  102. })
  103. },
  104. sendBtn: function (options) {//送朋友 - 提示弹窗
  105. var that = this;
  106. that.setData({
  107. showSendFriendMsg: true
  108. })
  109. },
  110. sureSendFriend: function (e) {//送朋友 - 确定
  111. var that = this;
  112. var formId = e.detail;
  113. console.log("confirmeList - formId:" + formId.formId);
  114. var order_number = that.data.order_number;
  115. var imgSrc = that.data.goosdListnew.list_order_aff_data[0].logo
  116. that.setData({
  117. showSendFriendMsg: false,
  118. orderState: 3,
  119. order_type: 1
  120. })
  121. var newCarts = JSON.stringify(that.data.goosdListnew);
  122. newCarts = newCarts.replace(/&/g, "zss");
  123. setTimeout(function () {
  124. wx.navigateTo({
  125. url: '/pages/share/share?src=' + imgSrc + "&id=" + that.data.goosdListnew.list_order_aff_data[0].com_id + '&order_number=' + that.data.goosdListnew.order_number + '&order_userid=' + that.data.goosdListnew.list_order_aff_data[0].order_userid + "&goodsNme=" + that.data.goosdListnew.list_order_aff_data[0].com_name + "&goodsNum=" + that.data.goosdListnew.list_order_aff_data[0].com_num + "&goodsList=" + newCarts + "&flag=0&formId=" + formId.formId,
  126. success: function (res) {
  127. }
  128. })
  129. }, 500)
  130. },
  131. cancelSendFriend: function (e) {//送朋友 - 取消
  132. var that = this;
  133. that.setData({
  134. order_id: '',
  135. order_number : '',
  136. showSendFriendMsg: false
  137. })
  138. },
  139. sendMineBtn: function (options) {//送自己
  140. var that = this;
  141. that.setData({
  142. showSendMineMsg: true,
  143. order_number: that.data.goosdListnew.order_number
  144. })
  145. },
  146. sureSendMine: function (e) {//送自己 - 确认
  147. var that = this;
  148. var host = getApp().globalData.servsers;
  149. var order_number = that.data.order_number;
  150. that.setData({
  151. showSendMineMsg: false
  152. })
  153. wx.navigateTo({
  154. url: '/pages/sendOwnAddress/sendOwnAddress?order_number=' + order_number,
  155. })
  156. },
  157. cancelSendMine: function (e) {//取消送自己
  158. var that = this;
  159. that.setData({
  160. showSendMineMsg: false,
  161. order_number: ''
  162. })
  163. },
  164. dzwc: function (e) {//定制完成 - 提示弹窗
  165. var that = this;
  166. var id = e.currentTarget.dataset.id;
  167. var host = getApp().globalData.servsers;
  168. that.setData({
  169. showQrfhMode: true
  170. })
  171. },
  172. cancelFh: function (e) {//取消定制完成
  173. var that = this;
  174. that.setData({
  175. showQrfhMode: false,
  176. })
  177. },
  178. sureFh: function (e) {//定制完成
  179. var that = this;
  180. var order_number = that.data.order_number;
  181. var host = getApp().globalData.servsers;
  182. wx.request({
  183. url: host + "orderapi/updateOrder_dzwc",
  184. data: {
  185. order_number: order_number
  186. },
  187. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  188. header: {
  189. 'Accept': 'application/json'
  190. },
  191. success: function (res) {
  192. that.setData({
  193. showQrfhMode: false,
  194. orderState : 10
  195. })
  196. if (res == null || res.data == null) {
  197. console.error('网络请求失败');
  198. return;
  199. }
  200. }
  201. })
  202. },
  203. qrsh: function (e) {
  204. var that = this;
  205. var order_number = that.data.order_number;
  206. var goosdListnew = that.data.goosdListnew;
  207. var host = getApp().globalData.servsers;
  208. wx.request({
  209. url: host + "orderapi/updateOrder_wc",
  210. data: {
  211. order_number: order_number
  212. },
  213. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  214. header: {
  215. 'Accept': 'application/json'
  216. },
  217. success: function (res) {
  218. console.log("ababa:");
  219. console.log(res);
  220. that.data.goosdListnew.order_sta = 5;
  221. that.setData({
  222. hiddenmodal: false,
  223. modalCont: '确认收货成功!',
  224. goosdListnew: that.data.goosdListnew,
  225. orderState : 5
  226. })
  227. console.log(that.data.goosdListnew);
  228. setTimeout(function () {
  229. that.setData({
  230. hiddenmodal: true
  231. })
  232. }, 2000);
  233. if (res == null || res.data == null) {
  234. console.error('网络请求失败');
  235. return;
  236. }
  237. }
  238. })
  239. },
  240. //立即付款
  241. save: function (e) {
  242. var that = this;
  243. var un_id = getApp().globalData.un_id;
  244. var timestamp = Date.parse(new Date());
  245. timestamp = timestamp / 1000;
  246. var timestamp1 = timestamp;
  247. var order_number = that.data.order_number;
  248. var len = that.data.goosdListnew.list_order_aff_data.length;//当前订单下商品数量
  249. //检测是否存在下架商品
  250. that.selectCartsSta( len, order_number, un_id);
  251. },
  252. //检查立即购买的商品中是否有下架商品
  253. selectCartsSta: function ( len, order_number, un_id) {
  254. var that = this;
  255. var host = getApp().globalData.servsers;
  256. if (len == 0) {
  257. wx.showLoading({
  258. title: '微信支付',
  259. icon: 'loading',
  260. mask: true,
  261. success: function () {
  262. that.setData({
  263. maskBg: true
  264. })
  265. }
  266. })
  267. //获取用户登录状态
  268. wx.login({
  269. success: function (res) {
  270. //发起网络请求,发起的是HTTPS请求,向服务端请求预支付
  271. var code = res.code;
  272. var title = that.data.goosdListnew.list_order_aff_data[0].com_name;
  273. var price = that.data.goosdListnew.total * 100;
  274. price = 1;
  275. console.log("price:" + price);
  276. console.log("title:" + title);
  277. console.log("order_number:" + order_number);
  278. wx.request({
  279. url: host + 'prePayOrder',
  280. data: {
  281. code: code,
  282. price: price,
  283. title: title,
  284. order_number: order_number
  285. //order_number: timestamp1
  286. },
  287. success: function (res) {
  288. wx.hideLoading()
  289. that.setData({
  290. maskBg: false
  291. })
  292. console.log(res.data);
  293. var timestamp = String(Date.parse(new Date())); //时间戳
  294. if (res.data.result == true) {
  295. var nonceStr = res.data.nonceStr
  296. var prepayId = res.data.prepayId
  297. // 按照字段首字母排序组成新字符串
  298. var payDataA = "appId=wx9e3f68fa2172f1c7&nonceStr=" + res.data.nonceStr + "&package=prepay_id=" + res.data.prepayId + "&signType=MD5&timeStamp=" + timestamp;
  299. var payDataB = payDataA + "&key=MlxMZWpZidKxCPPaOOztMP84XvQzqSOh";
  300. // 使用MD5加密算法计算加密字符串
  301. paySign = MD5Util.MD5(payDataB).toUpperCase();
  302. // 使用MD5加密算法计算加密字符串
  303. var paySign = MD5Util.MD5(payDataB).toUpperCase();
  304. // 发起微信支付
  305. wx.requestPayment({
  306. 'timeStamp': timestamp,
  307. 'nonceStr': nonceStr,
  308. 'package': 'prepay_id=' + prepayId,
  309. 'signType': 'MD5',
  310. 'paySign': paySign,
  311. 'success': function (res) {
  312. //人气推荐
  313. for (var i = 0; i < that.data.goosdListnew.list_order_aff_data.length; i++) {
  314. if (that.data.goosdListnew.list_order_aff_data[i].order_gy_id > -1) {
  315. that.setData({
  316. orderState: 2//待定制
  317. })
  318. } else {
  319. that.setData({
  320. orderState: 10//待送礼
  321. })
  322. }
  323. }
  324. wx.request({
  325. url: host + "orderapi/update",
  326. data: {
  327. order_sta: that.data.orderState,
  328. order_number: order_number,
  329. order_userid: un_id
  330. },
  331. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  332. header: {
  333. 'Accept': 'application/json'
  334. },
  335. success: function (res) {
  336. console.log("更新");
  337. that.loadFun();
  338. if (res == null || res.data == null) {
  339. console.error('网络请求失败');
  340. return;
  341. }
  342. }
  343. });
  344. // 保留当前页面,跳转到应用内某个页面,使用wx.nevigeteBack可以返回原页面
  345. },
  346. 'fail': function (res) {
  347. console.log(res.errMsg)
  348. }
  349. })
  350. } else {
  351. console.log('请求失败' + res.data.info);
  352. }
  353. }
  354. })
  355. }
  356. });
  357. } else {
  358. len -= 1;
  359. var com_id = that.data.goosdListnew.list_order_aff_data[len].com_id;
  360. var name = that.data.goosdListnew.list_order_aff_data[len].com_name;//商品名称
  361. var order_number = that.data.goosdListnew.order_number;
  362. //检测商品是否下架
  363. wx.request({
  364. url: host + "commodityapi/commoditview",
  365. data: {
  366. com_id: com_id
  367. },
  368. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  369. header: {
  370. 'Accept': 'application/json'
  371. },
  372. success: function (res) {
  373. //有此商品
  374. if (res.data.total > 0) {
  375. if (res.data.commodity.commodity_flag != 0) {//此商品为下架商品
  376. wx.hideLoading();
  377. that.setData({
  378. maskBg: false,
  379. hiddenmodal: false,
  380. modalCont: '"' + name + '"已下架,即将为您取消订单,请重新选购!',
  381. showCancelPay: false,
  382. order_id: id,
  383. order_number: order_number
  384. })
  385. setTimeout(function () {
  386. that.setData({
  387. hiddenmodal: true
  388. })
  389. that.sureSave();
  390. }, 2000);
  391. return false;
  392. } else {
  393. //不是失效商品,检测库存是否充足
  394. wx.request({
  395. url: host + "api/commodityGroup/checkCommodityGroupRepertory",
  396. data: {
  397. datasheetGroupId: that.data.goosdListnew.list_order_aff_data[len].com_group_id
  398. },
  399. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  400. header: {
  401. 'Accept': 'application/json'
  402. },
  403. success: function (res) {
  404. if (res.data.code == '200') {
  405. if (res.data.data.canBuy) {
  406. if (res.data.data.repertory < that.data.goosdListnew.list_order_aff_data[len].com_num) {//商品数量小于库存,置数量为库存数量
  407. wx.hideLoading();
  408. that.setData({
  409. maskBg: false,
  410. hiddenmodal: false,
  411. modalCont: '"' + name + '"已售罄,即将为您取消订单,请重新选购!',
  412. showCancelPay: false,
  413. //order_id: id,
  414. order_number: order_number
  415. })
  416. setTimeout(function () {
  417. that.setData({
  418. hiddenmodal: true
  419. })
  420. that.sureSave();
  421. }, 2500);
  422. return false;
  423. } else {
  424. var sumNum = parseInt(that.data.goosdListnew.list_order_aff_data[len].com_num);
  425. for (var t = 0; t < len; t++) {
  426. if (that.data.goosdListnew.list_order_aff_data[t].com_id == that.data.goosdListnew.list_order_aff_data[len].com_id && that.data.goosdListnew.list_order_aff_data[t].com_group_id == that.data.goosdListnew.list_order_aff_data[len].com_group_id) {
  427. sumNum += parseInt(that.data.goosdListnew.list_order_aff_data[t].com_num);
  428. }
  429. }
  430. console.log("立即购买-sumNum:" + sumNum);
  431. console.log("立即购买-repertory:" + res.data.data.repertory);
  432. if (sumNum > res.data.data.repertory) {
  433. wx.hideLoading();
  434. that.setData({
  435. maskBg: false,
  436. hiddenmodal: false,
  437. //order_id: id,
  438. order_number: order_number,
  439. modalCont: '“' + name + '”库存不足,,即将为您取消订单,请重新选购!'
  440. })
  441. setTimeout(function () {
  442. that.setData({
  443. hiddenmodal: true
  444. })
  445. //删除当前订单
  446. that.sureSave();
  447. }, 3000);
  448. return false;
  449. } else {
  450. //继续判断下架和库存
  451. that.selectCartsSta(len, order_number, un_id);
  452. }
  453. }
  454. } else {
  455. wx.hideLoading();
  456. that.setData({
  457. maskBg: false,
  458. hiddenmodal: false,
  459. modalCont: '"' + name + '"已售罄,即将为您取消订单,请重新选购!',
  460. showCancelPay: false,
  461. //order_id: id,
  462. order_number: order_number
  463. })
  464. setTimeout(function () {
  465. that.setData({
  466. hiddenmodal: true
  467. })
  468. that.sureSave();
  469. }, 2500);
  470. return false;
  471. }
  472. }
  473. }
  474. })
  475. }
  476. } else {
  477. wx.hideLoading();
  478. that.setData({
  479. maskBg: false,
  480. hiddenmodal: false,
  481. modalCont: '"' + name + '"已下架,即将为您取消订单,请重新选购!',
  482. showCancelPay: false,
  483. //order_id: id,
  484. order_number: order_number
  485. })
  486. setTimeout(function () {
  487. that.setData({
  488. hiddenmodal: true
  489. })
  490. }, 2500);
  491. that.sureSave();
  492. return false;
  493. }
  494. }
  495. })
  496. }
  497. },
  498. //取消付款 - 提示弹窗
  499. cancalSaveMsg: function (e) {
  500. var that = this;
  501. that.setData({
  502. showCancelPay: true
  503. })
  504. },
  505. //关闭“取消付款”的弹窗
  506. closeSaveMsg: function (e) {
  507. var that = this;
  508. that.setData({
  509. showCancelPay: false
  510. })
  511. },
  512. //取消付款
  513. sureSave: function (e) {
  514. var that = this;
  515. var host = getApp().globalData.servsers;
  516. var order_number = that.data.order_number;
  517. wx.request({
  518. url: host + "orderapi/updateOrder_del",
  519. data: {
  520. order_number: order_number
  521. },
  522. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  523. header: {
  524. 'Accept': 'application/json'
  525. },
  526. success: function (res) {
  527. that.setData({
  528. showCancelPay: false,
  529. hiddenmodal: false,
  530. modalCont: '取消订单成功'
  531. })
  532. setTimeout(function () {
  533. that.setData({
  534. hiddenmodal: true
  535. })
  536. }, 1500)
  537. if (res == null || res.data == null) {
  538. console.error('网络请求失败');
  539. return;
  540. }
  541. }
  542. })
  543. that.data.orderState = 6;
  544. that.setData({
  545. orderState: 6
  546. });
  547. },
  548. //拆分订单 - 送朋友
  549. breakFriend: function (e) {
  550. var that = this;
  551. var sendFlag = e.currentTarget.dataset.sendflag;
  552. var breakOrderList = e.currentTarget.dataset.order;//要拆分的订单
  553. var goods_list = breakOrderList.list_order_aff_data;
  554. var break_num = 0;
  555. var newTotal = 0;
  556. var breakAllNum = 0;
  557. for (var i = 0; i < goods_list.length; i++) {
  558. break_num = parseInt(goods_list[i].com_num);
  559. breakOrderList.list_order_aff_data[i].break_num = break_num;//可拆分的数量
  560. if (break_num == 0) {
  561. breakOrderList.list_order_aff_data[i].minus = 'no_opar';//默认不可减
  562. }
  563. breakOrderList.list_order_aff_data[i].add = 'no_opar';//默认不可加
  564. newTotal += parseFloat(breakOrderList.total);
  565. breakAllNum += break_num;
  566. }
  567. console.log("breakAllNum-11:" + breakAllNum);
  568. that.setData({
  569. sendFlag: sendFlag,
  570. breakOrderList: breakOrderList,
  571. showSendFriendMsg: true,
  572. newTotal: newTotal,
  573. breakAllNum: breakAllNum,
  574. })
  575. },
  576. //拆分 - 绑定加数量事件
  577. addCount(e) {
  578. var that = this;
  579. var id = e.currentTarget.dataset.id;
  580. var breakOrderList = that.data.breakOrderList;
  581. var break_num = e.currentTarget.dataset.breaknum;
  582. var breakAllNum = that.data.breakAllNum;
  583. var com_num = e.currentTarget.dataset.num;//可拆分总数量
  584. var price = e.currentTarget.dataset.price;
  585. if (break_num < com_num) {
  586. break_num++;
  587. if (break_num == com_num) {//已到上限
  588. breakOrderList.list_order_aff_data[id].add = 'no_opar';
  589. } else {
  590. breakOrderList.list_order_aff_data[id].add = '';
  591. }
  592. breakOrderList.list_order_aff_data[id].break_num = break_num;
  593. breakOrderList.list_order_aff_data[id].minus = '';
  594. that.data.breakAllNum = breakAllNum++;
  595. that.setData({
  596. breakOrderList: breakOrderList,
  597. breakAllNum: breakAllNum
  598. })
  599. } else {
  600. breakOrderList.list_order_aff_data[id].add = 'no_opar';
  601. breakOrderList.list_order_aff_data[id].minus = '';
  602. that.setData({
  603. breakOrderList: breakOrderList
  604. })
  605. return false;
  606. }
  607. },
  608. //拆分 - 手动填写数量
  609. writeNum: function (e) {
  610. var that = this;
  611. var val = e.detail.value;
  612. var id = e.currentTarget.dataset.id;
  613. var breakOrderList = that.data.breakOrderList;
  614. var com_num = e.currentTarget.dataset.num;//可拆分总数量
  615. var break_num = breakOrderList.list_order_aff_data[id].break_num;
  616. var breakAllNum = that.data.breakAllNum;//累计拆分数量加和
  617. if (parseInt(val) >= parseInt(com_num)) {
  618. breakOrderList.list_order_aff_data[id].break_num = com_num;
  619. breakAllNum = parseInt(breakAllNum) - parseInt(break_num) + parseInt(com_num);
  620. breakOrderList.list_order_aff_data[id].minus = '';
  621. breakOrderList.list_order_aff_data[id].add = 'no_opar';
  622. that.setData({
  623. breakOrderList: breakOrderList,
  624. breakAllNum: breakAllNum
  625. })
  626. } else if (parseInt(val) <= 0) {
  627. breakOrderList.list_order_aff_data[id].break_num = 0;
  628. breakAllNum = parseInt(breakAllNum) - parseInt(break_num);
  629. breakOrderList.list_order_aff_data[id].minus = 'no_opar';
  630. breakOrderList.list_order_aff_data[id].add = '';
  631. that.setData({
  632. breakOrderList: breakOrderList,
  633. breakAllNum: breakAllNum
  634. })
  635. } else {
  636. breakOrderList.list_order_aff_data[id].break_num = val;
  637. breakAllNum = parseInt(breakAllNum) - parseInt(break_num) + parseInt(val);
  638. breakOrderList.list_order_aff_data[id].minus = '';
  639. breakOrderList.list_order_aff_data[id].add = '';
  640. that.setData({
  641. breakOrderList: breakOrderList,
  642. breakAllNum: breakAllNum
  643. })
  644. }
  645. },
  646. //拆分 - 绑定减数量事件
  647. minusCount(e) {
  648. var that = this;
  649. var id = e.currentTarget.dataset.id;
  650. var break_num = e.currentTarget.dataset.breaknum;
  651. var breakAllNum = that.data.breakAllNum;//累计拆分数量加和
  652. var breakOrderList = that.data.breakOrderList;
  653. var price = e.currentTarget.dataset.price;
  654. if (break_num <= 0) {
  655. return false;
  656. } else {
  657. break_num--;
  658. if (break_num <= 0) {
  659. breakOrderList.list_order_aff_data[id].minus = 'no_opar';
  660. } else {
  661. breakOrderList.list_order_aff_data[id].minus = '';
  662. }
  663. breakOrderList.list_order_aff_data[id].break_num = break_num;
  664. breakOrderList.list_order_aff_data[id].add = '';
  665. that.data.breakAllNum = breakAllNum--;
  666. console.log("breakAllNum1111:" + breakAllNum);
  667. that.setData({
  668. breakOrderList: breakOrderList,
  669. breakAllNum: breakAllNum--
  670. })
  671. }
  672. },
  673. sureSendFriend: function (options) {//送朋友 - 确定
  674. var that = this;
  675. var userRole = getApp().globalData.userRole;//用户角色
  676. var breakOrderList = that.data.breakOrderList;
  677. var totalNumber = breakOrderList.totalNumber;
  678. console.log("totalNumber:" + totalNumber);
  679. var breakAllNum = that.data.breakAllNum;//总的拆分数量
  680. console.log("breakAllNum:" + breakAllNum);
  681. if (breakAllNum > 0 && breakAllNum <= totalNumber) {//商品总数不为0
  682. var id = that.data.order_id;//i
  683. var sendFlag = that.data.sendFlag;
  684. var order_number = breakOrderList.order_number;
  685. var imgSrc = breakOrderList.list_order_aff_data[0].logo;
  686. var com_id = breakOrderList.list_order_aff_data[0].com_id;
  687. var order_userid = breakOrderList.list_order_aff_data[0].order_userid;
  688. var com_name = breakOrderList.list_order_aff_data[0].com_name;
  689. var goodsNum = breakOrderList.list_order_aff_data[0].break_num;
  690. var newTotal = 0;
  691. var len = breakOrderList.list_order_aff_data.length;
  692. for (var i = 0; i < len; i++) {
  693. var goodsPrice = parseFloat(breakOrderList.list_order_aff_data[i].com_price);
  694. var boxPrice = parseFloat(breakOrderList.list_order_aff_data[i].box_price);
  695. var num = parseInt(breakOrderList.list_order_aff_data[i].break_num);
  696. newTotal += (goodsPrice + boxPrice) * num;
  697. }
  698. for (var i = 0; i < len; i++) {
  699. breakOrderList.list_order_aff_data[i].newTotal = newTotal;
  700. }
  701. that.setData({
  702. breakOrderList: breakOrderList
  703. })
  704. breakOrderList = that.data.breakOrderList;
  705. var newCarts = JSON.stringify(breakOrderList);
  706. newCarts = newCarts.replace(/&/g, "zss");
  707. var order_number_new = Date.parse(new Date());
  708. order_number_new = order_number_new / 1000;
  709. if (sendFlag == 0) {//点击送朋友
  710. setTimeout(function () {
  711. wx.navigateTo({
  712. url: '/pages/share/share?src=' + imgSrc + "&id=" + com_id + '&order_number=' + order_number + '&order_userid=' + order_userid + "&goodsNme=" + com_name + "&goodsNum=" + goodsNum + "&goodsList=" + newCarts + "&flag=0" + '&fromUserRole=' + userRole,
  713. success: function (res) {
  714. that.setData({
  715. showSendFriendMsg: false
  716. })
  717. }
  718. })
  719. }, 500)
  720. } else {//送自己
  721. that.setData({
  722. showSendFriendMsg: false
  723. })
  724. wx.navigateTo({
  725. url: '/pages/addAddressSendOwn/addAddressSendOwn?order_number_new=' + order_number_new + '&goodsList=' + newCarts + '&order_number=' + order_number,
  726. })
  727. }
  728. } else if (breakAllNum <= 0) {
  729. that.setData({
  730. hiddenmodal: false,
  731. modalCont: '请选择需要赠送的礼物及数量'
  732. })
  733. setTimeout(function () {
  734. that.setData({
  735. hiddenmodal: true
  736. })
  737. }, 1500)
  738. } else {
  739. that.setData({
  740. hiddenmodal: false,
  741. modalCont: '选择送礼商品数量超出现有商品数量!'
  742. })
  743. setTimeout(function () {
  744. that.setData({
  745. hiddenmodal: true
  746. })
  747. }, 1500)
  748. }
  749. },
  750. cancelSendFriend: function (e) {//送朋友 - 取消
  751. var that = this;
  752. that.setData({
  753. order_id: '',
  754. order_number : '',
  755. showSendFriendMsg: false
  756. })
  757. },
  758. //提醒发货
  759. fahuo: function () {
  760. var that = this;
  761. var host = getApp().globalData.servsers;
  762. var order_number = e.currentTarget.dataset.ordernum;
  763. wx.request({
  764. url: host + "orderapi/updateOrderInformation",
  765. data: {
  766. order_number: order_number,
  767. information_type: 3
  768. },
  769. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  770. header: {
  771. 'Accept': 'application/json'
  772. },
  773. success: function (res) {
  774. that.setData({
  775. hiddenmodal: false,
  776. modalCont: '已提醒商家发货,请您耐心等待'
  777. })
  778. setTimeout(function () {
  779. that.setData({
  780. hiddenmodal: true
  781. })
  782. }, 1500);
  783. if (res == null || res.data == null) {
  784. console.error('网络请求失败');
  785. return;
  786. }
  787. }
  788. })
  789. },
  790. //待定制 - 申请取消订单 - 显示提示弹窗
  791. openCancelWind: function (e) {
  792. var that = this;
  793. that.setData({
  794. showCancelOrder: true
  795. })
  796. },
  797. cancelCancelOrder: function (e) {//取消弹窗 - 待定制的取消的弹窗
  798. var that = this;
  799. that.setData({
  800. showCancelOrder: false
  801. })
  802. },
  803. //待定制 - 申请取消订单
  804. cancelOrder: function (e) {
  805. var that = this;
  806. var host = getApp().globalData.servsers;
  807. var order_number = that.data.order_number;
  808. wx.request({
  809. url: host + "orderapi/updateOrderInformation",
  810. data: {
  811. order_number: order_number,
  812. information_type: 1
  813. },
  814. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  815. header: {
  816. 'Accept': 'application/json'
  817. },
  818. success: function (res) {
  819. that.setData({
  820. showCancelOrder: false
  821. })
  822. that.setData({
  823. hiddenmodal: false,
  824. modalCont: '取消申请已受理,请等待审核!'
  825. })
  826. setTimeout(function () {
  827. that.setData({
  828. hiddenmodal: true
  829. })
  830. }, 1500)
  831. that.data.order_check_sta = 1;
  832. that.setData({
  833. order_check_sta: 1
  834. });
  835. if (res == null || res.data == null) {
  836. console.error('网络请求失败');
  837. return;
  838. }
  839. }
  840. })
  841. },
  842. //已完成 - 申请售后 - 显示提示弹窗
  843. openShowhouWind: function (e) {
  844. var that = this;
  845. that.setData({
  846. showShouhou: true
  847. })
  848. },
  849. cancelShouhou: function (e) {//取消弹窗 - 已完成的取消的弹窗
  850. var that = this;
  851. that.setData({
  852. showShouhou: false
  853. })
  854. },
  855. sureShouhou: function (e) {//确认弹窗 - 已完成的取消的弹窗
  856. var that = this;
  857. var host = getApp().globalData.servsers;
  858. var order_number = that.data.order_number;
  859. wx.request({
  860. url: host + "orderapi/updateOrderInformation",
  861. data: {
  862. order_number: order_number,
  863. information_type: 2
  864. },
  865. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  866. header: {
  867. 'Accept': 'application/json'
  868. },
  869. success: function (res) {
  870. that.setData({
  871. showShouhou: false
  872. })
  873. that.setData({
  874. hiddenmodal: false,
  875. modalCont: '售后申请已受理,请等待处理!'
  876. })
  877. setTimeout(function () {
  878. that.setData({
  879. hiddenmodal: true
  880. })
  881. }, 1500)
  882. that.data.order_check_sta = 1;
  883. that.setData({
  884. order_check_sta: 1
  885. });
  886. if (res == null || res.data == null) {
  887. console.error('网络请求失败');
  888. return;
  889. }
  890. }
  891. })
  892. },
  893. buyUrl:function(e){//跳转到当前商品对应的购买页
  894. var that = this;
  895. var host = getApp().globalData.servsers;
  896. var id = e.currentTarget.dataset.id;
  897. console.log(that.data.goosdListnew.list_order_aff_data[id]);
  898. var buyUrl = that.data.goosdListnew.list_order_aff_data[id].com_id;
  899. wx.request({
  900. url: host + "commodityapi/commoditview",
  901. data: {
  902. com_id: buyUrl,
  903. },
  904. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  905. header: {
  906. 'Accept': 'application/json'
  907. },
  908. success: function (res) {
  909. if (res.data.total > 0){
  910. wx.redirectTo({
  911. url: '/pages/buy/buy?com_id=' + buyUrl
  912. })
  913. }else{
  914. that.setData({
  915. hiddenmodal: false,
  916. modalCont: '该商品已下架!'
  917. })
  918. setTimeout(function () {
  919. that.setData({
  920. hiddenmodal: true
  921. })
  922. }, 1500)
  923. return false;
  924. }
  925. }
  926. })
  927. }
  928. })
  929. var that;
  930. var Util = require('../../utils/util.js');