buy.js 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549
  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(e) {
  1689. console.log(e)
  1690. wx.switchTab({
  1691. url: '/pages/car/index',
  1692. })
  1693. },
  1694. //收藏
  1695. collect: function (e) {
  1696. var dataState = e.currentTarget.dataset.state;
  1697. var host = getApp().globalData.servsers;
  1698. var un_id = getApp().globalData.un_id;
  1699. var openid = getApp().globalData.openid;
  1700. var that = this;
  1701. if ((un_id == undefined || un_id == '' || un_id == null) || (openid == undefined || openid == '' || openid == null)) {
  1702. wx.navigateTo({
  1703. url: '/pages/authorize/authorize?link=buy',
  1704. })
  1705. } else {
  1706. if (!dataState) {
  1707. //后台增加收藏用户收藏数据
  1708. wx.request({
  1709. url: host + "collectionapi/insertcollection",
  1710. data: {
  1711. user_id: un_id,
  1712. collection_clas: 2,
  1713. collection_name: that.data.com_id,
  1714. },
  1715. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  1716. header: {
  1717. 'Accept': 'application/json'
  1718. },
  1719. success: function (res) {
  1720. if (res == null || res.data == null) {
  1721. console.error('网络请求失败');
  1722. return;
  1723. }
  1724. }
  1725. })
  1726. this.setData({
  1727. collectState: true
  1728. })
  1729. } else {
  1730. wx.request({
  1731. url: host + "collectionapi / deleteforxcx",
  1732. data: {
  1733. user_id: un_id,
  1734. collection_clas: 2,
  1735. collection_name: that.data.com_id,
  1736. },
  1737. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  1738. header: {
  1739. 'Accept': 'application/json'
  1740. },
  1741. success: function (res) {
  1742. if (res == null || res.data == null) {
  1743. console.error('网络请求失败');
  1744. return;
  1745. }
  1746. }
  1747. })
  1748. this.setData({
  1749. collectState: false
  1750. })
  1751. }
  1752. }
  1753. },
  1754. //立即购买-去付款
  1755. tz: function (e) {
  1756. var that = this;
  1757. var host = getApp().globalData.servsers;
  1758. var un_id = getApp().globalData.un_id;
  1759. var openid = getApp().globalData.openid;
  1760. var id = e.currentTarget.dataset.id;
  1761. let carts = this.data.carts;
  1762. var shangpin_id = this.data.shangpin_id;
  1763. var name = this.data.title;
  1764. var logo = this.data.bannerSml;
  1765. var cost = this.data.newPrice;
  1766. var cyc = this.data.cycle;
  1767. var number = this.data.minNumber;
  1768. var limitNum = this.data.num;//起订量
  1769. var acceptance = this.data.title;
  1770. var region = this.data.title;
  1771. var specifications = this.data.title;
  1772. var comGroupId = [];
  1773. var styleName1 = '', styleName2 = '', styleName3 = '', styleName4 = '', styleName5 = '';
  1774. var styleId1 = '', styleId2 = '', styleId3 = '', styleId4 = '', styleId5 = '';
  1775. //规格 : 名称 当前选中的index 当前选中的对应数据Id
  1776. var style1 = that.data.Style1;
  1777. var style1 = that.data.Style1;
  1778. if (style1 == undefined || style1 == '' || style1 == null) {
  1779. styleName1 = '';
  1780. styleId1 = '';
  1781. } else {
  1782. var styleIndex1 = that.data.ruleClick1;
  1783. if (styleIndex1 == '-') {
  1784. that.setData({
  1785. hiddenmodal: false,
  1786. modalCont: '请选择' + that.data.style1_name
  1787. })
  1788. setTimeout(function () {
  1789. that.setData({
  1790. hiddenmodal: true
  1791. })
  1792. }, 1000)
  1793. return false;
  1794. } else {
  1795. styleId1 = that.data.Style1[styleIndex1].id;
  1796. styleName1 = that.data.Style1[styleIndex1].datasheet_name;
  1797. comGroupId.push(that.data.Style1[styleIndex1].datasheet_id);
  1798. }
  1799. }
  1800. var style2 = that.data.Style2;
  1801. if (style2 == undefined || style2 == '' || style2 == null) {
  1802. styleName2 = '';
  1803. styleId2 = '';
  1804. } else {
  1805. var styleIndex2 = that.data.ruleClick2;
  1806. if (styleIndex2 == '-') {
  1807. that.setData({
  1808. hiddenmodal: false,
  1809. modalCont: '请选择' + that.data.style2_name
  1810. })
  1811. setTimeout(function () {
  1812. that.setData({
  1813. hiddenmodal: true
  1814. })
  1815. }, 1000)
  1816. return false;
  1817. } else {
  1818. styleId2 = that.data.Style2[styleIndex2].id;
  1819. styleName2 = that.data.Style2[styleIndex2].datasheet_name;
  1820. comGroupId.push(that.data.Style2[styleIndex2].datasheet_id);
  1821. }
  1822. }
  1823. var style3 = that.data.Style3;
  1824. if (style3 == undefined || style3 == '' || style3 == null) {
  1825. styleName3 = '';
  1826. styleId3 = '';
  1827. } else {
  1828. var styleIndex3 = that.data.ruleClick3;
  1829. if (styleIndex3 == '-') {
  1830. that.setData({
  1831. hiddenmodal: false,
  1832. modalCont: '请选择' + that.data.style3_name
  1833. })
  1834. setTimeout(function () {
  1835. that.setData({
  1836. hiddenmodal: true
  1837. })
  1838. }, 1000)
  1839. return false;
  1840. } else {
  1841. styleId3 = that.data.Style3[styleIndex3].id;
  1842. styleName3 = that.data.Style3[styleIndex3].datasheet_name;
  1843. comGroupId.push(that.data.Style3[styleIndex3].datasheet_id);
  1844. }
  1845. }
  1846. var style4 = that.data.Style4;
  1847. if (style4 == undefined || style4 == '' || style4 == null) {
  1848. styleName4 = '';
  1849. styleId4 = '';
  1850. } else {
  1851. var styleIndex4 = that.data.ruleClick4;
  1852. if (styleIndex4 == '-') {
  1853. that.setData({
  1854. hiddenmodal: false,
  1855. modalCont: '请选择' + that.data.style4_name
  1856. })
  1857. setTimeout(function () {
  1858. that.setData({
  1859. hiddenmodal: true
  1860. })
  1861. }, 1000)
  1862. return false;
  1863. } else {
  1864. styleId4 = that.data.Style4[styleIndex4].id;
  1865. styleName4 = that.data.Style1[styleIndex4].datasheet_name;
  1866. comGroupId.push(that.data.Style4[styleIndex4].datasheet_id);
  1867. }
  1868. }
  1869. var style5 = that.data.Style5;
  1870. if (style5 == undefined || style5 == '' || style5 == null) {
  1871. styleName5 = '';
  1872. styleId5 = '';
  1873. } else {
  1874. var styleIndex5 = that.data.ruleClick5;
  1875. if (styleIndex5 == '-') {
  1876. that.setData({
  1877. hiddenmodal: false,
  1878. modalCont: '请选择' + that.data.style5_name
  1879. })
  1880. setTimeout(function () {
  1881. that.setData({
  1882. hiddenmodal: true
  1883. })
  1884. }, 1000)
  1885. return false;
  1886. } else {
  1887. styleId5 = that.data.Style5[styleIndex5].id;
  1888. styleName5 = that.data.Style5[styleIndex5].datasheet_name;
  1889. comGroupId.push(that.data.Style5[styleIndex5].datasheet_id);
  1890. }
  1891. }
  1892. var comGroupIdVal = comGroupId.join('-');
  1893. var saveStyleId = '';
  1894. for (var i = 0; i < that.data.groupList.length;i++){
  1895. if (that.data.groupList[i].datasheet_id == comGroupIdVal){
  1896. saveStyleId = that.data.groupList[i].id;
  1897. }
  1898. }
  1899. //礼盒 名称 当前选中的index 当前选中的对应数据Id
  1900. var selectBox = this.data.gixboxService;
  1901. if (selectBox == undefined || selectBox == '') {
  1902. var selectBoxName = '';
  1903. var selectBoxId = -1;
  1904. var selectBoxPrice = 0;
  1905. } else {
  1906. var gixboxIndex = this.data.boxClick;
  1907. if (gixboxIndex == '-') {
  1908. that.setData({
  1909. hiddenmodal: false,
  1910. modalCont: '请选择礼盒'
  1911. })
  1912. setTimeout(function () {
  1913. that.setData({
  1914. hiddenmodal: true
  1915. })
  1916. }, 1000)
  1917. return false;
  1918. } else {
  1919. var selectBoxId = this.data.gixboxService[gixboxIndex].id;
  1920. var selectBoxName = this.data.gixboxService[gixboxIndex].giftbox_name;
  1921. var selectBoxPrice = this.data.gixboxService[gixboxIndex].box_price;
  1922. }
  1923. }
  1924. //定制 名称 当前选中的index 当前选中的对应数据Id
  1925. var selectDingZhi = this.data.dingzhiService;
  1926. if (selectDingZhi == undefined || selectDingZhi == '') {
  1927. var selectDingZhiName = '';
  1928. var selectDingZhiId = -1;
  1929. } else {
  1930. var selectDingZhiIndex = this.data.dingZhiClick;
  1931. if (selectDingZhiIndex == '-') {
  1932. that.setData({
  1933. hiddenmodal: false,
  1934. modalCont: '请选择定制'
  1935. })
  1936. setTimeout(function () {
  1937. that.setData({
  1938. hiddenmodal: true
  1939. })
  1940. }, 1000)
  1941. return false;
  1942. } else {
  1943. var selectDingZhiId = this.data.dingzhiService[selectDingZhiIndex].id;
  1944. var selectDingZhiName = this.data.dingzhiService[selectDingZhiIndex].process_name;
  1945. }
  1946. }
  1947. if ((un_id == undefined || un_id == '' || un_id == null) || (openid == undefined || openid == '' || openid == null)) {
  1948. wx.navigateTo({
  1949. url: '/pages/authorize/authorize?link=buy',
  1950. })
  1951. } else {
  1952. var name = that.data.title;
  1953. var com_id = that.data.com_id;
  1954. var logo = that.data.bannerSml;
  1955. var cost = that.data.newPrice;
  1956. var acceptance = that.data.acceptance;
  1957. var cyc = that.data.cycle;
  1958. var minNumber = that.data.minNumber;
  1959. var limitNum = that.data.num;//起订量
  1960. var allPrice = parseFloat(that.data.showPrice);//商品总价格【价格 + 礼盒价格】
  1961. var goodPrice = parseFloat(that.data.showPrice) - parseFloat(that.data.clickBoxPrice);//商品单独的价格
  1962. if (id == 0) {//加入购物车
  1963. let num = parseInt(that.data.minNumber);
  1964. let oldNum = parseInt(that.data.cartNum);
  1965. let newNum = oldNum + num;
  1966. if (newNum > 99) {
  1967. that.setData({
  1968. 'cartNum': '99+'
  1969. })
  1970. } else {
  1971. that.setData({
  1972. 'cartNum': newNum
  1973. })
  1974. }
  1975. //加入购物车
  1976. wx.request({
  1977. url: host + "shoppingcartapi/insertshoppingcart",
  1978. data: {
  1979. user_id: un_id,
  1980. com_id: com_id,
  1981. name: name,
  1982. logo: logo,
  1983. cost: goodPrice,
  1984. cyc: cyc,
  1985. num: minNumber,
  1986. minNumber: limitNum,
  1987. acceptance: acceptance,
  1988. flag: 1,
  1989. giftbox: selectBoxId,
  1990. giftbox_name: selectBoxName,
  1991. box_price: that.data.clickBoxPrice,
  1992. process: selectDingZhiId,
  1993. process_name: selectDingZhiName,
  1994. style1_name: styleName1,
  1995. style1: styleId1,
  1996. style2_name: styleName2,
  1997. style2: styleId2,
  1998. style3_name: styleName3,
  1999. style3: styleId3,
  2000. style4_name: styleName4,
  2001. style4: styleId4,
  2002. style5_name: styleName5,
  2003. style5: styleId5,
  2004. comGroupId: saveStyleId,//商品组合规格id
  2005. },
  2006. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  2007. header: {
  2008. 'Accept': 'application/json'
  2009. },
  2010. success: function (res) {
  2011. if (res == null || res.data == null) {
  2012. console.error('网络请求失败');
  2013. return;
  2014. }
  2015. }
  2016. })
  2017. } else {
  2018. carts = [{
  2019. id: shangpin_id,
  2020. com_id: shangpin_id,
  2021. name: name,
  2022. logo: logo,
  2023. cost: goodPrice,//商品单独的价格
  2024. cyc: cyc,
  2025. num: minNumber,
  2026. acceptance: acceptance,
  2027. region: region,
  2028. specifications: specifications,
  2029. flag: 1,
  2030. giftbox: selectBoxId,
  2031. giftbox_name: selectBoxName,
  2032. box_price: that.data.clickBoxPrice,
  2033. style1: styleId1,
  2034. style1_name: styleName1,
  2035. style2: styleId2,
  2036. style2_name: styleName2,
  2037. style3: styleId3,
  2038. style3_name: styleName3,
  2039. style4: styleId4,
  2040. style4_name: styleName4,
  2041. style5: styleId5,
  2042. style5_name: styleName5,
  2043. process: selectDingZhiId,
  2044. process_name: selectDingZhiName,
  2045. new_price: that.data.showPrice,
  2046. com_group_id: saveStyleId,//商品组合规格id
  2047. }];
  2048. this.setData({
  2049. carts: carts
  2050. })
  2051. var newCarts = JSON.stringify(that.data.carts);
  2052. newCarts = newCarts.replace(/&/g, "zss");
  2053. wx.navigateTo({
  2054. url: '/pages/confirmOrder/confirmOrder?carts=' + newCarts,
  2055. })
  2056. }
  2057. wx.getSystemInfo({
  2058. success: function (res) {
  2059. animationShowHeight = res.windowHeight;
  2060. }
  2061. })
  2062. // 关闭遮罩层
  2063. var animation = wx.createAnimation({
  2064. duration: 400,
  2065. timingFunction: 'linear'
  2066. })
  2067. this.animation = animation;
  2068. animation.bottom(0).step()
  2069. this.setData({
  2070. isShow: false,
  2071. cont_hidden: '',
  2072. animationDataBuy: animation.export()
  2073. })
  2074. setTimeout(function () {
  2075. animation.bottom(-animationShowHeight).step()
  2076. this.setData({
  2077. animationDataBuy: animation.export()
  2078. })
  2079. }.bind(this), 200)
  2080. animation.opacity(1).step()
  2081. this.setData({
  2082. windBgShow: animation.export()
  2083. })
  2084. setTimeout(function () {
  2085. animation.opacity(0).step()
  2086. this.setData({
  2087. isShow: false,
  2088. windBgShow: animation.export()
  2089. })
  2090. }.bind(this), 200)
  2091. }
  2092. },
  2093. imageLoad: function (e) {
  2094. var that = this;
  2095. var imageSize = {};
  2096. var originalWidth = e.detail.width;//图片原始宽
  2097. var originalHeight = e.detail.height;//图片原始高
  2098. var originalScale = originalHeight / originalWidth;//图片高宽比
  2099. wx.getSystemInfo({
  2100. success: function (res) {
  2101. var windowWidth = res.windowWidth;
  2102. var windowHeight = res.windowHeight;
  2103. var windowscale = windowHeight / windowWidth;//屏幕高宽比
  2104. imageSize.imageHeight = (windowWidth * originalHeight) / originalWidth;
  2105. }
  2106. })
  2107. that.setData({
  2108. imageheight: imageSize.imageHeight,
  2109. })
  2110. },
  2111. windOpen: function () {
  2112. console.log("延时调用");
  2113. },
  2114. windClose: function () {
  2115. this.setData({
  2116. hidden: true
  2117. });
  2118. },
  2119. previewImg: function (e) {//banner图预览
  2120. var that = this;
  2121. var currentUrl = e.currentTarget.dataset.src;
  2122. wx.previewImage({
  2123. current: currentUrl,
  2124. urls: that.data.imgList
  2125. })
  2126. },
  2127. //显示选择商品&定制详情
  2128. showGoodsInfor: function () {
  2129. var that = this;
  2130. var scrollTop = that.data.scrollTop;
  2131. that.setData({
  2132. chooseFlag: 1,
  2133. cont_hidden: 'cont_hidden'
  2134. })
  2135. wx.getSystemInfo({
  2136. success: function (res) {
  2137. animationShowHeight = res.windowHeight;
  2138. }
  2139. })
  2140. // 显示遮罩层
  2141. var animation = wx.createAnimation({
  2142. duration: 400,
  2143. timingFunction: 'linear',
  2144. })
  2145. this.animation = animation
  2146. animation.opacity(0).step()
  2147. this.setData({
  2148. isShow: true,
  2149. windBgShow: animation.export()
  2150. })
  2151. setTimeout(function () {
  2152. animation.opacity(1).step()
  2153. this.setData({
  2154. windBgShow: animation.export()
  2155. })
  2156. }.bind(this), 200)
  2157. //内容
  2158. animation.bottom(-animationShowHeight).step()
  2159. this.setData({
  2160. animationDataBuy: animation.export()
  2161. })
  2162. setTimeout(function () {
  2163. animation.bottom(0).step()
  2164. this.setData({
  2165. animationDataBuy: animation.export()
  2166. })
  2167. }.bind(this), 200)
  2168. },
  2169. showServiceInfor: function () {//显示服务
  2170. var that = this;
  2171. var scrollTop = that.data.scrollTop;
  2172. that.setData({
  2173. stateId: 0,
  2174. cont_hidden: 'cont_hidden'
  2175. });
  2176. wx.getSystemInfo({
  2177. success: function (res) {
  2178. animationShowHeight = res.windowHeight;
  2179. }
  2180. })
  2181. var animation = wx.createAnimation({
  2182. duration: 400,
  2183. timingFunction: 'linear',
  2184. })
  2185. this.animation = animation
  2186. animation.opacity(0).step()
  2187. this.setData({
  2188. isShow: true,
  2189. windBgShow: animation.export()
  2190. })
  2191. setTimeout(function () {
  2192. animation.opacity(1).step()
  2193. this.setData({
  2194. windBgShow: animation.export()
  2195. })
  2196. }.bind(this), 200)
  2197. animation.bottom(-animationShowHeight).step()
  2198. this.setData({
  2199. animationDataSer: animation.export()
  2200. })
  2201. setTimeout(function () {
  2202. animation.bottom(0).step()
  2203. this.setData({
  2204. animationDataSer: animation.export()
  2205. })
  2206. }.bind(this), 200)
  2207. },
  2208. closeBuy: function () {//关闭购买弹窗
  2209. var that = this;
  2210. wx.getSystemInfo({
  2211. success: function (res) {
  2212. animationShowHeight = res.windowHeight;
  2213. }
  2214. })
  2215. var animation = wx.createAnimation({
  2216. duration: 400,
  2217. timingFunction: 'linear',
  2218. })
  2219. this.animation = animation
  2220. animation.opacity(1).step()
  2221. this.setData({
  2222. windBgShow: animation.export()
  2223. })
  2224. setTimeout(function () {
  2225. animation.opacity(0).step()
  2226. this.setData({
  2227. isShow: false,
  2228. windBgShow: animation.export(),
  2229. cont_hidden: ''
  2230. })
  2231. }.bind(this), 200)
  2232. // 显示遮罩层
  2233. animation.bottom(0).step()
  2234. this.setData({
  2235. animationDataBuy: animation.export()
  2236. })
  2237. setTimeout(function () {
  2238. animation.bottom(-animationShowHeight).step()
  2239. this.setData({
  2240. animationDataBuy: animation.export()
  2241. })
  2242. }.bind(this), 200)
  2243. },
  2244. closeService: function () {//关闭服务弹窗
  2245. var that = this;
  2246. that.setData({
  2247. chooseFlag: 0,
  2248. cont_hidden: ''
  2249. })
  2250. wx.getSystemInfo({
  2251. success: function (res) {
  2252. animationShowHeight = res.windowHeight;
  2253. }
  2254. })
  2255. var animation = wx.createAnimation({
  2256. duration: 400,
  2257. timingFunction: 'linear',
  2258. })
  2259. this.animation = animation
  2260. animation.opacity(1).step()
  2261. this.setData({
  2262. windBgShow: animation.export()
  2263. })
  2264. setTimeout(function () {
  2265. animation.opacity(0).step()
  2266. this.setData({
  2267. isShow: false,
  2268. windBgShow: animation.export()
  2269. })
  2270. }.bind(this), 200)
  2271. // 内容
  2272. animation.bottom(0).step()
  2273. this.setData({
  2274. animationDataSer: animation.export()
  2275. })
  2276. setTimeout(function () {
  2277. animation.bottom(-animationShowHeight).step()
  2278. this.setData({
  2279. animationDataSer: animation.export()
  2280. })
  2281. }.bind(this), 200)
  2282. },
  2283. onShareAppMessage: function (res) {//页面分享
  2284. var that = this;
  2285. var host = getApp().globalData.servsers;
  2286. if (res.from === 'button') {
  2287. // 来自页面内转发按钮
  2288. }
  2289. return {
  2290. title: that.data.title,
  2291. path: '/pages/buy/buy?com_id=' + that.data.com_id + '&from_flag=' + 1,
  2292. imageUrl: host + 'images/' + that.data.bannerShare,
  2293. success: function (res) {
  2294. // 转发成功
  2295. that.setData({
  2296. hiddenmodal: false,
  2297. modalCont: '分享成功'
  2298. })
  2299. setTimeout(function () {
  2300. that.setData({
  2301. hiddenmodal: true
  2302. })
  2303. }, 1000)
  2304. },
  2305. fail: function (res) {
  2306. // 取消分享、转发失败
  2307. }
  2308. }
  2309. },
  2310. //关闭具有时效性商品的购买提示
  2311. closeMsg: function () {
  2312. var that = this;
  2313. that.setData({
  2314. isSpecialGood: false
  2315. })
  2316. },
  2317. //返回首页
  2318. backIndex: function (e) {
  2319. wx.switchTab({
  2320. url: '/pages/index/index',
  2321. })
  2322. }
  2323. })
  2324. var that;
  2325. var imageUtil = require('../../utils/util.js');