buy.js 72 KB

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