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