buy.js 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548
  1. // buy.js
  2. var app = getApp();
  3. var WxParse = require('../../wxParse/wxParse.js');
  4. //规格
  5. var Style1 = [];
  6. var Style2 = [];
  7. var Style3 = [];
  8. var Style4 = [];
  9. var Style5 = [];
  10. let animationShowHeight = 1000;
  11. Page({
  12. data: {
  13. allHidden : '',
  14. authorize: 0,
  15. urlHttp: '',
  16. com_id: "",//商品id
  17. shangpin_id: '',//商品id
  18. banner: '',
  19. bannerSml: '',//商品弹窗的小图
  20. title: '',//商品名称
  21. intro: '',//商品详情
  22. minPrice : 0,//最低价格
  23. maxPrice : 0,//最高价格
  24. newPrice: '',//现价
  25. oldPrice: '',//原价
  26. goodPrice: 0,//商品单独的价格
  27. showPrice: 0,//显示的区间价格【 (商品价格 + 礼盒价格) 】
  28. num: 1, //起订量
  29. cycle: 1,//定制周期
  30. recommend: "",
  31. collectState: false,//是否收藏
  32. //品牌信息
  33. brandid: '',
  34. brandtitle: '',
  35. brandname: '',
  36. brandlogo: '',
  37. brandBanner: '',
  38. bannerShare: '',//分享链接上显示的图片
  39. goodsService: [], //服务
  40. giftboxsize: '', //礼盒长度
  41. gixboxService: [], //礼盒
  42. dingzhiService: [],//定制工艺
  43. Style1: [], //规格
  44. Style2: [],
  45. Style3: [],
  46. Style4: [],
  47. Style5: [],
  48. //每一类规格的数量
  49. style1: 0,
  50. style2: 0,
  51. style3: 0,
  52. style4: 0,
  53. style5: 0,
  54. //规格每个类别的类别名称
  55. style1_name: '',
  56. style2_name: '',
  57. style3_name: '',
  58. style4_name: '',
  59. style5_name: '',
  60. //立即购买中的规格,当前选中状态
  61. ruleClick1: "-",
  62. ruleClick2: "-",
  63. ruleClick3: "-",
  64. ruleClick4: "-",
  65. ruleClick5: "-",
  66. dingZhiClick: "-",//定制
  67. boxClick: "-",//礼盒选中状态
  68. //规格回显值
  69. rule1: "",
  70. rule2: "",
  71. rule3: "",
  72. rule4: "",
  73. rule5: "",
  74. selectBox: "",//选择的礼盒名称
  75. selectDingZhi: '',//选择的定制工艺
  76. //选中的规格组合id
  77. sheetid1: '',
  78. sheetid2: '',
  79. sheetid3: '',
  80. sheetid4: '',
  81. sheetid5: '',
  82. imagewidth: 0,//缩放后的宽
  83. imageheight: 0,//缩放后的高
  84. imageheight1: 0,
  85. state: '',//滚动条状态(有 auto/无 hidden)
  86. carts: [],
  87. hiddenmodal: true, //弹窗
  88. modalCont: '',
  89. stateId: 0,//判断是点击的加入购物车 - 0 / 立即购买 - 1
  90. maxHeight: 0,
  91. imgList: [],//banner数组
  92. serviceIsShow: false,
  93. isShow: false,
  94. chooseFlag: 0,
  95. chooseResult: 0,
  96. animationData: {},
  97. animationDataBuy: {},
  98. animationDataSer: {},
  99. animation: {},
  100. styleLen: 0,
  101. soldOutShow: false,//商品下架提示信息
  102. isSpecialGood: false, //特定具有时效性的商品标识
  103. specialGoodMsgShowCount: 0,//特定具有时效性的商品,提示显示次数
  104. cont_hidden: '',
  105. showBtn: false, //是否显示右侧返回首页按钮
  106. isSelectNew: 0, //默认
  107. from_flag: 0,//入口来源【 0:分享 商品列表】
  108. neibuFlag: 0,
  109. loadingFlag: 0,//所有规格加载完成的标志
  110. groupList: [], //组合信息
  111. sumTotal: 0, //总库存
  112. showNum: 0, //显示的库存数量
  113. keys: {},//总类别集合
  114. keys2: {},
  115. dataList: {},//组合类别集合对象
  116. SKUResult: {},//保存最后的组合结果信息
  117. sizeList: [], //总规格类别
  118. modelStyleNum: 0,//规格总类别数
  119. styleAllNum: 0, //分类规格总数量
  120. clickBoxPrice : 0, //选中的礼盒的价格
  121. saveStyleId : '', //最终选取的组合id
  122. clickNum: 0,//规格已选择数量
  123. cartNum: 0,//footer购物车显示的数量
  124. minNumber: 0,//购买数量
  125. },
  126. //重置所有变量
  127. resetVar : function(e){
  128. var that = this;
  129. that.setData({
  130. allHidden: '',
  131. goodPrice: 0,//商品单独的价格
  132. showPrice: 0,//显示的区间价格【 (商品价格 + 礼盒价格) 】
  133. num: 1, //起订量
  134. cartNum: 0,//footer购物车显示的数量
  135. minNumber: 0,//购买数量
  136. goodsService: [], //服务
  137. giftboxsize: '', //礼盒长度
  138. gixboxService: [], //礼盒
  139. dingzhiService: [],//定制工艺
  140. Style1: [], //规格
  141. Style2: [],
  142. Style3: [],
  143. Style4: [],
  144. Style5: [],
  145. //立即购买中的规格,当前选中状态
  146. ruleClick1: "-",
  147. ruleClick2: "-",
  148. ruleClick3: "-",
  149. ruleClick4: "-",
  150. ruleClick5: "-",
  151. boxClick: "-",//礼盒选中状态
  152. dingZhiClick: "-",//定制
  153. //规格回显值
  154. rule1: "",
  155. rule2: "",
  156. rule3: "",
  157. rule4: "",
  158. rule5: "",
  159. selectBox: "",//选择的礼盒名称
  160. selectDingZhi: '',//选择的定制工艺
  161. sheetid1: '',
  162. sheetid2: '',
  163. sheetid3: '',
  164. sheetid4: '',
  165. sheetid5: '',
  166. loadingFlag: 0,//所有规格加载完成的标志
  167. groupList: [], //组合信息
  168. showNum: 0, //显示的库存数量
  169. sumTotal: 0, //总库存
  170. dataList: {}, //组合类别集合对象
  171. SKUResult: {}, //保存最后的组合结果信息
  172. clickNum: 0,//规格已选择数量
  173. clickBoxPrice: 0, //选中的礼盒的价格
  174. saveStyleId: '', //最终选取的组合id
  175. hiddenmodal: true, //弹窗
  176. modalCont: '',
  177. stateId: 0,//判断是点击的加入购物车 - 0 / 立即购买 - 1
  178. maxHeight: 0,
  179. serviceIsShow: false,
  180. isShow: false,
  181. chooseFlag: 0,
  182. chooseResult: 0,
  183. animationData: {},
  184. animationDataBuy: {},
  185. animationDataSer: {},
  186. animation: {},
  187. styleLen: 0,
  188. isSpecialGood: false, //特定具有时效性的商品标识
  189. specialGoodMsgShowCount: 0,//特定具有时效性的商品,提示显示次数
  190. cont_hidden: '',
  191. isSelectNew: 0, //默认
  192. })
  193. },
  194. onLoad: function (options) {
  195. var that = this;
  196. var host = getApp().globalData.servsers;
  197. var un_id = getApp().globalData.un_id;
  198. var neibuFlag = options.flag;//来自内部员工,则为0
  199. if (options.flag == undefined) {
  200. neibuFlag = 1;
  201. } else {
  202. wx.hideShareMenu();
  203. }
  204. if (options.from_flag == 1) {//从分享链接进入
  205. that.setData({
  206. showBtn: true
  207. })
  208. } else {
  209. that.setData({
  210. showBtn: false
  211. })
  212. }
  213. that.setData({
  214. urlHttp: host,
  215. com_id: options.com_id,
  216. from_flag: options.from_flag,
  217. neibuFlag: neibuFlag,
  218. })
  219. //检测商品是否下架
  220. wx.request({
  221. url: host + "commodityapi/commoditview",
  222. data: {
  223. com_id: options.com_id
  224. },
  225. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  226. header: {
  227. 'Accept': 'application/json'
  228. },
  229. success: function (res) {
  230. console.log(res);
  231. //有此商品
  232. if (res.data.total > 0) {
  233. if (res.data.commodity.commodity_flag == '1') {//此商品为下架商品
  234. that.setData({
  235. soldOutShow: true
  236. })
  237. }
  238. }
  239. var article1 = res.data.commodity.commodity_details;
  240. WxParse.wxParse('article1', 'html', res.data.commodity.commodity_details, that, 5)
  241. var acceptance = res.data.commodity.commodity_acceptance;
  242. if (acceptance != null && acceptance != '') {
  243. wx.request({//服务保证
  244. url: host + "acceptanceapi/findBuy",
  245. data: {
  246. id: acceptance
  247. },
  248. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  249. header: {
  250. 'Accept': 'application/json'
  251. },
  252. success: function (res) {
  253. if (res.data.total > 0) {
  254. that.setData({
  255. goodsService: res.data.rows
  256. })
  257. }
  258. if (res == null || res.data == null) {
  259. console.error('网络请求失败');
  260. return;
  261. }
  262. }
  263. });
  264. }
  265. //是否收藏
  266. if (un_id != undefined && un_id != '' && un_id != null) {
  267. wx.request({
  268. url: host + "collectionapi/findAllforxcx",
  269. data: {
  270. user_id: un_id,
  271. collection_clas: 2,
  272. collection_name: options.com_id,
  273. },
  274. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  275. header: {
  276. 'Accept': 'application/json'
  277. },
  278. success: function (res) {
  279. if (res.data.total != 0) {
  280. that.setData({
  281. collectState: true
  282. })
  283. }
  284. if (res == null || res.data == null) {
  285. console.error('网络请求失败');
  286. return;
  287. }
  288. }
  289. })
  290. }
  291. that.setData({
  292. tuijian: res.data.commodity,
  293. banner: res.data.images,
  294. bannerShare: res.data.images[0],
  295. bannerSml: host + 'images/' + res.data.images[0],
  296. title: res.data.commodity.commodity_name,
  297. shangpin_id: res.data.commodity.id,
  298. intro: res.data.commodity.commodity_des,
  299. newPrice: res.data.commodity.commodity_sale,
  300. oldPrice: res.data.commodity.commodity_cost,
  301. cycle: res.data.commodity.commodity_cyc,
  302. minNumber: res.data.commodity.commodity_num,
  303. num: res.data.commodity.commodity_num,
  304. recommend: res.data.commodity.commodity_recommend,
  305. });
  306. var imgList = [];
  307. for (var i = 0; i < that.data.banner.length; i++) {
  308. imgList[i] = host + 'images/' + that.data.banner[i];
  309. }
  310. that.setData({
  311. imgList: imgList
  312. })
  313. wx.setNavigationBarTitle({
  314. title: res.data.commodity.commodity_name
  315. })
  316. if (res == null || res.data == null) {
  317. console.error('网络请求失败');
  318. return;
  319. }
  320. }
  321. })
  322. },
  323. //渲染
  324. loadFun: function (e) {
  325. var that = this;
  326. var host = getApp().globalData.servsers;
  327. var un_id = getApp().globalData.un_id;
  328. that.resetVar();
  329. //检测商品是否下架
  330. wx.request({
  331. url: host + "commodityapi/commoditview",
  332. data: {
  333. com_id: that.data.com_id
  334. },
  335. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  336. header: {
  337. 'Accept': 'application/json'
  338. },
  339. success: function (res) {
  340. console.log(res);
  341. //有此商品
  342. if (res.data.total > 0) {
  343. if (res.data.commodity.commodity_flag == '1') {//此商品为下架商品
  344. that.setData({
  345. soldOutShow: true
  346. })
  347. }
  348. }
  349. var loadingFlag = that.data.loadingFlag;//所有规则加载标识
  350. var giftbox = res.data.commodity.commodity_giftbox;
  351. if (giftbox != null && giftbox != '') {
  352. wx.request({//礼盒
  353. url: host + "giftboxapi/findBuy",
  354. data: {
  355. id: giftbox
  356. },
  357. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  358. header: {
  359. 'Accept': 'application/json'
  360. },
  361. success: function (res) {
  362. if (res.data.total > 0) {
  363. that.setData({
  364. giftboxsize: res.data.total,
  365. gixboxService: res.data.rows
  366. })
  367. }
  368. if (res == null || res.data == null) {
  369. console.error('网络请求失败');
  370. return;
  371. }
  372. }
  373. });
  374. }
  375. var process = res.data.commodity.commodity_process;
  376. if (process != null && process != '') {
  377. wx.request({//定制
  378. url: host + "processapi/findBuy",
  379. data: {
  380. id: process
  381. },
  382. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  383. header: {
  384. 'Accept': 'application/json'
  385. },
  386. success: function (res) {
  387. if (res.data.total > 0) {
  388. that.setData({
  389. iconNum: res.data.total,
  390. dingzhiService: res.data.rows
  391. });
  392. }
  393. if (res == null || res.data == null) {
  394. console.error('网络请求失败');
  395. return;
  396. }
  397. }
  398. });
  399. }
  400. var styleLength = 0;
  401. var keys = new Array();
  402. var keys2 = '';
  403. var modelStyleNum = 0;//规格总类别数量
  404. //所有规格的数量
  405. var styleAllNum = 0;
  406. var loadingFlag = 0;
  407. var style1 = res.data.commodity.style1;
  408. if (style1 != null && style1 != '' && style1 != undefined) {
  409. keys2 = '1_0';
  410. modelStyleNum++;
  411. wx.request({
  412. url: host + "datasheetapi/findAllforid",
  413. data: {
  414. id: style1
  415. },
  416. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  417. header: {
  418. 'Accept': 'application/json'
  419. },
  420. success: function (res) {
  421. console.log("style");
  422. console.log(res);
  423. if (res.data.total > 0) {
  424. that.setData({
  425. style1_name: res.data.rows[0].datasheet_com_name,
  426. style1: res.data.total,
  427. Style1: res.data.rows,
  428. });
  429. styleAllNum += res.data.total;
  430. keys[0] = new Array();
  431. for (var j = 0; j < res.data.total; j++) { //二维长度为5
  432. keys[0][j] = res.data.rows[j].datasheet_id;
  433. that.data.sizeList.push(res.data.rows[j]);
  434. that.data.Style1[j].clickTrue = true;
  435. }
  436. that.setData({
  437. Style1: that.data.Style1,
  438. keys: keys,
  439. })
  440. loadingFlag++;
  441. if (loadingFlag == 6) {
  442. //组合sku
  443. that.initSKU();
  444. }
  445. }
  446. if (res == null || res.data == null) {
  447. console.error('网络请求失败');
  448. return;
  449. }
  450. }
  451. });
  452. } else {
  453. loadingFlag++;
  454. if (loadingFlag == 6) {
  455. //组合sku
  456. that.initSKU();
  457. }
  458. }
  459. var style2 = res.data.commodity.style2;
  460. if (style2 != null && style2 != '' && style2 != undefined) {
  461. modelStyleNum++;
  462. keys2 = keys2 + '-2_0';
  463. wx.request({
  464. url: host + "datasheetapi/findAllforid",
  465. data: {
  466. id: style2
  467. },
  468. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  469. header: {
  470. 'Accept': 'application/json'
  471. },
  472. success: function (res) {
  473. if (res.data.total > 0) {
  474. styleAllNum += res.data.total;
  475. that.setData({
  476. style2_name: res.data.rows[0].datasheet_com_name,
  477. style2: res.data.total,
  478. Style2: res.data.rows,
  479. });
  480. keys[1] = new Array();
  481. for (var j = 0; j < res.data.total; j++) { //二维长度为5
  482. keys[1][j] = res.data.rows[j].datasheet_id;
  483. that.data.sizeList.push(res.data.rows[j]);
  484. that.data.Style2[j].clickTrue = true;
  485. }
  486. that.setData({
  487. Style2: that.data.Style2,
  488. keys: keys
  489. })
  490. loadingFlag++;
  491. if (loadingFlag == 6) {
  492. //组合sku
  493. that.initSKU();
  494. }
  495. }
  496. if (res == null || res.data == null) {
  497. console.error('网络请求失败');
  498. return;
  499. }
  500. }
  501. });
  502. } else {
  503. loadingFlag++;
  504. if (loadingFlag == 6) {
  505. //组合sku
  506. that.initSKU();
  507. }
  508. }
  509. var style3 = res.data.commodity.style3;
  510. if (style3 != null && style3 != '' && style3 != undefined) {
  511. modelStyleNum++;
  512. keys2 = keys2 + '-3_0';
  513. wx.request({
  514. url: host + "datasheetapi/findAllforid",
  515. data: {
  516. id: style3
  517. },
  518. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  519. header: {
  520. 'Accept': 'application/json'
  521. },
  522. success: function (res) {
  523. if (res.data.total > 0) {
  524. styleAllNum += res.data.total;
  525. that.setData({
  526. style3_name: res.data.rows[0].datasheet_com_name,
  527. style3: res.data.total,
  528. Style3: res.data.rows,
  529. });
  530. keys[2] = new Array();
  531. for (var j = 0; j < res.data.total; j++) { //二维长度为5
  532. keys[2][j] = res.data.rows[j].datasheet_id;
  533. that.data.sizeList.push(res.data.rows[j]);
  534. that.data.Style3[j].clickTrue = true;
  535. }
  536. that.setData({
  537. Style3: that.data.Style3,
  538. keys: keys
  539. });
  540. loadingFlag++;
  541. if (loadingFlag == 6) {
  542. //组合sku
  543. that.initSKU();
  544. }
  545. }
  546. if (res == null || res.data == null) {
  547. console.error('网络请求失败');
  548. return;
  549. }
  550. }
  551. });
  552. } else {
  553. loadingFlag++;
  554. if (loadingFlag == 6) {
  555. //组合sku
  556. that.initSKU();
  557. }
  558. }
  559. var style4 = res.data.commodity.style4;
  560. if (style4 != null && style4 != '' && style4 != undefined) {
  561. modelStyleNum++;
  562. keys2 = keys2 + '-4_0';
  563. wx.request({
  564. url: host + "datasheetapi/findAllforid",
  565. data: {
  566. id:style4
  567. },
  568. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  569. header: {
  570. 'Accept': 'application/json'
  571. },
  572. success: function (res) {
  573. if (res.data.total > 0) {
  574. styleAllNum += res.data.total;
  575. that.setData({
  576. style4_name: res.data.rows[0].datasheet_com_name,
  577. style4: res.data.total,
  578. Style4: res.data.rows,
  579. });
  580. keys[3] = new Array();
  581. for (var j = 0; j < res.data.total; j++) { //二维长度为5
  582. keys[3][j] = res.data.rows[j].datasheet_id;
  583. that.data.sizeList.push(res.data.rows[j]);
  584. that.data.Style4[j].clickTrue = true;
  585. }
  586. that.setData({
  587. Style4: that.data.Style4,
  588. keys: keys
  589. })
  590. loadingFlag++;
  591. if (loadingFlag == 6) {
  592. //组合sku
  593. that.initSKU();
  594. }
  595. }
  596. if (res == null || res.data == null) {
  597. console.error('网络请求失败');
  598. return;
  599. }
  600. }
  601. });
  602. } else {
  603. loadingFlag++;
  604. if (loadingFlag == 6) {
  605. //组合sku
  606. that.initSKU();
  607. }
  608. }
  609. var style5 = res.data.commodity.style5;
  610. if (style5 != null && style5 != '' && style5 != undefined) {
  611. modelStyleNum++;
  612. keys2 = keys2 + '-5_0';
  613. wx.request({
  614. url: host + "datasheetapi/findAllforid",
  615. data: {
  616. id: style5
  617. },
  618. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  619. header: {
  620. 'Accept': 'application/json'
  621. },
  622. success: function (res) {
  623. if (res.data.total > 0) {
  624. styleAllNum += res.data.total;
  625. that.setData({
  626. style5_name: res.data.rows[0].datasheet_com_name,
  627. style5: res.data.total,
  628. Style5: res.data.rows,
  629. });
  630. keys[4] = new Array();
  631. for (var j = 0; j < res.data.total; j++) {
  632. keys[4][j] = res.data.rows[j].datasheet_id;
  633. that.data.sizeList.push(res.data.rows[j]);
  634. that.data.Style5[j].clickTrue = true;
  635. }
  636. that.setData({
  637. Style5: that.data.Style5,
  638. keys: keys
  639. })
  640. loadingFlag++;
  641. if (loadingFlag == 6) {
  642. //组合sku
  643. that.initSKU();
  644. }
  645. }
  646. if (res == null || res.data == null) {
  647. console.error('网络请求失败');
  648. return;
  649. }
  650. }
  651. });
  652. } else {
  653. loadingFlag++;
  654. if (loadingFlag == 6) {
  655. //组合sku
  656. that.initSKU();
  657. }
  658. }
  659. var dataList = new Object();
  660. //获取商品规则的组合【价格和库存】
  661. wx.request({
  662. url: host + 'api/commodityGroup/getAllGroupByCommodityId',
  663. data: {
  664. commodityId: that.data.com_id
  665. },
  666. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  667. header: {
  668. 'Accept': 'application/json'
  669. },
  670. success: function (res) {
  671. console.log("CommodityId:");
  672. console.log(res);
  673. if (res.data.code == '200') {
  674. if (res.data.data.length > 0){
  675. var groupList = res.data.data;
  676. var sumTotal = 0;
  677. var dataLen = groupList.length;
  678. for (var i = 0; i < dataLen; i++) {
  679. sumTotal += groupList[i].product_repertory;
  680. var dataTit = groupList[i].datasheet_id;
  681. var dataContList = {
  682. id: groupList[i].id,
  683. product_price: groupList[i].product_price,
  684. product_repertory: groupList[i].product_repertory
  685. };
  686. dataList[dataTit] = dataContList;
  687. }
  688. that.setData({
  689. sumTotal: sumTotal,
  690. groupList: groupList,
  691. dataList: dataList,
  692. showNum: sumTotal
  693. })
  694. loadingFlag++;
  695. if (loadingFlag == 6) {
  696. //组合sku
  697. that.initSKU();
  698. }
  699. }else{
  700. that.setData({
  701. sumTotal: 0,
  702. showNum: 0
  703. })
  704. //每一个规则类别下的详细种类数量
  705. var style1 = that.data.style1;
  706. var style2 = that.data.style2;
  707. var style3 = that.data.style3;
  708. var style4 = that.data.style4;
  709. var style5 = that.data.style5;
  710. if (style1 > 0) {
  711. for (var j = 0; j < style1; j++) {
  712. that.data.Style1[j].clickTrue = false;
  713. that.setData({
  714. Style1: that.data.Style1,
  715. })
  716. }
  717. }
  718. if (style2 > 0) {
  719. for (var j = 0; j < style2; j++) {
  720. that.data.Style2[j].clickTrue = false;
  721. that.setData({
  722. Style2: that.data.Style2,
  723. })
  724. }
  725. }
  726. if (style3 > 0) {
  727. for (var j = 0; j < style3; j++) {
  728. var datasheetId = that.data.Style3[j].datasheet_id;
  729. that.data.Style3[j].clickTrue = false;
  730. that.setData({
  731. Style3: that.data.Style3,
  732. })
  733. }
  734. }
  735. if (style4 > 0) {
  736. for (var j = 0; j < style4; j++) {
  737. that.data.Style4[j].clickTrue = false;
  738. that.setData({
  739. Style4: that.data.Style4,
  740. })
  741. }
  742. }
  743. if (style5 > 0) {
  744. for (var j = 0; j < style5; j++) {
  745. that.data.Style5[j].clickTrue = false;
  746. that.setData({
  747. Style5: that.data.Style5,
  748. })
  749. }
  750. }
  751. that.setData({
  752. allHidden: 'allHidden'
  753. })
  754. wx.hideLoading();
  755. }
  756. }
  757. }
  758. })
  759. that.setData({
  760. showPrice: (res.data.maxAndMin.min == res.data.maxAndMin.max) ? res.data.maxAndMin.min :(res.data.maxAndMin.min + '-' + res.data.maxAndMin.max),
  761. minPrice: res.data.maxAndMin.min,//最低价格
  762. maxPrice: res.data.maxAndMin.max,//最高价格
  763. minNumber: res.data.commodity.commodity_num,
  764. num: res.data.commodity.commodity_num,
  765. keys2: [keys2],
  766. modelStyleNum: modelStyleNum,
  767. sizeList: that.data.sizeList,
  768. styleAllNum: styleAllNum,
  769. loadingFlag: that.data.loadingFlag
  770. });
  771. if (res == null || res.data == null) {
  772. console.error('网络请求失败');
  773. return;
  774. }
  775. }
  776. });
  777. wx.getSystemInfo({
  778. success: function (res) {
  779. animationShowHeight = res.windowHeight;
  780. }
  781. })
  782. // 显示遮罩层
  783. var animation = wx.createAnimation({
  784. duration: 200,
  785. timingFunction: 'linear',
  786. })
  787. this.animation = animation
  788. animation.bottom(-animationShowHeight).step()
  789. this.setData({
  790. animationDataBuy: animation.export()
  791. })
  792. setTimeout(function () {
  793. animation.bottom(-animationShowHeight).step()
  794. this.setData({
  795. animationDataBuy: animation.export()
  796. })
  797. }.bind(this), 200)
  798. },
  799. onShow:function(e){
  800. var that = this;
  801. wx.showLoading({
  802. title: '',
  803. icon: 'loading',
  804. mask: true,
  805. success: function () {
  806. }
  807. })
  808. that.loadFun();
  809. },
  810. //获得对象的key
  811. getObjKeys: function (obj) {
  812. var that = this;
  813. if (obj !== Object(obj)) throw new TypeError('Invalid object');
  814. var keys = [];
  815. for (var key in obj) {
  816. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  817. keys[keys.length] = key;
  818. }
  819. }
  820. return keys;
  821. },
  822. //初始化得到结果集
  823. initSKU: function () {
  824. var that = this;
  825. var dataList = that.data.dataList;//已有的规则组合信息
  826. //数据已有组合类
  827. var i, j, skuKeys = that.getObjKeys(dataList);
  828. //每一个规则类别下的详细种类数量
  829. var style1 = that.data.style1;
  830. var style2 = that.data.style2;
  831. var style3 = that.data.style3;
  832. var style4 = that.data.style4;
  833. var style5 = that.data.style5;
  834. for (i = 0; i < skuKeys.length; i++) {
  835. var skuKey = skuKeys[i];//一条SKU信息key
  836. var sku = dataList[skuKey]; //一条SKU信息value
  837. var skuKeyAttrs = skuKey.split("-"); //SKU信息key属性值数组
  838. skuKeyAttrs.sort(function (value1, value2) {
  839. return parseInt(value1) - parseInt(value2);
  840. });
  841. //对每个SKU信息key属性值进行拆分组合
  842. var combArr = that.combInArray(skuKeyAttrs);
  843. for (j = 0; j < combArr.length; j++) {
  844. that.addSKUResult(combArr[j], sku);
  845. }
  846. //结果集接放入SKUResult
  847. var SKUResult = that.data.SKUResult;
  848. SKUResult[skuKeyAttrs.join("-")] = {
  849. product_repertory: sku.product_repertory,
  850. product_price: [sku.product_price]
  851. };
  852. }
  853. var SKUResultLength = Object.keys(SKUResult).length;
  854. var forNum1 = 0, forNum2 = 0, forNum3 = 0, forNum4 = 0, forNum5 = 0;
  855. //初始化,现有单独规格是否有库存
  856. if (style1 > 0) {
  857. for (var j = 0; j < style1; j++) {
  858. var datasheetId = that.data.Style1[j].datasheet_id;
  859. if (!SKUResult[datasheetId]) {
  860. forNum1++;
  861. that.data.Style1[j].clickTrue = false;
  862. } else {
  863. that.data.Style1[j].clickTrue = true;
  864. }
  865. that.setData({
  866. Style1: that.data.Style1,
  867. })
  868. }
  869. }
  870. if (style2 > 0) {
  871. for (var j = 0; j < style2; j++) {
  872. var datasheetId = that.data.Style2[j].datasheet_id;
  873. if (!SKUResult[datasheetId]) {
  874. forNum2++;
  875. that.data.Style2[j].clickTrue = false;
  876. } else {
  877. that.data.Style2[j].clickTrue = true;
  878. }
  879. that.setData({
  880. Style2: that.data.Style2,
  881. })
  882. }
  883. }
  884. if (style3 > 0) {
  885. for (var j = 0; j < style3; j++) {
  886. var datasheetId = that.data.Style3[j].datasheet_id;
  887. if (!SKUResult[datasheetId]) {
  888. forNum3++;
  889. that.data.Style3[j].clickTrue = false;
  890. } else {
  891. that.data.Style3[j].clickTrue = true;
  892. }
  893. that.setData({
  894. Style3: that.data.Style3,
  895. })
  896. }
  897. }
  898. if (style4 > 0) {
  899. for (var j = 0; j < style4; j++) {
  900. var datasheetId = that.data.Style4[j].datasheet_id;
  901. if (!SKUResult[datasheetId]) {
  902. forNum4++;
  903. that.data.Style4[j].clickTrue = false;
  904. } else {
  905. that.data.Style4[j].clickTrue = true;
  906. }
  907. that.setData({
  908. Style4: that.data.Style4,
  909. })
  910. }
  911. }
  912. if (style5 > 0) {
  913. for (var j = 0; j < style5; j++) {
  914. var datasheetId = that.data.Style5[j].datasheet_id;
  915. if (!SKUResult[datasheetId]) {
  916. forNum5++;
  917. that.data.Style5[j].clickTrue = false;
  918. } else {
  919. that.data.Style5[j].clickTrue = true;
  920. }
  921. that.setData({
  922. Style5: that.data.Style5,
  923. })
  924. }
  925. }
  926. that.setData({
  927. SKUResult: SKUResult,
  928. allHidden: 'allHidden'
  929. })
  930. wx.hideLoading();
  931. },
  932. //把组合的key放入结果集SKUResult
  933. addSKUResult: function ( combArrItem, sku) {
  934. var that = this;
  935. var key = combArrItem.join("-");
  936. var SKUResult = that.data.SKUResult;
  937. if (SKUResult[key]) {//SKU信息key属性·
  938. SKUResult[key].product_repertory += sku.product_repertory;
  939. SKUResult[key].product_price.push(sku.product_price);
  940. } else {
  941. SKUResult[key] = {
  942. product_repertory: sku.product_repertory,
  943. product_price: [sku.product_price]
  944. };
  945. }
  946. that.setData({
  947. SKUResult: SKUResult
  948. })
  949. },
  950. /**
  951. * 从数组中生成指定长度的组合
  952. * 方法: 先生成[0,1...]形式的数组, 然后根据0,1从原数组取元素,得到组合数组
  953. */
  954. combInArray: function (aData) {
  955. var that = this;
  956. if (!aData || !aData.length) {
  957. return [];
  958. }
  959. var len = aData.length;
  960. var aResult = [];
  961. for (var n = 1; n < len; n++) {
  962. var aaFlags = that.getCombFlags(len, n);
  963. while (aaFlags.length) {
  964. var aFlag = aaFlags.shift();
  965. var aComb = [];
  966. for (var i = 0; i < len; i++) {
  967. aFlag[i] && aComb.push(aData[i]);
  968. }
  969. aResult.push(aComb);
  970. }
  971. }
  972. return aResult;
  973. },
  974. /**
  975. * 得到从 m 元素中取 n 元素的所有组合
  976. * 结果为[0,1...]形式的数组, 1表示选中,0表示不选
  977. */
  978. getCombFlags: function (m, n) {
  979. var that = this;
  980. if (!n || n < 1) {
  981. return [];
  982. }
  983. var aResult = [];
  984. var aFlag = [];
  985. var bNext = true;
  986. var i, j, iCnt1;
  987. for (i = 0; i < m; i++) {
  988. aFlag[i] = i < n ? 1 : 0;
  989. }
  990. aResult.push(aFlag.concat());
  991. while (bNext) {
  992. iCnt1 = 0;
  993. for (i = 0; i < m - 1; i++) {
  994. if (aFlag[i] == 1 && aFlag[i + 1] == 0) {
  995. for (j = 0; j < i; j++) {
  996. aFlag[j] = j < iCnt1 ? 1 : 0;
  997. }
  998. aFlag[i] = 0;
  999. aFlag[i + 1] = 1;
  1000. var aTmp = aFlag.concat();
  1001. aResult.push(aTmp);
  1002. if (aTmp.slice(-n).join("").indexOf('0') == -1) {
  1003. bNext = false;
  1004. }
  1005. break;
  1006. }
  1007. aFlag[i] == 1 && iCnt1++;
  1008. }
  1009. }
  1010. return aResult;
  1011. },
  1012. //选择规格时的判断 - 判断价格和库存
  1013. chooseStyleSetData: function (datasheetId, clickNum) {
  1014. var that = this;
  1015. var styleAllNum = that.data.styleAllNum;
  1016. var modelStyleNum = that.data.modelStyleNum;
  1017. var clickBoxPrice = that.data.clickBoxPrice;//已选礼盒价格
  1018. var SKUResult = that.data.SKUResult;
  1019. //每个大规格下选择的小规格id
  1020. var ruleClick1 = that.data.ruleClick1;
  1021. var ruleClick2 = that.data.ruleClick2;
  1022. var ruleClick3 = that.data.ruleClick3;
  1023. var ruleClick4 = that.data.ruleClick4;
  1024. var ruleClick5 = that.data.ruleClick5;
  1025. //每一个规则类别下的详细种类数量
  1026. var style1 = that.data.style1;
  1027. var style2 = that.data.style2;
  1028. var style3 = that.data.style3;
  1029. var style4 = that.data.style4;
  1030. var style5 = that.data.style5;
  1031. if (clickNum > 0) {
  1032. //获得组合key价格
  1033. var selectedIds = [];
  1034. (that.data.sheetid1 == '') ? '' : selectedIds.push(that.data.sheetid1);
  1035. (that.data.sheetid2 == '') ? '' : selectedIds.push(that.data.sheetid2);
  1036. (that.data.sheetid3 == '') ? '' : selectedIds.push(that.data.sheetid3);
  1037. (that.data.sheetid4 == '') ? '' : selectedIds.push(that.data.sheetid4);
  1038. (that.data.sheetid5 == '') ? '' : selectedIds.push(that.data.sheetid5);
  1039. console.log("selectedIds:");
  1040. console.log(selectedIds);
  1041. selectedIds.sort(function (value1, value2) {
  1042. return parseInt(value1) - parseInt(value2);
  1043. });
  1044. var len = selectedIds.length;
  1045. console.log("selectedIds.join('-'):"+selectedIds.join('-'));
  1046. var prices = SKUResult[selectedIds.join('-')].product_price;
  1047. var maxPrice = parseFloat(Math.max.apply(Math, prices)) + + parseFloat(clickBoxPrice);
  1048. var minPrice = parseFloat(Math.min.apply(Math, prices)) + + parseFloat(clickBoxPrice);
  1049. var showNum = SKUResult[selectedIds.join('-')].product_repertory;//当前规格下的库存
  1050. var showPrice = maxPrice > minPrice ? minPrice + "-" + maxPrice : maxPrice; //当前规格下的价格
  1051. var num = this.data.minNumber;//当前数量
  1052. if (num >= showNum){
  1053. that.setData({
  1054. minNumber: showNum
  1055. })
  1056. }
  1057. that.setData({
  1058. showPrice: showPrice,
  1059. showNum: showNum
  1060. })
  1061. var siblingsSelectedObj = [];//已点选
  1062. var siblingsSelectedObjId = [];//已点选的id的集合
  1063. var noClickList = [];//未点选的id的集合
  1064. var oldNoClickList = [];
  1065. if (style1 > 0) {
  1066. for (var i = 0; i < style1; i++) {
  1067. var datasheet_id = that.data.Style1[i].datasheet_id;
  1068. if (i == ruleClick1) {
  1069. siblingsSelectedObjId.push(datasheet_id);
  1070. } else {
  1071. noClickList.push(datasheet_id);
  1072. oldNoClickList.push(datasheet_id);
  1073. }
  1074. }
  1075. }
  1076. if (style2 > 0) {
  1077. for (var i = 0; i < style2; i++) {
  1078. var datasheet_id = that.data.Style2[i].datasheet_id;
  1079. if (i == ruleClick2) {
  1080. siblingsSelectedObjId.push(datasheet_id);
  1081. } else {
  1082. noClickList.push(datasheet_id);
  1083. oldNoClickList.push(datasheet_id);
  1084. }
  1085. }
  1086. }
  1087. if (style3 > 0) {
  1088. for (var i = 0; i < style3; i++) {
  1089. var datasheet_id = that.data.Style3[i].datasheet_id;
  1090. console.log("3-datasheetId: " + datasheet_id);
  1091. console.log("3-1: " + i);
  1092. console.log("3-ruleClick3: " + ruleClick3);
  1093. if (i == ruleClick3) {
  1094. siblingsSelectedObjId.push(datasheet_id);
  1095. } else {
  1096. noClickList.push(datasheet_id);
  1097. oldNoClickList.push(datasheet_id);
  1098. }
  1099. }
  1100. }
  1101. if (style4 > 0) {
  1102. for (var i = 0; i < style4; i++) {
  1103. var datasheet_id = that.data.Style4[i].datasheet_id;
  1104. if (i == ruleClick4) {
  1105. siblingsSelectedObjId.push(datasheet_id);
  1106. } else {
  1107. noClickList.push(datasheet_id);
  1108. oldNoClickList.push(datasheet_id);
  1109. }
  1110. }
  1111. }
  1112. if (style5 > 0) {
  1113. for (var i = 0; i < style5; i++) {
  1114. var datasheet_id = that.data.Style5[i].datasheet_id;
  1115. if (i == ruleClick5) {
  1116. siblingsSelectedObjId.push(datasheet_id);
  1117. } else {
  1118. noClickList.push(datasheet_id);
  1119. oldNoClickList.push(datasheet_id);
  1120. }
  1121. }
  1122. }
  1123. var selectedLength = 0;
  1124. for (var i = 0; i < noClickList.length; i++) {
  1125. var selectedLength = 0;
  1126. var siblingsSelectedObjId = '';//选中规格的id
  1127. var testAttrIds = [];//从选中节点中去掉选中的兄弟节点
  1128. if (style1 > 0 && ruleClick1 != '-') {
  1129. for (var m = 0; m < style1; m++){
  1130. if (that.data.Style1[m].datasheet_id == noClickList[i]){
  1131. if (that.data.Style1[ruleClick1].datasheet_id != noClickList[i]) {
  1132. selectedLength = 1;
  1133. siblingsSelectedObjId = that.data.Style1[ruleClick1].datasheet_id;
  1134. break;
  1135. }
  1136. }
  1137. }
  1138. }
  1139. if (style2 > 0 && ruleClick2 != '-') {
  1140. for (var m = 0; m < style2; m++) {
  1141. if (that.data.Style2[m].datasheet_id == noClickList[i]) {
  1142. if (that.data.Style2[ruleClick2].datasheet_id != noClickList[i]) {
  1143. selectedLength = 1;
  1144. siblingsSelectedObjId = that.data.Style2[ruleClick2].datasheet_id;
  1145. break;
  1146. }
  1147. }
  1148. }
  1149. }
  1150. if (style3 > 0 && ruleClick3 != '-') {
  1151. for (var m = 0; m < style3; m++) {
  1152. if (that.data.Style3[m].datasheet_id == noClickList[i]) {
  1153. if (that.data.Style3[ruleClick3].datasheet_id != noClickList[i]) {
  1154. selectedLength = 1;
  1155. siblingsSelectedObjId = that.data.Style3[ruleClick3].datasheet_id;
  1156. break;
  1157. }
  1158. }
  1159. }
  1160. }
  1161. if (style4 > 0 && ruleClick4 != '-') {
  1162. for (var m = 0; m < style4; m++) {
  1163. if (that.data.Style4[m].datasheet_id == noClickList[i]) {
  1164. if (that.data.Style4[ruleClick4].datasheet_id != noClickList[i]) {
  1165. selectedLength = 1;
  1166. siblingsSelectedObjId = that.data.Style4[ruleClick4].datasheet_id;
  1167. break;
  1168. }
  1169. }
  1170. }
  1171. }
  1172. if (style5 > 0 && ruleClick5 != '-') {
  1173. for (var m = 0; m < style5; m++) {
  1174. if (that.data.Style5[m].datasheet_id == noClickList[i]) {
  1175. if (that.data.Style5[ruleClick5].datasheet_id != noClickList[i]) {
  1176. selectedLength = 1;
  1177. siblingsSelectedObjId = that.data.Style5[ruleClick5].datasheet_id;
  1178. break;
  1179. }
  1180. }
  1181. }
  1182. }
  1183. if (selectedLength ) {
  1184. for (var j = 0; j < len; j++) {
  1185. (selectedIds[j] != siblingsSelectedObjId) && testAttrIds.push(selectedIds[j]);
  1186. }
  1187. } else {
  1188. testAttrIds = selectedIds.concat();
  1189. }
  1190. testAttrIds = testAttrIds.concat(noClickList[i]);
  1191. testAttrIds.sort(function (value1, value2) {
  1192. return parseInt(value1) - parseInt(value2);
  1193. });
  1194. if (style1 > 0) {
  1195. for (var k = 0; k < style1; k++) {
  1196. if (that.data.Style1[k].datasheet_id == noClickList[i]) {
  1197. if (!SKUResult[testAttrIds.join('-')]) {
  1198. that.data.Style1[k].clickTrue = false;
  1199. if (that.data.ruleClick1 == k) {
  1200. that.data.ruleClick1 = '-';
  1201. }
  1202. } else {
  1203. that.data.Style1[k].clickTrue = true;
  1204. }
  1205. }
  1206. }
  1207. }
  1208. if (style2 > 0) {
  1209. for (var k = 0; k < style2; k++) {
  1210. if (that.data.Style2[k].datasheet_id == noClickList[i]) {
  1211. if (!SKUResult[testAttrIds.join('-')]) {
  1212. that.data.Style2[k].clickTrue = false;
  1213. if (that.data.ruleClick2 == k){
  1214. that.data.ruleClick2 = '-';
  1215. }
  1216. } else {
  1217. that.data.Style2[k].clickTrue = true;
  1218. }
  1219. }
  1220. }
  1221. }
  1222. if (style3 > 0) {
  1223. for (var k = 0; k < style3; k++) {
  1224. if (that.data.Style3[k].datasheet_id == noClickList[i]) {
  1225. if (!SKUResult[testAttrIds.join('-')]) {
  1226. that.data.Style3[k].clickTrue = false;
  1227. if (that.data.ruleClick3 == k) {
  1228. that.data.ruleClick3 = '-';
  1229. }
  1230. } else {
  1231. that.data.Style3[k].clickTrue = true;
  1232. }
  1233. }
  1234. }
  1235. }
  1236. if (style4 > 0) {
  1237. for (var k = 0; k < style4; k++) {
  1238. if (that.data.Style4[k].datasheet_id == noClickList[i]) {
  1239. if (!SKUResult[testAttrIds.join('-')]) {
  1240. that.data.Style4[k].clickTrue = false;
  1241. if (that.data.ruleClick4 == k) {
  1242. that.data.ruleClick4 = '-';
  1243. }
  1244. } else {
  1245. that.data.Style4[k].clickTrue = true;
  1246. }
  1247. }
  1248. }
  1249. }
  1250. if (style5 > 0) {
  1251. for (var k = 0; k < style5; k++) {
  1252. if (that.data.Style5[k].datasheet_id == noClickList[i]) {
  1253. if (!SKUResult[testAttrIds.join('-')]) {
  1254. that.data.Style5[k].clickTrue = false;
  1255. if (that.data.ruleClick5 == k) {
  1256. that.data.ruleClick5 = '-';
  1257. }
  1258. } else {
  1259. that.data.Style5[k].clickTrue = true;
  1260. }
  1261. }
  1262. }
  1263. }
  1264. }
  1265. } else {
  1266. var showPrice = that.data.showPrice;
  1267. var showPrice = that.data.newPrice;
  1268. var showNum = that.data.showNum;
  1269. that.setData({
  1270. showPrice: showPrice,
  1271. showNum: showNum
  1272. })
  1273. }
  1274. that.setData({
  1275. Style1: that.data.Style1,
  1276. Style2: that.data.Style2,
  1277. Style3: that.data.Style3,
  1278. Style4: that.data.Style4,
  1279. Style5: that.data.Style5,
  1280. ruleClick1: that.data.ruleClick1,
  1281. ruleClick2: that.data.ruleClick2,
  1282. ruleClick3: that.data.ruleClick3,
  1283. ruleClick4: that.data.ruleClick4,
  1284. ruleClick5: that.data.ruleClick5
  1285. })
  1286. },
  1287. //立即购买下的规格选择
  1288. ruleSelect: function (e) {
  1289. var that = this
  1290. var id = e.currentTarget.dataset.id;
  1291. var datasheetId = e.currentTarget.dataset.sheetid;//规格id
  1292. var ruleNum = e.currentTarget.dataset.rule;//当前规格1-5
  1293. var styleLen = that.data.styleLen;
  1294. var clickNum = that.data.clickNum;
  1295. var clickBoxPrice = that.data.clickBoxPrice;
  1296. if (ruleNum == 1) {
  1297. if (that.data.ruleClick1 == id) {//当前为选中状态,变为取消状态
  1298. clickNum = clickNum - 1;
  1299. that.setData({
  1300. ruleClick1: '-',
  1301. rule1: '',
  1302. styleLen: styleLen--,
  1303. clickNum: clickNum,
  1304. sheetid1: ''
  1305. })
  1306. } else {
  1307. if (that.data.ruleClick1 == '-') {
  1308. clickNum = clickNum + 1;
  1309. that.setData({
  1310. clickNum: clickNum,
  1311. })
  1312. }
  1313. that.setData({
  1314. ruleClick1: id,
  1315. rule1: that.data.Style1[id].datasheet_name,
  1316. styleLen: styleLen++,
  1317. sheetid1: datasheetId
  1318. })
  1319. }
  1320. } else if (ruleNum == 2) {
  1321. if (that.data.ruleClick2 == id) {
  1322. clickNum = clickNum - 1;
  1323. that.setData({
  1324. ruleClick2: '-',
  1325. rule2: '',
  1326. styleLen: styleLen--,
  1327. clickNum: clickNum,
  1328. sheetid2: ''
  1329. })
  1330. } else {
  1331. if (that.data.ruleClick2 == '-') {
  1332. clickNum = clickNum + 1;
  1333. that.setData({
  1334. clickNum: clickNum,
  1335. })
  1336. }
  1337. that.setData({
  1338. ruleClick2: id,
  1339. rule2: that.data.Style2[id].datasheet_name,
  1340. styleLen: styleLen++,
  1341. sheetid2: datasheetId
  1342. })
  1343. }
  1344. } else if (ruleNum == 3) {
  1345. if (that.data.ruleClick3 == id) {
  1346. clickNum = clickNum - 1;
  1347. that.setData({
  1348. ruleClick3: '-',
  1349. rule3: '',
  1350. styleLen: styleLen--,
  1351. clickNum: clickNum,
  1352. sheetid3: ''
  1353. })
  1354. } else {
  1355. if (that.data.ruleClick3 == '-') {
  1356. clickNum = clickNum + 1;
  1357. that.setData({
  1358. clickNum: clickNum,
  1359. })
  1360. }
  1361. that.setData({
  1362. ruleClick3: id,
  1363. rule3: that.data.Style3[id].datasheet_name,
  1364. styleLen: styleLen++,
  1365. sheetid3: datasheetId,
  1366. })
  1367. }
  1368. } else if (ruleNum == 4) {
  1369. if (that.data.ruleClick4 == id) {
  1370. clickNum = clickNum - 1;
  1371. that.setData({
  1372. ruleClick4: '-',
  1373. rule4: '',
  1374. styleLen: styleLen--,
  1375. clickNum: clickNum,
  1376. sheetid4: ''
  1377. })
  1378. } else {
  1379. if (that.data.ruleClick4 == '-') {
  1380. clickNum = clickNum + 1;
  1381. that.setData({
  1382. clickNum: clickNum,
  1383. })
  1384. }
  1385. that.setData({
  1386. ruleClick4: id,
  1387. rule4: that.data.Style4[id].datasheet_name,
  1388. styleLen: styleLen++,
  1389. sheetid4: datasheetId
  1390. })
  1391. }
  1392. } else {
  1393. if (that.data.ruleClick5 == id) {
  1394. clickNum = clickNum - 1;
  1395. that.setData({
  1396. ruleClick5: '-',
  1397. rule5: '',
  1398. styleLen: styleLen--,
  1399. clickNum: clickNum,
  1400. sheetid5: ''
  1401. })
  1402. } else {
  1403. if (that.data.ruleClick5 == '-') {
  1404. clickNum = clickNum + 1;
  1405. that.setData({
  1406. clickNum: clickNum,
  1407. })
  1408. }
  1409. that.setData({
  1410. ruleClick5: id,
  1411. rule5: that.data.Style5[id].datasheet_name,
  1412. styleLen: styleLen++,
  1413. sheetid5: datasheetId
  1414. })
  1415. }
  1416. }
  1417. //分别与已点规格组合,判断是否有库存可选
  1418. that.chooseStyleSetData(datasheetId, clickNum);
  1419. if (that.data.styleLen == 0) {
  1420. that.setData({
  1421. chooseResult: 0
  1422. })
  1423. } else {
  1424. that.setData({
  1425. chooseResult: 1
  1426. })
  1427. }
  1428. },
  1429. //立即购买下的选择礼盒
  1430. boxSelect: function (options) {
  1431. var that = this
  1432. var id = options.currentTarget.dataset.id;
  1433. var boxPrice = that.data.gixboxService[id].box_price;
  1434. var modelStyleNum = that.data.modelStyleNum;//规格类别数
  1435. var clickNum = that.data.clickNum;
  1436. if (boxPrice == '' || boxPrice == null || boxPrice == undefined) {
  1437. that.setData({
  1438. clickBoxPrice: 0
  1439. })
  1440. }
  1441. if (that.data.boxClick == id) {//变为取消状态
  1442. if (modelStyleNum == clickNum) {
  1443. that.setData({
  1444. showPrice: parseFloat(that.data.showPrice) - parseFloat(boxPrice)
  1445. })
  1446. }
  1447. that.setData({
  1448. boxClick: '-',
  1449. selectBox: '',
  1450. clickBoxPrice : 0
  1451. })
  1452. if (that.data.styleLen == 0) {
  1453. that.setData({
  1454. chooseResult: 0
  1455. })
  1456. }
  1457. } else {
  1458. if (modelStyleNum == clickNum) {
  1459. that.setData({
  1460. showPrice: parseFloat(that.data.showPrice) - parseFloat(that.data.clickBoxPrice) + parseFloat(boxPrice)
  1461. })
  1462. }
  1463. that.setData({
  1464. chooseResult: 1,
  1465. boxClick: id,
  1466. selectBox: that.data.gixboxService[id].giftbox_name,
  1467. clickBoxPrice: boxPrice
  1468. })
  1469. }
  1470. },
  1471. //立即购买下的定制
  1472. dingZhiSelect: function (options) {
  1473. var that = this
  1474. var id = options.currentTarget.dataset.id;
  1475. if (that.data.dingZhiClick == id) {//变为取消状态
  1476. that.setData({
  1477. dingZhiClick: '-',
  1478. selectDingZhi: ''
  1479. })
  1480. } else {
  1481. that.setData({
  1482. chooseResult: 1,
  1483. dingZhiClick: id,
  1484. selectDingZhi: that.data.dingzhiService[id].process_name
  1485. })
  1486. }
  1487. //判断当前是否有选择的规格
  1488. if (that.data.styleLen == 0) {
  1489. that.setData({
  1490. chooseResult: 0
  1491. })
  1492. } else {
  1493. that.setData({
  1494. chooseResult: 1
  1495. })
  1496. }
  1497. },
  1498. //绑定加数量事件
  1499. addCount(e) {
  1500. var that = this;
  1501. var showNum = that.data.showNum;
  1502. let num = this.data.minNumber;
  1503. if (num >= showNum){
  1504. that.setData({
  1505. hiddenmodal: false,
  1506. modalCont: '超出库存',
  1507. minNumber: showNum
  1508. })
  1509. setTimeout(function () {
  1510. that.setData({
  1511. hiddenmodal: true,
  1512. })
  1513. }, 1000)
  1514. return false;
  1515. }else{
  1516. num++;
  1517. if (num == showNum){
  1518. this.setData({
  1519. "minNumber": num,
  1520. })
  1521. }else{
  1522. this.setData({
  1523. "minNumber": num,
  1524. })
  1525. }
  1526. }
  1527. },
  1528. //绑定减数量事件
  1529. minusCount(e) {
  1530. let num = this.data.minNumber;
  1531. let minnum = this.data.num;
  1532. if (num <= minnum) {
  1533. that.setData({
  1534. hiddenmodal: false,
  1535. modalCont: '起订量为' + minnum + '件',
  1536. minNumber: showNum
  1537. })
  1538. setTimeout(function () {
  1539. that.setData({
  1540. hiddenmodal: true,
  1541. })
  1542. }, 1000)
  1543. return false;
  1544. }
  1545. num--;
  1546. this.setData({
  1547. "minNumber": num
  1548. })
  1549. },
  1550. //手动填写数量
  1551. writeNum: function (e) {
  1552. var that = this;
  1553. var val = e.detail.value;
  1554. var minnum = that.data.num;//起订量
  1555. var showNum = that.data.showNum;//获取库存
  1556. if (parseInt(val) >= parseInt(showNum)) {//大于库存
  1557. that.setData({
  1558. minNumber: showNum
  1559. })
  1560. } else if (parseInt(val) < parseInt(minnum)) {//小于起订量
  1561. that.setData({
  1562. minNumber: minnum
  1563. })
  1564. } else {
  1565. that.setData({
  1566. minNumber: val
  1567. })
  1568. }
  1569. },
  1570. //加入购物车 - 打开选择弹窗
  1571. addCart: function (e) {
  1572. var that = this;
  1573. var scrollTop = that.data.scrollTop;
  1574. var com_id = that.data.com_id;//商品id
  1575. var specialGoodMsgShowCount = that.data.specialGoodMsgShowCount;//有时效性的商品,提示显示的次数
  1576. //判断商品是否已下架,若下架则不可点击
  1577. var soldOutShow = that.data.soldOutShow;
  1578. if (soldOutShow == true) {
  1579. return false;
  1580. }
  1581. that.setData({
  1582. chooseFlag: 0,//判断进入购买的入口【底部footer】
  1583. stateId: 0,
  1584. cont_hidden: 'cont_hidden'
  1585. });
  1586. wx.getSystemInfo({
  1587. success: function (res) {
  1588. animationShowHeight = res.windowHeight;
  1589. }
  1590. })
  1591. // 显示遮罩层
  1592. var animation = wx.createAnimation({
  1593. duration: 400,
  1594. timingFunction: 'linear',
  1595. })
  1596. this.animation = animation
  1597. animation.opacity(0).step()
  1598. this.setData({
  1599. isShow: true,
  1600. windBgShow: animation.export()
  1601. })
  1602. setTimeout(function () {
  1603. animation.opacity(1).step()
  1604. this.setData({
  1605. windBgShow: animation.export()
  1606. })
  1607. }.bind(this), 200)
  1608. //内容
  1609. animation.bottom(-animationShowHeight).step()
  1610. this.setData({
  1611. animationDataBuy: animation.export()
  1612. })
  1613. setTimeout(function () {
  1614. animation.bottom(0).step()
  1615. this.setData({
  1616. animationDataBuy: animation.export()
  1617. })
  1618. }.bind(this), 200);
  1619. //判断是否是特定的时效商品
  1620. if (com_id == '3419') {
  1621. if (specialGoodMsgShowCount == 0) {
  1622. that.setData({
  1623. isSpecialGood: true,
  1624. specialGoodMsgShowCount: specialGoodMsgShowCount + 1
  1625. })
  1626. }
  1627. }
  1628. },
  1629. //立即购买 - 打开选择弹窗
  1630. buyCart: function (e) {
  1631. var that = this;
  1632. var scrollTop = that.data.scrollTop;
  1633. var com_id = that.data.com_id;//商品id
  1634. var specialGoodMsgShowCount = that.data.specialGoodMsgShowCount;//有时效性的商品,提示显示的次数
  1635. //判断商品是否已下架,若下架则不可点击
  1636. var soldOutShow = that.data.soldOutShow;
  1637. if (soldOutShow == true) {
  1638. return false;
  1639. }
  1640. this.setData({
  1641. chooseFlag: 0,//判断进入购买的入口【底部footer】
  1642. stateId: 1,
  1643. cont_hidden: 'cont_hidden'
  1644. })
  1645. wx.getSystemInfo({
  1646. success: function (res) {
  1647. animationShowHeight = res.windowHeight;
  1648. }
  1649. })
  1650. var animation = wx.createAnimation({
  1651. duration: 400,
  1652. timingFunction: 'linear',
  1653. })
  1654. this.animation = animation
  1655. animation.opacity(0).step()
  1656. this.setData({
  1657. isShow: true,
  1658. windBgShow: animation.export()
  1659. })
  1660. setTimeout(function () {
  1661. animation.opacity(1).step()
  1662. this.setData({
  1663. windBgShow: animation.export()
  1664. })
  1665. }.bind(this), 200)
  1666. // 显示遮罩层
  1667. animation.bottom(-animationShowHeight).step()
  1668. this.setData({
  1669. animationDataBuy: animation.export()
  1670. })
  1671. setTimeout(function () {
  1672. animation.bottom(0).step()
  1673. this.setData({
  1674. animationDataBuy: animation.export()
  1675. })
  1676. }.bind(this), 200);
  1677. //判断是否是特定的时效商品
  1678. if (com_id == '3419') {
  1679. if (specialGoodMsgShowCount == 0) {
  1680. that.setData({
  1681. isSpecialGood: true,
  1682. specialGoodMsgShowCount: specialGoodMsgShowCount + 1
  1683. })
  1684. }
  1685. }
  1686. },
  1687. //跳转到购物车
  1688. linkCart: function (e) {
  1689. wx.navigateTo({
  1690. url: '/pages/carInsert/carInsert'
  1691. })
  1692. },
  1693. //收藏
  1694. collect: function (e) {
  1695. var dataState = e.currentTarget.dataset.state;
  1696. var host = getApp().globalData.servsers;
  1697. var un_id = getApp().globalData.un_id;
  1698. var openid = getApp().globalData.openid;
  1699. var that = this;
  1700. if ((un_id == undefined || un_id == '' || un_id == null) || (openid == undefined || openid == '' || openid == null)) {
  1701. wx.navigateTo({
  1702. url: '/pages/authorize/authorize?link=buy',
  1703. })
  1704. } else {
  1705. if (!dataState) {
  1706. //后台增加收藏用户收藏数据
  1707. wx.request({
  1708. url: host + "collectionapi/insertcollection",
  1709. data: {
  1710. user_id: un_id,
  1711. collection_clas: 2,
  1712. collection_name: that.data.com_id,
  1713. },
  1714. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  1715. header: {
  1716. 'Accept': 'application/json'
  1717. },
  1718. success: function (res) {
  1719. if (res == null || res.data == null) {
  1720. console.error('网络请求失败');
  1721. return;
  1722. }
  1723. }
  1724. })
  1725. this.setData({
  1726. collectState: true
  1727. })
  1728. } else {
  1729. wx.request({
  1730. url: host + "collectionapi / deleteforxcx",
  1731. data: {
  1732. user_id: un_id,
  1733. collection_clas: 2,
  1734. collection_name: that.data.com_id,
  1735. },
  1736. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  1737. header: {
  1738. 'Accept': 'application/json'
  1739. },
  1740. success: function (res) {
  1741. if (res == null || res.data == null) {
  1742. console.error('网络请求失败');
  1743. return;
  1744. }
  1745. }
  1746. })
  1747. this.setData({
  1748. collectState: false
  1749. })
  1750. }
  1751. }
  1752. },
  1753. //立即购买-去付款
  1754. tz: function (e) {
  1755. var that = this;
  1756. var host = getApp().globalData.servsers;
  1757. var un_id = getApp().globalData.un_id;
  1758. var openid = getApp().globalData.openid;
  1759. var id = e.currentTarget.dataset.id;
  1760. let carts = this.data.carts;
  1761. var shangpin_id = this.data.shangpin_id;
  1762. var name = this.data.title;
  1763. var logo = this.data.bannerSml;
  1764. var cost = this.data.newPrice;
  1765. var cyc = this.data.cycle;
  1766. var number = this.data.minNumber;
  1767. var limitNum = this.data.num;//起订量
  1768. var acceptance = this.data.title;
  1769. var region = this.data.title;
  1770. var specifications = this.data.title;
  1771. var comGroupId = [];
  1772. var styleName1 = '', styleName2 = '', styleName3 = '', styleName4 = '', styleName5 = '';
  1773. var styleId1 = '', styleId2 = '', styleId3 = '', styleId4 = '', styleId5 = '';
  1774. //规格 : 名称 当前选中的index 当前选中的对应数据Id
  1775. var style1 = that.data.Style1;
  1776. var style1 = that.data.Style1;
  1777. if (style1 == undefined || style1 == '' || style1 == null) {
  1778. styleName1 = '';
  1779. styleId1 = '';
  1780. } else {
  1781. var styleIndex1 = that.data.ruleClick1;
  1782. if (styleIndex1 == '-') {
  1783. that.setData({
  1784. hiddenmodal: false,
  1785. modalCont: '请选择' + that.data.style1_name
  1786. })
  1787. setTimeout(function () {
  1788. that.setData({
  1789. hiddenmodal: true
  1790. })
  1791. }, 1000)
  1792. return false;
  1793. } else {
  1794. styleId1 = that.data.Style1[styleIndex1].id;
  1795. styleName1 = that.data.Style1[styleIndex1].datasheet_name;
  1796. comGroupId.push(that.data.Style1[styleIndex1].datasheet_id);
  1797. }
  1798. }
  1799. var style2 = that.data.Style2;
  1800. if (style2 == undefined || style2 == '' || style2 == null) {
  1801. styleName2 = '';
  1802. styleId2 = '';
  1803. } else {
  1804. var styleIndex2 = that.data.ruleClick2;
  1805. if (styleIndex2 == '-') {
  1806. that.setData({
  1807. hiddenmodal: false,
  1808. modalCont: '请选择' + that.data.style2_name
  1809. })
  1810. setTimeout(function () {
  1811. that.setData({
  1812. hiddenmodal: true
  1813. })
  1814. }, 1000)
  1815. return false;
  1816. } else {
  1817. styleId2 = that.data.Style2[styleIndex2].id;
  1818. styleName2 = that.data.Style2[styleIndex2].datasheet_name;
  1819. comGroupId.push(that.data.Style2[styleIndex2].datasheet_id);
  1820. }
  1821. }
  1822. var style3 = that.data.Style3;
  1823. if (style3 == undefined || style3 == '' || style3 == null) {
  1824. styleName3 = '';
  1825. styleId3 = '';
  1826. } else {
  1827. var styleIndex3 = that.data.ruleClick3;
  1828. if (styleIndex3 == '-') {
  1829. that.setData({
  1830. hiddenmodal: false,
  1831. modalCont: '请选择' + that.data.style3_name
  1832. })
  1833. setTimeout(function () {
  1834. that.setData({
  1835. hiddenmodal: true
  1836. })
  1837. }, 1000)
  1838. return false;
  1839. } else {
  1840. styleId3 = that.data.Style3[styleIndex3].id;
  1841. styleName3 = that.data.Style3[styleIndex3].datasheet_name;
  1842. comGroupId.push(that.data.Style3[styleIndex3].datasheet_id);
  1843. }
  1844. }
  1845. var style4 = that.data.Style4;
  1846. if (style4 == undefined || style4 == '' || style4 == null) {
  1847. styleName4 = '';
  1848. styleId4 = '';
  1849. } else {
  1850. var styleIndex4 = that.data.ruleClick4;
  1851. if (styleIndex4 == '-') {
  1852. that.setData({
  1853. hiddenmodal: false,
  1854. modalCont: '请选择' + that.data.style4_name
  1855. })
  1856. setTimeout(function () {
  1857. that.setData({
  1858. hiddenmodal: true
  1859. })
  1860. }, 1000)
  1861. return false;
  1862. } else {
  1863. styleId4 = that.data.Style4[styleIndex4].id;
  1864. styleName4 = that.data.Style1[styleIndex4].datasheet_name;
  1865. comGroupId.push(that.data.Style4[styleIndex4].datasheet_id);
  1866. }
  1867. }
  1868. var style5 = that.data.Style5;
  1869. if (style5 == undefined || style5 == '' || style5 == null) {
  1870. styleName5 = '';
  1871. styleId5 = '';
  1872. } else {
  1873. var styleIndex5 = that.data.ruleClick5;
  1874. if (styleIndex5 == '-') {
  1875. that.setData({
  1876. hiddenmodal: false,
  1877. modalCont: '请选择' + that.data.style5_name
  1878. })
  1879. setTimeout(function () {
  1880. that.setData({
  1881. hiddenmodal: true
  1882. })
  1883. }, 1000)
  1884. return false;
  1885. } else {
  1886. styleId5 = that.data.Style5[styleIndex5].id;
  1887. styleName5 = that.data.Style5[styleIndex5].datasheet_name;
  1888. comGroupId.push(that.data.Style5[styleIndex5].datasheet_id);
  1889. }
  1890. }
  1891. var comGroupIdVal = comGroupId.join('-');
  1892. var saveStyleId = '';
  1893. for (var i = 0; i < that.data.groupList.length;i++){
  1894. if (that.data.groupList[i].datasheet_id == comGroupIdVal){
  1895. saveStyleId = that.data.groupList[i].id;
  1896. }
  1897. }
  1898. //礼盒 名称 当前选中的index 当前选中的对应数据Id
  1899. var selectBox = this.data.gixboxService;
  1900. if (selectBox == undefined || selectBox == '') {
  1901. var selectBoxName = '';
  1902. var selectBoxId = -1;
  1903. var selectBoxPrice = 0;
  1904. } else {
  1905. var gixboxIndex = this.data.boxClick;
  1906. if (gixboxIndex == '-') {
  1907. that.setData({
  1908. hiddenmodal: false,
  1909. modalCont: '请选择礼盒'
  1910. })
  1911. setTimeout(function () {
  1912. that.setData({
  1913. hiddenmodal: true
  1914. })
  1915. }, 1000)
  1916. return false;
  1917. } else {
  1918. var selectBoxId = this.data.gixboxService[gixboxIndex].id;
  1919. var selectBoxName = this.data.gixboxService[gixboxIndex].giftbox_name;
  1920. var selectBoxPrice = this.data.gixboxService[gixboxIndex].box_price;
  1921. }
  1922. }
  1923. //定制 名称 当前选中的index 当前选中的对应数据Id
  1924. var selectDingZhi = this.data.dingzhiService;
  1925. if (selectDingZhi == undefined || selectDingZhi == '') {
  1926. var selectDingZhiName = '';
  1927. var selectDingZhiId = -1;
  1928. } else {
  1929. var selectDingZhiIndex = this.data.dingZhiClick;
  1930. if (selectDingZhiIndex == '-') {
  1931. that.setData({
  1932. hiddenmodal: false,
  1933. modalCont: '请选择定制'
  1934. })
  1935. setTimeout(function () {
  1936. that.setData({
  1937. hiddenmodal: true
  1938. })
  1939. }, 1000)
  1940. return false;
  1941. } else {
  1942. var selectDingZhiId = this.data.dingzhiService[selectDingZhiIndex].id;
  1943. var selectDingZhiName = this.data.dingzhiService[selectDingZhiIndex].process_name;
  1944. }
  1945. }
  1946. if ((un_id == undefined || un_id == '' || un_id == null) || (openid == undefined || openid == '' || openid == null)) {
  1947. wx.navigateTo({
  1948. url: '/pages/authorize/authorize?link=buy',
  1949. })
  1950. } else {
  1951. var name = that.data.title;
  1952. var com_id = that.data.com_id;
  1953. var logo = that.data.bannerSml;
  1954. var cost = that.data.newPrice;
  1955. var acceptance = that.data.acceptance;
  1956. var cyc = that.data.cycle;
  1957. var minNumber = that.data.minNumber;
  1958. var limitNum = that.data.num;//起订量
  1959. var allPrice = parseFloat(that.data.showPrice);//商品总价格【价格 + 礼盒价格】
  1960. var goodPrice = parseFloat(that.data.showPrice) - parseFloat(that.data.clickBoxPrice);//商品单独的价格
  1961. if (id == 0) {//加入购物车
  1962. let num = parseInt(that.data.minNumber);
  1963. let oldNum = parseInt(that.data.cartNum);
  1964. let newNum = oldNum + num;
  1965. if (newNum > 99) {
  1966. that.setData({
  1967. 'cartNum': '99+'
  1968. })
  1969. } else {
  1970. that.setData({
  1971. 'cartNum': newNum
  1972. })
  1973. }
  1974. //加入购物车
  1975. wx.request({
  1976. url: host + "shoppingcartapi/insertshoppingcart",
  1977. data: {
  1978. user_id: un_id,
  1979. com_id: com_id,
  1980. name: name,
  1981. logo: logo,
  1982. cost: goodPrice,
  1983. cyc: cyc,
  1984. num: minNumber,
  1985. minNumber: limitNum,
  1986. acceptance: acceptance,
  1987. flag: 1,
  1988. giftbox: selectBoxId,
  1989. giftbox_name: selectBoxName,
  1990. box_price: that.data.clickBoxPrice,
  1991. process: selectDingZhiId,
  1992. process_name: selectDingZhiName,
  1993. style1_name: styleName1,
  1994. style1: styleId1,
  1995. style2_name: styleName2,
  1996. style2: styleId2,
  1997. style3_name: styleName3,
  1998. style3: styleId3,
  1999. style4_name: styleName4,
  2000. style4: styleId4,
  2001. style5_name: styleName5,
  2002. style5: styleId5,
  2003. comGroupId: saveStyleId,//商品组合规格id
  2004. },
  2005. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  2006. header: {
  2007. 'Accept': 'application/json'
  2008. },
  2009. success: function (res) {
  2010. if (res == null || res.data == null) {
  2011. console.error('网络请求失败');
  2012. return;
  2013. }
  2014. }
  2015. })
  2016. } else {
  2017. carts = [{
  2018. id: shangpin_id,
  2019. com_id: shangpin_id,
  2020. name: name,
  2021. logo: logo,
  2022. cost: goodPrice,//商品单独的价格
  2023. cyc: cyc,
  2024. num: minNumber,
  2025. acceptance: acceptance,
  2026. region: region,
  2027. specifications: specifications,
  2028. flag: 1,
  2029. giftbox: selectBoxId,
  2030. giftbox_name: selectBoxName,
  2031. box_price: that.data.clickBoxPrice,
  2032. style1: styleId1,
  2033. style1_name: styleName1,
  2034. style2: styleId2,
  2035. style2_name: styleName2,
  2036. style3: styleId3,
  2037. style3_name: styleName3,
  2038. style4: styleId4,
  2039. style4_name: styleName4,
  2040. style5: styleId5,
  2041. style5_name: styleName5,
  2042. process: selectDingZhiId,
  2043. process_name: selectDingZhiName,
  2044. new_price: that.data.showPrice,
  2045. com_group_id: saveStyleId,//商品组合规格id
  2046. }];
  2047. this.setData({
  2048. carts: carts
  2049. })
  2050. var newCarts = JSON.stringify(that.data.carts);
  2051. newCarts = newCarts.replace(/&/g, "zss");
  2052. wx.navigateTo({
  2053. url: '/pages/confirmOrder/confirmOrder?carts=' + newCarts,
  2054. })
  2055. }
  2056. wx.getSystemInfo({
  2057. success: function (res) {
  2058. animationShowHeight = res.windowHeight;
  2059. }
  2060. })
  2061. // 关闭遮罩层
  2062. var animation = wx.createAnimation({
  2063. duration: 400,
  2064. timingFunction: 'linear'
  2065. })
  2066. this.animation = animation;
  2067. animation.bottom(0).step()
  2068. this.setData({
  2069. isShow: false,
  2070. cont_hidden: '',
  2071. animationDataBuy: animation.export()
  2072. })
  2073. setTimeout(function () {
  2074. animation.bottom(-animationShowHeight).step()
  2075. this.setData({
  2076. animationDataBuy: animation.export()
  2077. })
  2078. }.bind(this), 200)
  2079. animation.opacity(1).step()
  2080. this.setData({
  2081. windBgShow: animation.export()
  2082. })
  2083. setTimeout(function () {
  2084. animation.opacity(0).step()
  2085. this.setData({
  2086. isShow: false,
  2087. windBgShow: animation.export()
  2088. })
  2089. }.bind(this), 200)
  2090. }
  2091. },
  2092. imageLoad: function (e) {
  2093. var that = this;
  2094. var imageSize = {};
  2095. var originalWidth = e.detail.width;//图片原始宽
  2096. var originalHeight = e.detail.height;//图片原始高
  2097. var originalScale = originalHeight / originalWidth;//图片高宽比
  2098. wx.getSystemInfo({
  2099. success: function (res) {
  2100. var windowWidth = res.windowWidth;
  2101. var windowHeight = res.windowHeight;
  2102. var windowscale = windowHeight / windowWidth;//屏幕高宽比
  2103. imageSize.imageHeight = (windowWidth * originalHeight) / originalWidth;
  2104. }
  2105. })
  2106. that.setData({
  2107. imageheight: imageSize.imageHeight,
  2108. })
  2109. },
  2110. windOpen: function () {
  2111. console.log("延时调用");
  2112. },
  2113. windClose: function () {
  2114. this.setData({
  2115. hidden: true
  2116. });
  2117. },
  2118. previewImg: function (e) {//banner图预览
  2119. var that = this;
  2120. var currentUrl = e.currentTarget.dataset.src;
  2121. wx.previewImage({
  2122. current: currentUrl,
  2123. urls: that.data.imgList
  2124. })
  2125. },
  2126. //显示选择商品&定制详情
  2127. showGoodsInfor: function () {
  2128. var that = this;
  2129. var scrollTop = that.data.scrollTop;
  2130. that.setData({
  2131. chooseFlag: 1,
  2132. cont_hidden: 'cont_hidden'
  2133. })
  2134. wx.getSystemInfo({
  2135. success: function (res) {
  2136. animationShowHeight = res.windowHeight;
  2137. }
  2138. })
  2139. // 显示遮罩层
  2140. var animation = wx.createAnimation({
  2141. duration: 400,
  2142. timingFunction: 'linear',
  2143. })
  2144. this.animation = animation
  2145. animation.opacity(0).step()
  2146. this.setData({
  2147. isShow: true,
  2148. windBgShow: animation.export()
  2149. })
  2150. setTimeout(function () {
  2151. animation.opacity(1).step()
  2152. this.setData({
  2153. windBgShow: animation.export()
  2154. })
  2155. }.bind(this), 200)
  2156. //内容
  2157. animation.bottom(-animationShowHeight).step()
  2158. this.setData({
  2159. animationDataBuy: animation.export()
  2160. })
  2161. setTimeout(function () {
  2162. animation.bottom(0).step()
  2163. this.setData({
  2164. animationDataBuy: animation.export()
  2165. })
  2166. }.bind(this), 200)
  2167. },
  2168. showServiceInfor: function () {//显示服务
  2169. var that = this;
  2170. var scrollTop = that.data.scrollTop;
  2171. that.setData({
  2172. stateId: 0,
  2173. cont_hidden: 'cont_hidden'
  2174. });
  2175. wx.getSystemInfo({
  2176. success: function (res) {
  2177. animationShowHeight = res.windowHeight;
  2178. }
  2179. })
  2180. var animation = wx.createAnimation({
  2181. duration: 400,
  2182. timingFunction: 'linear',
  2183. })
  2184. this.animation = animation
  2185. animation.opacity(0).step()
  2186. this.setData({
  2187. isShow: true,
  2188. windBgShow: animation.export()
  2189. })
  2190. setTimeout(function () {
  2191. animation.opacity(1).step()
  2192. this.setData({
  2193. windBgShow: animation.export()
  2194. })
  2195. }.bind(this), 200)
  2196. animation.bottom(-animationShowHeight).step()
  2197. this.setData({
  2198. animationDataSer: animation.export()
  2199. })
  2200. setTimeout(function () {
  2201. animation.bottom(0).step()
  2202. this.setData({
  2203. animationDataSer: animation.export()
  2204. })
  2205. }.bind(this), 200)
  2206. },
  2207. closeBuy: function () {//关闭购买弹窗
  2208. var that = this;
  2209. wx.getSystemInfo({
  2210. success: function (res) {
  2211. animationShowHeight = res.windowHeight;
  2212. }
  2213. })
  2214. var animation = wx.createAnimation({
  2215. duration: 400,
  2216. timingFunction: 'linear',
  2217. })
  2218. this.animation = animation
  2219. animation.opacity(1).step()
  2220. this.setData({
  2221. windBgShow: animation.export()
  2222. })
  2223. setTimeout(function () {
  2224. animation.opacity(0).step()
  2225. this.setData({
  2226. isShow: false,
  2227. windBgShow: animation.export(),
  2228. cont_hidden: ''
  2229. })
  2230. }.bind(this), 200)
  2231. // 显示遮罩层
  2232. animation.bottom(0).step()
  2233. this.setData({
  2234. animationDataBuy: animation.export()
  2235. })
  2236. setTimeout(function () {
  2237. animation.bottom(-animationShowHeight).step()
  2238. this.setData({
  2239. animationDataBuy: animation.export()
  2240. })
  2241. }.bind(this), 200)
  2242. },
  2243. closeService: function () {//关闭服务弹窗
  2244. var that = this;
  2245. that.setData({
  2246. chooseFlag: 0,
  2247. cont_hidden: ''
  2248. })
  2249. wx.getSystemInfo({
  2250. success: function (res) {
  2251. animationShowHeight = res.windowHeight;
  2252. }
  2253. })
  2254. var animation = wx.createAnimation({
  2255. duration: 400,
  2256. timingFunction: 'linear',
  2257. })
  2258. this.animation = animation
  2259. animation.opacity(1).step()
  2260. this.setData({
  2261. windBgShow: animation.export()
  2262. })
  2263. setTimeout(function () {
  2264. animation.opacity(0).step()
  2265. this.setData({
  2266. isShow: false,
  2267. windBgShow: animation.export()
  2268. })
  2269. }.bind(this), 200)
  2270. // 内容
  2271. animation.bottom(0).step()
  2272. this.setData({
  2273. animationDataSer: animation.export()
  2274. })
  2275. setTimeout(function () {
  2276. animation.bottom(-animationShowHeight).step()
  2277. this.setData({
  2278. animationDataSer: animation.export()
  2279. })
  2280. }.bind(this), 200)
  2281. },
  2282. onShareAppMessage: function (res) {//页面分享
  2283. var that = this;
  2284. var host = getApp().globalData.servsers;
  2285. if (res.from === 'button') {
  2286. // 来自页面内转发按钮
  2287. }
  2288. return {
  2289. title: that.data.title,
  2290. path: '/pages/buy/buy?com_id=' + that.data.com_id + '&from_flag=' + 1,
  2291. imageUrl: host + 'images/' + that.data.bannerShare,
  2292. success: function (res) {
  2293. // 转发成功
  2294. that.setData({
  2295. hiddenmodal: false,
  2296. modalCont: '分享成功'
  2297. })
  2298. setTimeout(function () {
  2299. that.setData({
  2300. hiddenmodal: true
  2301. })
  2302. }, 1000)
  2303. },
  2304. fail: function (res) {
  2305. // 取消分享、转发失败
  2306. }
  2307. }
  2308. },
  2309. //关闭具有时效性商品的购买提示
  2310. closeMsg: function () {
  2311. var that = this;
  2312. that.setData({
  2313. isSpecialGood: false
  2314. })
  2315. },
  2316. //返回首页
  2317. backIndex: function (e) {
  2318. wx.switchTab({
  2319. url: '/pages/index/index',
  2320. })
  2321. }
  2322. })
  2323. var that;
  2324. var imageUtil = require('../../utils/util.js');