chooseGoodsCommon.js 98 KB

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