chooseGoodsCommon.js 99 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715
  1. /*******************************************************************************
  2. * Copyright(c) 2022 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:商品选择相关共通方法
  5. * 2.功能描述:首页 促销商品选择,购物车页面,开单选商品,退还补选商品
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 于继渤 2022-09-01 1.00 商品选择相关共通方法(方便维护)
  9. *******************************************************************************/
  10. const app = getApp()
  11. const api = require('./api.js');
  12. const Constants = require('./Constants.js');
  13. const common = require('./common.js');
  14. const util = require('./util.js');
  15. /**
  16. * @desc : 打开商品
  17. * @author : 于继渤
  18. * @date : 2022/7/2 20:16
  19. */
  20. function openAddItemInfoCommon(e, _this, page, type) {
  21. _this.setData({
  22. goodsSkuList: []
  23. })
  24. let item = e.currentTarget.dataset.item
  25. //促销类型
  26. let promotionType = e.currentTarget.dataset.item.promotionType
  27. item['priceStandardTemp'] = item.priceStandard
  28. //开单/退还补选商品页面
  29. if (page == 'choose-goods') {
  30. item.itemQuantity = 1
  31. //促销价
  32. item.pricePromotion = e.currentTarget.dataset.item.pricePromotion
  33. item.activityId = e.currentTarget.dataset.item.activityId
  34. item.warehouseId = app.globalData.user.whId
  35. item.whId = app.globalData.user.whId
  36. item.warehouseName = app.globalData.user.whName
  37. // 组合促销
  38. if (promotionType == Constants.PROMOTION_TYPE.COMBINED) {
  39. getCombinedByPriceId(e, _this);
  40. _this.setData({
  41. show1: false,
  42. show2: false,
  43. show3: false,
  44. show4: true,
  45. show5: false
  46. })
  47. }
  48. else {
  49. //非标淋浴房 2定制
  50. if (item.flgNonStandardType == 1 || item.flgNonStandardType == 2) {
  51. item.nonStandardList = []
  52. item.nonStandardArea = 1
  53. //加载默认spu非标参数数据
  54. getFlgNonStandardList(item, _this)
  55. _this.setData({
  56. show7: true
  57. })
  58. }
  59. // 根据spuId获取sku相关信息
  60. getSkuBySpuId(e, _this);
  61. _this.setData({
  62. show1: true,
  63. show2: false,
  64. show3: false,
  65. show4: false,
  66. show5: false
  67. })
  68. }
  69. _this.setData({
  70. currentChoosedItem: item,
  71. showAdd: true,
  72. })
  73. }
  74. //购物车页面
  75. if (page == 'shopping') {
  76. item.itemQuantity = 1
  77. //促销价
  78. item.pricePromotion = e.currentTarget.dataset.item.pricePromotion
  79. item.activityId = e.currentTarget.dataset.item.activityId
  80. item.warehouseId = app.globalData.user.whId
  81. item.whId = app.globalData.user.whId
  82. item.warehouseName = app.globalData.user.whName
  83. // 组合促销
  84. if (promotionType == Constants.PROMOTION_TYPE.COMBINED) {
  85. getCombinedByPriceId(e, _this, type);
  86. _this.setData({
  87. show1: false,
  88. show2: false,
  89. show3: false,
  90. show4: true,
  91. show5: false
  92. })
  93. }
  94. else {
  95. //非标淋浴房
  96. if (item.flgNonStandardType == 1 || item.flgNonStandardType == 2) {
  97. item.nonStandardArea = 1
  98. item.nonStandardList = []
  99. //加载默认spu非标参数数据
  100. getFlgNonStandardList(item, _this)
  101. _this.setData({
  102. show7: true
  103. })
  104. }
  105. // 根据spuId获取sku相关信息
  106. getSkuBySpuId(e, _this);
  107. _this.setData({
  108. show1: true,
  109. show2: false,
  110. show3: false,
  111. show4: false,
  112. show5: false
  113. })
  114. }
  115. _this.setData({
  116. currentChoosedItem: item,
  117. showAdd: true,
  118. })
  119. }
  120. //其他出库页面
  121. if (page == 'otherOutbound') {
  122. item.itemQuantity = 1
  123. _this.setData({
  124. currentChoosedItem: item,
  125. showAdd: true,
  126. })
  127. }
  128. //其他入库页面
  129. if (page == 'choose-sku-product') {
  130. item.itemQuantity = 1
  131. //非标淋浴房 2定制
  132. if (item.flgNonStandardType == 1 || item.flgNonStandardType == 2) {
  133. item.nonStandardList = []
  134. item.nonStandardArea = 1
  135. //加载默认spu非标参数数据
  136. // getFlgNonStandardList(item, _this)
  137. _this.setData({
  138. show7: true
  139. })
  140. }
  141. // 根据spuId获取sku相关信息
  142. //getSkuBySpuIdProduct(e, _this);
  143. _this.setData({
  144. show1: false,
  145. show2: false,
  146. show3: false,
  147. show4: false,
  148. show5: false,
  149. show5: true
  150. })
  151. _this.setData({
  152. currentChoosedItem: item,
  153. showAdd: true,
  154. })
  155. }
  156. }
  157. /**
  158. * @desc : 选择非标参数事件
  159. * @author : 于继渤
  160. * @date : 2022/8/24 13:16
  161. */
  162. function nonStandardTap(e, _this) {
  163. let currentChoosedItem = _this.data.currentChoosedItem
  164. let nonStandardList = currentChoosedItem.nonStandardList
  165. let pindex = e.currentTarget.dataset.pindex //父索引
  166. let indext = e.currentTarget.dataset.indext //子索引
  167. let itemt = e.currentTarget.dataset.itemt //子对象
  168. console.log('选择非标参数事件', currentChoosedItem)
  169. nonStandardList[pindex].options.forEach(res => {
  170. res.infotype = 'default'
  171. })
  172. if (itemt.infotype == 'info') {
  173. return
  174. }
  175. nonStandardList[pindex].options[indext].infotype = itemt.infotype == 'info' ? 'default' : 'info'
  176. _this.setData({
  177. currentChoosedItem: currentChoosedItem
  178. })
  179. //设置非标匹配参数
  180. setNonStandardMatchingParameters(_this)
  181. }
  182. /**
  183. * @desc : 设置非标匹配参数
  184. * @author : 于继渤
  185. * @date : 2022/8/24 13:16
  186. */
  187. function setNonStandardMatchingParameters(_this) {
  188. //当前选择的商品信息
  189. let currentChoosedItem = _this.data.currentChoosedItem
  190. //非标参数 数组(根据参数不同对应不同数据)
  191. let nonStandardList = currentChoosedItem.nonStandardList
  192. //非标参数保存用的 json 数据
  193. let nonGlassList = []
  194. let skuData = currentChoosedItem.skuData
  195. if (nonStandardList && nonStandardList.length > 0) {
  196. //判断哪些按钮状态为info 代表当前选中
  197. nonStandardList.forEach(res => {
  198. if (res.options && res.options.length > 0) {
  199. //遍历可选中的参数
  200. res.options.forEach(item => {
  201. if (item.infotype == 'info') {
  202. //选中的数据
  203. //编辑非标JSON
  204. nonGlassList.push({
  205. fieldId: res.fieldId,
  206. fieldCode: res.fieldCode,
  207. fieldName: res.fieldName,
  208. option_code: item.code,
  209. option_name: item.name,
  210. })
  211. }
  212. })
  213. }
  214. })
  215. currentChoosedItem.nonGlassList = nonStandardList
  216. //设置显示非标参数 (展示非标text)
  217. if (nonGlassList && nonGlassList.length > 0) {
  218. let nonGlassListShowTemp = []
  219. nonGlassList.forEach(it => {
  220. if (it.option_name && it.option_name != undefined) {
  221. nonGlassListShowTemp.push(it.fieldName + ':' + it.option_name)
  222. }
  223. })
  224. //非标参数显示/匹配命中标价的数据
  225. currentChoosedItem.nonGlassListShow = nonGlassListShowTemp.join(',')
  226. }
  227. //设置当前sku的所有非标标价数组
  228. skuData.forEach(res => {
  229. if (res.skuId == currentChoosedItem.skuId) {
  230. //赋值
  231. currentChoosedItem.nonGlassPriceItems = res.nonGlassPriceItems
  232. }
  233. })
  234. //非标商品匹配标价
  235. matchingListPrice(currentChoosedItem, currentChoosedItem.nonGlassPriceItems, currentChoosedItem.nonGlassListShow, _this)
  236. _this.setData({
  237. currentChoosedItem: currentChoosedItem
  238. })
  239. }else{
  240. console.log('没有匹配SKU')
  241. }
  242. }
  243. /**
  244. * @desc : 非标商品匹配标价
  245. * @author : 于继渤
  246. * @date : 2022/8/24 13:16
  247. */
  248. function matchingListPrice(currentChoosedItem, nonGlassPriceItems, nonGlassListShow, _this) {
  249. console.log('currentChoosedItem', currentChoosedItem)
  250. //铝材颜色:亮光-不锈钢,工艺:蒙砂-正,定制柜系列:B系列
  251. if (nonGlassPriceItems && nonGlassPriceItems.length > 0) {
  252. let flgItemList = [] //匹配到的标价数据
  253. // console.log('已选参非标商参数',nonGlassListShow)
  254. nonGlassPriceItems.forEach(res => {
  255. let flag = true
  256. let nonGlassListShowArr = res.nonGlassListShowArr
  257. if (nonGlassListShowArr && nonGlassListShowArr.length > 0) {
  258. console.log('-----------------------')
  259. res.nonGlassListShowArr.forEach(item => {
  260. let nonGlassListShowTwo = nonGlassListShow.split(',')
  261. console.log('已选参数=> ', nonGlassListShow)
  262. console.log('可用参数=> ', res.nonGlassListShow)
  263. console.log('是否包含=> ', (!nonGlassListShowTwo.includes(item) || res.nonGlassListShowArr.length != nonGlassListShowTwo.length) ? '不包含->' : '包含->', item)
  264. console.log('-----------------------')
  265. if (!nonGlassListShowTwo.includes(item) || res.nonGlassListShowArr.length != nonGlassListShowTwo.length) {
  266. flag = false
  267. }
  268. })
  269. } else {
  270. flag = false
  271. }
  272. if (flag) {
  273. flgItemList.push(res)
  274. }
  275. })
  276. //如果匹配到数据 设置默认标价
  277. if (flgItemList.length > 0) {
  278. console.log('匹配到数据', flgItemList)
  279. currentChoosedItem.priceStandard = flgItemList[0].itemPrice //标价
  280. currentChoosedItem.priceSale = currentChoosedItem.priceStandard
  281. currentChoosedItem.itemAmount = currentChoosedItem.orderItemQuantity * currentChoosedItem.priceSale
  282. getCombinedDiscount(currentChoosedItem)
  283. //面积计算
  284. if (currentChoosedItem.nonStandardArea) {
  285. calculateFormulaItemAmount(currentChoosedItem, currentChoosedItem.nonStandardArea)
  286. _this.setData({
  287. currentChoosedItem: currentChoosedItem
  288. })
  289. }
  290. } else {
  291. if (currentChoosedItem.flgNonStandardType == 1) {
  292. currentChoosedItem.priceStandard = currentChoosedItem.nonGlassPriceDef ? currentChoosedItem.nonGlassPriceDef : Number(0)
  293. }
  294. //匹配到sku 但是没有匹配到标价 但是有价格
  295. if (currentChoosedItem.nonGlassPriceItems && currentChoosedItem.nonGlassPriceItems.length > 0) {
  296. let objItems = currentChoosedItem.nonGlassPriceItems.filter(res => {
  297. if (res.flgDefItem && (!res.nonGlassListShowArr || res.nonGlassListShowArr.length == 0)) {
  298. return res;
  299. }
  300. })
  301. if (objItems && objItems.length > 0) {
  302. console.log('匹配到sku 但是没有匹配到标价 但是有价格')
  303. currentChoosedItem.priceStandard = objItems[0].itemPrice
  304. } else {
  305. //sku标价改为spu标价
  306. console.log('sku标价改为spu标价')
  307. currentChoosedItem.priceStandard = currentChoosedItem.skuData.length > 0 ? currentChoosedItem.skuData[0].priceStandard : currentChoosedItem.priceStandardtemp
  308. }
  309. }
  310. currentChoosedItem.priceSale = currentChoosedItem.priceStandard
  311. currentChoosedItem.itemAmount = currentChoosedItem.orderItemQuantity * currentChoosedItem.priceSale
  312. getCombinedDiscount(currentChoosedItem)
  313. }
  314. } else {
  315. console.log('没有设置非标参数')
  316. if (currentChoosedItem.flgNonStandardType == 1 || currentChoosedItem.flgNonStandardType == 2) {
  317. currentChoosedItem.priceStandard = Number(currentChoosedItem.priceStandardTemp ? currentChoosedItem.priceStandardTemp : 0)
  318. }
  319. currentChoosedItem.priceSale = currentChoosedItem.priceStandard
  320. currentChoosedItem.itemAmount = currentChoosedItem.orderItemQuantity * currentChoosedItem.priceSale
  321. getCombinedDiscount(currentChoosedItem)
  322. }
  323. }
  324. /**
  325. * @desc : 非标商品选择事件
  326. * @author : 于继渤
  327. * @date : 2022/8/24 13:16
  328. */
  329. function nonGlassSpuItemsTap(e, _this) {
  330. let currentChoosedItem = _this.data.currentChoosedItem
  331. let skuData = currentChoosedItem.skuData
  332. let indext = e.currentTarget.dataset.indext //子索引
  333. let itemt = e.currentTarget.dataset.itemt //子对象
  334. //初始化按钮状态
  335. skuData.forEach(res => {
  336. res.infotype = 'default'
  337. })
  338. let nonStandardList = []
  339. if (itemt.infotype == 'info') {
  340. return
  341. }
  342. //设置按钮状态
  343. skuData[indext].infotype = itemt.infotype == 'info' ? 'default' : 'info'
  344. // 设置默认skuId
  345. currentChoosedItem.defSkuId = itemt.skuId
  346. let nonStandardListFlag = true
  347. if (skuData[indext].infotype == 'info') {
  348. nonStandardList = skuData[indext].nonGlassSpuItems
  349. if (!skuData[indext].nonGlassSpuItems || skuData[indext].nonGlassSpuItems.length == 0) {
  350. if (currentChoosedItem.nonGlassList) {
  351. let nonStandardListCopy = util.copyObj(currentChoosedItem.nonGlassList)
  352. //没设置标价显示spu默认
  353. nonStandardList = nonStandardListCopy
  354. nonStandardListFlag = false
  355. }
  356. } else {
  357. console.log('没有匹配上SKU')
  358. currentChoosedItem.priceSale = itemt.nonGlassPriceDef
  359. currentChoosedItem.itemAmount = itemt.nonGlassPriceDef
  360. }
  361. }
  362. _this.setData({
  363. nonStandardListFlag: nonStandardListFlag
  364. })
  365. currentChoosedItem.nonStandardList = nonStandardList
  366. _this.setData({
  367. skuData: skuData,
  368. defSkuId: skuData[indext].skuId,
  369. currentChoosedItem: currentChoosedItem
  370. })
  371. //数据格式化
  372. chooseSkuItem(_this);
  373. //设置默认参数
  374. if (skuData && skuData.length > 0 && itemt.skuId) {
  375. setDefault(skuData, itemt.skuId, _this)
  376. }
  377. //没匹配到标价为0
  378. // if (!nonStandardListFlag ) {
  379. // currentChoosedItem.priceStandard = 0
  380. // _this.setData({
  381. // currentChoosedItem: currentChoosedItem
  382. // })
  383. // }
  384. }
  385. /**
  386. * @desc : 非标商品非标参数输入事件
  387. * @author : 于继渤
  388. * @date : 2022/8/24 13:16
  389. */
  390. function bindInputIsScopeOne(e, _this) {
  391. }
  392. function bindBlurIsScopeOne(e, _this) {
  393. let currentChoosedItem = _this.data.currentChoosedItem
  394. let specialFormulaName = currentChoosedItem.specialFormulaName //面积公式
  395. let nonStandardList = currentChoosedItem.nonStandardList
  396. let index = e.currentTarget.dataset.pindex //大数组所在索引
  397. let item = e.currentTarget.dataset.item
  398. let value = e.detail.value
  399. if (value) {
  400. value = value.replace(/\s/g, '')
  401. }
  402. // if (nonStandardList[index].fieldType == 3) {
  403. // //数字类型判断最大值最小值
  404. // let maxValue = Number(nonStandardList[index].maxValue)
  405. // let minValue = Number(nonStandardList[index].minValue)
  406. // if(Number(value) > maxValue){
  407. // //大于最大值 为最大值
  408. // nonStandardList[index].optionName = maxValue
  409. // nonStandardList[index].optionCode = maxValue
  410. // } else if(Number(value) < minValue){
  411. // //小于最小值 为最小值
  412. // nonStandardList[index].optionName = minValue
  413. // nonStandardList[index].optionCode = minValue
  414. // }
  415. // else if (maxValue >= Number(value) >= minValue) {
  416. // //最大值最小值之间
  417. // nonStandardList[index].optionName = Number(value)
  418. // nonStandardList[index].optionCode = Number(value)
  419. // }
  420. // }else{
  421. //TODO 非标参数 ios复制问题 2023/03/13 于继渤
  422. if (nonStandardList[index].fieldType == 3) {
  423. console.log('面积公式输入参数', value)
  424. //数字类型
  425. if (!checkNumber(value)) {
  426. console.log('请输入正确数字->', value)
  427. nonStandardList[index].optionName = ""
  428. nonStandardList[index].optionCode = ""
  429. } else {
  430. nonStandardList[index].optionName = value
  431. nonStandardList[index].optionCode = value
  432. }
  433. } else {
  434. nonStandardList[index].optionName = value
  435. nonStandardList[index].optionCode = value
  436. }
  437. // }
  438. calculateFormula(_this, currentChoosedItem)
  439. _this.setData({
  440. currentChoosedItem: currentChoosedItem
  441. })
  442. }
  443. function checkNumber(theObj) {
  444. var reg = /^[0-9]+.?[0-9]*$/;
  445. if (reg.test(theObj)) {
  446. return true;
  447. }
  448. return false;
  449. }
  450. function bindBlurIsScopeOne_t(e, _this) {
  451. let currentChoosedItem = _this.data.currentChoosedItem
  452. let specialFormulaName = currentChoosedItem.specialFormulaName //面积公式
  453. let nonStandardList = currentChoosedItem.nonStandardList
  454. let index = e.currentTarget.dataset.pindex //大数组所在索引
  455. let item = e.currentTarget.dataset.item
  456. let value = e.detail.value
  457. nonStandardList[index].optionName = value
  458. nonStandardList[index].optionCode = value
  459. calculateFormula_t(_this, currentChoosedItem)
  460. _this.setData({
  461. currentChoosedItem: currentChoosedItem
  462. })
  463. }
  464. /**
  465. * @desc : 计算面积
  466. * @author : 于继渤
  467. * @date : 2022/9/21 13:16
  468. */
  469. function calculateFormula(_this, currentChoosedItem) {
  470. let nonStandardList = currentChoosedItem.nonStandardList
  471. let itemAmount = currentChoosedItem.itemAmount
  472. currentChoosedItem.itemAmount_Temp = itemAmount
  473. _this.setData({
  474. currentChoosedItem: currentChoosedItem
  475. })
  476. let formula = currentChoosedItem.specialFormulaName.toUpperCase()//公式
  477. let param = {
  478. }
  479. let API_FLAG = true
  480. if (nonStandardList && nonStandardList.length > 0) {
  481. let list = nonStandardList.filter(item => {
  482. return item.isScope == 1
  483. })
  484. if (list && list.length > 0) {
  485. list.forEach(res => {
  486. // if (res.optionCode && res.optionCode != '' && res.optionCode != 0) {
  487. // if (res.fieldName.indexOf('W1') != -1) {
  488. // param.W1 = Number(res.optionCode)
  489. // }
  490. // if (res.fieldName.indexOf('W2') != -1) {
  491. // param.W2 = Number(res.optionCode)
  492. // }
  493. // if (res.fieldName.indexOf('H') != -1) {
  494. // param.H = Number(res.optionCode)
  495. // }
  496. param[res.fieldName] = Number(res.optionCode) ? Number(res.optionCode) : null
  497. // } else {
  498. // //其中输入没参数 不计算
  499. // API_FLAG = false
  500. // }
  501. if (res.optionCode == "" || res.optionCode == null || res.optionCode == undefined) {
  502. API_FLAG = false
  503. }
  504. })
  505. }
  506. }
  507. let paramData = {
  508. formula: formula,//公式
  509. param: param
  510. }
  511. if (API_FLAG) {
  512. api.request(Constants.BPM_FORMULA_APPRAVAL + 'calculate_formula', 'POST', paramData).then(res => {
  513. console.log(res)
  514. if (res.data.code == 200) {
  515. if (typeof res.data.data === 'number') {
  516. //面积公式中包含【/1000】字符时,输入值不用除以1000,如不包括就要除以1000再计算
  517. //现在面积公式【(W1/1000+2*W2/1000)*H1/1000】、【(W1+2*W2)*H1】混合存在
  518. if (formula.indexOf('/1000') != -1) {
  519. //包含
  520. currentChoosedItem.nonStandardArea = res.data.data ? Number(res.data.data).toFixed(2) : 0
  521. } else {
  522. //不包含
  523. currentChoosedItem.nonStandardArea = res.data.data ? Number(res.data.data / 1000).toFixed(2) : 0
  524. }
  525. }
  526. if (currentChoosedItem.nonStandardArea) {
  527. //计算金额
  528. calculateFormulaItemAmount(currentChoosedItem, currentChoosedItem.nonStandardArea)
  529. }
  530. _this.setData({
  531. currentChoosedItem: currentChoosedItem
  532. })
  533. }
  534. })
  535. }
  536. }
  537. function calculateFormula_t(_this, currentChoosedItem) {
  538. let nonStandardList = currentChoosedItem.nonStandardList
  539. let itemAmount = currentChoosedItem.itemAmount
  540. currentChoosedItem.itemAmount_Temp = itemAmount
  541. _this.setData({
  542. currentChoosedItem: currentChoosedItem
  543. })
  544. let formula = currentChoosedItem.specialFormulaName.toUpperCase()//公式
  545. let param = {
  546. }
  547. let API_FLAG = true
  548. if (nonStandardList && nonStandardList.length > 0) {
  549. let list = nonStandardList.filter(item => {
  550. return item.isScope == 1
  551. })
  552. if (list && list.length > 0) {
  553. console.log('面积接口', list)
  554. list.forEach(res => {
  555. // if (res.optionCode && res.optionCode != '' && res.optionCode != 0) {
  556. // if (res.fieldName.indexOf('W1') != -1) {
  557. // param.W1 = Number(res.optionCode)
  558. // }
  559. // if (res.fieldName.indexOf('W2') != -1) {
  560. // param.W2 = Number(res.optionCode)
  561. // }
  562. // if (res.fieldName.indexOf('H') != -1) {
  563. // param.H = Number(res.optionCode)
  564. // }
  565. param[res.fieldName] = Number(res.optionCode) ? Number(res.optionCode) : null
  566. // } else {
  567. // //其中输入没参数 不计算
  568. // API_FLAG = false
  569. // }
  570. if (res.optionCode == "" || res.optionCode == null || res.optionCode == undefined) {
  571. API_FLAG = false
  572. }
  573. })
  574. }
  575. }
  576. let paramData = {
  577. formula: formula,//公式
  578. param: param
  579. }
  580. if (API_FLAG) {
  581. api.request(Constants.BPM_FORMULA_APPRAVAL + 'calculate_formula', 'POST', paramData).then(res => {
  582. if (res.data.code == 200) {
  583. if (typeof res.data.data === 'number') {
  584. currentChoosedItem.nonStandardArea = res.data.data ? Number(res.data.data / 1000).toFixed(2) : 0
  585. }
  586. if (currentChoosedItem.nonStandardArea) {
  587. //计算金额
  588. calculateFormulaItemAmount(currentChoosedItem, currentChoosedItem.nonStandardArea, true)
  589. }
  590. _this.setData({
  591. currentChoosedItem: currentChoosedItem
  592. })
  593. }
  594. })
  595. }
  596. }
  597. //面积离焦事件
  598. function bindBlurNonStantardArea(e, _this, flag) {
  599. let value = e.detail.value
  600. if (value) {
  601. value = value.replace(/\s/g, '')
  602. }
  603. let currentChoosedItem = _this.data.currentChoosedItem
  604. if (value) {
  605. currentChoosedItem.nonStandardArea = Number(value)
  606. //调用 面积计算合计金额 面积*数量*售价
  607. calculateFormulaItemAmount(currentChoosedItem, currentChoosedItem.nonStandardArea, flag)
  608. } else {
  609. currentChoosedItem.nonStandardArea = 0
  610. }
  611. _this.setData({
  612. currentChoosedItem: currentChoosedItem
  613. })
  614. }
  615. // 面积计算合计金额 面积*数量*售价
  616. function calculateFormulaItemAmount(currentChoosedItem, value, flag) {
  617. if (flag) {
  618. if (currentChoosedItem.nonStandardArea) {
  619. currentChoosedItem.tItemAmount = Number(value * currentChoosedItem.itemQuantity * currentChoosedItem.priceSale).toFixed(2)
  620. } else {
  621. currentChoosedItem.tItemAmount = Number(currentChoosedItem.tItemQuantity * currentChoosedItem.priceSale)
  622. }
  623. } else {
  624. if (currentChoosedItem.nonStandardArea) {
  625. currentChoosedItem.itemAmount = Number(value * currentChoosedItem.itemQuantity * currentChoosedItem.priceSale).toFixed(2)
  626. } else {
  627. currentChoosedItem.itemAmount = Number(currentChoosedItem.itemQuantity * currentChoosedItem.priceSale).toFixed(2)
  628. }
  629. }
  630. }
  631. function bindInputNonStantardArea(e, _this) {
  632. }
  633. /**
  634. * @desc : 根据spuid查询非标参数
  635. * @author : 于继渤
  636. * @date : 2022/8/24 13:16
  637. */
  638. function getFlgNonStandardList(item, _this) {
  639. let param = {
  640. spuId: item.spuId,
  641. cpId: app.globalData.user.cpId
  642. }
  643. api.request(Constants.GOODS_SPU_API + 'get_flg_non_standard_list', 'POST', param).then(res => {
  644. if (res.data.code == 200) {
  645. let data = res.data.data
  646. if (data && data.length > 0) {
  647. data.forEach(item => {
  648. if (item.options && item.options.value && item.options.value != '[]') {
  649. item.options = JSON.parse(item.options.value)
  650. item.options.forEach(it => {
  651. it.infotype = 'default'
  652. })
  653. }
  654. })
  655. }
  656. let dataTemp = util.copyObj(data) //拷贝数据
  657. _this.setData({
  658. nonStandardList: dataTemp
  659. })
  660. item.nonGlassList = []
  661. item.nonGlassListShow = ''
  662. let data_nonStandardList = [...data]
  663. item.nonStandardList = data_nonStandardList
  664. }
  665. })
  666. }
  667. /**
  668. * @desc : 根据spuId获取sku数据
  669. * @date : 2022/9/1 13:49
  670. * @author : 于继渤
  671. */
  672. function getSkuBySpuId(e, _this) {
  673. _this.setData({
  674. skuloading: true
  675. })
  676. let item = e.currentTarget.dataset.item
  677. let param = {}
  678. // 要记录原始的标价、促销,活动Id
  679. item.standardIdSocial = item.standardIdSocial ? item.standardIdSocial : item.standardId
  680. item.promotionIdSocial = item.promotionIdSocial ? item.promotionIdSocial : item.promotionId
  681. item.activityIdSocial = item.activityIdSocial ? item.activityIdSocial : item.activityId
  682. param.spuId = item.spuId
  683. param.standardId = item.standardIdSocial
  684. param.promotionId = item.promotionIdSocial
  685. param.activityId = item.activityIdSocial
  686. param.cpId = app.globalData.user.cpId;
  687. param.orgId = app.globalData.user.orgId;
  688. param.customerId = app.globalData.user.sale2CustomerId ? app.globalData.user.sale2CustomerId : null
  689. api.request(Constants.GOODS_SPU_SPECS + 'select_sku_by_spu_id', 'POST', param).then(res => {
  690. if (res.data.code === 200) {
  691. let currentChoosedItem = _this.data.currentChoosedItem
  692. currentChoosedItem.nonGlassList = []
  693. currentChoosedItem.skuData = []
  694. let list = res.data
  695. // 获取默认的skuId
  696. let defSkuId = e.currentTarget.dataset.item.defSkuId;
  697. // 判断如果默认的skuId没有设置标价,那么要取价格最低的作为默认sku
  698. let filters = list.data.skuData.filter(it => it.skuId == defSkuId)
  699. if (filters && filters.length > 0) {
  700. if (filters[0].disabled) {
  701. defSkuId = null;
  702. item.pricePromotion = undefined;
  703. item.priceStandard = undefined;
  704. _this.setData({
  705. defSkuId: null
  706. })
  707. }
  708. }
  709. //判断规格是否有数据
  710. if (list.data.specsData && list.data.specsData.length == 0) {
  711. let flgNonStandardTypeFlag = false;
  712. list.data.skuData.forEach(item => {
  713. //设置默认商品按钮
  714. if (defSkuId == item.skuId) {
  715. //设置默认显示商品按钮
  716. item.infotype = 'info'
  717. if (item.flgNonStandardType && item.flgNonStandardType != 0) {
  718. flgNonStandardTypeFlag = true;
  719. if (item.flgNonStandardType == 2) {
  720. } else if (item.flgNonStandardType == 1) {
  721. item.priceStandard = item.nonGlassPriceDef
  722. }
  723. }
  724. // 有问题,直接跳过了促销价
  725. // item.priceSale = item.priceStandard ? item.priceStandard : 0
  726. item.priceSale = item.priceSale ? item.priceSale : (item.priceStandard ? item.priceStandard : 0)
  727. item.itemAmount = item.orderItemQuantity * item.priceSale
  728. getCombinedDiscount(item)
  729. }
  730. })
  731. if (flgNonStandardTypeFlag) {
  732. _this.setData({
  733. show6: true
  734. })
  735. }
  736. } else {
  737. _this.setData({
  738. show6: false
  739. })
  740. }
  741. if (list.data.specsData.length == 0 && list.data.skuData && list.data.skuData.length > 1) {
  742. _this.setData({
  743. show6: true
  744. })
  745. }
  746. currentChoosedItem.skuData = list.data.skuData
  747. currentChoosedItem.specsData = list.data.specsData
  748. currentChoosedItem.skuSpecsList = list.data.specsData
  749. _this.setData({
  750. skuData: list.data.skuData,
  751. currentChoosedItem: currentChoosedItem,
  752. skuSpecsList: list.data.specsData,
  753. defSkuId: defSkuId,
  754. })
  755. setSkuData(_this); // 把sku处理为相应的格式
  756. getSkuSpecs(defSkuId, _this); //判断规格是否可用
  757. if (e.currentTarget.dataset.item.flgNonStandardType == 1 || e.currentTarget.dataset.item.flgNonStandardType == 2) {
  758. //非标标价设置默认值
  759. setDefault(list.data.skuData, defSkuId, _this)
  760. }
  761. }
  762. // 设置赠品
  763. setFlgGift(_this);
  764. setTimeout(() => {
  765. _this.setData({
  766. skuloading: false
  767. })
  768. }, 100)
  769. })
  770. }
  771. /**
  772. * @desc : 根据spuId获取sku数据
  773. * @date : 2023年9月8日
  774. * @author : 王英杰
  775. */
  776. function getSkuBySpuIdProduct(e, _this) {
  777. _this.setData({
  778. skuloading: true
  779. })
  780. let item = e.currentTarget.dataset.item
  781. let param = {}
  782. param.spuId = item.spuId
  783. param.cpId = app.globalData.user.cpId;
  784. api.request(Constants.OTHER_IN + 'get_sku_for_other_entry', 'POST', param).then(res => {
  785. if (res.data.code === 200) {
  786. let currentChoosedItem = _this.data.currentChoosedItem
  787. currentChoosedItem.nonGlassList = []
  788. currentChoosedItem.skuData = []
  789. let list = res.data
  790. // 获取默认的skuId
  791. let defSkuId = e.currentTarget.dataset.item.defSkuId;
  792. // 判断如果默认的skuId没有设置标价,那么要取价格最低的作为默认sku
  793. let filters = list.data.skuData.filter(it => it.skuId == defSkuId)
  794. if (filters && filters.length > 0) {
  795. if (filters[0].disabled) {
  796. defSkuId = null;
  797. item.pricePromotion = undefined;
  798. item.priceStandard = undefined;
  799. _this.setData({
  800. defSkuId: null
  801. })
  802. }
  803. }
  804. //判断规格是否有数据
  805. if (list.data.specsData && list.data.specsData.length == 0) {
  806. let flgNonStandardTypeFlag = false;
  807. list.data.skuData.forEach(item => {
  808. //设置默认商品按钮
  809. if (defSkuId == item.skuId) {
  810. //设置默认显示商品按钮
  811. item.infotype = 'info'
  812. if (item.flgNonStandardType && item.flgNonStandardType != 0) {
  813. flgNonStandardTypeFlag = true;
  814. if (item.flgNonStandardType == 2) {
  815. } else if (item.flgNonStandardType == 1) {
  816. item.priceStandard = item.nonGlassPriceDef
  817. }
  818. }
  819. // 有问题,直接跳过了促销价
  820. // item.priceSale = item.priceStandard ? item.priceStandard : 0
  821. item.priceSale = item.priceSale ? item.priceSale : (item.priceStandard ? item.priceStandard : 0)
  822. item.itemAmount = item.orderItemQuantity * item.priceSale
  823. getCombinedDiscount(item)
  824. }
  825. })
  826. if (flgNonStandardTypeFlag) {
  827. _this.setData({
  828. show6: true
  829. })
  830. }
  831. } else {
  832. _this.setData({
  833. show6: false
  834. })
  835. }
  836. if (list.data.specsData.length == 0 && list.data.skuData && list.data.skuData.length > 1) {
  837. _this.setData({
  838. show6: true
  839. })
  840. }
  841. currentChoosedItem.skuData = list.data.skuData
  842. currentChoosedItem.specsData = list.data.specsData
  843. currentChoosedItem.skuSpecsList = list.data.specsData
  844. _this.setData({
  845. skuData: list.data.skuData,
  846. currentChoosedItem: currentChoosedItem,
  847. skuSpecsList: list.data.specsData,
  848. defSkuId: defSkuId,
  849. })
  850. setSkuData(_this); // 把sku处理为相应的格式
  851. getSkuSpecs(defSkuId, _this); //判断规格是否可用
  852. if (e.currentTarget.dataset.item.flgNonStandardType == 1 || e.currentTarget.dataset.item.flgNonStandardType == 2) {
  853. //非标标价设置默认值
  854. setDefault(list.data.skuData, defSkuId, _this)
  855. }
  856. }
  857. // 设置赠品
  858. setFlgGift(_this);
  859. setTimeout(() => {
  860. _this.setData({
  861. skuloading: false
  862. })
  863. }, 100)
  864. })
  865. }
  866. /**
  867. * @desc :非标标价设置默认值
  868. * @date : 2022/8/25 9:56
  869. * @author : 于继渤
  870. */
  871. function setDefault(skuData, defSkuId, _this) {
  872. //当前选中的商品非标参数数组
  873. let currentChoosedItem = _this.data.currentChoosedItem
  874. //校验数据不为空 否则报异常
  875. if (currentChoosedItem.nonStandardList && currentChoosedItem.nonStandardList.length > 0 && _this.data.nonStandardListFlag) {
  876. let list = []
  877. let obj = []
  878. //视图初始化非标标价组
  879. let nonStandardList = currentChoosedItem.nonStandardList
  880. //过滤出默认数据
  881. if (skuData && skuData.length > 0) {
  882. list = skuData.filter((item) => {
  883. return item.skuId == defSkuId;
  884. })
  885. }
  886. if (list.length > 0) {
  887. if (list[0].nonGlassPriceItems) {
  888. obj = list[0].nonGlassPriceItems.filter((item) => {
  889. return item.flgDefItem == true && list[0].skuId == item.skuId;
  890. })
  891. }
  892. }
  893. //默认标价组
  894. if (obj.length > 0) {
  895. let nonGlassList = obj[0].nonGlassList ? obj[0].nonGlassList : {}
  896. nonStandardList.forEach(res => {
  897. let temp = nonGlassList.filter((item) => {
  898. return item.fieldCode == res.fieldCode;
  899. })
  900. if (temp.length > 0) {
  901. //过滤出 spu显示的非标参数与默认的非标参数并改变按钮状态
  902. let options = res.options.filter((item) => {
  903. return item.infotype = ((item.code == temp[0].optionCode) || (item.code == temp[0].option_code)) ? 'default' : '';
  904. })
  905. if (options && options.length > 0) {
  906. options[0].infotype = 'info'
  907. }
  908. }
  909. })
  910. //设置显示非标参数 (展示非标text)
  911. if (nonGlassList && nonGlassList.length > 0) {
  912. let nonGlassListShowTemp = []
  913. nonGlassList.forEach(it => {
  914. if (it.optionName && it.optionName != undefined) {
  915. nonGlassListShowTemp.push(it.fieldName + ':' + it.optionName)
  916. }
  917. })
  918. //非标参数显示/匹配命中标价的数据
  919. currentChoosedItem.nonGlassListShow = nonGlassListShowTemp.join(',')
  920. }
  921. currentChoosedItem.pricePromotion = obj[0].itemPrice
  922. }
  923. currentChoosedItem.priceStandard = currentChoosedItem.priceStandard ? currentChoosedItem.priceStandard : 0
  924. currentChoosedItem.priceSale = currentChoosedItem.priceSale ? currentChoosedItem.priceSale : 0
  925. currentChoosedItem.itemAmount = currentChoosedItem.itemAmount ? currentChoosedItem.itemAmount : 0
  926. currentChoosedItem.nonStandardList = nonStandardList
  927. _this.setData({
  928. currentChoosedItem: currentChoosedItem
  929. })
  930. } else {
  931. _this.setData({
  932. currentChoosedItem: currentChoosedItem
  933. })
  934. }
  935. }
  936. /**
  937. * @desc : 根据组合促销Id获取促销信息
  938. * @date : 2022/7/2 16:49
  939. * @author : 周兴
  940. */
  941. function getCombinedByPriceId(e, _this, type) {
  942. _this.setData({
  943. skuloading: true
  944. })
  945. let param = {}
  946. param.cpId = app.globalData.user.cpId;
  947. param.priceId = e.currentTarget.dataset.item.promotionId;
  948. param.orgId = app.globalData.user.orgId;
  949. api.request(Constants.PRICE_PROMOTION_ITEM + 'select_combined_by_price_id', 'POST', param).then(res => {
  950. _this.setData({
  951. loading: false
  952. })
  953. if (res.data.code === 200) {
  954. let currentChoosedItem = util.copyObj(_this.data.currentChoosedItem)
  955. let combinedData = res.data.data
  956. currentChoosedItem.combinedData = combinedData;
  957. currentChoosedItem.itemQuantity = 1; // 数量默认为1
  958. currentChoosedItem.itemAmount = currentChoosedItem.priceSale // 金额默认等于销售价格
  959. currentChoosedItem.discountPromotion = 100; // 默认为100
  960. if (combinedData.combinedItem != null && combinedData.combinedItem.length > 0) {
  961. currentChoosedItem.combinedData.combinedItem.forEach(item => {
  962. if (item.cpFlgGift) {
  963. item.flgGift = true
  964. item.priceSale_Temp = item.priceSale
  965. item.itemAmount_Temp = item.itemAmount
  966. item.discountStandard_Temp = item.discountStandard
  967. item.discountPromotion_Temp = item.discountPromotion
  968. item.priceSale = 0
  969. item.discountStandard = 0
  970. item.discountPromotion = 0
  971. item.itemAmount = 0
  972. if (item.skuType == 2) {
  973. if (item.bomItems && item.bomItems.length > 0) {
  974. item.bomItems.forEach(res => {
  975. res.priceSale = 0
  976. res.discountStandard = 0
  977. res.discountPromotion = 0
  978. res.itemAmount = 0
  979. })
  980. }
  981. }
  982. }
  983. })
  984. }
  985. let filterRows = currentChoosedItem.combinedData.combinedItem.filter(it => it.infotype == 'info');
  986. if (filterRows && filterRows.length > 0) {
  987. currentChoosedItem.combinedList = filterRows;// 把组合赋值给选择数据
  988. let itemAmountTemp = 0
  989. currentChoosedItem.combinedList.forEach(it => {
  990. // if (!it.cpFlgGift) {
  991. // itemAmountTemp += it.itemAmount
  992. // }
  993. if (!it.cpFlgGift) {
  994. itemAmountTemp += it.itemAmount * it.orderItemQuantity
  995. }
  996. })
  997. currentChoosedItem.priceSale = itemAmountTemp
  998. currentChoosedItem.itemAmount = Number(currentChoosedItem.priceSale * currentChoosedItem.itemQuantity).toFixed(2)
  999. // 判断是否有可换件
  1000. getReplaceFlag(filterRows, _this);
  1001. if (type == 'sale') {
  1002. changeCombinedItemCommonSale(filterRows[0], currentChoosedItem, _this)
  1003. }
  1004. }
  1005. _this.setData({
  1006. skuData: [],
  1007. skuSpecsList: [],
  1008. defSkuId: null,
  1009. currentChoosedItem: currentChoosedItem
  1010. })
  1011. // 计算折扣
  1012. getDiscount(_this);
  1013. }
  1014. setTimeout(() => {
  1015. _this.setData({
  1016. skuloading: false
  1017. })
  1018. }, 100)
  1019. })
  1020. }
  1021. /**
  1022. * @desc : 改变组合促销明细后,重新计算价格
  1023. * @date : 2022/7/5 16:49
  1024. * @author : 周兴
  1025. */
  1026. function getCombinedPriceByChange(_this) {
  1027. if (_this.data.currentChoosedItem) {
  1028. let currentChoosedItem = _this.data.currentChoosedItem;
  1029. if (currentChoosedItem.combinedData && currentChoosedItem.combinedData.combinedItem && currentChoosedItem.combinedData.combinedItem.length > 0) {
  1030. let combinedData = currentChoosedItem.combinedData;
  1031. let filterRows = combinedData.combinedItem.filter(it => it.infotype == 'info');
  1032. if (filterRows && filterRows.length > 0) {
  1033. let pricePromotion = 0;
  1034. filterRows.forEach(row => {
  1035. pricePromotion += Number(row.pricePromotion) * Number(row.orderItemQuantity)
  1036. })
  1037. currentChoosedItem.pricePromotion = pricePromotion;
  1038. currentChoosedItem.combinedList = filterRows;// 把组合赋值给选择数据
  1039. _this.changeSalesPrice(pricePromotion, _this); // 修改价格后修改相关金额
  1040. _this.setData({
  1041. currentChoosedItem: currentChoosedItem
  1042. })
  1043. }
  1044. }
  1045. }
  1046. }
  1047. /**
  1048. * @desc : 把sku信息处理成对应的格式
  1049. * @date : 2022/7/2 16:49
  1050. * @author : 周兴
  1051. */
  1052. function setSkuData(_this) {
  1053. let skuSpecsData = []
  1054. let currentChoosedItem = _this.data.currentChoosedItem;
  1055. let skuData = currentChoosedItem.skuData;
  1056. if (skuData.length > 0 && skuData) {
  1057. skuData.forEach(it => {
  1058. let specs = {}
  1059. specs.skuId = it.skuId;
  1060. let specsValuesList = it.specsValues
  1061. if (specsValuesList && specsValuesList.length > 0) {
  1062. let title = ''
  1063. it.specsValues.forEach(row => {
  1064. specs['specsId_' + row.specsId] = row.specsValues
  1065. title = title + (row.specsId + ':' + row.specsValues[0]) + ","
  1066. })
  1067. // 在前面拼上, 方便进行匹配,要带逗号进行匹配这样才是准确的
  1068. if (title && title != ',') {
  1069. title = ',' + title
  1070. }
  1071. specs.title = title;
  1072. }
  1073. skuSpecsData.push(specs);
  1074. currentChoosedItem.skuSpecsData = skuSpecsData
  1075. })
  1076. _this.setData({
  1077. skuSpecsData: skuSpecsData,
  1078. currentChoosedItem: currentChoosedItem
  1079. })
  1080. }
  1081. }
  1082. /**
  1083. * @desc : 判断规格是否可用
  1084. * @date : 2022/7/2 16:49
  1085. * @author : 周兴
  1086. */
  1087. function getSkuSpecs(defSkuId, _this) {
  1088. let currentChoosedItem = _this.data.currentChoosedItem
  1089. let skuSpecsList = currentChoosedItem.skuSpecsList
  1090. let skuData = currentChoosedItem.skuData
  1091. let defSku = []
  1092. if (defSkuId) {
  1093. defSku = skuData.filter(it => it.skuId == defSkuId)[0];
  1094. }
  1095. // 查询是否有未设置标价的商品
  1096. // let noPriceStandardFlag = false;
  1097. // let noPriceStandardList = skuData.filter(it => it.disabled);
  1098. // if(noPriceStandardList && noPriceStandardList.length > 0){
  1099. // noPriceStandardFlag = true;
  1100. // }
  1101. let defSkuValues = [] // 默认sku的规格
  1102. //处理规格
  1103. if (skuSpecsList && skuSpecsList.length > 0) {
  1104. skuSpecsList.forEach(it => {
  1105. it.specsList = [];
  1106. let defaultFlag = false;
  1107. it.specsValues.forEach(item => {
  1108. let defSkuValue = {}
  1109. let specs = {};
  1110. specs.specsId = it.specsId;
  1111. specs.key = item;
  1112. specs.specsValue = item;
  1113. specs.default = false;
  1114. // 如果没有商品,那么规格都设置为不可用
  1115. if (!skuData || skuData.length == 0) {
  1116. specs.disabled = true;
  1117. }
  1118. // 设置默认值
  1119. if (defSku && defSku.specsValues && defSku.specsValues.length > 0) {
  1120. let filterRows = defSku.specsValues.filter(row => row.specsId == it.specsId
  1121. && row.specsValues && row.specsValues.indexOf(item) >= 0);
  1122. if (filterRows && filterRows.length > 0) {
  1123. if (!defaultFlag) {
  1124. specs.default = true;
  1125. defaultFlag = true;
  1126. //记录默认sku的规格信息
  1127. defSkuValue.specsId = it.specsId;
  1128. defSkuValue.specsValue = item;
  1129. defSkuValues.push(defSkuValue);
  1130. }
  1131. }
  1132. }
  1133. it.specsList.push(specs);
  1134. })
  1135. })
  1136. _this.setData({
  1137. skuSpecsList: skuSpecsList
  1138. })
  1139. if (defSkuValues && defSkuValues.length > 0) {
  1140. // defSkuValues.forEach(it => {
  1141. // // 判断规格是否可用
  1142. // checkSpecsIsEnable(it.specsId, it.specsValue, false, _this);
  1143. // })
  1144. checkSpecsIsEnableNew(_this, defSkuValues, false);
  1145. }
  1146. }
  1147. // 设置选中的sku信息
  1148. chooseSkuItem(_this)
  1149. }
  1150. /**
  1151. * @desc : 判断规格是否可用
  1152. * @date : 2022/9/25 16:49
  1153. * @author : 周兴
  1154. */
  1155. function checkSpecsIsEnableNew(_this, defSkuValues, changeDefSkuId) {
  1156. let currentChoosedItem = _this.data.currentChoosedItem
  1157. let skuSpecsList = currentChoosedItem.skuSpecsList;
  1158. let skuSpecsData = currentChoosedItem.skuSpecsData;
  1159. // 获取当前已经选中规格
  1160. if (!defSkuValues || defSkuValues.length == 0) {
  1161. defSkuValues = []
  1162. skuSpecsList.forEach(it => {
  1163. defSkuValues = defSkuValues.concat(it.specsList.filter(it2 => it2.default))
  1164. })
  1165. }
  1166. defSkuValues = defSkuValues ? defSkuValues : []
  1167. console.log('defSkuValues',defSkuValues)
  1168. // let filterSkus = []
  1169. if (defSkuValues && defSkuValues.length > 0) {
  1170. let title = ''
  1171. defSkuValues.forEach(it => {
  1172. // filterSkus = skuSpecsData.filter(row => row['specsId_' + it.specsId]
  1173. // && row['specsId_' + it.specsId].indexOf(it.specsValue) >= 0);
  1174. if (it.specsValue) {
  1175. // 设置当前sku
  1176. title = title + it.specsId + ":" + it.specsValue + ","
  1177. }
  1178. })
  1179. // 在前面拼上, 方便进行匹配,要带逗号进行匹配这样才是准确的
  1180. if (title && title != ',') {
  1181. title = ',' + title
  1182. }
  1183. // 根据选择sku信息
  1184. if (changeDefSkuId && title) {
  1185. let filterRows = skuSpecsData.filter(it => it.title == title);
  1186. if (filterRows && filterRows.length > 0) {
  1187. _this.setData({
  1188. defSkuId: filterRows[0].skuId
  1189. })
  1190. console.log('filterRows ')
  1191. // 设置选中的sku信息
  1192. chooseSkuItem(_this)
  1193. } else {
  1194. console.log('filterRows 空 根据选择sku信息')
  1195. let currentChoosedItem = _this.data.currentChoosedItem;
  1196. currentChoosedItem.skuId = null;
  1197. currentChoosedItem.skuCode = null;
  1198. currentChoosedItem.skuName = null;
  1199. currentChoosedItem.skuModel = null;
  1200. currentChoosedItem.priceStandard = Number(0);
  1201. currentChoosedItem.itemAmount = Number(0);
  1202. currentChoosedItem.priceSale = Number(0);
  1203. currentChoosedItem.discountStandard = Number(0);
  1204. //HC0129DT
  1205. _this.setData({
  1206. defSkuId: null,
  1207. currentChoosedItem: currentChoosedItem
  1208. })
  1209. }
  1210. }
  1211. }
  1212. // 如果都没有选中的sku则全部清空
  1213. if (defSkuValues.length == 0) {
  1214. clearDefaultCommon(_this);
  1215. } else {
  1216. skuSpecsList.forEach(it => {
  1217. // 判断时要去掉当前规格进行判断
  1218. let filterRows = defSkuValues.filter(d => d.specsId != it.specsId);
  1219. if (!filterRows || filterRows.length == 0) {
  1220. // 说明其他规格没有选中的了,那么这个规格下都可用
  1221. it.specsList.forEach(item => {
  1222. // 未设置标价的不允许可用
  1223. if (!item.noPriceStandardFlag) {
  1224. item.disabled = false;
  1225. }
  1226. })
  1227. } else {
  1228. let title = ''
  1229. let skuSpecsDataTmp = JSON.parse(JSON.stringify(skuSpecsData))
  1230. filterRows.forEach(d => {
  1231. if (d.specsValue) {
  1232. // 设置当前sku
  1233. title = ',' + d.specsId + ":" + d.specsValue + ","
  1234. skuSpecsDataTmp = filterDataByTitle(skuSpecsDataTmp, title);
  1235. }
  1236. })
  1237. it.specsList.forEach(item => {
  1238. let itemFilters = skuSpecsDataTmp.filter(row => row['title'] && !row.noPriceStandardFlag
  1239. && row['title'].indexOf("," + item.specsId + ":" + item.specsValue + ",") >= 0);
  1240. if (itemFilters && itemFilters.length > 0) {
  1241. item.disabled = false;
  1242. } else {
  1243. item.disabled = true;
  1244. }
  1245. })
  1246. }
  1247. })
  1248. let currentChoosedItem = _this.data.currentChoosedItem;
  1249. currentChoosedItem.skuSpecsList = skuSpecsList;
  1250. _this.setData({
  1251. currentChoosedItem: currentChoosedItem
  1252. })
  1253. }
  1254. }
  1255. /**
  1256. * @desc : 根据内容进行匹配数据
  1257. * @date : 2022/7/2 16:49
  1258. * @author : 周兴
  1259. */
  1260. function filterDataByTitle(data, title) {
  1261. if (data && data.length > 0) {
  1262. let filters = data.filter(row => row['title']
  1263. && row['title'].indexOf(title) >= 0);
  1264. return filters;
  1265. }
  1266. return data;
  1267. }
  1268. /**
  1269. * @desc : 判断规格是否可用
  1270. * @date : 2022/7/2 16:49
  1271. * @author : 周兴
  1272. */
  1273. function checkSpecsIsEnable(specsId, specsValue, changeDefSkuId, _this) {
  1274. let currentChoosedItem = _this.data.currentChoosedItem
  1275. let skuSpecsList = currentChoosedItem.skuSpecsList;
  1276. let skuSpecsData = currentChoosedItem.skuSpecsData;
  1277. // 先获取符合当前规格的商品
  1278. let filterSkus = skuSpecsData.filter(row => row['specsId_' + specsId] && row['specsId_' + specsId].indexOf(specsValue) >= 0);
  1279. //判断其他规格分类是否可用
  1280. let otherSpecsList = skuSpecsList.filter(it => it.specsId != specsId)
  1281. if (otherSpecsList && otherSpecsList.length > 0) {
  1282. otherSpecsList.forEach(it => {
  1283. it.specsList.forEach(item => {
  1284. // 设置是否可用
  1285. if (filterSkus && filterSkus.length > 0) {
  1286. let filterRows = filterSkus.filter(row => row['specsId_' + it.specsId] && row['specsId_' + it.specsId].indexOf(item.key) >= 0);
  1287. if (filterRows && filterRows.length > 0) {
  1288. // 设置默认的skuId
  1289. if (changeDefSkuId && item.default) {
  1290. _this.setData({
  1291. defSkuId: filterRows[0].skuId
  1292. })
  1293. // 设置选中的sku信息
  1294. chooseSkuItem(_this)
  1295. }
  1296. //说明存在
  1297. item.disabled = false;
  1298. } else {
  1299. item.disabled = true;
  1300. }
  1301. }
  1302. })
  1303. });
  1304. } else {
  1305. if (changeDefSkuId && filterSkus && filterSkus.length > 0) {
  1306. _this.setData({
  1307. defSkuId: filterSkus[0].skuId
  1308. })
  1309. // 设置选中的sku信息
  1310. chooseSkuItem(_this)
  1311. }
  1312. }
  1313. currentChoosedItem.skuSpecsList = skuSpecsList;
  1314. _this.setData({
  1315. currentChoosedItem: currentChoosedItem
  1316. })
  1317. }
  1318. /**
  1319. * @desc : 选择sku,记录sku相关信息
  1320. * @date : 2022/9/1 13:49
  1321. * @author : 于继渤
  1322. */
  1323. function chooseSkuItem(_this) {
  1324. let currentChoosedItem = _this.data.currentChoosedItem;
  1325. let defSkuId = _this.data.defSkuId;
  1326. let skuData = currentChoosedItem.skuData;
  1327. let filterRows = skuData.filter(it => it.skuId == defSkuId);
  1328. console.log('chooseSkuItem')
  1329. if (filterRows && filterRows.length > 0) {
  1330. console.log('filterRows 111',filterRows)
  1331. let row = filterRows[0];
  1332. currentChoosedItem.titleTag = row.titleTag
  1333. currentChoosedItem.orderItemQuantity = row.orderItemQuantity
  1334. currentChoosedItem.activityId = row.activityId ? row.activityId : null
  1335. currentChoosedItem.promotionItemId = row.promotionItemId
  1336. currentChoosedItem.promotionPriceType = row.promotionPriceType
  1337. currentChoosedItem.skuId = row.skuId
  1338. currentChoosedItem.promotionId = row.promotionId
  1339. currentChoosedItem.promotionType = row.promotionType
  1340. currentChoosedItem.promotionTypeName = row.promotionTypeName
  1341. currentChoosedItem.hasChild = row.hasChild
  1342. currentChoosedItem.id = row.id
  1343. currentChoosedItem.cpFlgGift = row.cpFlgGift ? row.cpFlgGift : null
  1344. currentChoosedItem.parentId = row.parentId
  1345. currentChoosedItem.skuType = row.skuType
  1346. currentChoosedItem.skuCode = row.skuCode
  1347. currentChoosedItem.skuName = row.skuName
  1348. currentChoosedItem.spuCode = row.spuCode
  1349. currentChoosedItem.priceCost = (row.priceCost == 0 || row.priceCost) ? row.priceCost : null
  1350. currentChoosedItem.spuId = row.spuId
  1351. currentChoosedItem.pricePromotion = row.pricePromotion
  1352. currentChoosedItem.priceStandard = row.priceStandard
  1353. currentChoosedItem.priceSale = row.priceSale ? row.priceSale : 0
  1354. currentChoosedItem.itemAmount = currentChoosedItem.priceSale
  1355. currentChoosedItem.discountPromotion = 100;
  1356. currentChoosedItem.discountStandard = 100;
  1357. if (row.priceStandard == 0) {
  1358. currentChoosedItem.discountStandard = 0;
  1359. }
  1360. //面积公式
  1361. if (row.specialFormulaName) {
  1362. currentChoosedItem.specialFormulaName = row.specialFormulaName
  1363. currentChoosedItem.specialFormula = row.specialFormulaName
  1364. }
  1365. currentChoosedItem.titleTag = row.titleTag
  1366. currentChoosedItem.standardId = row.standardId
  1367. currentChoosedItem.standardItemId = row.standardItemId
  1368. currentChoosedItem.skuVolume = row.skuVolume
  1369. currentChoosedItem.skuWeight = row.skuWeight
  1370. currentChoosedItem.bomItems = row.bomItems
  1371. currentChoosedItem.glassThickness = row.glassThickness
  1372. currentChoosedItem.glassCraft = row.glassCraft
  1373. currentChoosedItem.substrateColor = row.substrateColor
  1374. currentChoosedItem.standardId = row.standardId
  1375. currentChoosedItem.skuModel = row.skuModel
  1376. currentChoosedItem.flgAllowSpecsUndefine = row.flgAllowSpecsUndefine
  1377. // currentChoosedItem.skuSpecsList = _this.data.skuSpecsList
  1378. // currentChoosedItem.skuSpecsData = _this.data.skuSpecsData
  1379. //非标
  1380. if (row.flgNonStandardType == 1 || row.flgNonStandardType == 2) {
  1381. if (row.flgNonStandardType == 1) {
  1382. currentChoosedItem.nonGlassPriceDef = row.nonGlassPriceDef ? row.nonGlassPriceDef : null
  1383. currentChoosedItem.priceStandard = currentChoosedItem.nonGlassPriceDef ? currentChoosedItem.nonGlassPriceDef : 0
  1384. currentChoosedItem.priceSale = currentChoosedItem.nonGlassPriceDef ? currentChoosedItem.nonGlassPriceDef : 0
  1385. currentChoosedItem.itemAmount = currentChoosedItem.nonGlassPriceDef ? currentChoosedItem.nonGlassPriceDef : 0
  1386. }
  1387. if (row.flgNonStandardType == 2) {
  1388. currentChoosedItem.priceStandard = currentChoosedItem.priceStandard
  1389. currentChoosedItem.priceSale = currentChoosedItem.priceStandard
  1390. currentChoosedItem.itemAmount = currentChoosedItem.priceStandard
  1391. }
  1392. currentChoosedItem.nonGlassPriceItems = row.nonGlassPriceItems ? row.nonGlassPriceItems : []
  1393. if (row.nonGlassPriceItems && row.nonGlassPriceItems.length > 0) {
  1394. let flgDefItemList = row.nonGlassPriceItems.filter(res => {
  1395. return res.flgDefItem
  1396. })
  1397. currentChoosedItem.priceStandard = flgDefItemList[0].itemPrice
  1398. currentChoosedItem.priceSale = currentChoosedItem.nonGlassPriceDef ? currentChoosedItem.nonGlassPriceDef : flgDefItemList[0].itemPrice
  1399. currentChoosedItem.itemAmount = currentChoosedItem.nonGlassPriceDef ? currentChoosedItem.nonGlassPriceDef : flgDefItemList[0].itemPrice
  1400. }else{
  1401. console.log('规格没有匹配上sku')
  1402. currentChoosedItem.priceStandard = row.priceStandard
  1403. currentChoosedItem.priceSale = row.priceStandard
  1404. currentChoosedItem.itemAmount = row.priceStandard
  1405. }
  1406. }
  1407. // 设置赠品
  1408. setFlgGift(_this);
  1409. // 判断是否有可换件
  1410. getReplaceFlag([row], _this);
  1411. } else {
  1412. console.log('没有匹配到sku')
  1413. currentChoosedItem.skuId = null
  1414. currentChoosedItem.skuName = null
  1415. currentChoosedItem.skuCode = null
  1416. currentChoosedItem.priceStandard = 0
  1417. currentChoosedItem.itemAmount = Number((currentChoosedItem.itemQuantity ? currentChoosedItem.itemQuantity : 0) * (currentChoosedItem.priceSale ? currentChoosedItem.priceSale : 0));
  1418. }
  1419. _this.setData({
  1420. currentChoosedItem: currentChoosedItem
  1421. })
  1422. }
  1423. /**
  1424. * @desc : 切换sku商品规格
  1425. * @author : 周兴
  1426. * @date : 2022/6/1 10:16
  1427. */
  1428. function changeSkuSpecsCommon(e, _this) {
  1429. let disabled = e.target.dataset.itemt.disabled;
  1430. // 说明是不能用的,就不需要切换
  1431. if (disabled) {
  1432. return;
  1433. }
  1434. let currentChoosedItem = _this.data.currentChoosedItem;
  1435. let specsValue = e.target.dataset.itemt.key;
  1436. let specsId = e.target.dataset.itemt.specsId;
  1437. let skuSpecsList = currentChoosedItem.skuSpecsList;
  1438. let defaultFlag = !e.target.dataset.itemt.default;
  1439. // 默认值取反向
  1440. // 更改默认值
  1441. let filterRows = skuSpecsList.filter(it => it.specsId == specsId);
  1442. if (filterRows && filterRows.length > 0) {
  1443. filterRows[0].specsList.forEach(row => {
  1444. if (row.key == specsValue) {
  1445. row.default = defaultFlag;
  1446. } else {
  1447. row.default = false;
  1448. }
  1449. })
  1450. }
  1451. _this.setData({
  1452. currentChoosedItem: currentChoosedItem
  1453. })
  1454. // 判断规格是否可用
  1455. // checkSpecsIsEnable(specsId, specsValue, true, _this);
  1456. checkSpecsIsEnableNew(_this, null, true);
  1457. }
  1458. /**
  1459. * @desc : 判断是否可以进行替换
  1460. * @date : 2022/9/1 13:49
  1461. * @author : 于继渤
  1462. */
  1463. function getReplaceFlag(rows, _this) {
  1464. let currentChoosedItem = _this.data.currentChoosedItem;
  1465. currentChoosedItem.replaceFlag = false;
  1466. if (rows && rows.length > 0) {
  1467. for (let j = 0; j < rows.length; j++) {
  1468. if (rows[j].bomItems != null && rows[j].bomItems.length > 0) {
  1469. for (let i = 0; i < rows[j].bomItems.length; i++) {
  1470. if (rows[j].bomItems[i].replaceableSku != null
  1471. && rows[j].bomItems[i].replaceableSku.length > 0) {
  1472. currentChoosedItem.replaceFlag = true;
  1473. return;
  1474. }
  1475. }
  1476. }
  1477. }
  1478. }
  1479. }
  1480. /**
  1481. * @desc : 改变标识
  1482. * @author : 周兴
  1483. * @date : 2022/8/6 17:16
  1484. */
  1485. function changeAllReadyCheckBoxCommon(e, _this) {
  1486. let key = e.currentTarget.dataset.key
  1487. let currentChoosedItem = _this.data.currentChoosedItem
  1488. //根据商品的cpFlgGift赠品标识,如果没有设置,不允许订单明细的售价为0,赠品标识也不修改(bom子级按照总单来,组合是可以按照明细控制)
  1489. //bom
  1490. if (currentChoosedItem.skuType == 2) {
  1491. if (currentChoosedItem.cpFlgGift) {
  1492. currentChoosedItem.flgGift = e.detail
  1493. if (e.detail) {
  1494. currentChoosedItem.priceSale_Temp = currentChoosedItem.priceSale ? currentChoosedItem.priceSale : currentChoosedItem.priceSale_Temp
  1495. currentChoosedItem.itemAmount_Temp = currentChoosedItem.itemAmount ? currentChoosedItem.itemAmount : currentChoosedItem.itemAmount_Temp
  1496. currentChoosedItem.discountStandard_Temp = currentChoosedItem.discountStandard
  1497. currentChoosedItem.discountPromotion_Temp = currentChoosedItem.discountPromotion
  1498. currentChoosedItem.priceSale = 0
  1499. currentChoosedItem.discountStandard = 0
  1500. currentChoosedItem.discountPromotion = 0
  1501. currentChoosedItem.itemAmount = 0
  1502. } else {
  1503. // 取消赠品标识时,价格是0时价格恢复成标价,如价格手动改过,则不变
  1504. if (currentChoosedItem.priceSale == 0) {
  1505. // 恢复到以前的金额
  1506. currentChoosedItem.priceSale = Number(currentChoosedItem.priceSale_Temp)
  1507. currentChoosedItem.itemAmount = Number(currentChoosedItem.itemAmount_Temp)
  1508. currentChoosedItem.discountStandard = Number(currentChoosedItem.discountStandard_Temp)
  1509. currentChoosedItem.discountPromotion = Number(currentChoosedItem.discountPromotion_Temp)
  1510. }
  1511. }
  1512. }
  1513. } else {
  1514. currentChoosedItem.flgGift = e.detail
  1515. if (e.detail) {
  1516. currentChoosedItem.priceSale_Temp = currentChoosedItem.priceSale
  1517. currentChoosedItem.itemAmount_Temp = currentChoosedItem.itemAmount
  1518. currentChoosedItem.discountStandard_Temp = currentChoosedItem.discountStandard
  1519. currentChoosedItem.discountPromotion_Temp = currentChoosedItem.discountPromotion
  1520. currentChoosedItem.priceSale = 0
  1521. currentChoosedItem.discountStandard = 0
  1522. currentChoosedItem.discountPromotion = 0
  1523. currentChoosedItem.itemAmount = 0
  1524. } else {
  1525. // 取消赠品标识时,价格是0时价格恢复成标价,如价格手动改过,则不变
  1526. if (currentChoosedItem.priceSale == 0) {
  1527. // 恢复到以前的金额
  1528. currentChoosedItem.priceSale = currentChoosedItem.priceSale_Temp
  1529. currentChoosedItem.itemAmount = currentChoosedItem.itemAmount_Temp
  1530. currentChoosedItem.discountStandard = currentChoosedItem.discountStandard_Temp
  1531. currentChoosedItem.discountPromotion = currentChoosedItem.discountPromotion_Temp
  1532. }
  1533. }
  1534. }
  1535. _this.setData({
  1536. currentChoosedItem: currentChoosedItem
  1537. })
  1538. }
  1539. /**
  1540. * @desc : 清空选中数据(确定)
  1541. * @date : 2022/7/4 16:49
  1542. * @author : 周兴
  1543. */
  1544. function clearDefaultCommon(_this) {
  1545. let currentChoosedItem = _this.data.currentChoosedItem
  1546. // 清空sku数据
  1547. currentChoosedItem.skuId = null;
  1548. currentChoosedItem.skuName = null;
  1549. currentChoosedItem.skuCode = null;
  1550. currentChoosedItem.skuModel = null;
  1551. currentChoosedItem.pricePromotion = null;
  1552. currentChoosedItem.priceStandard = null;
  1553. let skuSpecsList = currentChoosedItem.skuSpecsList;
  1554. if (skuSpecsList && skuSpecsList.length > 0) {
  1555. skuSpecsList.forEach(it => {
  1556. if (it.specsList && it.specsList.length > 0) {
  1557. it.specsList.forEach(s => {
  1558. s.default = false;
  1559. if (!s.noPriceStandardFlag) {
  1560. s.disabled = false;
  1561. }
  1562. })
  1563. _this.setData({
  1564. currentChoosedItem: currentChoosedItem
  1565. })
  1566. }
  1567. })
  1568. }
  1569. }
  1570. /**
  1571. * @desc : 选择数据(确定)
  1572. * @date : 2022/7/4 16:49
  1573. * @author : 周兴
  1574. */
  1575. function chooseSkuInfoCommon(_this) {
  1576. let currentChoosedItem = _this.data.currentChoosedItem
  1577. currentChoosedItem.goodsSkuList = _this.data.goodsSkuList
  1578. //校验选择商品数量不能为0
  1579. if (currentChoosedItem.itemQuantity === 0 || !currentChoosedItem.itemQuantity) {
  1580. wx.showToast({
  1581. title: '数量不能为0',
  1582. image: '/static/image/warning.png',
  1583. duration: 1000
  1584. })
  1585. return
  1586. }
  1587. // 如果没有sku 那么不允许
  1588. if (currentChoosedItem.promotionType != Constants.PROMOTION_TYPE.COMBINED && (!currentChoosedItem.skuId || currentChoosedItem.skuId == 0)) {
  1589. wx.showToast({
  1590. title: '未选择商品规格',
  1591. image: '/static/image/warning.png',
  1592. duration: 1000
  1593. })
  1594. return
  1595. }
  1596. //非标定制品标价参数赋值
  1597. if (currentChoosedItem.nonStandardList && currentChoosedItem.nonStandardList.length > 0) {
  1598. let nonStandardList = util.copyObj(currentChoosedItem.nonStandardList)
  1599. let nonStandardObjList = []
  1600. nonStandardList.forEach(res => {
  1601. let nonStandardObj = {
  1602. fieldId: null,
  1603. fieldCode: null,
  1604. fieldName: null,
  1605. optionCode: null,
  1606. optionName: null,
  1607. }
  1608. nonStandardObj.fieldId = res.fieldId
  1609. nonStandardObj.fieldCode = res.fieldCode
  1610. nonStandardObj.fieldName = res.fieldName
  1611. nonStandardObj.isScope = res.isScope
  1612. nonStandardObj.fieldType = res.fieldType
  1613. //判断是否是范围值
  1614. if (res.isScope == 1) {
  1615. if (res.optionCode && res.optionCode) {
  1616. nonStandardObj.optionCode = res.optionCode
  1617. nonStandardObj.optionName = res.optionName
  1618. }
  1619. }
  1620. if (res.options && res.options.length > 0) {
  1621. res.options.forEach(it => {
  1622. if (it.infotype == 'info') {
  1623. nonStandardObj.optionCode = it.code
  1624. nonStandardObj.optionName = it.name
  1625. }
  1626. })
  1627. }
  1628. //没有选择的参数不会设置
  1629. if (nonStandardObj.optionCode) {
  1630. nonStandardObjList.push(nonStandardObj)
  1631. }
  1632. })
  1633. currentChoosedItem.nonGlassList = nonStandardObjList //订单明细字段
  1634. //设置显示非标参数 (展示非标text)
  1635. if (nonStandardObjList && nonStandardObjList.length > 0) {
  1636. let nonGlassListShowTemp = []
  1637. nonStandardObjList.forEach(it => {
  1638. if (it.optionName && it.optionName != undefined) {
  1639. nonGlassListShowTemp.push(it.fieldName + ':' + it.optionName)
  1640. }
  1641. })
  1642. //非标参数显示/匹配命中标价的数据
  1643. currentChoosedItem.nonGlassListShow = nonGlassListShowTemp.join(',')
  1644. }
  1645. }
  1646. // 已选商品列表
  1647. let choosedGoodsList = util.copyObj(_this.data.choosedGoodsList)
  1648. let currentChoosedItemCopy = util.copyObj(currentChoosedItem)
  1649. //判断已选是不是修改
  1650. if (_this.data.active == 1 || _this.data.active == '1') {
  1651. if (typeof _this.data.activeOneIndex == 'number') {
  1652. choosedGoodsList[_this.data.activeOneIndex] = {}
  1653. choosedGoodsList[_this.data.activeOneIndex] = currentChoosedItemCopy
  1654. }
  1655. _this.setData({
  1656. choosedGoodsList: choosedGoodsList
  1657. })
  1658. }
  1659. // 判断商品是否在已选列表中存在
  1660. let filterRows = choosedGoodsList.filter(it => it.id == currentChoosedItem.id);
  1661. let currentChoosedItemTemp = { ...currentChoosedItem }
  1662. if (!filterRows || filterRows.length == 0) {
  1663. if (_this.data.active != 1 || _this.data.active != '1') {
  1664. choosedGoodsList.push(currentChoosedItemTemp)
  1665. }
  1666. }
  1667. choosedGoodsList.forEach(it => {
  1668. it.flgInstalled = true
  1669. })
  1670. console.log('choosedGoodsList', choosedGoodsList)
  1671. _this.setData({
  1672. choosedGoodsList: choosedGoodsList,
  1673. choosedGoodsListLength: choosedGoodsList.length,
  1674. showAdd: false,
  1675. show6: false
  1676. })
  1677. // 更新购物车已选数量
  1678. handleChoosedNum(_this);
  1679. //计算合计金额
  1680. getSumAmount(_this);
  1681. }
  1682. /**
  1683. * @desc : 计算合计金额
  1684. * @date : 2022/7/4 16:49
  1685. * @author : 于继渤
  1686. */
  1687. function getSumAmount(_this) {
  1688. // 逸轩商品的数组
  1689. let choosedGoodsList = _this.data.choosedGoodsList
  1690. let sumQuantity = 0 // 合计数量
  1691. let sumGoodsAmount = 0 // 货物金额
  1692. let categoryQuantityList = [] // 品类数
  1693. choosedGoodsList.forEach(item => {
  1694. sumGoodsAmount += Number(item.itemAmount)
  1695. // 如果有子级,计算子级的数量
  1696. if (item.bomItems && item.bomItems.length > 0) {
  1697. item.bomItems.forEach(it => {
  1698. sumQuantity += Number(item.itemQuantity * it.orderItemQuantity);
  1699. if (it.skuSpecs == null) {
  1700. it.skuSpecs = " "
  1701. }
  1702. if (it.skuSpecs && !categoryQuantityList.includes(it.skuSpecs)) {
  1703. categoryQuantityList.push(it.skuSpecs)
  1704. }
  1705. })
  1706. } else if (item.combinedList && item.combinedList.length > 0) {
  1707. item.combinedList.forEach(it => {
  1708. if (it.bomItems && it.bomItems.length > 0) {
  1709. it.bomItems.forEach(itemt => {
  1710. sumQuantity += Number(it.itemQuantity * itemt.orderItemQuantity);
  1711. if (itemt.skuSpecs == null) {
  1712. itemt.skuSpecs = " "
  1713. }
  1714. if (itemt.skuSpecs && !categoryQuantityList.includes(itemt.skuSpecs)) {
  1715. categoryQuantityList.push(itemt.skuSpecs)
  1716. }
  1717. })
  1718. } else {
  1719. sumQuantity += Number(item.itemQuantity * it.orderItemQuantity);
  1720. }
  1721. if (it.skuSpecs == null) {
  1722. it.skuSpecs = " "
  1723. }
  1724. if (it.skuSpecs && !categoryQuantityList.includes(it.skuSpecs)) {
  1725. categoryQuantityList.push(it.skuSpecs)
  1726. }
  1727. })
  1728. } else {
  1729. // 如果没有子级,就加上即可
  1730. sumQuantity += Number(item.itemQuantity);
  1731. if (item.skuSpecs == null) {
  1732. item.skuSpecs = " "
  1733. }
  1734. if (item.skuSpecs && !categoryQuantityList.includes(item.skuSpecs)) {
  1735. categoryQuantityList.push(item.skuSpecs)
  1736. }
  1737. }
  1738. // 如果有组合
  1739. })
  1740. _this.setData({
  1741. sumGoodsAmount: sumGoodsAmount,
  1742. sumQuantity: sumQuantity,
  1743. categoryQuantity: categoryQuantityList.length,
  1744. })
  1745. }
  1746. /**
  1747. * @desc : 确定时处理数据
  1748. * @date : 2022/7/5 16:49
  1749. * @author : 周兴
  1750. */
  1751. function handleData(goodsList, _this) {
  1752. let followFlag = _this.data.followFlag;
  1753. let choosedGoodsList = util.copyObj(_this.data.choosedGoodsList)
  1754. let title = ''
  1755. if (choosedGoodsList != null && choosedGoodsList.length > 0) {
  1756. let skuTypeFlag = false
  1757. choosedGoodsList.forEach(it => {
  1758. if (!it.id) {
  1759. it.id = util.getGuid()
  1760. }
  1761. //判断bom是否有子级
  1762. if (it.skuType == 2 && (it.bomItems == null || it.bomItems.length == 0)) {
  1763. title = it.title
  1764. skuTypeFlag = true
  1765. } else {
  1766. skuTypeFlag = false
  1767. }
  1768. // 父级id
  1769. it.parentId = null;
  1770. it.hasChild = 0; // 默认设置为无子级
  1771. // 处理金额
  1772. it.itemAmount = Number(it.itemAmount).toFixed(2)
  1773. // 跟单处理为实际量
  1774. if (followFlag) {
  1775. it.tItemQuantity = it.itemQuantity
  1776. it.tItemAmount = it.itemAmount
  1777. }
  1778. console.log('it.bomItems前', it.bomItems)
  1779. // ***如果有子级,需要处理子级的数据 TODO
  1780. if (it.bomItems != null && it.bomItems.length > 0) {
  1781. it.hasChild = 1; // 说明有子级
  1782. it.flgInstalled = true
  1783. it.bomItems.forEach(row => {
  1784. row['flgBomCombined'] = false;
  1785. // 父级id
  1786. row.parentId = it.id;
  1787. // 数量的处理
  1788. if (followFlag) {
  1789. row.tItemQuantity = it.itemQuantity * row.orderItemQuantity
  1790. } else {
  1791. row.itemQuantity = it.itemQuantity * row.orderItemQuantity
  1792. }
  1793. console.log('bomItem数量的处理', row.itemQuantity)
  1794. // 如果单品促销
  1795. if (it.promotionType == Constants.PROMOTION_TYPE.PRMOTION ||
  1796. it.promotionType == Constants.PROMOTION_TYPE.COMBINED) {
  1797. // 把促销的信息替换上去
  1798. //设置明细活动ID
  1799. row.activityId = it.activityId
  1800. row.promotionType = it.promotionType;
  1801. row.promotionId = it.promotionId;
  1802. if (it.pricePromotion == 0) {
  1803. row.priceSale = 0
  1804. } else {
  1805. // 销售价(子级)= 销售价(父级)/ 标售售价(父级)* 标售售价(子级)
  1806. row.priceSale = Number((it.priceSale / it.pricePromotion * row.pricePromotion).toFixed(2))
  1807. }
  1808. } else {
  1809. // 正常品
  1810. if (it.priceStandard == 0 || !it.priceStandard) {
  1811. row.priceSale = 0
  1812. } else {
  1813. // 销售价(子级)= 销售价(父级)/ 标售售价(父级)* 标售售价(子级)
  1814. row.priceSale = Number((it.priceSale / it.priceStandard * row.priceStandard).toFixed(2))
  1815. }
  1816. }
  1817. if (followFlag) {
  1818. row.tItemAmount = Number((row.priceSale * row.tItemQuantity).toFixed(2))
  1819. row.itemAmount = row.tItemAmount
  1820. } else {
  1821. row.itemAmount = Number((row.priceSale * row.itemQuantity).toFixed(2))
  1822. }
  1823. // 设置标题
  1824. getTitle(it, row);
  1825. // 处理图标
  1826. common.setRowImagePath(row);
  1827. })
  1828. it.goodsSkuList = it.bomItems
  1829. }
  1830. // **** 如果有组合促销,需要进行数据的处理
  1831. if (it.combinedList != null && it.combinedList.length > 0) {
  1832. it.flgInstalled = true
  1833. it.hasChild = 1; // 说明有子级
  1834. it.goodsSkuList = []
  1835. let priceStandard = 0; // 重新计算标价
  1836. it.combinedList.forEach(row => {
  1837. row.activityId = it.activityId
  1838. row.parentId = it.id;
  1839. row.hasChild = 0;
  1840. if (row.bomItems == null || row.bomItems.length == 0) {
  1841. if (row.cpFlgGift) {
  1842. row.priceSale = 0
  1843. row.discountStandard = 0
  1844. row.discountPromotion = 0
  1845. row.itemAmount = 0
  1846. } else {
  1847. // 重新计算价格
  1848. row.priceSale = getCombinedSalePrice(it, row);
  1849. }
  1850. // 重新计算折扣
  1851. getCombinedDiscount(row);
  1852. // 计算数量
  1853. row.itemQuantity = Number(it.itemQuantity) * Number(row.orderItemQuantity)
  1854. row.itemAmount = Number(row.itemQuantity) * Number(row.priceSale)
  1855. // 跟单处理为实际量
  1856. if (followFlag) {
  1857. row.tItemQuantity = row.itemQuantity
  1858. row.tItemAmount = row.itemAmount
  1859. }
  1860. // 把促销的信息替换上去
  1861. row.promotionType = it.promotionType;
  1862. row.promotionId = it.promotionId;
  1863. // 设置标题
  1864. getTitle(it, row);
  1865. // 处理图标
  1866. common.setRowImagePath(row);
  1867. row.flgBomCombined = false;
  1868. it.goodsSkuList.push(row);
  1869. // 计算标价
  1870. priceStandard += Number(row.orderItemQuantity) * Number(row.priceStandard)
  1871. } else {
  1872. let bomAmount = 0;
  1873. // bom也需要保存进去,方便报表统计
  1874. row.itemQuantity = it.itemQuantity * row.orderItemQuantity;
  1875. row.itemAmount = bomAmount;
  1876. row.bomItems.forEach(bRow => {
  1877. // 父级id
  1878. bRow.parentId = it.id;
  1879. bRow.hasChild = 0;
  1880. if (row.cpFlgGift) {
  1881. bRow.priceSale = 0
  1882. bRow.discountStandard = 0
  1883. bRow.discountPromotion = 0
  1884. bRow.itemAmount = 0
  1885. } else {
  1886. // 重新计算价格
  1887. bRow.priceSale = getCombinedSalePrice(it, bRow);
  1888. }
  1889. // 重新计算折扣
  1890. getCombinedDiscount(bRow);
  1891. // 数量的处理
  1892. bRow.itemQuantity = Number(row.itemQuantity) * Number(bRow.orderItemQuantity)
  1893. bRow.itemAmount = Number(bRow.priceSale) * Number(bRow.itemQuantity).toFixed(2)
  1894. bomAmount += bRow.itemAmount;
  1895. if (followFlag) {
  1896. bRow.tItemQuantity = bRow.itemQuantity
  1897. bRow.tItemAmount = bRow.itemAmount
  1898. }
  1899. bRow.activityId = it.activityId
  1900. // 把促销的信息替换上去
  1901. bRow.promotionType = it.promotionType;
  1902. bRow.promotionId = it.promotionId;
  1903. // 设置标题
  1904. getTitle(it, bRow);
  1905. // 处理图标
  1906. common.setRowImagePath(bRow);
  1907. bRow.flgBomCombined = false;
  1908. it.goodsSkuList.push(bRow);
  1909. // 计算标价
  1910. priceStandard += Number(bRow.orderItemQuantity) * Number(bRow.priceStandard)
  1911. })
  1912. row.priceSale = row.itemQuantity == 0 ? 0 : (Number(row.itemAmount) / Number(row.itemQuantity)).toFixed(2)
  1913. if (followFlag) {
  1914. row.tItemQuantity = row.itemQuantity
  1915. row.tItemAmount = row.itemAmount
  1916. }
  1917. row.hasChild = 1;
  1918. row.flgBomCombined = true;
  1919. it.goodsSkuList.push(row);
  1920. }
  1921. })
  1922. // 给组合的标价总额赋值
  1923. it.priceStandard = priceStandard
  1924. }
  1925. // 计算品类数
  1926. it.categoryQuantity = common.getCategoryQuantity(it.goodsSkuList);
  1927. getCombinedPriceByChange(_this)
  1928. it['flgBomCombined'] = false;
  1929. })
  1930. // 重新计算最后一条数据的金额,用父级金额-其他条金额合计
  1931. common.countLastAmount(choosedGoodsList, followFlag);
  1932. // 把选择的数据加到明细中
  1933. for (let i = 0; i < choosedGoodsList.length; i++) {
  1934. let newGood = choosedGoodsList[i];
  1935. let alreadyExists = false;
  1936. for (let j = 0; j < goodsList.length; j++) {
  1937. if (goodsList[j].id === newGood.id) {
  1938. alreadyExists = true;
  1939. break;
  1940. }
  1941. }
  1942. if (!alreadyExists) {
  1943. goodsList.push(newGood);
  1944. }
  1945. }
  1946. // goodsList = goodsList.concat(choosedGoodsList);
  1947. if (skuTypeFlag) {
  1948. wx.showToast({
  1949. title: title + '该BOM没有子件',
  1950. icon: 'none'
  1951. })
  1952. }
  1953. }
  1954. goodsList.forEach(res => {
  1955. res.skuVolume = 0
  1956. res.skuWeight = 0
  1957. if (res.goodsSkuList && res.goodsSkuList.length > 0) {
  1958. res.goodsSkuList.forEach(item => {
  1959. res.skuVolume += item.skuVolume
  1960. res.skuWeight += item.skuWeight
  1961. })
  1962. }
  1963. })
  1964. console.log('goodsList==>', goodsList)
  1965. return goodsList;
  1966. }
  1967. /**
  1968. * @desc : 重新计算组合子件的价格
  1969. * @date : 2022/7/6 16:49
  1970. * @author : 周兴
  1971. */
  1972. function getCombinedSalePrice(pRow, row) {
  1973. let priceSale = 0;
  1974. // 销售价(子级)= 销售价(父级)/ 标售售价(父级)* 标售售价(子级)
  1975. if (pRow.pricePromotion == 0) {
  1976. priceSale = 0
  1977. } else {
  1978. // 销售价(子级)= 销售价(父级)/ 标售售价(父级)* 标售售价(子级)
  1979. priceSale = Number(pRow.priceSale / pRow.pricePromotion * row.pricePromotion).toFixed(2)
  1980. }
  1981. return priceSale;
  1982. }
  1983. /**
  1984. * @desc : 计算折扣
  1985. * @date : 2022/7/6 16:49
  1986. * @author : 周兴
  1987. */
  1988. function getCombinedDiscount(row) {
  1989. let discountStandard = 0;
  1990. let discountPromotion = 0;
  1991. // 标价折扣= 售价/标价
  1992. if (!row.priceStandard || row.priceStandard == 0) {
  1993. discountStandard = 0;
  1994. } else {
  1995. discountStandard = Number(row.priceSale * 100 / row.priceStandard).toFixed(2)
  1996. }
  1997. // 促销折扣= 售价/促销价
  1998. if (!row.pricePromotion || row.pricePromotion == 0) {
  1999. discountPromotion = 100;
  2000. } else {
  2001. discountPromotion = Number(row.priceSale * 100 / row.pricePromotion).toFixed(2)
  2002. }
  2003. row.discountPromotion = discountPromotion;
  2004. row.discountStandard = discountStandard;
  2005. }
  2006. /**
  2007. * @desc : 设置子级设置标题等信息
  2008. * @date : 2022/7/6 16:49
  2009. * @author : 周兴
  2010. */
  2011. function getTitle(pRow, row) {
  2012. // titleTag 标题标签
  2013. if (pRow.promotionType == Constants.PROMOTION_TYPE.COMBINED) {
  2014. row.titleTag = '组合促销';
  2015. } else if (pRow.promotionType == Constants.PROMOTION_TYPE.PRMOTION) {
  2016. row.titleTag = '单品促销';
  2017. } else {
  2018. // 显示品牌
  2019. row.titleTag = row.brandName;
  2020. }
  2021. // title
  2022. row.title = row.skuName;
  2023. row.desc = row.skuCode;
  2024. }
  2025. /**
  2026. * @desc : 切换组合促销明细
  2027. * @date : 2022/7/5 16:49
  2028. * @author : 周兴
  2029. */
  2030. function changeCombinedItemCommon(e, _this) {
  2031. let itemt = e.currentTarget.dataset.itemt;
  2032. let currentChoosedItem = _this.data.currentChoosedItem;
  2033. let combinedData = currentChoosedItem.combinedData
  2034. let combinedItem = combinedData.combinedItem
  2035. // 切换默认项
  2036. combinedItem.forEach(it => {
  2037. //相同类别进行处理
  2038. if (it.combinedTypeId === itemt.combinedTypeId) {
  2039. it.infotype = 'default';
  2040. if (it.id == itemt.id) {
  2041. it.infotype = 'info'
  2042. }
  2043. }
  2044. })
  2045. currentChoosedItem.combinedData = combinedData;
  2046. _this.setData({
  2047. currentChoosedItem: currentChoosedItem
  2048. })
  2049. // 修改相关价格
  2050. getCombinedPriceByChange(_this);
  2051. }
  2052. function changeCombinedItemCommonSale(itemt, currentChoosedItem, _this) {
  2053. let combinedData = currentChoosedItem.combinedData
  2054. let combinedItem = combinedData.combinedItem
  2055. // 切换默认项
  2056. combinedItem.forEach(it => {
  2057. //相同类别进行处理
  2058. if (it.combinedTypeId === itemt.combinedTypeId) {
  2059. it.infotype = 'default';
  2060. if (it.id == itemt.id) {
  2061. it.infotype = 'info'
  2062. }
  2063. }
  2064. })
  2065. currentChoosedItem.combinedData = combinedData;
  2066. _this.setData({
  2067. currentChoosedItem: currentChoosedItem
  2068. })
  2069. // 修改相关价格
  2070. getCombinedPriceByChange(_this);
  2071. }
  2072. /**
  2073. * @desc : 设置查询参数
  2074. * @date : 2022/7/5 16:49
  2075. * @author : 周兴
  2076. */
  2077. function setParam(_this) {
  2078. let param = {}
  2079. param.specsId = undefined;
  2080. if (_this.data.specsId) {
  2081. param.specsId = Number(_this.data.specsId);
  2082. } else if (_this.data.specsId == 0) {
  2083. param.specsId = 0;
  2084. }
  2085. param.pageSize = _this.data.pageInfo.pageSize;
  2086. param.currentPage = _this.data.pageInfo.currentPage;
  2087. param.orgId = app.globalData.user.orgId
  2088. param.searchText = _this.data.searchText
  2089. param.cpId = app.globalData.user.cpId
  2090. let searchText = _this.data.searchText;
  2091. if (searchText) {
  2092. param.spuQuerys = JSON.stringify({
  2093. queryText: searchText,
  2094. })
  2095. }
  2096. return param;
  2097. }
  2098. /**
  2099. * @desc : 删除选中的数据
  2100. * @author : 周兴
  2101. * @date : 2022/7/4 20:16
  2102. */
  2103. function delChoosedGoodsItemCommon(e, _this, flag) {
  2104. let focusIndex = e.target.dataset.index;
  2105. let choosedGoodsList = _this.data.choosedGoodsList;
  2106. // 根据行号进行删除
  2107. choosedGoodsList = choosedGoodsList.filter((it, index) => index != focusIndex);
  2108. _this.setData({
  2109. choosedGoodsList: choosedGoodsList,
  2110. choosedGoodsListLength: choosedGoodsList.length
  2111. })
  2112. if (flag) {
  2113. // 统计已选数量
  2114. handleChoosedNum(_this);
  2115. }
  2116. // 计算合计金额
  2117. getSumAmount(_this);
  2118. }
  2119. /**
  2120. * @desc : 设置已选数据
  2121. * @author : 周兴
  2122. * @date : 2022/11/10 20:16
  2123. */
  2124. function handleChoosedNum(_this) {
  2125. let choosedGoodsList = _this.data.choosedGoodsList;
  2126. choosedGoodsList = choosedGoodsList ? choosedGoodsList : []
  2127. wx.setStorageSync('choosedGoodsList', choosedGoodsList)
  2128. let cartNum = choosedGoodsList.length //默认数据
  2129. if (cartNum != 0) {
  2130. //设置角标
  2131. wx.setTabBarBadge({
  2132. index: 2, //第几个tab
  2133. text: cartNum.toString()
  2134. })
  2135. } else {
  2136. //移除角标
  2137. wx.removeTabBarBadge({
  2138. index: 2,
  2139. })
  2140. }
  2141. }
  2142. /**
  2143. * @desc : 打开选择明细
  2144. * @author : 周兴
  2145. * @date : 2022/7/4 20:16
  2146. */
  2147. function openChoosedItemInfoCommon(e, _this) {
  2148. let currentChoosedItem = e.currentTarget.dataset.item;
  2149. if (_this.data.active && (_this.data.active == 1 || _this.data.active == '1')) {
  2150. _this.setData({
  2151. activeOneIndex: e.currentTarget.dataset.index //已选触发位置索引
  2152. })
  2153. }
  2154. // 根据类型显示对应的数据
  2155. if (currentChoosedItem.promotionType == Constants.PROMOTION_TYPE.COMBINED) {
  2156. _this.setData({
  2157. show4: true,
  2158. show1: false,
  2159. show6: false,
  2160. show7: false,
  2161. })
  2162. } else {
  2163. _this.setData({
  2164. show1: true,
  2165. show4: false,
  2166. show6: false,
  2167. show7: false,
  2168. })
  2169. }
  2170. if (currentChoosedItem.flgNonStandardType == 1 || currentChoosedItem.flgNonStandardType == 2) {
  2171. _this.setData({
  2172. show6: false,
  2173. show7: true,
  2174. })
  2175. }
  2176. if (currentChoosedItem.specsData && currentChoosedItem.specsData.length == 0 && currentChoosedItem.skuData && currentChoosedItem.skuData.length > 1) {
  2177. _this.setData({
  2178. show6: true
  2179. })
  2180. }
  2181. _this.setData({
  2182. showAdd: true,
  2183. currentChoosedItem: currentChoosedItem
  2184. })
  2185. }
  2186. //关闭poup商品
  2187. function closeAddItemInfoCommon(_this) {
  2188. _this.setData({
  2189. showAdd: false,
  2190. currentChoosedItem: {},
  2191. })
  2192. }
  2193. /**
  2194. * @desc : 修改销售价格
  2195. * @author : 周兴
  2196. * @date : 2022/7/6 14:45
  2197. */
  2198. function changeSalesPriceCommon(priceSale, _this, flag) {
  2199. let currentChoosedItem = _this.data.currentChoosedItem
  2200. currentChoosedItem.priceSale = priceSale // 销售价格赋值
  2201. let itemAmountTemp = null
  2202. if (flag && currentChoosedItem.combinedList && currentChoosedItem.combinedList.length > 0) {
  2203. currentChoosedItem.combinedList.forEach(it => {
  2204. if (!it.cpFlgGift) {
  2205. itemAmountTemp += it.itemAmount * it.orderItemQuantity
  2206. }
  2207. })
  2208. }
  2209. currentChoosedItem.priceSale = itemAmountTemp ? itemAmountTemp : priceSale
  2210. if (currentChoosedItem.nonStandardArea) {
  2211. currentChoosedItem.itemAmount = Number(currentChoosedItem.priceSale * currentChoosedItem.itemQuantity * currentChoosedItem.nonStandardArea).toFixed(2)
  2212. } else {
  2213. currentChoosedItem.itemAmount = Number(currentChoosedItem.priceSale * currentChoosedItem.itemQuantity).toFixed(2)
  2214. }
  2215. _this.setData({
  2216. currentChoosedItem: currentChoosedItem
  2217. })
  2218. // 计算折扣
  2219. getDiscount(_this);
  2220. }
  2221. /**
  2222. * @desc : 修改销售金额
  2223. * @author : 周兴
  2224. * @date : 2022/7/4 14:45
  2225. */
  2226. function changeItemAmountFieldCommon(e, _this) {
  2227. let currentChoosedItem = _this.data.currentChoosedItem
  2228. let key = e.currentTarget.dataset.key
  2229. // currentChoosedItem.itemAmount = e.detail.value // 销售金额赋值
  2230. if (currentChoosedItem.priceStandard < 0 || currentChoosedItem.pricePromotion < 0) {
  2231. currentChoosedItem.itemAmount = Number(0 - e.detail.value)
  2232. } else {
  2233. currentChoosedItem.itemAmount = e.detail.value // 销售金额赋值
  2234. }
  2235. if (currentChoosedItem.flgNonStandardType == 1 || currentChoosedItem.flgNonStandardType == 2) {
  2236. let nonStandardArea = Number(currentChoosedItem.nonStandardArea)
  2237. //非标
  2238. if (currentChoosedItem.itemQuantity && (currentChoosedItem.itemQuantity > 0) && nonStandardArea && (nonStandardArea > 0)) {
  2239. let tempNumber = Number(currentChoosedItem.itemAmount / currentChoosedItem.itemQuantity).toFixed(2)
  2240. currentChoosedItem.priceSale = Number(tempNumber / currentChoosedItem.nonStandardArea).toFixed(2)
  2241. }
  2242. } else {
  2243. if (currentChoosedItem.itemQuantity && currentChoosedItem.itemQuantity > 0) {
  2244. currentChoosedItem.priceSale = Number(currentChoosedItem.itemAmount / currentChoosedItem.itemQuantity).toFixed(2)
  2245. }
  2246. }
  2247. _this.setData({
  2248. currentChoosedItem: currentChoosedItem
  2249. })
  2250. // 计算折扣
  2251. getDiscount(_this);
  2252. }
  2253. /**
  2254. * @desc : 编辑商品算折扣
  2255. * @author : 于继渤
  2256. * @date : 2022/5/31 18:16
  2257. */
  2258. function getDiscount(_this) {
  2259. let currentChoosedItem = _this.data.currentChoosedItem
  2260. //标价计算折扣
  2261. if (currentChoosedItem.priceStandard && currentChoosedItem.priceStandard != 0) {
  2262. // 售价/标价
  2263. if (currentChoosedItem.priceSale < 0) {
  2264. //负数
  2265. currentChoosedItem.discountStandard = Number((currentChoosedItem.priceSale / currentChoosedItem.priceStandard)).toFixed(2)
  2266. } else {
  2267. currentChoosedItem.discountStandard = Number((currentChoosedItem.priceSale / currentChoosedItem.priceStandard) * 100).toFixed(2)
  2268. }
  2269. } else {
  2270. currentChoosedItem.discountStandard = 0
  2271. }
  2272. //促销价计算折扣
  2273. if (currentChoosedItem.discountPromotion && currentChoosedItem.pricePromotion != 0) {
  2274. // 售价/促销价
  2275. currentChoosedItem.discountPromotion = Number((currentChoosedItem.priceSale / currentChoosedItem.pricePromotion) * 100).toFixed(2)
  2276. } else {
  2277. currentChoosedItem.discountPromotion = 100
  2278. }
  2279. _this.setData({
  2280. currentChoosedItem: currentChoosedItem
  2281. })
  2282. }
  2283. /**
  2284. * @desc : 单品促销单选
  2285. * @author : 于继渤
  2286. * @date : 2022/5/31 18:16
  2287. */
  2288. function clickDPCommon(e, _this) {
  2289. let currentChoosedItem = _this.data.currentChoosedItem
  2290. let itemt = e.currentTarget.dataset.itemt;
  2291. let PricePromotionData = _this.data.PricePromotionData
  2292. let infotype = itemt.infotype
  2293. currentChoosedItem.pricePromotion = itemt.priceStandard
  2294. PricePromotionData.forEach(it => {
  2295. if (it.typeId === itemt.typeId) {
  2296. it.infotype = 'default'
  2297. }
  2298. })
  2299. if (infotype == 'default') {
  2300. infotype = 'info'
  2301. } else {
  2302. infotype = 'default'
  2303. }
  2304. PricePromotionData.forEach(it => {
  2305. if (it.skuId === itemt.skuId && it.typeId === itemt.typeId) {
  2306. it.infotype = infotype
  2307. }
  2308. })
  2309. _this.setData({
  2310. PricePromotionData: PricePromotionData,
  2311. })
  2312. let PricePromotionList = []
  2313. PricePromotionData.forEach(it => {
  2314. if (it.infotype === 'info') {
  2315. PricePromotionList.push(it)
  2316. }
  2317. })
  2318. currentChoosedItem.PricePromotionList = PricePromotionList
  2319. _this.setData({
  2320. currentChoosedItem: currentChoosedItem
  2321. })
  2322. }
  2323. //定制品单选
  2324. function clickDZPCommon(e, _this) {
  2325. let itemt = e.target.dataset.itemt;
  2326. let pindex = e.target.dataset.pindex;
  2327. let indext = e.target.dataset.indext;
  2328. let formDZP = _this.data.formDZP
  2329. let infotype = formDZP[pindex].tags[indext].infotype
  2330. infotype = 'default'
  2331. formDZP[pindex].tags.forEach(res => {
  2332. res.infotype = 'default'
  2333. })
  2334. if (infotype == 'default') {
  2335. infotype = 'info'
  2336. } else {
  2337. infotype = 'default'
  2338. }
  2339. formDZP[pindex].tags[indext].infotype = infotype
  2340. _this.setData({
  2341. formDZP
  2342. })
  2343. }
  2344. //主柜规格单选
  2345. function clickZGGGCommon(e, _this) {
  2346. let itemt = e.target.dataset.itemt;
  2347. let pindex = e.target.dataset.pindex;
  2348. let indext = e.target.dataset.indext;
  2349. let formZGGG = _this.data.formZGGG
  2350. let infotype = formZGGG[pindex].tags[indext].infotype
  2351. infotype = 'default'
  2352. formZGGG[pindex].tags.forEach(res => {
  2353. res.infotype = 'default'
  2354. })
  2355. if (infotype == 'default') {
  2356. infotype = 'info'
  2357. } else {
  2358. infotype = 'default'
  2359. }
  2360. formZGGG[pindex].tags[indext].infotype = infotype
  2361. _this.setData({
  2362. formZGGG
  2363. })
  2364. }
  2365. /**
  2366. *@desc:设置默认的标价
  2367. *@date:2022/9/149:56
  2368. *@author:周兴
  2369. */
  2370. function setFlgGift(_this) {
  2371. let currentChoosedItem = _this.data.currentChoosedItem
  2372. if (currentChoosedItem.cpFlgGift) {
  2373. currentChoosedItem.flgGift = true
  2374. currentChoosedItem.priceSale_Temp = currentChoosedItem.priceSale
  2375. currentChoosedItem.itemAmount_Temp = currentChoosedItem.itemAmount
  2376. currentChoosedItem.discountStandard_Temp = currentChoosedItem.discountStandard
  2377. currentChoosedItem.discountPromotion_Temp = currentChoosedItem.discountPromotion
  2378. currentChoosedItem.priceSale = 0
  2379. currentChoosedItem.discountStandard = 0
  2380. currentChoosedItem.discountPromotion = 0
  2381. currentChoosedItem.itemAmount = 0
  2382. if (currentChoosedItem.skuType == 2) {
  2383. if (currentChoosedItem.bomItems && currentChoosedItem.bomItems.length > 0) {
  2384. currentChoosedItem.bomItems.forEach(res => {
  2385. res.priceSale_Temp = res.priceSale
  2386. res.discountStandard_Temp = res.discountStandard
  2387. res.discountPromotion_Temp = res.discountPromotion
  2388. res.itemAmount_Temp = res.itemAmount
  2389. res.priceSale = 0
  2390. res.discountStandard = 0
  2391. res.discountPromotion = 0
  2392. res.itemAmount = 0
  2393. })
  2394. }
  2395. }
  2396. _this.setData({
  2397. currentChoosedItem: currentChoosedItem,
  2398. })
  2399. }
  2400. }
  2401. /**
  2402. * @desc : 计算折扣反算销售价格
  2403. * @author : 于继渤
  2404. * @date : 2022/7/4 14:45
  2405. */
  2406. function changeDiscountFieldCommon(e, _this, returnFlag) {
  2407. let key = e.currentTarget.dataset.key
  2408. let currentChoosedItem = _this.data.currentChoosedItem
  2409. let priceSale = 0
  2410. if (key == 'discountStandard') {
  2411. let discountStandard = e.detail.value ? Number(e.detail.value) : 0
  2412. if (!currentChoosedItem.priceStandard || currentChoosedItem.priceStandard == 0) {
  2413. priceStandard = 0;
  2414. } else {
  2415. // 售价 = 标价折扣* 标价
  2416. priceSale = Number((discountStandard / 100) * currentChoosedItem.priceStandard).toFixed(2)
  2417. }
  2418. currentChoosedItem.discountStandard = Number(e.detail.value)
  2419. }
  2420. if (key == 'discountPromotion') {
  2421. let discountPromotion = e.detail.value ? Number(e.detail.value) : 0
  2422. if (!currentChoosedItem.pricePromotion || currentChoosedItem.pricePromotion == 0) {
  2423. pricePromotion = 0;
  2424. } else {
  2425. // 售价= 促销折扣 * 促销价
  2426. priceSale = Number((discountPromotion / 100) * currentChoosedItem.pricePromotion).toFixed(2)
  2427. }
  2428. currentChoosedItem.discountPromotion = Number(e.detail.value)
  2429. }
  2430. currentChoosedItem.priceSale = priceSale
  2431. //退还补
  2432. if (returnFlag) {
  2433. currentChoosedItem.tItemAmount = Number(priceSale) * Number(currentChoosedItem.tItemQuantity)
  2434. } else {
  2435. currentChoosedItem.itemAmount = Number(priceSale) * Number(currentChoosedItem.itemQuantity)
  2436. }
  2437. _this.setData({
  2438. currentChoosedItem: currentChoosedItem
  2439. })
  2440. }
  2441. //chooseGoodsCommon
  2442. module.exports = {
  2443. openAddItemInfoCommon: openAddItemInfoCommon,
  2444. chooseSkuItem: chooseSkuItem,
  2445. getReplaceFlag: getReplaceFlag,
  2446. getSkuBySpuId: getSkuBySpuId,
  2447. checkSpecsIsEnable: checkSpecsIsEnable,
  2448. getCombinedByPriceId: getCombinedByPriceId,
  2449. getSumAmount: getSumAmount,
  2450. getCombinedPriceByChange: getCombinedPriceByChange,
  2451. chooseSkuInfoCommon: chooseSkuInfoCommon,
  2452. changeDiscountFieldCommon: changeDiscountFieldCommon,
  2453. handleData: handleData,
  2454. handleChoosedNum: handleChoosedNum,
  2455. changeCombinedItemCommon: changeCombinedItemCommon,
  2456. changeSkuSpecsCommon: changeSkuSpecsCommon,
  2457. setParam: setParam,
  2458. changeAllReadyCheckBoxCommon: changeAllReadyCheckBoxCommon,
  2459. delChoosedGoodsItemCommon: delChoosedGoodsItemCommon,
  2460. openChoosedItemInfoCommon: openChoosedItemInfoCommon,
  2461. changeSalesPriceCommon: changeSalesPriceCommon,
  2462. changeItemAmountFieldCommon: changeItemAmountFieldCommon,
  2463. getDiscount: getDiscount,
  2464. clickDPCommon: clickDPCommon,
  2465. clickDZPCommon: clickDZPCommon,
  2466. clickZGGGCommon: clickZGGGCommon,
  2467. closeAddItemInfoCommon: closeAddItemInfoCommon,
  2468. clearDefaultCommon: clearDefaultCommon,
  2469. //非标
  2470. nonStandardTap: nonStandardTap,
  2471. nonGlassSpuItemsTap: nonGlassSpuItemsTap,
  2472. bindInputIsScopeOne: bindInputIsScopeOne,
  2473. bindBlurIsScopeOne: bindBlurIsScopeOne,
  2474. bindBlurNonStantardArea: bindBlurNonStantardArea,
  2475. bindInputNonStantardArea: bindInputNonStantardArea,
  2476. calculateFormulaItemAmount: calculateFormulaItemAmount,
  2477. bindBlurIsScopeOne_t: bindBlurIsScopeOne_t
  2478. }