app-attr.vue 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376
  1. <template>
  2. <view class="app-attr">
  3. <view @click="alert">
  4. <slot name="button"></slot>
  5. </view>
  6. <view class="modal" v-if="display === 'block'" @click="close">
  7. <view class="safe-area-inset-bottom u-attr-fixed">
  8. <view class="content" @tap.native.stop="preventD">
  9. <image src="../../../static/image/icon/close.png" class="close" @click="close"></image>
  10. <view class="first dir-left-nowrap" :class="sign =='wholesale' ? 'no-border' : ''">
  11. <view class="box-grow-0 img" @click="clickImg(attrPic)">
  12. <app-image :img-src="attrPic" width="100%" height="100%"></app-image>
  13. </view>
  14. <view class="info">
  15. <view class="dir-left-nowrap cross-center" :class="priceColor">
  16. <view class="dir-left-nowrap cross-center">
  17. <view class="dir-left-nowrap cross-center" :class="theme+'-m-text ' + theme"
  18. v-if="selectAttr.extra || goods.extra">
  19. <view>{{selectAttr.extra ? selectAttr.extra.value + selectAttr.extra.name :
  20. goods.extra.value + goods.extra.name}}
  21. </view>
  22. <view v-if="!(goods.sign === 'integral_mall' && attrPrice == 0)">+</view>
  23. </view>
  24. <app-price :theme="theme"
  25. v-if="!(goods.sign === 'integral_mall' && attrPrice == 0) && sign != 'wholesale'"
  26. type="text-price-all" :price="attrPrice" :default-price="goods.price">
  27. </app-price>
  28. <app-price :theme="theme" v-if="sign == 'wholesale'" type="text-price-all"
  29. :price="attrPrice"
  30. :max="goods.level_show == 1 ? goods.price_member_max : goods.price_max"
  31. :min="goods.level_show == 1 ? goods.price_member_min : goods.price_min">
  32. </app-price>
  33. </view>
  34. <view v-if="goods.level_show === 1 && (selectAttr || sign == 'wholesale')">
  35. <app-member-mark :theme="themeObject"></app-member-mark>
  36. </view>
  37. </view>
  38. <view class="stock">库存:{{attrNum}}</view>
  39. </view>
  40. </view>
  41. <view class="second" :class="sign =='wholesale' ? 'no-padding' : ''">
  42. <slot name="extra"></slot>
  43. <view class="wholesale" v-if="sign =='wholesale'">
  44. <view class="wholesale-attr-list dir-left-nowrap cross-center"
  45. v-if="index != goods.attr_groups.length -1" v-for="(item, index) in goods.attr_groups"
  46. :key="index">
  47. <view class="wholesale-attr-group t-omit-two">{{item.attr_group_name}}</view>
  48. <scroll-view @scroll="scrollGet($event,index)" :scroll-left="item.scrollLeft"
  49. class="wholesale-attr-item" scroll-x="true">
  50. <view class="attr-name" v-for="(attr, key) in item.attr_list" :key="key"
  51. :class="attr.active ? theme + '-m-back ' + theme : 'attr-background'"
  52. @click="chooseAttr(index,attr)">{{attr.attr_name}}
  53. <view class="attr-number" :style="{'right':`${attr.length + 'rpx'}`}"
  54. :class="theme + '-m-back ' + theme" v-if="index == 0 && attr.number > 0">
  55. {{attr.number}}
  56. </view>
  57. </view>
  58. <view class="attr-name attr-background" style="visibility: hidden">占位
  59. </view>
  60. </scroll-view>
  61. <view @click.stop="toBottom(index)" class="right-icon">
  62. <view></view>
  63. <image src="/static/image/icon/right.png"></image>
  64. </view>
  65. </view>
  66. <view class="wholesale-attr-group-list">
  67. <view class="wholesale-attr-group" v-for="(item, index) in goodsAttr" :key="index">
  68. <view class="dir-left-nowrap">
  69. <view class="wholesale-attr-item main-between">
  70. <view class="dir-top-nowrap main-center attr-name t-omit">
  71. <view class="t-omit">
  72. {{item.attr_list[item.attr_list.length - 1].attr_name}}
  73. </view>
  74. <view class="attr-price">
  75. ¥{{goods.level_show === 1 ? item.price_member : item.price}}</view>
  76. </view>
  77. <view class="dir-left-nowrap wholesale-number-box cross-center">
  78. <image
  79. :src="item.number <= 0 ? '/static/image/plugins/un-low.png' : '/static/image/plugins/low.png'"
  80. class="block box-grow-0 cross-center main-center"
  81. @click="wholesaleNumberSub(index)">
  82. </image>
  83. <view
  84. class="wholesale-number-input box-grow-0 cross-center main-center">
  85. <app-input height="60" type="number" v-model="item.number"
  86. paddingLeft="0" :center="true" placeholder=" "
  87. @blur="wholesaleNumberBlur(index)" :focus="false" width="88">
  88. </app-input>
  89. </view>
  90. <image
  91. :src="item.number >= item.stock? '/static/image/plugins/un-add.png' : '/static/image/plugins/add.png'"
  92. class="block box-grow-0 cross-center main-center"
  93. @click="wholesaleNumberAdd(index)"></image>
  94. </view>
  95. </view>
  96. </view>
  97. </view>
  98. </view>
  99. </view>
  100. <view class="attr-group" v-if="goods.type === 'goods' && sign !='wholesale'"
  101. v-for="(item, index) in newAttrGroupList" :key="index">
  102. <view class="attr-group-name">{{item.attr_group_name}}</view>
  103. <view class="dir-left-wrap">
  104. <view v-for="(attr, key) in item.attr_list" :key="key" class="attr-item"
  105. :class="attr.checked && sign !== 'gift' ? theme + '-m-back active ' + theme : attr.checked && sign === 'gift' ? theme + '-background active' : 'attr-item-default' + (attr.attr_num_0 ? ' attr_num_0' : '')"
  106. @click="storeAttrClick(attr.attr_id, item.attr_group_id)">{{attr.attr_name}}
  107. </view>
  108. </view>
  109. </view>
  110. <view v-if="chooseNumber" class="dir-left-nowrap number-box cross-center">
  111. <view class="box-grow-1">数量</view>
  112. <image
  113. :src="number <= 1 ? '/static/image/icon/can-be-reduced.png' : '/static/image/cart/can-be-reduced.png'"
  114. class="block box-grow-0 cross-center main-center" @click="numberSub">
  115. </image>
  116. <view class="number-input box-grow-0 cross-center main-center">
  117. <app-input type="number" v-model="number" paddingLeft="0" :center="true" placeholder=" "
  118. @blur="numberBlur" :focus="false" width="88"></app-input>
  119. </view>
  120. <image src="/static/image/cart/can-be-added.png"
  121. class="block box-grow-0 cross-center main-center" @click="numberAdd"></image>
  122. </view>
  123. <view class="service"
  124. v-if="service_screen&&service_screen.screenList&&service_screen.screenList.length>0">
  125. <view class="service_title">全优汇服务</view>
  126. <view class="service_item" style="align-items: center;">
  127. <image style="width: 26upx;height:26upx;"
  128. src="https://t12.9026.com/web/statics/icon1/sp.png"> </image>
  129. <view style="flex: 1;">
  130. <view style="float: left;">碎屏险</view>
  131. <view class="slh">{{screenDescription}}</view>
  132. </view>
  133. <view style="color: red;" @click="gotoSpDetail">服务说明
  134. <image style="width: 26upx;height:26upx;"
  135. src="https://t12.9026.com/web/statics/icon1/问号.png"> </image>
  136. </view>
  137. <!-- <view>{{service_screen.screenList.intro}}</view> -->
  138. </view>
  139. <view class="service_value">
  140. <view class="service_block" v-for="(item,index) of service_screen.screenList"
  141. :key="index" :class="{service_block_active:index == serviceId}"
  142. @click="select_service(index)">
  143. {{item.name}} ¥{{item.price}}
  144. </view>
  145. </view>
  146. </view>
  147. </view>
  148. <view v-if="sign =='wholesale'" class="total">已选<text>{{totalNumber}}</text>件
  149. 总计<text>¥{{totalPrice > 0? totalPrice : '0.00'}}</text></view>
  150. <view class="three dir-left-nowrap">
  151. <view class="box-grow-1 main-center cross-center" v-if="cartShow"
  152. :class="sign === 'pick' ? theme + '-m-back ' + 'buy ' + theme : theme === 'b' || theme === 'f' || theme === 'a' ? theme + '-s-back ' + 'buy ' + theme : theme + '-s-back ' + theme+ '-m-text ' + theme"
  153. @click="cart">{{addText}}
  154. </view>
  155. <view v-if="is_show_buy" class="box-grow-1 main-center cross-center buy"
  156. :class="sign !== 'gift' ? theme + '-m-back '+ theme : theme + '-background'" @click="buy">
  157. {{buyText}}
  158. </view>
  159. </view>
  160. </view>
  161. </view>
  162. </view>
  163. </view>
  164. </template>
  165. <script>
  166. import {
  167. mapState,
  168. mapGetters
  169. } from "vuex";
  170. import appPrice from "../../page-component/goods/app-price.vue";
  171. import appImage from "../../basic-component/app-image/app-image.vue";
  172. import appMemberMark from '../../page-component/app-member-mark/app-member-mark.vue';
  173. export default {
  174. name: "app-attr",
  175. components: {
  176. appPrice,
  177. 'app-image': appImage,
  178. appMemberMark
  179. },
  180. props: {
  181. goods: Object,
  182. attrGroupList: Array,
  183. attrCart: {
  184. type: Array,
  185. default () {
  186. return [];
  187. }
  188. },
  189. cartShow: {
  190. type: Boolean,
  191. default () {
  192. return true
  193. }
  194. },
  195. previewUrl: String,
  196. submitUrl: String,
  197. goodsId: {
  198. type: Number,
  199. default () {
  200. return 0
  201. }
  202. },
  203. show: Number,
  204. buyText: {
  205. type: String,
  206. default () {
  207. return '立即购买';
  208. }
  209. },
  210. plugin: {
  211. default: '',
  212. },
  213. theme: {
  214. type: String,
  215. default: 'a',
  216. },
  217. chooseNumber: {
  218. type: Boolean,
  219. default: true,
  220. },
  221. noPay: {
  222. type: Boolean,
  223. default: false,
  224. },
  225. buyClick: {
  226. type: Boolean,
  227. default: false,
  228. },
  229. addText: {
  230. type: String,
  231. default: '加入购物车',
  232. },
  233. is_show_buy: {
  234. type: Boolean,
  235. default: true,
  236. },
  237. sign: {
  238. type: String
  239. },
  240. totalPrice: {
  241. type: String,
  242. default: '0.00',
  243. },
  244. totalNumber: {
  245. type: Number,
  246. default: 0,
  247. },
  248. discount: {
  249. type: Number,
  250. default: 0,
  251. },
  252. wholesaleType: {
  253. type: Number,
  254. default: 0,
  255. }
  256. },
  257. data() {
  258. return {
  259. display: 'none',
  260. number: 1,
  261. selectAttr: null,
  262. newAttrGroupList: null,
  263. pic_url: null,
  264. // 商品批发
  265. activeAttr: [],
  266. goodsAttr: [],
  267. service_screen: null, //碎屏险
  268. service_label: null, //当前对屏对象
  269. serviceId: null, //碎屏险ID
  270. card_id: null,
  271. screenDescription: '',
  272. };
  273. },
  274. watch: {
  275. show() {
  276. if (this.display === 'block') {
  277. this.selectAttr = null;
  278. this.close();
  279. } else if (this.display === 'none') {
  280. this.serviceId = null
  281. this.screenDescription = ""
  282. this.service_label = null
  283. this.card_id = null
  284. this.service_screen = null
  285. this.alert();
  286. }
  287. },
  288. newData: {
  289. handler() {
  290. this.$emit('attr', this.newData)
  291. },
  292. immediate: true,
  293. },
  294. attrGroupList: {
  295. handler() {
  296. this.newAttrGroupList = this.attrGroupList;
  297. if (this.display == 'block') {
  298. this.alert();
  299. }
  300. },
  301. immediate: true
  302. },
  303. goods: {
  304. handler() {
  305. if (this.display == 'block') {
  306. this.alert();
  307. }
  308. },
  309. immediate: true
  310. }
  311. },
  312. mounted() {
  313. if (this.sign == 'wholesale') {
  314. this.pic_url = this.goods.attr_groups[0].attr_list[0].pic_url
  315. if (this.goods.attr_groups.length == 1) {
  316. this.goodsAttr = this.goods.attr;
  317. } else {
  318. for (let item of this.goods.attr_groups) {
  319. let para = {
  320. attr_group_name: '',
  321. attr_group_id: '',
  322. attr_id: '',
  323. attr_name: ''
  324. };
  325. para.attr_group_name = item.attr_group_name
  326. para.attr_group_id = item.attr_group_id
  327. para.attr_id = item.attr_list[0].attr_id
  328. para.attr_name = item.attr_list[0].attr_name
  329. this.activeAttr.push(para)
  330. }
  331. for (let item of this.goods.attr) {
  332. let same = true;
  333. for (let i = 0; i < item.attr_list.length - 1; i++) {
  334. let first = {
  335. attr_group_name: item.attr_list[i].attr_group_name,
  336. attr_group_id: item.attr_list[i].attr_group_id,
  337. attr_id: item.attr_list[i].attr_id,
  338. attr_name: item.attr_list[i].attr_name
  339. }
  340. if (JSON.stringify(first) != JSON.stringify(this.activeAttr[i])) {
  341. same = false;
  342. }
  343. }
  344. if (same) {
  345. this.goodsAttr.push(item)
  346. }
  347. }
  348. }
  349. }
  350. },
  351. methods: {
  352. select_service(index) {
  353. if (this.serviceId == index) {
  354. this.serviceId = null
  355. this.screenDescription = ""
  356. this.service_label = null
  357. this.card_id = null
  358. } else {
  359. this.serviceId = index
  360. this.screenDescription = this.service_screen.screenList[index]['description'] || ''
  361. this.service_label = this.service_screen.screenList[index]
  362. this.card_id = this.service_screen.screenList['card_id']
  363. }
  364. },
  365. alert() {
  366. if (this.attrGroupList.length === 0) {
  367. return;
  368. }
  369. if (this.sign != 'wholesale') {
  370. let attr_group_list = this.attrGroupList;
  371. let attrs = this.goods.attr;
  372. let select_attr = null;
  373. this.number = 1;
  374. if (attr_group_list.length === 1) {
  375. for (let i in attrs) {
  376. for (let j in attr_group_list[0].attr_list) {
  377. if (attr_group_list[0].attr_list[j].attr_id == attrs[i].attr_list[0].attr_id) {
  378. if (attrs[i].stock > 0) {
  379. if (attrs.length === 1) {
  380. attr_group_list[0].attr_list[j].checked = true;
  381. }
  382. attr_group_list[0].attr_list[j].attr_num_0 = false;
  383. this.pic_url = attr_group_list[0].attr_list[j].pic_url;
  384. } else {
  385. this.number = 0;
  386. attr_group_list[0].attr_list[j].checked = false;
  387. attr_group_list[0].attr_list[j].attr_num_0 = true;
  388. }
  389. }
  390. }
  391. }
  392. if (attrs.length === 1) {
  393. select_attr = attrs[0];
  394. this.$emit('attrtap', select_attr);
  395. }
  396. }
  397. this.newAttrGroupList = attr_group_list;
  398. if (this.goods.selectAttr) {
  399. this.selectAttr = this.goods.selectAttr
  400. } else {
  401. this.selectAttr = select_attr;
  402. }
  403. }
  404. // this.getservice()
  405. this.display = 'block';
  406. },
  407. gotoSpDetail() {
  408. uni.navigateTo({
  409. url: "/pages/goods/spDetail"
  410. })
  411. },
  412. getservice(select_val) {
  413. if (select_val.length <= 1) return false
  414. this.goods.attr.forEach((item, index) => {
  415. let select_item_list = []
  416. let select_item_value = ''
  417. let attrList = item.attr_list || [];
  418. attrList.forEach((value, key) => {
  419. select_item_value = value.attr_group_id + '-' + value.attr_id
  420. select_item_list.push(select_item_value)
  421. })
  422. if (JSON.stringify(select_val) == JSON.stringify(select_item_list)) {
  423. this.service_screen = item
  424. }
  425. console.log(this.service_screen, "oooooooooooooooo")
  426. })
  427. },
  428. scrollGet(e, index) {
  429. this.goods.attr_groups[index].scrollLeft = e.detail.scrollLeft;
  430. this.$forceUpdate();
  431. },
  432. toBottom(index) {
  433. this.$nextTick().then(() => {
  434. this.goods.attr_groups[index].scrollLeft = 99999;
  435. this.$forceUpdate();
  436. })
  437. },
  438. chooseAttr(index, attrItem) {
  439. let that = this;
  440. for (let attr of that.goods.attr_groups[index].attr_list) {
  441. attr.active = false;
  442. if (attr.attr_id == attrItem.attr_id && attr.attr_name == attrItem.attr_name) {
  443. attr.active = true;
  444. }
  445. }
  446. if (index == 0) {
  447. that.pic_url = attrItem.pic_url;
  448. }
  449. that.activeAttr[index].attr_id = attrItem.attr_id
  450. that.activeAttr[index].attr_name = attrItem.attr_name
  451. that.goodsAttr = [];
  452. for (let item of that.goods.attr) {
  453. let same = true;
  454. for (let i = 0; i < item.attr_list.length - 1; i++) {
  455. let first = {
  456. attr_group_name: item.attr_list[i].attr_group_name,
  457. attr_group_id: item.attr_list[i].attr_group_id,
  458. attr_id: item.attr_list[i].attr_id,
  459. attr_name: item.attr_list[i].attr_name
  460. }
  461. if (JSON.stringify(first) != JSON.stringify(this.activeAttr[i])) {
  462. same = false;
  463. }
  464. }
  465. if (same) {
  466. that.goodsAttr.push(item)
  467. }
  468. }
  469. that.$forceUpdate();
  470. that.count();
  471. },
  472. wholesaleNumberSub(index) {
  473. if (this.goodsAttr[index].number == 0) {
  474. return false;
  475. }
  476. this.goodsAttr[index].number--;
  477. if (this.goods.attr_groups.length == 1) {
  478. this.pic_url = this.goodsAttr[index].pic_url;
  479. }
  480. this.count(index);
  481. },
  482. wholesaleNumberAdd(index) {
  483. if (this.goodsAttr[index].number > this.goodsAttr[index].stock || this.goodsAttr[index].number == this
  484. .goodsAttr[index].stock) {
  485. return false
  486. }
  487. this.goodsAttr[index].number++;
  488. if (this.goods.attr_groups.length == 1) {
  489. this.pic_url = this.goodsAttr[index].pic_url;
  490. }
  491. this.count(index);
  492. },
  493. wholesaleNumberBlur(index) {
  494. if (+this.goodsAttr[index].number > +this.goodsAttr[index].stock) {
  495. this.goodsAttr[index].number = this.goodsAttr[index].stock
  496. }
  497. if (this.goods.attr_groups.length == 1) {
  498. this.pic_url = this.goodsAttr[index].pic_url;
  499. }
  500. this.count(index);
  501. },
  502. count(index) {
  503. let that = this;
  504. this.$emit('attrtap', that.goods, that.goodsAttr);
  505. setTimeout(() => {
  506. that.selectAttr = that.goodsAttr[index]
  507. })
  508. },
  509. close() {
  510. this.display = 'none';
  511. this.$emit('close', false)
  512. },
  513. preventD() {},
  514. storeAttrClick(attr_id, attr_group_id) {
  515. let select_num = []
  516. let attr_group_list = JSON.parse(JSON.stringify(this.newAttrGroupList));
  517. let attrs = this.goods.attr;
  518. let checkedAttr = [];
  519. let attr_cart = this.attrCart;
  520. for (let i in attr_group_list) {
  521. for (let j in attr_group_list[i].attr_list) {
  522. let temp = attr_group_list[i].attr_list[j];
  523. if (parseInt(attr_group_list[i].attr_group_id) == parseInt(attr_group_id)) {
  524. if (parseInt(temp.attr_id) === parseInt(attr_id)) {
  525. if (temp.checked) {
  526. temp.checked = false;
  527. } else {
  528. temp.checked = true;
  529. }
  530. if (temp.attr_num_0) {
  531. return;
  532. }
  533. } else {
  534. temp.checked = false;
  535. }
  536. }
  537. if (temp.checked) {
  538. if (i == 0) {
  539. this.pic_url = attr_group_list[0].attr_list[j].pic_url;
  540. }
  541. checkedAttr.push(attr_group_list[i].attr_group_id + '-' + temp.attr_id);
  542. }
  543. }
  544. }
  545. this.getservice(checkedAttr)
  546. function inArray(val, arr) {
  547. return arr.some(function(v) {
  548. return val == v;
  549. })
  550. }
  551. let attrNum_0 = [];
  552. let select_attr = null;
  553. let number = 1;
  554. for (let i in attrs) {
  555. let arr = [];
  556. let sign = 0;
  557. for (let j in attrs[i].attr_list) {
  558. let param = attrs[i].attr_list[j].attr_group_id + '-' + attrs[i].attr_list[j].attr_id;
  559. if (!inArray(param, checkedAttr)) {
  560. sign += 1;
  561. arr.push(param);
  562. }
  563. }
  564. if (attrs[i].stock == 0 && sign <= 1) {
  565. attrNum_0 = attrNum_0.concat(arr);
  566. }
  567. if (sign == 0) {
  568. if (!select_attr) {
  569. select_attr = {};
  570. }
  571. select_attr = attrs[i];
  572. attr_cart.forEach(item => {
  573. if (item.attr_id == select_attr.id) {
  574. number = item.num;
  575. }
  576. });
  577. if (select_attr.stock <= 0) {
  578. uni.showToast({
  579. title: '库存不足',
  580. icon: 'none'
  581. });
  582. return;
  583. }
  584. if (select_attr.stock <= number) {
  585. number = select_attr.stock;
  586. }
  587. }
  588. }
  589. if (checkedAttr.length == 0) {
  590. select_attr = null;
  591. }
  592. //库存为0的规格添加标识
  593. for (let i in attr_group_list) {
  594. for (let j in attr_group_list[i].attr_list) {
  595. let cAttr = attr_group_list[i].attr_list[j];
  596. let cParam = attr_group_list[i].attr_group_id + '-' + cAttr.attr_id;
  597. if (inArray(cParam, attrNum_0) && !inArray(cParam, checkedAttr)) {
  598. cAttr.attr_num_0 = true;
  599. } else {
  600. cAttr.attr_num_0 = false;
  601. }
  602. }
  603. }
  604. this.newAttrGroupList = attr_group_list;
  605. this.selectAttr = select_attr;
  606. this.number = number;
  607. this.$emit('attrtap', this.selectAttr);
  608. },
  609. numberBlur(number) {
  610. number = parseInt(number.value);
  611. if (number > this.attrNum) {
  612. uni.showToast({
  613. title: '库存不足',
  614. icon: 'none'
  615. });
  616. number = this.attrNum;
  617. }
  618. this.$emit('attrtap', this.selectAttr);
  619. return this.number = number;
  620. },
  621. numberSub() {
  622. let number = this.number;
  623. if (number <= 1) {
  624. return true;
  625. }
  626. number--;
  627. this.number = number;
  628. this.$emit('attrtap', this.selectAttr);
  629. },
  630. numberAdd() {
  631. let number = this.number;
  632. number++;
  633. if (number > this.attrNum) {
  634. uni.showToast({
  635. title: '库存不足',
  636. icon: 'none'
  637. });
  638. this.number = this.attrNum;
  639. return;
  640. }
  641. this.number = number;
  642. this.$emit('attrtap', this.selectAttr);
  643. },
  644. cart() {
  645. if (!this.submit()) {
  646. return false;
  647. }
  648. let select_attr = this.selectAttr;
  649. if (this.goods.sign === 'pick' || this.goods.sign === 'community') {
  650. this.$emit('add', select_attr, this.number);
  651. return;
  652. }
  653. // 普通商品
  654. if (this.goods.type === 'goods') {
  655. if (this.goods.sign === 'miaosha') {
  656. this.$request({
  657. url: this.$api.miaosha.add_cart,
  658. data: {
  659. miaosha_goods_id: select_attr.goods_id,
  660. attr_id: select_attr.id,
  661. num: this.number
  662. },
  663. method: 'post'
  664. }).then(e => {
  665. uni.showToast({
  666. title: e.msg,
  667. type: 'success'
  668. });
  669. this.display = 'none';
  670. this.selectAttr.number = this.number;
  671. this.$emit('selectNumber', this.selectAttr);
  672. }).catch(() => {
  673. this.display = 'none';
  674. });
  675. } else if (this.goods.sign === 'flash_sale') {
  676. this.$request({
  677. url: this.$api.flash_sale.add_cart,
  678. data: {
  679. flash_goods_id: select_attr.goods_id,
  680. attr_id: select_attr.id,
  681. num: this.number
  682. },
  683. method: 'post'
  684. }).then(e => {
  685. uni.showToast({
  686. title: e.msg,
  687. type: 'success'
  688. });
  689. this.display = 'none';
  690. this.selectAttr.number = this.number;
  691. this.$emit('selectNumber', this.selectAttr);
  692. }).catch(() => {
  693. this.display = 'none';
  694. });
  695. } else if (this.goods.sign == 'wholesale') {
  696. if (this.totalNumber < this.goods.wholesaleGoods.rise_num) {
  697. uni.showToast({
  698. title: '至少采购' + this.goods.wholesaleGoods.rise_num + this.goods.unit,
  699. image: '/static/image/plugins/tip.png',
  700. duration: 1000
  701. });
  702. return false
  703. }
  704. let para = [];
  705. for (let item of this.goods.attr) {
  706. if (item.number > 0) {
  707. para.push(item)
  708. }
  709. }
  710. this.$request({
  711. url: this.$api.wholesale.cart,
  712. data: {
  713. attr: JSON.stringify(para)
  714. },
  715. method: 'post'
  716. }).then(response => {
  717. this.display = 'none';
  718. if (response.code === 0) {
  719. for (let item of this.goods.attr) {
  720. item.number = '0'
  721. }
  722. for (let item of this.goodsAttr) {
  723. item.number = '0'
  724. }
  725. this.count();
  726. uni.hideLoading();
  727. uni.showToast({
  728. title: '添加成功',
  729. duration: 1000
  730. });
  731. }
  732. }).catch(response => {
  733. this.display = 'none';
  734. })
  735. } else {
  736. this.$request({
  737. url: this.$api.cart.add,
  738. data: {
  739. goods_id: select_attr.goods_id,
  740. attr: select_attr.id,
  741. num: this.number
  742. },
  743. method: 'post'
  744. }).then(e => {
  745. if (e.code === 0) {
  746. uni.showToast({
  747. title: e.msg,
  748. type: 'success'
  749. });
  750. this.display = 'none';
  751. this.selectAttr.number = this.number;
  752. this.$emit('selectNumber', this.selectAttr);
  753. } else {
  754. uni.showToast({
  755. title: e.msg,
  756. icon: "none",
  757. duration: 2500
  758. });
  759. this.display = 'none';
  760. }
  761. }).catch(() => {
  762. this.display = 'none';
  763. });
  764. }
  765. // 虚拟商品
  766. } else if (this.goods.type === 'ecard') {
  767. uni.showToast({
  768. title: '虚拟商品不允许加入购物车',
  769. icon: 'none'
  770. });
  771. }
  772. },
  773. buy() {
  774. if (this.$user.isLogin() && this.$store.state.user.info) {
  775. let member_level = this.$store.state.user.info.identity.member_level;
  776. if (member_level < this.goods.member_level) {
  777. uni.showModal({
  778. title: "提示",
  779. content: "需达到" + this.goods.member_name + "会员才可购买",
  780. showCancel: true,
  781. buttonText: '升级',
  782. success: (res) => {
  783. if (res.confirm) {
  784. uni.navigateTo({
  785. // url:"/pages/member/index/index",
  786. url: '/pages/member/upgrade/upgrade?level=' + member_level +
  787. '&other=' + this.goods.member_level
  788. })
  789. } else if (res.cancel) {
  790. console.log('用户点击取消');
  791. }
  792. }
  793. })
  794. return;
  795. }
  796. }
  797. if (!this.submit()) return false;
  798. if (this.noPay) {
  799. this.$emit('pay', this.number);
  800. return;
  801. }
  802. if (this.buyClick) {
  803. this.display = 'none';
  804. this.selectAttr.number = this.number;
  805. this.selectAttr.service_label = this.service_label
  806. this.$emit('buyClick', this.selectAttr);
  807. return false;
  808. }
  809. if (this.goods.sign == 'wholesale') {
  810. if (this.totalNumber < this.goods.wholesaleGoods.rise_num) {
  811. uni.showToast({
  812. title: '至少采购' + this.goods.wholesaleGoods.rise_num + this.goods.unit,
  813. image: '/static/image/plugins/tip.png',
  814. duration: 1000
  815. });
  816. return false
  817. }
  818. let para = {};
  819. let mch_list = [{
  820. mch_id: 0,
  821. goods_list: []
  822. }];
  823. for (let item of this.goods.attr) {
  824. if (item.number > 0) {
  825. para = {
  826. id: item.goods_id,
  827. attr: [],
  828. num: item.number,
  829. cat_id: 0,
  830. goods_attr_id: item.id
  831. }
  832. for (let attr of item.attr_list) {
  833. let attrList = {
  834. attr_id: attr.attr_id,
  835. attr_group_id: attr.attr_group_id
  836. }
  837. para.attr.push(attrList)
  838. }
  839. mch_list[0].goods_list.push(para)
  840. }
  841. }
  842. let url = `/pages/order-submit/order-submit?mch_list=${JSON.stringify(mch_list)}`;
  843. if (this.submitUrl && this.previewUrl) {
  844. url +=
  845. `&preview_url=${encodeURIComponent(this.previewUrl)}&submit_url=${encodeURIComponent(this.submitUrl)}&plugin=${this.plugin}`;
  846. }
  847. uni.navigateTo({
  848. url: url
  849. })
  850. } else {
  851. let goods = this.goods;
  852. let number = this.number;
  853. let select_attr = this.selectAttr;
  854. let goods_attr_id = select_attr.id;
  855. let attr = [];
  856. for (let i in select_attr.attr_list) {
  857. attr.push({
  858. attr_id: select_attr.attr_list[i].attr_id,
  859. attr_group_id: select_attr.attr_list[i].attr_group_id
  860. });
  861. }
  862. let mch_list = [{
  863. mch_id: goods.mch_id ? goods.mch_id : 0,
  864. goods_list: [{
  865. id: this.goodsId ? this.goodsId : goods.id,
  866. attr: attr,
  867. num: number,
  868. cat_id: 0,
  869. goods_attr_id: goods_attr_id,
  870. service_label: this.service_label
  871. }]
  872. }];
  873. console.log(mch_list, "*******///////////")
  874. let url = `/pages/order-submit/order-submit?mch_list=${JSON.stringify(mch_list)}`;
  875. if (this.submitUrl && this.previewUrl) {
  876. url +=
  877. `&preview_url=${encodeURIComponent(this.previewUrl)}&submit_url=${encodeURIComponent(this.submitUrl)}&plugin=${this.plugin}`;
  878. }
  879. uni.navigateTo({
  880. url: url
  881. })
  882. }
  883. },
  884. submit() {
  885. let select_attr = this.selectAttr;
  886. if (this.goods.sign === 'wholesale') {
  887. return true;
  888. }
  889. if (!select_attr) {
  890. uni.showToast({
  891. title: '请先选规格',
  892. icon: 'none'
  893. });
  894. return false;
  895. }
  896. if (select_attr.stock <= 0) {
  897. uni.showToast({
  898. title: '库存不足',
  899. icon: 'none'
  900. });
  901. return false;
  902. }
  903. if (this.number <= 0) {
  904. uni.showToast({
  905. title: '数量不能为0',
  906. icon: 'none'
  907. });
  908. return false;
  909. }
  910. if (!this.goods) {
  911. return false;
  912. }
  913. return true;
  914. },
  915. clickImg(src) {
  916. uni.previewImage({
  917. current: 0,
  918. urls: [src]
  919. });
  920. },
  921. },
  922. computed: {
  923. ...mapState({
  924. gConfig: state => state.gConfig,
  925. }),
  926. attrPic() {
  927. if (this.pic_url) {
  928. return this.pic_url;
  929. } else if (this.goods) {
  930. return this.goods.cover_pic;
  931. } else {
  932. return ``;
  933. }
  934. },
  935. priceColor() {
  936. if (this.goods && this.goods.level_show === 1) {
  937. return `member`;
  938. } else {
  939. return this.theme + '-color';
  940. }
  941. },
  942. attrNum() {
  943. if (this.selectAttr) {
  944. return this.selectAttr.stock;
  945. } else if (this.goods) {
  946. return this.goods.goods_num;
  947. } else {
  948. return 0;
  949. }
  950. },
  951. attrPrice() {
  952. if (this.selectAttr) {
  953. let price;
  954. if (this.goods.level_show === 1) {
  955. price = this.selectAttr.price_member
  956. } else {
  957. price = this.selectAttr.price;
  958. }
  959. if (this.sign == 'wholesale') {
  960. if (this.selectAttr.number == 0) {
  961. return 'undefined'
  962. }
  963. if (this.wholesaleType == 0) {
  964. price = (price * (this.discount / 10)).toFixed(2);
  965. return price
  966. } else {
  967. price = (price - this.discount).toFixed(2);
  968. return price
  969. }
  970. } else {
  971. return price
  972. }
  973. } else if (this.sign == 'wholesale') {
  974. return 'undefined';
  975. } else if (this.goods) {
  976. if (this.goods.hasOwnProperty('price_min')) {
  977. return this.goods.price_min;
  978. } else {
  979. return this.goods.price;
  980. }
  981. } else {
  982. return 0;
  983. }
  984. },
  985. newData() {
  986. const {
  987. number,
  988. display,
  989. selectAttr
  990. } = this;
  991. return {
  992. number,
  993. display,
  994. selectAttr
  995. }
  996. },
  997. themeObject: function() {
  998. return {
  999. back: this.theme + '-m-back ' + this.theme,
  1000. theme: this.theme,
  1001. color: this.theme + '-m-text ' + this.theme,
  1002. sBack: this.theme + '-s-back ' + this.theme
  1003. }
  1004. },
  1005. ...mapGetters('iPhoneX', {
  1006. boolEmpty: 'getBoolEmpty'
  1007. })
  1008. }
  1009. }
  1010. </script>
  1011. <style scoped lang="scss">
  1012. .app-attr {
  1013. background-color: #ffffff;
  1014. .modal {
  1015. background-color: rgba(0, 0, 0, 0.5);
  1016. position: fixed;
  1017. top: 0;
  1018. left: 0;
  1019. width: 100%;
  1020. height: 100%;
  1021. z-index: 1603;
  1022. }
  1023. .content {
  1024. width: 100%;
  1025. background-color: #ffffff;
  1026. border-radius: #{16rpx} #{16rpx} 0 0;
  1027. .close {
  1028. width: #{30rpx};
  1029. height: #{30rpx};
  1030. position: absolute;
  1031. right: #{24rpx};
  1032. top: #{24rpx};
  1033. background-color: #ffffff;
  1034. }
  1035. .first {
  1036. margin: 0 #{24rpx};
  1037. border-bottom: #{1rpx} solid #e2e2e2;
  1038. &.no-border {
  1039. border-bottom: 0;
  1040. }
  1041. .img {
  1042. width: #{200rpx};
  1043. height: #{200rpx};
  1044. border: #{4rpx} solid #ffffff;
  1045. border-radius: #{8rpx};
  1046. margin-top: #{-64rpx};
  1047. display: block;
  1048. }
  1049. .info {
  1050. margin: #{36rpx} 0 #{26rpx} #{24rpx};
  1051. font-size: $uni-font-size-import-two;
  1052. line-height: 1;
  1053. .stock {
  1054. font-size: $uni-font-size-weak-one;
  1055. color: $uni-general-color-two;
  1056. margin-top: #{18rpx};
  1057. }
  1058. view {
  1059. &:first-child {
  1060. margin-right: #{12rpx};
  1061. }
  1062. }
  1063. .member {
  1064. color: #f39800;
  1065. }
  1066. }
  1067. }
  1068. .second {
  1069. max-height: #{650rpx};
  1070. overflow-y: auto;
  1071. overflow-x: hidden;
  1072. padding: #{4rpx} #{24rpx};
  1073. font-size: $uni-font-size-general-two;
  1074. &.no-padding {
  1075. padding: 0;
  1076. }
  1077. .attr-group {
  1078. padding: #{32rpx} 0;
  1079. border-bottom: #{1rpx} solid #e2e2e2;
  1080. .attr-group-name {
  1081. color: $uni-general-color-one;
  1082. margin-bottom: #{20rpx};
  1083. }
  1084. .attr-item {
  1085. margin-right: #{20rpx};
  1086. padding: #{15rpx 24rpx};
  1087. border-radius: #{8rpx};
  1088. margin-bottom: #{20rpx};
  1089. &.attr-item-default {
  1090. background-color: #f2f2f2;
  1091. color: $uni-important-color-black;
  1092. }
  1093. &.active {
  1094. color: #ffffff;
  1095. }
  1096. &.attr_num_0 {
  1097. color: #cdcdcd;
  1098. background-color: #f7f7f7;
  1099. }
  1100. }
  1101. }
  1102. .number-box {
  1103. color: $uni-general-color-one;
  1104. height: #{100rpx};
  1105. .block {
  1106. width: #{60rpx};
  1107. height: #{60rpx};
  1108. margin: 0 #{4rpx};
  1109. &.disabled {
  1110. background-color: #fbfbfb;
  1111. color: $uni-general-color-two;
  1112. }
  1113. }
  1114. .number-input {
  1115. width: #{88rpx};
  1116. height: #{60rpx};
  1117. color: $uni-important-color-black;
  1118. font-size: $uni-font-size-general-one;
  1119. background-color: $uni-weak-color-two;
  1120. }
  1121. }
  1122. }
  1123. .three {
  1124. height: #{110rpx};
  1125. width: 100%;
  1126. font-size: $uni-font-size-general-one;
  1127. }
  1128. }
  1129. }
  1130. .buy {
  1131. color: #ffffff;
  1132. }
  1133. .wholesale {
  1134. .wholesale-attr-list {
  1135. height: 88rpx;
  1136. margin: 0 24rpx;
  1137. border-bottom: 1rpx solid #e2e2e2;
  1138. position: relative;
  1139. &:first-of-type {
  1140. border-top: 1rpx solid #e2e2e2;
  1141. }
  1142. .wholesale-attr-group {
  1143. max-width: 200rpx;
  1144. flex-shrink: 0;
  1145. margin-right: 4rpx;
  1146. font-size: 20rpx;
  1147. color: #666666;
  1148. }
  1149. .right-icon {
  1150. position: absolute;
  1151. right: -24rpx;
  1152. top: 0;
  1153. height: 84rpx;
  1154. padding-left: 10rpx;
  1155. width: 50rpx;
  1156. z-index: 10000;
  1157. background-color: #fff;
  1158. view {
  1159. height: 40rpx;
  1160. width: 3rpx;
  1161. background-color: #e2e2e2;
  1162. position: absolute;
  1163. left: 0;
  1164. top: 24rpx;
  1165. }
  1166. image {
  1167. margin-top: 33rpx;
  1168. height: 22rpx;
  1169. width: 16rpx;
  1170. }
  1171. }
  1172. .wholesale-attr-item {
  1173. height: 100%;
  1174. white-space: nowrap;
  1175. .attr-name {
  1176. margin-top: 16rpx;
  1177. color: #fff;
  1178. padding: 0 22rpx;
  1179. height: 56rpx;
  1180. line-height: 56rpx;
  1181. border-radius: 8rpx;
  1182. font-size: 26rpx;
  1183. margin-left: 20rpx;
  1184. display: inline-block;
  1185. position: relative;
  1186. .attr-number {
  1187. color: #fff;
  1188. position: absolute;
  1189. top: -15rpx;
  1190. height: 30rpx;
  1191. line-height: 26rpx;
  1192. border: 2rpx solid #fff;
  1193. padding: 0 10rpx;
  1194. border-radius: 15rpx;
  1195. font-size: 20rpx;
  1196. z-index: 100;
  1197. }
  1198. &.attr-background {
  1199. background-color: #f2f2f2;
  1200. color: #353535;
  1201. }
  1202. }
  1203. }
  1204. }
  1205. .wholesale-attr-group-list {
  1206. margin-top: 20rpx;
  1207. .wholesale-attr-group {
  1208. margin-bottom: 20rpx;
  1209. .wholesale-attr-item {
  1210. padding: 20rpx;
  1211. background-color: #f7f7f7;
  1212. width: 100%;
  1213. .attr-name {
  1214. width: 60%;
  1215. .attr-price {
  1216. color: #999999;
  1217. font-size: 24rpx;
  1218. }
  1219. }
  1220. .wholesale-number-box {
  1221. color: $uni-general-color-one;
  1222. .block {
  1223. width: #{60rpx};
  1224. height: #{60rpx};
  1225. margin: 0 #{4rpx};
  1226. &.disabled {
  1227. background-color: #fbfbfb;
  1228. color: $uni-general-color-two;
  1229. }
  1230. }
  1231. .wholesale-number-input {
  1232. width: #{88rpx};
  1233. height: #{60rpx};
  1234. color: $uni-important-color-black;
  1235. font-size: $uni-font-size-general-one;
  1236. background-color: #fff;
  1237. }
  1238. }
  1239. }
  1240. }
  1241. }
  1242. }
  1243. .total {
  1244. width: 100%;
  1245. height: 80rpx;
  1246. line-height: 80rpx;
  1247. text-align: right;
  1248. padding: 0 24rpx;
  1249. color: #353535;
  1250. font-size: 28rpx;
  1251. border-top: 1rpx solid #e2e2e2;
  1252. text {
  1253. color: #ff4544;
  1254. }
  1255. }
  1256. .u-attr-fixed {
  1257. position: fixed;
  1258. bottom: 0;
  1259. left: 0;
  1260. width: 100%;
  1261. background-color: #ffffff;
  1262. }
  1263. .service {
  1264. margin-bottom: 20rpx;
  1265. }
  1266. .service_title {
  1267. padding-top: 10px;
  1268. // margin: 14px 10px 10px;
  1269. font-weight: 700;
  1270. font-size: 13px;
  1271. }
  1272. .service_item {
  1273. margin: 14px 0px 0px;
  1274. font-size: 26rpx;
  1275. color: #666;
  1276. display: flex;
  1277. justify-content: space-between;
  1278. }
  1279. .service_value {
  1280. display: flex;
  1281. flex-wrap: wrap;
  1282. padding: 0px 10px;
  1283. }
  1284. .service_block {
  1285. min-width: 46%;
  1286. height: 28px;
  1287. line-height: 26px;
  1288. border: 1px solid #f5f5f5;
  1289. border-radius: 16px;
  1290. text-align: center;
  1291. margin-right: 10px;
  1292. margin-top: 10px;
  1293. font-size: 12px;
  1294. background-color: #f5f5f5;
  1295. position: relative;
  1296. }
  1297. .service_block_active {
  1298. color: #f21c1c;
  1299. border: 1px solid #f21c1c;
  1300. }
  1301. .slh {
  1302. margin-left: 5upx;
  1303. overflow: hidden;
  1304. text-overflow: ellipsis;
  1305. width: 460upx;
  1306. white-space: nowrap;
  1307. float: left;
  1308. /* display: -webkit-box;
  1309. -webkit-line-clamp: 1;
  1310. -webkit-box-orient: vertical; */
  1311. }
  1312. </style>