index.vue 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377
  1. <template>
  2. <view class="goods-sku-popup" catchtouchmove="true" :class="valueCom && complete ? 'show' : 'none'" @touchmove.stop.prevent="moveHandle"
  3. @click.stop="stop">
  4. <!-- 页面内容开始 -->
  5. <view class="mask" @click="close('mask')"></view>
  6. <view class="layer attr-content" :class="{'safe-area-inset-bottom':safeAreaInsetBottom }"
  7. :style="{ borderRadius: borderRadius + 'rpx ' + borderRadius + 'rpx 0 0' }">
  8. <view class="specification-wrapper">
  9. <scroll-view class="specification-wrapper-content" scroll-y="true">
  10. <view class="specification-header">
  11. <view class="specification-left">
  12. <image class="product-img" :src="selectShop.image ? selectShop.image : goodsInfo[goodsThumbName]"
  13. :style="{ backgroundColor: goodsThumbBackgroundColor }" mode="aspectFill" @click="previewImage"></image>
  14. </view>
  15. <view class="specification-right">
  16. <view class="price-content" :style="{ color: themeColorFn('priceColor') }">
  17. <text class="sign">¥</text>
  18. <text class="price" :class="priceCom.length > 16 ? 'price2' : ''">{{ priceCom }}</text>
  19. </view>
  20. <view class="inventory" v-if="!hideStock">{{ stockText }}:{{ stockCom }}</view>
  21. <view class="inventory" v-else></view>
  22. <view class="choose" v-show="isManyCom">
  23. <text v-if="!selectArr.every(val => val == '')">已选:{{ selectArr.join(' ') }}</text>
  24. </view>
  25. </view>
  26. </view>
  27. <view class="specification-content">
  28. <view v-show="isManyCom" class="specification-item" v-for="(item, index1) in goodsInfo[specListName]" :key="index1">
  29. <view class="item-title">{{ item.name }}</view>
  30. <view class="item-wrapper">
  31. <view class="item-content" v-for="(item_value, index2) in item.list" :key="index2"
  32. :class="[item_value.ishow ? '' : 'noactived', subIndex[index1] == index2 ? 'actived' : '']" :style="[
  33. item_value.ishow ? '' : themeColorFn('disableStyle'),
  34. item_value.ishow ? themeColorFn('btnStyle') : '',
  35. subIndex[index1] == index2 ? themeColorFn('activedStyle') : ''
  36. ]" @click="skuClick(item_value, index1, index2)">
  37. {{ item_value.name }}
  38. </view>
  39. </view>
  40. </view>
  41. <view class="number-box-view">
  42. <view style="flex: 1;">数量</view>
  43. <view style="flex: 4;text-align: right;">
  44. <number-box v-model="selectNum" :min="minBuyNum || 1" :max="maxBuyNumCom" :step="stepBuyNum || 1"
  45. :step-strictly="stepStrictly" :positive-integer="true" @change="numChange" />
  46. </view>
  47. </view>
  48. </view>
  49. </scroll-view>
  50. <view class="close" @click="close('close')" v-if="showClose != false">
  51. <image class="close-item" :src="closeImage"></image>
  52. </view>
  53. </view>
  54. <view class="btn-wrapper" v-if="outFoStock || mode == 4">
  55. <view class="sure" style="color:#ffffff;background-color:#cccccc">{{ noStockText }}</view>
  56. </view>
  57. <view class="btn-wrapper" v-else-if="mode == 1">
  58. <view class="sure add-cart" style="border-radius:38rpx 0rpx 0rpx 38rpx;" :style="{
  59. color: themeColorFn('addCartColor'),
  60. backgroundColor: themeColorFn('addCartBackgroundColor')
  61. }" @click="addCart">
  62. {{ addCartText }}
  63. </view>
  64. <view class="sure" style="border-radius:0rpx 38rpx 38rpx 0rpx;" :style="{
  65. color: themeColorFn('buyNowColor'),
  66. backgroundColor: themeColorFn('buyNowBackgroundColor')
  67. }" @click="buyNow">
  68. {{ buyNowText }}
  69. </view>
  70. </view>
  71. <view class="btn-wrapper" v-else-if="mode == 2">
  72. <view class="sure add-cart" :style="{
  73. color: themeColorFn('addCartColor'),
  74. backgroundColor: themeColorFn('addCartBackgroundColor')
  75. }" @click="addCart">
  76. {{ addCartText }}
  77. </view>
  78. </view>
  79. <view class="btn-wrapper" v-else-if="mode == 3">
  80. <view class="sure" :style="{
  81. color: themeColorFn('buyNowColor'),
  82. backgroundColor: themeColorFn('buyNowBackgroundColor')
  83. }" @click="buyNow">
  84. {{ buyNowText }}
  85. </view>
  86. </view>
  87. </view>
  88. <!-- 页面内容结束 -->
  89. </view>
  90. </template>
  91. <script>
  92. import NumberBox from './number-box'
  93. var vk; // vk依赖
  94. var goodsCache = {}; // 本地商品缓存
  95. export default {
  96. name: 'GoodsSkuPopup',
  97. components: { NumberBox },
  98. emits: ['update:modelValue', 'input', 'update-goods', 'open', 'close', 'add-cart', 'buy-now', 'cart', 'buy', 'num-change'],
  99. props: {
  100. // true 组件显示 false 组件隐藏
  101. value: {
  102. Type: Boolean,
  103. default: false
  104. },
  105. modelValue: {
  106. Type: Boolean,
  107. default: false
  108. },
  109. // vk云函数路由模式参数开始-----------------------------------------------------------
  110. // 商品id
  111. goodsId: {
  112. Type: String,
  113. default: ''
  114. },
  115. // vk路由模式框架下的云函数地址
  116. action: {
  117. Type: String,
  118. default: ''
  119. },
  120. // vk云函数路由模式参数结束-----------------------------------------------------------
  121. // 该商品已抢完时的按钮文字
  122. noStockText: {
  123. Type: String,
  124. default: '该商品已抢完'
  125. },
  126. // 库存文字
  127. stockText: {
  128. Type: String,
  129. default: '库存'
  130. },
  131. // 商品表id的字段名
  132. goodsIdName: {
  133. Type: String,
  134. default: '_id'
  135. },
  136. // sku表id的字段名
  137. skuIdName: {
  138. Type: String,
  139. default: '_id'
  140. },
  141. // sku_list的字段名
  142. skuListName: {
  143. Type: String,
  144. default: 'sku_list'
  145. },
  146. // spec_list的字段名
  147. specListName: {
  148. Type: String,
  149. default: 'spec_list'
  150. },
  151. // 库存的字段名 默认 stock
  152. stockName: {
  153. Type: String,
  154. default: 'stock'
  155. },
  156. // sku组合路径的字段名
  157. skuArrName: {
  158. Type: String,
  159. default: 'sku_name_arr'
  160. },
  161. // 默认单规格时的规格组名称
  162. defaultSingleSkuName: {
  163. Type: String,
  164. default: '默认'
  165. },
  166. // 模式 1:都显示 2:只显示购物车 3:只显示立即购买 4:显示缺货按钮 默认 1
  167. mode: {
  168. Type: Number,
  169. default: 1
  170. },
  171. // 点击遮罩是否关闭组件 true 关闭 false 不关闭 默认true
  172. maskCloseAble: {
  173. Type: Boolean,
  174. default: true
  175. },
  176. // 顶部圆角值
  177. borderRadius: {
  178. Type: [String, Number],
  179. default: 0
  180. },
  181. // 商品缩略图字段名(未选择sku时)
  182. goodsThumbName: {
  183. Type: [String],
  184. default: 'goods_thumb'
  185. },
  186. // 商品缩略图背景颜色,如#999999
  187. goodsThumbBackgroundColor: {
  188. Type: String,
  189. default: '#999999'
  190. },
  191. // 最小购买数量 默认 1
  192. minBuyNum: {
  193. Type: [Number, String],
  194. default: 1
  195. },
  196. // 最大购买数量 默认 100000
  197. maxBuyNum: {
  198. Type: [Number, String],
  199. default: 100000
  200. },
  201. // 步进器步长 默认 1
  202. stepBuyNum: {
  203. Type: [Number, String],
  204. default: 1
  205. },
  206. // 是否只能输入 step 的倍数
  207. stepStrictly: {
  208. Type: Boolean,
  209. default: false
  210. },
  211. // 自定义获取商品信息的函数,支付宝小程序不支持该属性,请使用localdata属性
  212. customAction: {
  213. Type: [Function],
  214. default: null
  215. },
  216. // 本地数据源
  217. localdata: {
  218. type: Object
  219. },
  220. // 价格的字体颜色
  221. priceColor: {
  222. Type: String
  223. },
  224. // 立即购买按钮的文字
  225. buyNowText: {
  226. Type: String,
  227. default: '立即购买'
  228. },
  229. // 立即购买按钮的字体颜色
  230. buyNowColor: {
  231. Type: String
  232. },
  233. // 立即购买按钮的背景颜色
  234. buyNowBackgroundColor: {
  235. Type: String
  236. },
  237. // 加入购物车按钮的文字
  238. addCartText: {
  239. Type: String,
  240. default: '加入购物车'
  241. },
  242. // 加入购物车按钮的字体颜色
  243. addCartColor: {
  244. Type: String
  245. },
  246. // 加入购物车按钮的背景颜色
  247. addCartBackgroundColor: {
  248. Type: String
  249. },
  250. // 不可点击时,按钮的样式
  251. disableStyle: {
  252. Type: Object,
  253. default: null
  254. },
  255. // 按钮点击时的样式
  256. activedStyle: {
  257. Type: Object,
  258. default: null
  259. },
  260. // 按钮常态的样式
  261. btnStyle: {
  262. Type: Object,
  263. default: null
  264. },
  265. // 是否显示右上角关闭按钮
  266. showClose: {
  267. Type: Boolean,
  268. default: true
  269. },
  270. // 关闭按钮的图片地址 https://img.alicdn.com/imgextra/i1/121022687/O1CN01ImN0O11VigqwzpLiK_!!121022687.png
  271. closeImage: {
  272. Type: String,
  273. default: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACoAAAAqCAYAAADFw8lbAAAEyUlEQVR42sSZeWwNURTGp4OqtBo7sSXELragdkpQsRRJ1Zr4hyJiJ9YgxNIg1qANiT+E1i5IY0kVVWtQEbuEKLFGUSH27/ANN5PXmTvzupzkl/tm8t6b7517lnvvC0lKSjJ8WmnQAUSDFqABqALKgl8gD7wE90E2SAeXwFf1SxISErQeVtKHwCgwFsSDSIf3hYFKoCkYDBaDdyAViHdueHmoF6FtwDLQ23b/E7gM7oIcejIERIDaoBFoC8qA8mA8SQNz6W1XC9GY+nCQCCYAk/c+gF0gBZwH312+IxR0BCPBUIaH2A+wHsxHCHxx+gLT5QGN6a2JfG8uvVCDws9oiDQYlxkMGfHyQvARlADTwcXk5OT6foV2kS8ATXidymlcyen1a/Jjl9IJh3hPkjELYqO8Cu0KjjNZvtETw5jFBWXPmGSTGQKSeOn5iQ0kVLL0CINfPNcPbDMKyRCbGzEMBJ+ZD8cChYFdqGTqfsWT8otPGoVsEHsMwxDFs3shNsxJ6BrQ0Po8OGUUkVHsNCVml+cntB1jUWwn2GEUsTEMrASbDK+2CCQ0kYX6nfLLisMmKqUr0S60M+jG10vAm+JSCa8+x7CKlzHwaktV6DiObzUzPJIxFO1BQ12wGtTReO9GetVgY/kjNJzZbcWmTjHfxw51AsRqvL8eOAtmsJuFu3g1l+1ZLB5eDTVZ3K0P7tL0TkWOpSg61kVkBtuuNRthGs+wtJST5aQI7cEbkkRXNYVKgX6kIdYuUhYzMQwxN8tiExCLFqHNeSF9/aem0BzGp5PYQCJ7c/Gsk1RfuSD6U1dNpcDf9ZigTmKbMRZ9iVTsHscGJluW2FMf1SSQWGnBmaB6kCJVTVVNJZE++Cx9drEllS1KMCINpURFmEbBWA63Fz9s95cGIdJgp/zXmT4pZcOvSUzuZttTbblmnc3PIjjmidDXvKgdhMh0JdbzuCjWrbNOVovjS5P7bkPJ/mBESkz2BO0166ybNeJ431S2q+01NntuIq3E0amzjiZtk9tssWyTDzO4525bACK9NAUn68TtkNhpEXpOSagRml+S6iLSSeweHv242Qhl13rRyvoDvDlKyTQny/ZQJ+1iH7vVbEx7OR5UiKVIO7VicgvHCtwrudloMIV7/0uadVYW57O4Wvvi8v4pymlKkrpwvsDeLLZAY2pkwbAB3PSQfC+4cH7l4k1ZH8zkZRq8ecO+Z5rN40JJqnXFuGfaxPCTLjcn0OZOpnArXw8HY4paIbw5CcMgXq6HN2/mt6+XGLrN15tBryIUGavMpCTrfKcDCKkAceA9S8nhAOehhSUyhXpkBxxnP4YM1InugP7cBkjBPcqVUWFYCEROxXiQz5JlXV+IfKh7mpfJac+lZ6V87QXVClBkTc7YWsWTPSDyitfzUTlJlj8TbvE6jluDOdwZ+jX57GLO3ADeuyZrDYi86vV81FD2UVGsmT+5Zl0BnkhoseOEaogL46pqO4v/IqUEyalIR4h85BgjHv6+aUWRMbb7EstX6O0cpT1Gco0ry8fWygLDMjmDnQeBt3Qe7uVfkeugDwVLcsVzGsuwLXbV+I63XNAkG5r/hvgRqgqWs6pJPKrsbvz/Q6yyun0w/h6lP+BnzrCpfPMT2L8FGAA7k1GZ/vnaqAAAAABJRU5ErkJggg=='
  274. },
  275. // 是否隐藏库存显示
  276. hideStock: {
  277. Type: Boolean,
  278. default: false
  279. },
  280. // 颜色主题
  281. theme: {
  282. Type: String,
  283. default: 'default'
  284. },
  285. // 请求中的提示
  286. actionTips: {
  287. Type: String,
  288. default: '请求中...'
  289. },
  290. // 默认选中的SKU
  291. defaultSelect: {
  292. Type: Object
  293. },
  294. // 是否使用缓存
  295. useCache: {
  296. Type: Boolean,
  297. default: true
  298. },
  299. /**
  300. * 默认商品,设置该值可快速展示商品
  301. * 逻辑: 先展示 defaultGoods 信息,再取数据库,再更新页面(通常为更新库存)
  302. */
  303. defaultGoods: {
  304. Type: Object
  305. },
  306. /**
  307. * 金额是否需要除以100
  308. * 1:金额会除以100
  309. * 0:金额不会除以100
  310. */
  311. amountType: {
  312. Type: Number,
  313. default: 1
  314. },
  315. // 每次选择完SKU后,购买数量归1,如果有最小购买数量,则设置为最小购买数量
  316. selectedInit: {
  317. Type: Boolean,
  318. default: false
  319. },
  320. // 是否开启底部安全区适配,默认true
  321. safeAreaInsetBottom: {
  322. Type: Boolean,
  323. default: true
  324. },
  325. },
  326. data() {
  327. return {
  328. complete: false, // 组件是否加载完成
  329. goodsInfo: {}, // 商品信息
  330. isShow: false, // true 显示 false 隐藏
  331. initKey: true, // 是否需要初始化 true 是 false 否
  332. // #ifndef MP-BAIDU
  333. shopItemInfo: {}, // 存放要和选中的值进行匹配的数据(因百度小程序setData不支持中文字段,故不编译shopItemInfo变量)
  334. // #endif
  335. selectArr: [], // 存放被选中的值
  336. subIndex: [], // 是否选中 因为不确定是多规格还是单规格,所以这里定义数组来判断
  337. selectShop: {}, // 存放最后选中的商品
  338. selectNum: this.minBuyNum || 1, // 选中数量
  339. outFoStock: false, // 是否全部sku都缺货
  340. openTime: 0,
  341. themeColor: {
  342. // 默认主题
  343. default: {
  344. priceColor: 'rgb(254, 86, 10)',
  345. buyNowColor: '#ffffff',
  346. buyNowBackgroundColor: 'rgb(254, 86, 10)',
  347. addCartColor: '#ffffff',
  348. addCartBackgroundColor: 'rgb(255, 148, 2)',
  349. btnStyle: {
  350. color: '#333333',
  351. borderColor: '#f4f4f4',
  352. backgroundColor: '#ffffff'
  353. },
  354. activedStyle: {
  355. color: 'rgb(254, 86, 10)',
  356. borderColor: 'rgb(254, 86, 10)',
  357. backgroundColor: 'rgba(254,86,10,0.1)'
  358. },
  359. disableStyle: {
  360. color: '#c3c3c3',
  361. borderColor: '#f6f6f6',
  362. backgroundColor: '#f6f6f6'
  363. }
  364. },
  365. // 红黑主题
  366. 'red-black': {
  367. priceColor: 'rgb(255, 68, 68)',
  368. buyNowColor: '#ffffff',
  369. buyNowBackgroundColor: 'rgb(255, 68, 68)',
  370. addCartColor: '#ffffff',
  371. addCartBackgroundColor: 'rgb(85, 85, 85)',
  372. activedStyle: {
  373. color: 'rgb(255, 68, 68)',
  374. borderColor: 'rgb(255, 68, 68)',
  375. backgroundColor: 'rgba(255,68,68,0.1)'
  376. }
  377. },
  378. // 黑白主题
  379. 'black-white': {
  380. priceColor: 'rgb(47, 47, 52)',
  381. buyNowColor: '#ffffff',
  382. buyNowBackgroundColor: 'rgb(47, 47, 52)',
  383. addCartColor: 'rgb(47, 47, 52)',
  384. addCartBackgroundColor: 'rgb(235, 236, 242)',
  385. // btnStyle:{
  386. // color:"rgb(47, 47, 52)",
  387. // borderColor:"rgba(235,236,242,0.5)",
  388. // backgroundColor:"rgba(235,236,242,0.5)",
  389. // },
  390. activedStyle: {
  391. color: 'rgb(47, 47, 52)',
  392. borderColor: 'rgba(47,47,52,0.12)',
  393. backgroundColor: 'rgba(47,47,52,0.12)'
  394. }
  395. },
  396. // 咖啡色主题
  397. coffee: {
  398. priceColor: 'rgb(195, 167, 105)',
  399. buyNowColor: '#ffffff',
  400. buyNowBackgroundColor: 'rgb(195, 167, 105)',
  401. addCartColor: 'rgb(195, 167, 105)',
  402. addCartBackgroundColor: 'rgb(243, 238, 225)',
  403. activedStyle: {
  404. color: 'rgb(195, 167, 105)',
  405. borderColor: 'rgb(195, 167, 105)',
  406. backgroundColor: 'rgba(195, 167, 105,0.1)'
  407. }
  408. },
  409. // 浅绿色主题
  410. green: {
  411. priceColor: 'rgb(99, 190, 114)',
  412. buyNowColor: '#ffffff',
  413. buyNowBackgroundColor: 'rgb(99, 190, 114)',
  414. addCartColor: 'rgb(99, 190, 114)',
  415. addCartBackgroundColor: 'rgb(225, 244, 227)',
  416. activedStyle: {
  417. color: 'rgb(99, 190, 114)',
  418. borderColor: 'rgb(99, 190, 114)',
  419. backgroundColor: 'rgba(99, 190, 114,0.1)'
  420. }
  421. }
  422. }
  423. };
  424. },
  425. created() {
  426. let that = this;
  427. vk = that.vk;
  428. if (that.valueCom) {
  429. that.open();
  430. }
  431. },
  432. mounted() {},
  433. methods: {
  434. // 初始化
  435. init(notAutoClick) {
  436. let that = this;
  437. // 清空之前的数据
  438. that.selectArr = [];
  439. that.subIndex = [];
  440. that.selectShop = {};
  441. that.selectNum = that.minBuyNum || 1;
  442. that.outFoStock = false;
  443. that.shopItemInfo = {};
  444. let specListName = that.specListName;
  445. that.goodsInfo[specListName].map(item => {
  446. that.selectArr.push('');
  447. that.subIndex.push(-1);
  448. });
  449. that.checkItem(); // 计算sku里面规格形成路径
  450. that.checkInpath(-1); // 传-1是为了不跳过循环
  451. if (!notAutoClick) that.autoClickSku(); // 自动选择sku策略
  452. },
  453. // 使用vk路由模式框架获取商品信息
  454. findGoodsInfo(obj = {}) {
  455. let that = this;
  456. let { useCache } = obj;
  457. if (typeof vk == 'undefined') {
  458. that.toast('custom-action必须是function', 'none');
  459. return false;
  460. }
  461. let { actionTips } = that;
  462. let actionTitle = '';
  463. let actionAoading = false;
  464. if (actionTips !== 'custom') {
  465. actionTitle = useCache ? '' : '请求中...';
  466. } else {
  467. actionAoading = useCache ? false : true;
  468. }
  469. vk.callFunction({
  470. url: that.action,
  471. title: actionTitle,
  472. loading: actionAoading,
  473. data: {
  474. goods_id: that.goodsId
  475. },
  476. success(data) {
  477. that.updateGoodsInfo(data.goodsInfo);
  478. // 更新缓存
  479. goodsCache[that.goodsId] = data.goodsInfo;
  480. that.$emit('update-goods', data.goodsInfo);
  481. },
  482. fail() {
  483. that.updateValue(false);
  484. }
  485. });
  486. },
  487. updateValue(value) {
  488. let that = this;
  489. if (value) {
  490. that.$emit('open', true);
  491. that.$emit('input', true);
  492. that.$emit('update:modelValue', true);
  493. } else {
  494. that.$emit('input', false);
  495. that.$emit('close', 'close');
  496. that.$emit('update:modelValue', false);
  497. }
  498. },
  499. // 更新商品信息(库存、名称、图片)
  500. updateGoodsInfo(goodsInfo) {
  501. let that = this;
  502. // goodsInfo.sku_list.map((item, index) => {
  503. // item.sku_name_arr = ["20ml/瓶"];
  504. // });
  505. let { skuListName } = that;
  506. if (JSON.stringify(that.goodsInfo) === '{}' || that.goodsInfo[that.goodsIdName] !== goodsInfo[that.goodsIdName]) {
  507. that.goodsInfo = goodsInfo;
  508. that.initKey = true;
  509. } else {
  510. that.goodsInfo[skuListName] = goodsInfo[skuListName];
  511. }
  512. if (that.initKey) {
  513. that.initKey = false;
  514. // 是否默认选中第一个SKU
  515. // 条件是 单规格商品或者多规格单SKU商品
  516. const skuList = that.goodsInfo[that.skuListName]
  517. const autoClickSku = !that.isManyCom ? true : skuList.length === 1
  518. that.init(!autoClickSku)
  519. }
  520. // 更新选中sku的库存信息
  521. let select_sku_info = that.getListItem(that.goodsInfo[skuListName], that.skuIdName, that.selectShop[that.skuIdName]);
  522. Object.assign(that.selectShop, select_sku_info);
  523. that.defaultSelectSku();
  524. that.complete = true;
  525. },
  526. async open() {
  527. let that = this;
  528. that.openTime = new Date().getTime();
  529. let findGoodsInfoRun = true;
  530. let skuListName = that.skuListName;
  531. // 先获取缓存中的商品信息
  532. let useCache = false;
  533. let goodsInfo = goodsCache[that.goodsId];
  534. if (goodsInfo && that.useCache) {
  535. useCache = true;
  536. that.updateGoodsInfo(goodsInfo);
  537. } else {
  538. that.complete = false;
  539. }
  540. if (that.customAction && typeof that.customAction === 'function') {
  541. try {
  542. goodsInfo = await that
  543. .customAction({
  544. useCache,
  545. goodsId: that.goodsId,
  546. goodsInfo,
  547. close: function() {
  548. setTimeout(function() {
  549. that.close();
  550. }, 500);
  551. }
  552. })
  553. .catch(err => {
  554. setTimeout(function() {
  555. that.close();
  556. }, 500);
  557. });
  558. } catch (err) {
  559. let { message = '' } = err;
  560. if (message.indexOf('.catch is not a function') > -1) {
  561. that.toast('custom-action必须返回一个Promise', 'none');
  562. setTimeout(function() {
  563. that.close();
  564. }, 500);
  565. return false;
  566. }
  567. }
  568. // 更新缓存
  569. goodsCache[that.goodsId] = goodsInfo;
  570. if (goodsInfo && typeof goodsInfo == 'object' && JSON.stringify(goodsInfo) != '{}') {
  571. findGoodsInfoRun = false;
  572. that.updateGoodsInfo(goodsInfo);
  573. that.updateValue(true);
  574. } else {
  575. that.toast('未获取到商品信息', 'none');
  576. that.$emit('input', false);
  577. return false;
  578. }
  579. } else if (typeof that.localdata !== 'undefined' && that.localdata !== null) {
  580. goodsInfo = that.localdata;
  581. if (goodsInfo && typeof goodsInfo == 'object' && JSON.stringify(goodsInfo) != '{}') {
  582. findGoodsInfoRun = false;
  583. that.updateGoodsInfo(goodsInfo);
  584. that.updateValue(true);
  585. } else {
  586. that.toast('未获取到商品信息', 'none');
  587. that.$emit('input', false);
  588. return false;
  589. }
  590. } else {
  591. if (findGoodsInfoRun) that.findGoodsInfo({ useCache });
  592. }
  593. },
  594. // 监听 - 弹出层收起
  595. close(s) {
  596. let that = this;
  597. if (new Date().getTime() - that.openTime < 400) {
  598. return false;
  599. }
  600. if (s == 'mask') {
  601. if (that.maskCloseAble !== false) {
  602. that.$emit('input', false);
  603. that.$emit('close', 'mask');
  604. that.$emit('update:modelValue', false);
  605. }
  606. } else {
  607. that.$emit('input', false);
  608. that.$emit('close', 'close');
  609. that.$emit('update:modelValue', false);
  610. }
  611. },
  612. moveHandle() {
  613. //禁止父元素滑动
  614. },
  615. // sku按钮的点击事件
  616. skuClick(value, index1, index2) {
  617. let that = this;
  618. if (value.ishow) {
  619. if (that.selectArr[index1] != value.name) {
  620. that.$set(that.selectArr, index1, value.name);
  621. that.$set(that.subIndex, index1, index2);
  622. } else {
  623. that.$set(that.selectArr, index1, '');
  624. that.$set(that.subIndex, index1, -1);
  625. }
  626. that.checkInpath(index1);
  627. // 如果全部选完
  628. that.checkSelectShop();
  629. }
  630. },
  631. // 检测是否已经选完sku
  632. checkSelectShop() {
  633. let that = this;
  634. // 如果全部选完
  635. if (that.selectArr.every(item => item != '')) {
  636. that.selectShop = that.shopItemInfo[that.getArrayToSting(that.selectArr)];
  637. let stock = that.selectShop[that.stockName];
  638. if (typeof stock !== 'undefined' && that.selectNum > stock) {
  639. that.selectNum = stock;
  640. }
  641. if (that.selectNum > that.maxBuyNum) {
  642. that.selectNum = that.maxBuyNum;
  643. }
  644. if (that.selectNum < that.minBuyNum) {
  645. that.selectNum = that.minBuyNum;
  646. }
  647. if (that.selectedInit) {
  648. that.selectNum = that.minBuyNum || 1;
  649. }
  650. } else {
  651. that.selectShop = {};
  652. }
  653. },
  654. // 检查路径
  655. checkInpath(clickIndex) {
  656. let that = this;
  657. let specListName = that.specListName;
  658. //console.time('筛选可选路径需要的时间是');
  659. //循环所有属性判断哪些属性可选
  660. //当前选中的兄弟节点和已选中属性不需要循环
  661. let specList = that.goodsInfo[specListName];
  662. for (let i = 0, len = specList.length; i < len; i++) {
  663. if (i == clickIndex) {
  664. continue;
  665. }
  666. let len2 = specList[i].list.length;
  667. for (let j = 0; j < len2; j++) {
  668. if (that.subIndex[i] != -1 && j == that.subIndex[i]) {
  669. continue;
  670. }
  671. let choosed_copy = [...that.selectArr];
  672. that.$set(choosed_copy, i, specList[i].list[j].name);
  673. let choosed_copy2 = choosed_copy.filter(item => item !== '' && typeof item !== 'undefined');
  674. if (that.shopItemInfo.hasOwnProperty(that.getArrayToSting(choosed_copy2))) {
  675. specList[i].list[j].ishow = true;
  676. } else {
  677. specList[i].list[j].ishow = false;
  678. }
  679. }
  680. }
  681. that.$set(that.goodsInfo, specListName, specList);
  682. // console.timeEnd('筛选可选路径需要的时间是');
  683. },
  684. // 计算sku里面规格形成路径
  685. checkItem() {
  686. let that = this;
  687. // console.time('计算有多小种可选路径需要的时间是');
  688. let { stockName } = that;
  689. let skuListName = that.skuListName;
  690. // 去除库存小于等于0的商品sku
  691. let originalSkuList = that.goodsInfo[skuListName];
  692. let skuList = [];
  693. let stockNum = 0;
  694. originalSkuList.map((skuItem, index) => {
  695. if (skuItem[stockName] > 0) {
  696. skuList.push(skuItem);
  697. stockNum += skuItem[stockName];
  698. }
  699. });
  700. if (stockNum <= 0) {
  701. that.outFoStock = true;
  702. }
  703. // 计算有多小种可选路径
  704. let result = skuList.reduce(
  705. (arrs, items) => {
  706. return arrs.concat(
  707. items[that.skuArrName].reduce(
  708. (arr, item) => {
  709. return arr.concat(
  710. arr.map(item2 => {
  711. // 利用对象属性的唯一性实现二维数组去重
  712. //console.log(1,that.shopItemInfo,that.getArrayToSting([...item2, item]),item2,item,items);
  713. if (!that.shopItemInfo.hasOwnProperty(that.getArrayToSting([...item2, item]))) {
  714. that.shopItemInfo[that.getArrayToSting([...item2, item])] = items;
  715. }
  716. return [...item2, item];
  717. })
  718. );
  719. },
  720. [
  721. []
  722. ]
  723. )
  724. );
  725. },
  726. [
  727. []
  728. ]
  729. );
  730. // console.timeEnd('计算有多小种可选路径需要的时间是');
  731. },
  732. getArrayToSting(arr) {
  733. let str = '';
  734. arr.map((item, index) => {
  735. item = item.replace(/\./g, '。');
  736. if (index == 0) {
  737. str += item;
  738. } else {
  739. str += ',' + item;
  740. }
  741. });
  742. return str;
  743. },
  744. // 检测sku选项是否已全部选完,且有库存
  745. checkSelectComplete(obj = {}) {
  746. let that = this;
  747. let clickTime = new Date().getTime();
  748. if (that.clickTime && clickTime - that.clickTime < 400) {
  749. return false;
  750. }
  751. that.clickTime = clickTime;
  752. let { selectShop, selectNum, stockText, stockName } = that;
  753. if (!selectShop || !selectShop[that.skuIdName]) {
  754. that.toast('请先选择对应规格', 'none');
  755. return false;
  756. }
  757. if (selectNum <= 0) {
  758. that.toast('购买数量必须>0', 'none');
  759. return false;
  760. }
  761. // 判断库存
  762. if (selectNum > selectShop[stockName]) {
  763. that.toast(stockText + '不足', 'none');
  764. return false;
  765. }
  766. if (typeof obj.success == 'function') obj.success(selectShop);
  767. },
  768. // 加入购物车
  769. addCart() {
  770. let that = this;
  771. that.checkSelectComplete({
  772. success: function(selectShop) {
  773. selectShop.buy_num = that.selectNum;
  774. that.$emit('add-cart', selectShop);
  775. that.$emit('cart', selectShop);
  776. // setTimeout(function() {
  777. // that.init();
  778. // }, 300);
  779. }
  780. });
  781. },
  782. // 立即购买
  783. buyNow() {
  784. let that = this;
  785. that.checkSelectComplete({
  786. success: function(selectShop) {
  787. selectShop.buy_num = that.selectNum;
  788. that.$emit('buy-now', selectShop);
  789. that.$emit('buy', selectShop);
  790. }
  791. });
  792. },
  793. // 弹窗
  794. toast(title, icon) {
  795. uni.showToast({
  796. title: title,
  797. icon: icon
  798. });
  799. },
  800. // 获取对象数组中的某一个item,根据指定的键值
  801. getListItem(list, key, value) {
  802. let that = this;
  803. let item;
  804. for (let i in list) {
  805. if (typeof value == 'object') {
  806. if (JSON.stringify(list[i][key]) === JSON.stringify(value)) {
  807. item = list[i];
  808. break;
  809. }
  810. } else {
  811. if (list[i][key] === value) {
  812. item = list[i];
  813. break;
  814. }
  815. }
  816. }
  817. return item;
  818. },
  819. getListIndex(list, key, value) {
  820. let that = this;
  821. let index = -1;
  822. for (let i = 0; i < list.length; i++) {
  823. if (list[i][key] === value) {
  824. index = i;
  825. break;
  826. }
  827. }
  828. return index;
  829. },
  830. // 自动选择sku前提是只有一组sku,默认自动选择最前面的有库存的sku
  831. autoClickSku() {
  832. let that = this;
  833. let { stockName } = that;
  834. let skuList = that.goodsInfo[that.skuListName];
  835. let specListArr = that.goodsInfo[that.specListName];
  836. if (specListArr.length == 1) {
  837. let specList = specListArr[0].list;
  838. for (let i = 0; i < specList.length; i++) {
  839. let sku = that.getListItem(skuList, that.skuArrName, [specList[i].name]);
  840. if (sku && sku[stockName] > 0) {
  841. that.skuClick(specList[i], 0, i);
  842. break;
  843. }
  844. }
  845. }
  846. },
  847. // 主题颜色
  848. themeColorFn(name) {
  849. let that = this;
  850. let { theme, themeColor } = that;
  851. let color = that[name] ? that[name] : themeColor[theme][name];
  852. return color;
  853. },
  854. defaultSelectSku() {
  855. let that = this;
  856. let { defaultSelect } = that;
  857. if (defaultSelect && defaultSelect.sku && defaultSelect.sku.length > 0) {
  858. that.selectSku(defaultSelect);
  859. }
  860. },
  861. /**
  862. * 主动方法 - 设置sku
  863. that.$refs.skuPopup.selectSku({
  864. sku:["红色","256G","公开版"],
  865. num:5
  866. });
  867. */
  868. selectSku(obj = {}) {
  869. let that = this;
  870. let { sku: skuArr, num: selectNum } = obj;
  871. let specListArr = that.goodsInfo[that.specListName];
  872. if (skuArr && specListArr.length === skuArr.length) {
  873. // 先清空
  874. let skuClickArr = [];
  875. let clickKey = true;
  876. for (let index = 0; index < skuArr.length; index++) {
  877. let skuName = skuArr[index];
  878. let specList = specListArr[index].list;
  879. let index1 = index;
  880. let index2 = that.getListIndex(specList, 'name', skuName);
  881. if (index2 == -1) {
  882. clickKey = false;
  883. break;
  884. }
  885. skuClickArr.push({
  886. spec: specList[index2],
  887. index1: index1,
  888. index2: index2
  889. });
  890. }
  891. if (clickKey) {
  892. that.init(true);
  893. skuClickArr.map(item => {
  894. that.skuClick(item.spec, item.index1, item.index2);
  895. });
  896. }
  897. }
  898. if (selectNum > 0) that.selectNum = selectNum;
  899. },
  900. priceFilter(n = 0) {
  901. let that = this;
  902. if (typeof n == 'string') {
  903. n = parseFloat(n);
  904. }
  905. if (that.amountType === 0) {
  906. return n.toFixed(2);
  907. } else {
  908. return (n / 100).toFixed(2);
  909. }
  910. },
  911. pushGoodsCache(goodsInfo) {
  912. let that = this;
  913. let { goodsIdName } = that;
  914. goodsCache[goodsInfo[goodsIdName]] = goodsInfo;
  915. },
  916. // 用于阻止冒泡
  917. stop() {},
  918. // 图片预览
  919. previewImage() {
  920. let that = this;
  921. let { selectShop, goodsInfo, goodsThumbName } = that;
  922. let src = selectShop.image ? selectShop.image : goodsInfo[goodsThumbName];
  923. if (src) {
  924. uni.previewImage({
  925. urls: [src]
  926. });
  927. }
  928. },
  929. getMaxStock() {
  930. let maxStock = 0;
  931. let that = this;
  932. let { selectShop = {}, goodsInfo = {}, skuListName, stockName } = that;
  933. if (selectShop[stockName]) {
  934. maxStock = selectShop[stockName];
  935. } else {
  936. let skuList = goodsInfo[skuListName];
  937. if (skuList && skuList.length > 0) {
  938. let valueArr = [];
  939. skuList.map((skuItem, index) => {
  940. valueArr.push(skuItem[stockName]);
  941. });
  942. let max = Math.max(...valueArr);
  943. maxStock = max;
  944. }
  945. }
  946. return maxStock;
  947. },
  948. numChange(e) {
  949. this.$emit("num-change", e.value);
  950. }
  951. },
  952. // 计算属性
  953. computed: {
  954. valueCom() {
  955. // #ifndef VUE3
  956. return this.value;
  957. // #endif
  958. // #ifdef VUE3
  959. return this.modelValue;
  960. // #endif
  961. },
  962. // 最大购买数量
  963. maxBuyNumCom() {
  964. let that = this;
  965. let maxStock = that.getMaxStock();
  966. let max = that.maxBuyNum || 100000;
  967. // 最大购买量不能超过当前商品的库存
  968. if (max > maxStock) {
  969. max = maxStock;
  970. }
  971. return max;
  972. },
  973. // 是否是多规格
  974. isManyCom() {
  975. let that = this;
  976. let { goodsInfo, defaultSingleSkuName, specListName } = that;
  977. let isMany = true;
  978. if (
  979. goodsInfo[specListName] &&
  980. goodsInfo[specListName].length === 1 &&
  981. goodsInfo[specListName][0].list.length === 1 &&
  982. goodsInfo[specListName][0].name === defaultSingleSkuName
  983. ) {
  984. isMany = false;
  985. }
  986. return isMany;
  987. },
  988. // 默认价格区间计算
  989. priceCom() {
  990. let str = '';
  991. let that = this;
  992. let { selectShop = {}, goodsInfo = {}, skuListName, skuIdName } = that;
  993. if (selectShop[skuIdName]) {
  994. str = that.priceFilter(selectShop.price);
  995. } else {
  996. let skuList = goodsInfo[skuListName];
  997. if (skuList && skuList.length > 0) {
  998. let valueArr = [];
  999. skuList.map((skuItem, index) => {
  1000. valueArr.push(skuItem.price);
  1001. });
  1002. let min = that.priceFilter(Math.min(...valueArr));
  1003. let max = that.priceFilter(Math.max(...valueArr));
  1004. if (min === max) {
  1005. str = min + '';
  1006. } else {
  1007. str = `${min} - ${max}`;
  1008. }
  1009. }
  1010. }
  1011. return str;
  1012. },
  1013. // 库存显示
  1014. stockCom() {
  1015. let str = '';
  1016. let that = this;
  1017. let { selectShop = {}, goodsInfo = {}, skuListName, stockName } = that;
  1018. if (selectShop[stockName]) {
  1019. str = selectShop[stockName];
  1020. } else {
  1021. let skuList = goodsInfo[skuListName];
  1022. if (skuList && skuList.length > 0) {
  1023. let valueArr = [];
  1024. skuList.map((skuItem, index) => {
  1025. valueArr.push(skuItem[stockName]);
  1026. });
  1027. let min = Math.min(...valueArr);
  1028. let max = Math.max(...valueArr);
  1029. if (min === max) {
  1030. str = min;
  1031. } else {
  1032. str = `${min} - ${max}`;
  1033. }
  1034. }
  1035. }
  1036. return str;
  1037. }
  1038. },
  1039. watch: {
  1040. valueCom(newVal, oldValue) {
  1041. let that = this;
  1042. if (newVal) {
  1043. that.open();
  1044. }
  1045. },
  1046. defaultGoods: {
  1047. immediate: true,
  1048. handler: function(newVal, oldValue) {
  1049. let that = this;
  1050. let { goodsIdName } = that;
  1051. if (typeof newVal === 'object' && newVal && newVal[goodsIdName] && !goodsCache[newVal[goodsIdName]]) {
  1052. that.pushGoodsCache(newVal);
  1053. }
  1054. }
  1055. }
  1056. }
  1057. };
  1058. </script>
  1059. <style lang="scss" scoped>
  1060. /* sku弹出层 */
  1061. .goods-sku-popup {
  1062. position: fixed;
  1063. left: var(--window-left);
  1064. right: var(--window-right);
  1065. bottom: var(--window-bottom);
  1066. top: var(--window-top);
  1067. z-index: 21;
  1068. overflow: hidden;
  1069. &.show {
  1070. display: block;
  1071. .mask {
  1072. animation: showPopup 0.2s linear both;
  1073. }
  1074. .layer {
  1075. animation: showLayer 0.2s linear both;
  1076. bottom: var(--window-bottom);
  1077. }
  1078. }
  1079. &.hide {
  1080. .mask {
  1081. animation: hidePopup 0.2s linear both;
  1082. }
  1083. .layer {
  1084. animation: hideLayer 0.2s linear both;
  1085. }
  1086. }
  1087. &.none {
  1088. display: none;
  1089. }
  1090. .mask {
  1091. position: fixed;
  1092. left: var(--window-left);
  1093. right: var(--window-right);
  1094. top: 0;
  1095. width: 100%;
  1096. height: 100%;
  1097. z-index: 1;
  1098. background-color: rgba(0, 0, 0, 0.65);
  1099. }
  1100. .layer {
  1101. display: flex;
  1102. flex-direction: column;
  1103. position: fixed;
  1104. left: var(--window-left);
  1105. right: var(--window-right);
  1106. bottom: var(--window-bottom);
  1107. z-index: 99;
  1108. border-radius: 10rpx 10rpx 0 0;
  1109. background-color: #fff;
  1110. // 设置ios刘海屏底部横线安全区域
  1111. padding-bottom: constant(safe-area-inset-bottom);
  1112. padding-bottom: env(safe-area-inset-bottom);
  1113. .specification-wrapper {
  1114. width: 100%;
  1115. padding: 30rpx 25rpx;
  1116. box-sizing: border-box;
  1117. .specification-wrapper-content {
  1118. width: 100%;
  1119. max-height: 900rpx;
  1120. min-height: 300rpx;
  1121. &::-webkit-scrollbar {
  1122. /*隐藏滚轮*/
  1123. display: none;
  1124. }
  1125. .specification-header {
  1126. width: 100%;
  1127. display: flex;
  1128. flex-direction: row;
  1129. position: relative;
  1130. margin-bottom: 40rpx;
  1131. .specification-left {
  1132. width: 180rpx;
  1133. height: 180rpx;
  1134. flex: 0 0 180rpx;
  1135. .product-img {
  1136. width: 180rpx;
  1137. height: 180rpx;
  1138. }
  1139. }
  1140. .specification-right {
  1141. flex: 1;
  1142. padding: 0 35rpx 10rpx 28rpx;
  1143. box-sizing: border-box;
  1144. display: flex;
  1145. flex-direction: column;
  1146. justify-content: flex-end;
  1147. font-weight: 500;
  1148. .price-content {
  1149. color: #fe560a;
  1150. margin-bottom: 10rpx;
  1151. .sign {
  1152. font-size: 28rpx;
  1153. margin-right: 4rpx;
  1154. }
  1155. .price {
  1156. margin-left: 4rpx;
  1157. font-size: 48rpx;
  1158. }
  1159. .price2 {
  1160. margin-left: 4rpx;
  1161. font-size: 36rpx;
  1162. }
  1163. }
  1164. .inventory {
  1165. font-size: 24rpx;
  1166. color: #525252;
  1167. margin-bottom: 14rpx;
  1168. }
  1169. .choose {
  1170. font-size: 24rpx;
  1171. color: #525252;
  1172. min-height: 32rpx;
  1173. }
  1174. }
  1175. }
  1176. .specification-content {
  1177. font-weight: 500;
  1178. .specification-item {
  1179. margin-bottom: 40rpx;
  1180. &:last-child {
  1181. margin-bottom: 0;
  1182. }
  1183. .item-title {
  1184. margin-bottom: 20rpx;
  1185. font-size: 28rpx;
  1186. color: #999999;
  1187. }
  1188. .item-wrapper {
  1189. display: flex;
  1190. flex-direction: row;
  1191. flex-flow: wrap;
  1192. margin-bottom: -20rpx;
  1193. .item-content {
  1194. display: inline-block;
  1195. padding: 10rpx 35rpx;
  1196. font-size: 24rpx;
  1197. border-radius: 10rpx;
  1198. background-color: #ffffff;
  1199. color: #333333;
  1200. margin-right: 20rpx;
  1201. margin-bottom: 20rpx;
  1202. border: 2rpx solid #f4f4f4;
  1203. box-sizing: border-box;
  1204. &.actived {
  1205. border-color: #fe560a;
  1206. color: #fe560a;
  1207. }
  1208. &.noactived {
  1209. // background-color: #f6f6f6;
  1210. // border-color: #f6f6f6;
  1211. // color: #c3c3c3;
  1212. color: #c8c9cc;
  1213. background: #f2f3f5;
  1214. border-color: #f2f3f5;
  1215. }
  1216. }
  1217. }
  1218. }
  1219. .number-box-view {
  1220. display: flex;
  1221. padding-top: 20rpx;
  1222. }
  1223. }
  1224. }
  1225. .close {
  1226. position: absolute;
  1227. top: 30rpx;
  1228. right: 25rpx;
  1229. width: 50rpx;
  1230. height: 50rpx;
  1231. display: flex;
  1232. justify-content: center;
  1233. align-items: center;
  1234. .close-item {
  1235. width: 40rpx;
  1236. height: 40rpx;
  1237. }
  1238. }
  1239. }
  1240. .btn-wrapper {
  1241. display: flex;
  1242. width: 100%;
  1243. height: 120rpx;
  1244. flex: 0 0 120rpx;
  1245. align-items: center;
  1246. justify-content: space-between;
  1247. padding: 0 26rpx;
  1248. box-sizing: border-box;
  1249. .layer-btn {
  1250. width: 335rpx;
  1251. height: 76rpx;
  1252. border-radius: 38rpx;
  1253. color: #fff;
  1254. font-weight: 500;
  1255. font-size: 28rpx;
  1256. display: flex;
  1257. justify-content: center;
  1258. align-items: center;
  1259. &.add-cart {
  1260. background: #ffbe46;
  1261. }
  1262. &.buy {
  1263. background: #fe560a;
  1264. }
  1265. }
  1266. .sure {
  1267. margin: 0 auto;
  1268. width: 95%;
  1269. max-width: 1200rpx;
  1270. height: 80rpx;
  1271. border-radius: 38rpx;
  1272. color: #fff;
  1273. font-weight: 500;
  1274. font-size: 28rpx;
  1275. background: #fe560a;
  1276. display: flex;
  1277. justify-content: center;
  1278. align-items: center;
  1279. }
  1280. .sure.add-cart {
  1281. background: #ff9402;
  1282. }
  1283. }
  1284. .btn-wrapper.safe-area-inset-bottom {
  1285. padding-bottom: 0;
  1286. padding-bottom: constant(safe-area-inset-bottom);
  1287. padding-bottom: env(safe-area-inset-bottom);
  1288. }
  1289. }
  1290. @keyframes showPopup {
  1291. 0% {
  1292. opacity: 0;
  1293. }
  1294. 100% {
  1295. opacity: 1;
  1296. }
  1297. }
  1298. @keyframes hidePopup {
  1299. 0% {
  1300. opacity: 1;
  1301. }
  1302. 100% {
  1303. opacity: 0;
  1304. }
  1305. }
  1306. @keyframes showLayer {
  1307. 0% {
  1308. transform: translateY(120%);
  1309. }
  1310. 100% {
  1311. transform: translateY(0%);
  1312. }
  1313. }
  1314. @keyframes hideLayer {
  1315. 0% {
  1316. transform: translateY(0);
  1317. }
  1318. 100% {
  1319. transform: translateY(120%);
  1320. }
  1321. }
  1322. }
  1323. </style>