buyMoonCake.js 71 KB

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