buy.js 74 KB

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