cart.vue 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951
  1. <template>
  2. <app-layout :overflow='false'>
  3. <view class="app-cart">
  4. <view class="app-announcement dir-left-nowrap main-between cross-center">
  5. <text class="app-announcement-text">商品库存有限,请尽快下单</text>
  6. <app-form-id @click="editSwitch">
  7. <text class="app-edit-text">{{editStatus ? '完成' : '编辑'}}</text>
  8. </app-form-id>
  9. </view>
  10. <view class="app-item" v-for="(mch, index) in listObj" :key="index" v-if="listObj.length > 0">
  11. <app-shop-product :theme="getTheme" @change="change" @update="update" :mch="mch" :editStatus="editStatus" @changeSingleRadio="changeSingleRadio" @changeRadioAll="changeRadioAll" ></app-shop-product>
  12. </view>
  13. <view class="no-cart" v-if="listObj.length === 0">
  14. <view class="cart-icon">
  15. <image class="cart-image" src="../../static/image/icon/nav-icon-cart.png"></image>
  16. </view>
  17. <view class="cart-text">购物车还是空的哦</view>
  18. </view>
  19. <view>
  20. <app-empty-bottom backgroundColor="#f7f7f7" :botBool="botBool" :height="Number(100)"></app-empty-bottom>
  21. </view>
  22. <view v-if="!tabbarbool" :style="{background: 'white', position: 'fixed', bottom: 0, height: `${getEmpty}rpx`, width: '750rpx'}"></view>
  23. <view class="safe-area-inset-bottom bd-fixed-bottom">
  24. <view class="app-settlement dir-left-nowrap main-between cross-center" :style="{bottom: `${tabbarbool ? BotHeight : getEmpty}rpx`}">
  25. <view class="app-radio dir-left-nowrap main-right cross-center">
  26. <app-radio type="round" :theme="getTheme" @click="setALl" v-model="all"></app-radio>
  27. <text class="app-all-text">全选</text>
  28. <text class="app-price" v-if="!editStatus" :class="getTheme + '-m-text ' + getTheme">总计: ¥{{priceNum}}</text>
  29. </view>
  30. <button :disabled="submitDis" :class="submitDis ? 'delete-disabled' : getTheme + '-m-text ' + getTheme" class="app-delete" v-if="editStatus" @click="deleteProduct">
  31. 删除
  32. </button>
  33. <button :disabled="submitDis" :class="submitDis ? 'disabled-background' : getTheme + '-m-back ' + getTheme" class="app-settlement-button" v-else @click="settlement">
  34. 去结算
  35. </button>
  36. </view>
  37. <view v-if="tabbarbool" class="bd-bottom-height-0"></view>
  38. </view>
  39. </view>
  40. </app-layout>
  41. </template>
  42. <script>
  43. import { mapState, mapGetters } from 'vuex';
  44. import appShopProduct from './components/app-shop-product/app-shop-product.vue';
  45. import appRadio from '../../components/basic-component/app-radio/app-radio.vue';
  46. import appEmptyBottom from '../../components/basic-component/app-empty-bottom/app-empty-bottom.vue';
  47. export default {
  48. name: 'cart',
  49. components:{
  50. 'app-shop-product': appShopProduct,
  51. 'app-radio': appRadio,
  52. 'app-empty-bottom': appEmptyBottom,
  53. },
  54. data() {
  55. return {
  56. editStatus: false,
  57. listObj: [],
  58. all: false,
  59. editList: [],
  60. priceNum: 0,
  61. edit: false,
  62. botBool: true,
  63. currentRoute: this.$platDiff.route(),
  64. tabbarbool: false,
  65. spike: -1,
  66. submitDis: true
  67. }
  68. },
  69. computed:{
  70. ...mapState({
  71. tabBarHeight: (state) => {
  72. return state.gConfig.tabBarHeight;
  73. },
  74. iphoneHeight: (state) =>{
  75. return state.gConfig.iphoneHeight;
  76. },
  77. iphone: (state) => {
  78. return state.gConfig.iphone
  79. }
  80. }),
  81. ...mapGetters('iPhoneX', {
  82. BotHeight: 'getBotHeight',
  83. getEmpty: 'getEmpty',
  84. }),
  85. ...mapGetters('mallConfig', {
  86. getTheme: 'getTheme',
  87. }),
  88. ...mapState({
  89. tabBarNavs: state => state.mallConfig.navbar.navs,
  90. is_edit: state => state.cart.is_edit
  91. }),
  92. },
  93. methods: {
  94. update(good) {
  95. for(let idx in this.listObj) {
  96. for(let index in this.listObj[idx].goods_list) {
  97. if(this.listObj[idx].goods_list[index].sign == 'wholesale' && this.listObj[idx].goods_list[index].goods_id == good.goods_id) {
  98. this.listObj[idx].goods_list[index] = good;
  99. this.$set(this.listObj[idx].goods_list, index, good);
  100. this.$forceUpdate();
  101. }
  102. }
  103. }
  104. },
  105. setALl(data) {
  106. this.selectAll(data);
  107. },
  108. // 编辑
  109. editSwitch() {
  110. this.all = false;
  111. for (let i = 0; i < this.listObj.length; i++) {
  112. this.listObj[i].is_active = false;
  113. for (let j = 0; j < this.listObj[i].goods_list.length; j++) {
  114. this.listObj[i].goods_list[j].is_active = false;
  115. if(this.listObj[i].goods_list[j].sign === 'wholesale') {
  116. for(let attr of this.listObj[i].goods_list[j].attr_arr) {
  117. attr.is_active = false;
  118. }
  119. }
  120. }
  121. }
  122. this.editStatus = !this.editStatus;
  123. },
  124. async getProductList() {
  125. uni.showLoading({
  126. title: '加载中'
  127. });
  128. const res = await this.$request({
  129. url: this.$api.cart.list,
  130. method: 'get',
  131. });
  132. if (res.code === 0) {
  133. this.listObj = res.data.list;
  134. this.spikeTime(res.data.list);
  135. }
  136. uni.hideLoading();
  137. },
  138. // 商城全选
  139. changeRadioAll(data) {
  140. for (let i = 0; i < this.listObj.length; i++) {
  141. let {mch_id , goods_list } = this.listObj[i];
  142. if (data.mch_id === mch_id) {
  143. for (let j = 0; j < goods_list.length; j++) {
  144. if (!this.editStatus) {
  145. if (goods_list[j].new_status === 0) goods_list[j].is_active = !data.is_active;
  146. } else {
  147. goods_list[j].is_active = !data.is_active;
  148. }
  149. if(goods_list[j].sign === 'wholesale') {
  150. goods_list[j].choose_num = goods_list[j].is_active ? goods_list[j].attrs.num : 0;
  151. goods_list[j].discount = goods_list[j].is_active ? goods_list[j].attrs.discount : goods_list[j].plugin_data.discount_type == 1 ? 0 : 10;
  152. for(let attr of goods_list[j].attr_arr) {
  153. attr.is_active = goods_list[j].is_active;
  154. }
  155. }
  156. }
  157. this.listObj[i].is_active = !data.is_active;
  158. }
  159. }
  160. },
  161. // 单选
  162. changeSingleRadio(mch, item) {
  163. for (let i = 0; i < this.listObj.length; i++) {
  164. if (this.listObj[i].mch_id === mch.mch_id) {
  165. let goods_list_len = mch.goods_list.length;
  166. let active_num = 0;
  167. for (let j = 0; j < this.listObj[i].goods_list.length; j++) {
  168. if(this.listObj[i].goods_list[j].sign === 'wholesale') {
  169. this.listObj[i].goods_list[j].discount = this.listObj[i].goods_list[j].plugin_data.discount_type == 1 ? 0 : 10;
  170. if(item.goods_id) {
  171. if (item.id === this.listObj[i].goods_list[j].id) {
  172. this.listObj[i].goods_list[j].is_active = !this.listObj[i].goods_list[j].is_active;
  173. for(let attr of this.listObj[i].goods_list[j].attr_arr) {
  174. attr.is_active = this.listObj[i].goods_list[j].is_active
  175. }
  176. if(!this.editStatus) {
  177. this.listObj[i].goods_list[j].choose_num = this.listObj[i].goods_list[j].is_active ? this.listObj[i].goods_list[j].attrs.num : 0;
  178. this.listObj[i].goods_list[j].discount = this.listObj[i].goods_list[j].is_active ? this.listObj[i].goods_list[j].attrs.discount : this.listObj[i].goods_list[j].plugin_data.discount_type == 1 ? 0 : 10;
  179. }
  180. }
  181. }else {
  182. let choose = 0;
  183. this.listObj[i].goods_list[j].choose_num = 0;
  184. for(let attr of this.listObj[i].goods_list[j].attr_arr) {
  185. if (item.id === attr.id) {
  186. attr.is_active = !attr.is_active;
  187. }
  188. if(attr.is_active) {
  189. choose++;
  190. this.listObj[i].goods_list[j].choose_num += +attr.num;
  191. for(let rule of this.listObj[i].goods_list[j].plugin_data.discount_rules) {
  192. if(!(+this.listObj[i].goods_list[j].choose_num < +rule.num)) {
  193. this.listObj[i].goods_list[j].discount = rule.discount
  194. }
  195. }
  196. }
  197. }
  198. if(choose == this.listObj[i].goods_list[j].attr_arr.length) {
  199. this.listObj[i].goods_list[j].is_active = true;
  200. }else {
  201. this.listObj[i].goods_list[j].is_active = false;
  202. }
  203. }
  204. }else {
  205. if (item.id === this.listObj[i].goods_list[j].id) {
  206. this.listObj[i].goods_list[j].is_active = !this.listObj[i].goods_list[j].is_active;
  207. }
  208. }
  209. if (this.listObj[i].goods_list[j].is_active) {
  210. active_num++;
  211. }
  212. if (this.editStatus === false && this.listObj[i].goods_list[j].new_status !== 0) {
  213. goods_list_len --;
  214. }
  215. }
  216. if (goods_list_len === active_num) {
  217. this.listObj[i].is_active = true;
  218. } else {
  219. this.listObj[i].is_active = false;
  220. }
  221. }
  222. }
  223. },
  224. selectAll(bool) {
  225. this.listObj.map(item => {
  226. item.is_active = bool;
  227. item.goods_list.map(good => {
  228. if (this.editStatus === false) {
  229. if (item.new_status === 0 && good.new_status === 0) {
  230. good.is_active = bool;
  231. if(good.sign === 'wholesale') {
  232. good.choose_num = bool ? good.attrs.num : 0;
  233. good.discount = bool ? good.attrs.discount : good.plugin_data.discount_type == 1 ? 0 : 10;
  234. for(let attr of good.attr_arr) {
  235. attr.is_active = bool;
  236. }
  237. }
  238. }
  239. } else {
  240. good.is_active = bool;
  241. if(good.sign === 'wholesale') {
  242. good.choose_num = bool ? good.attrs.num : 0;
  243. good.discount = bool ? good.attrs.discount : good.plugin_data.discount_type == 1 ? 0 : 10;
  244. for(let attr of good.attr_arr) {
  245. attr.is_active = bool;
  246. }
  247. }
  248. }
  249. })
  250. });
  251. },
  252. // 结算
  253. settlement() {
  254. let all_product = [];
  255. let is_miaosha = false;
  256. for (let i = 0; i < this.listObj.length; i++) {
  257. let mch = {
  258. mch_id: this.listObj[i].mch_id,
  259. goods_list: [],
  260. };
  261. for (let j = 0; j < this.listObj[i].goods_list.length; j++) {
  262. let good = this.listObj[i].goods_list[j];
  263. console.log(good,">>>>>>>>>>>>>>>>>>>>>>")
  264. if (good.new_status === 0) {
  265. if(good.is_active) {
  266. if (good.sign === 'miaosha') is_miaosha = true;
  267. if(good.sign === 'wholesale') {
  268. for(let item of good.attr_arr) {
  269. if(item.num > 0 && item.is_active) {
  270. let product = {
  271. id: item.attr_info.goods_id,
  272. attr: [],
  273. num: item.num,
  274. cart_id: item.id,
  275. goods_attr_id: item.attr_id
  276. }
  277. for(let attr of item.attrs.attr) {
  278. let para = {
  279. attr_id: attr.attr_id,
  280. attr_group_id: attr.attr_group_id
  281. }
  282. product.attr.push(para)
  283. }
  284. mch.goods_list.push(product);
  285. }
  286. }
  287. }else {
  288. let product = {
  289. id: good.goods_id,
  290. attr: [
  291. ],
  292. num: good.num,
  293. cart_id: good.id,
  294. goods_attr_id: good.attr_id,
  295. service_label:good.attrs.service_label
  296. };
  297. for (let n in good.attrs.attr) {
  298. let attr = {
  299. attr_id: good.attrs.attr[n].attr_id,
  300. attr_group_id: good.attrs.attr[n].attr_group_id,
  301. };
  302. product.attr.push(attr);
  303. }
  304. mch.goods_list.push(product);
  305. }
  306. }else {
  307. if(good.sign === 'wholesale') {
  308. for(let item of good.attr_arr) {
  309. if(item.num > 0 && item.is_active) {
  310. let product = {
  311. id: item.attr_info.goods_id,
  312. attr: [],
  313. num: item.num,
  314. cart_id: item.id,
  315. goods_attr_id: item.attr_id
  316. }
  317. for(let attr of item.attrs.attr) {
  318. let para = {
  319. attr_id: attr.attr_id,
  320. attr_group_id: attr.attr_group_id
  321. }
  322. product.attr.push(para)
  323. }
  324. mch.goods_list.push(product);
  325. }
  326. }
  327. }
  328. }
  329. }
  330. }
  331. if (mch.goods_list.length > 0) {
  332. all_product.push(mch);
  333. }
  334. }
  335. let jump_url = `/pages/order-submit/order-submit?mch_list=${JSON.stringify(all_product)}`;
  336. if (is_miaosha) {
  337. jump_url += `&preview_url=${encodeURIComponent(this.$api.miaosha.order_preview)}&submit_url=${encodeURIComponent(this.$api.miaosha.order_submit)}`;
  338. }
  339. this.$jump({
  340. open_type: 'navigate',
  341. url: jump_url,
  342. });
  343. setTimeout(()=> {
  344. this.listObj = [];
  345. }, 1000);
  346. },
  347. editNum() {
  348. let editList = [];
  349. for (let i = 0; i < this.listObj.length; i++) {
  350. let goods = this.listObj[i].goods_list;
  351. for (let j = 0; j < goods.length; j++) {
  352. if (goods[j].new_status === 0) {
  353. if(goods[j].sign === 'wholesale') {
  354. for(let attr of goods[j].attr_arr) {
  355. editList.push({
  356. goods_id: attr.attr_info.goods_id,
  357. num: attr.num,
  358. attr: attr.attr_id,
  359. })
  360. }
  361. }else {
  362. editList.push({
  363. goods_id: goods[j].goods_id,
  364. num: goods[j].num,
  365. attr: goods[j].attr_id,
  366. })
  367. }
  368. }
  369. }
  370. }
  371. this.$request({
  372. method: 'post',
  373. url: this.$api.cart.edit,
  374. data: {
  375. list: JSON.stringify(editList)
  376. }
  377. }).then(() => {
  378. this.$store.dispatch('cart/is_edit', false);
  379. })
  380. },
  381. // 删除商品
  382. async deleteProduct() {
  383. let product_list = [];
  384. for (let i = 0 ; i < this.listObj.length; i++) {
  385. let goods = this.listObj[i].goods_list;
  386. for (let j = 0 ; j < goods.length; j++) {
  387. if (goods[j].is_active) {
  388. if(goods[j].sign == 'wholesale') {
  389. for(let item of goods[j].attr_arr) {
  390. product_list.push({
  391. mch_id: goods[j].mch_id,
  392. id: item.id,
  393. })
  394. }
  395. }else {
  396. product_list.push({
  397. mch_id: goods[j].mch_id,
  398. id: goods[j].id,
  399. })
  400. }
  401. }else {
  402. if(goods[j].sign == 'wholesale') {
  403. for(let item of goods[j].attr_arr) {
  404. if(item.is_active) {
  405. product_list.push({
  406. mch_id: goods[j].mch_id,
  407. id: item.id,
  408. })
  409. }
  410. }
  411. }
  412. }
  413. }
  414. }
  415. if (!product_list.length) return;
  416. const res = await this.$request({
  417. method: 'post',
  418. url: this.$api.cart.delete,
  419. data: {
  420. cart_id_list: JSON.stringify(product_list),
  421. }
  422. });
  423. if (res.code === 0) {
  424. this.editStatus = false;
  425. for (let j = 0; j < this.listObj.length; j++) {
  426. for (let i = 0; i < product_list.length; i++) {
  427. if (this.listObj[j].mch_id == product_list[i].mch_id) {
  428. for (let k = 0; k < this.listObj[j].goods_list.length; k++) {
  429. if(this.listObj[j].goods_list[k].sign === 'wholesale') {
  430. for(let index in this.listObj[j].goods_list[k].attr_arr) {
  431. if (this.listObj[j].goods_list[k].attr_arr[index].id == product_list[i].id) {
  432. this.$delete(this.listObj[j].goods_list[k].attr_arr, index);
  433. if(this.listObj[j].goods_list[k].attr_arr.length == 0) {
  434. this.$delete(this.listObj[j].goods_list, k);
  435. }
  436. }
  437. }
  438. this.count();
  439. }else {
  440. if (this.listObj[j].goods_list[k].id == product_list[i].id) {
  441. this.$delete(this.listObj[j].goods_list, k);
  442. }
  443. }
  444. }
  445. if (this.listObj[j].goods_list.length === 0) {
  446. this.$delete(this.listObj, j);
  447. }
  448. }
  449. }
  450. }
  451. }
  452. },
  453. b() {
  454. let currentRoute = this.currentRoute;
  455. for (let i = 0; i < this.tabBarNavs.length; i++) {
  456. if(currentRoute.includes(this.tabBarNavs[i].url.split('?')[0])) {
  457. return this.tabbarbool = true;
  458. }
  459. }
  460. return this.tabbarbool = false;
  461. },
  462. change(number, id, mch_id) {
  463. for (let i = 0; i < this.listObj.length; i++) {
  464. if (this.listObj[i].mch_id === mch_id) {
  465. for (let j = 0; j < this.listObj[i].goods_list.length; j++) {
  466. if(this.listObj[i].goods_list[j].sign === 'wholesale' && this.listObj[i].goods_list[j].new_status != 3) {
  467. for (let x = 0; x < this.listObj[i].goods_list[j].attr_arr.length; x++) {
  468. if (this.listObj[i].goods_list[j].attr_arr[x].id == id) {
  469. this.listObj[i].goods_list[j].attr_arr[x].num = Number(number);
  470. this.count();
  471. return;
  472. }
  473. }
  474. }else {
  475. if (this.listObj[i].goods_list[j].id === id) {
  476. this.listObj[i].goods_list[j].num = Number(number);
  477. return;
  478. }
  479. }
  480. }
  481. }
  482. }
  483. },
  484. count() {
  485. let that = this;
  486. for(let item of that.listObj) {
  487. for(let goods of item.goods_list) {
  488. goods.price = 0;
  489. if(goods.sign === 'wholesale' && (goods.new_status == 0 || goods.new_status == 6)) {
  490. if(goods.plugin_data.discount_type == 0) {
  491. goods.attrs.discount = 10
  492. }else {
  493. goods.attrs.discount = 0;
  494. }
  495. goods.attrs.num = 0;
  496. let price = 0;
  497. goods.choose_num = 0;
  498. for(let attr of goods.attr_arr) {
  499. price += (+attr.num * +attr.attrs.price)
  500. goods.attrs.num += +attr.num
  501. if(attr.is_active) {
  502. goods.choose_num += +attr.num
  503. }
  504. }
  505. let chooseNum = 0;
  506. for(let item of goods.attr_arr) {
  507. if(item.is_active) {
  508. chooseNum += +item.num
  509. }
  510. }
  511. for(let i of goods.plugin_data.discount_rules) {
  512. if(!(+goods.attrs.num < +i.num)) {
  513. goods.attrs.discount = i.discount
  514. }
  515. if(!(+chooseNum < +i.num)) {
  516. goods.discount = i.discount
  517. }
  518. }
  519. if(goods.plugin_data.discount_type == 0) {
  520. goods.price = (price*(goods.attrs.discount/10)).toFixed(2);
  521. }else {
  522. goods.price = (price - (goods.attrs.discount*goods.attrs.num)).toFixed(2);
  523. }
  524. if(goods.attrs.num < goods.plugin_data.up_num) {
  525. goods.new_status = 6;
  526. }else {
  527. goods.new_status = 0;
  528. }
  529. }
  530. }
  531. }
  532. },
  533. setTime(data) {
  534. let is_spike = false;
  535. for (let i = 0; i < data.length; i++) {
  536. for (let j = 0; j < data[i].goods_list.length; j++) {
  537. if (data[i].goods_list[j].sign === 'miaosha' && data[i].goods_list[j].miaosha_status === 1) {
  538. is_spike = true;
  539. data[i].goods_list[j].miaosha_time--;
  540. let second = parseInt(data[i].goods_list[j].miaosha_time);
  541. let minute = 0;
  542. let hour = 0;
  543. if (second > 60) {
  544. minute = parseInt(second / 60);
  545. second = parseInt(second % 60);
  546. if (minute > 60) {
  547. hour = parseInt(minute / 60);
  548. minute = parseInt(minute % 60);
  549. }
  550. }
  551. let timeDaily = {
  552. h: hour < 10 ? ('0' + hour) : hour,
  553. m: minute < 10 ? ('0' + minute) : minute,
  554. s: second < 10 ? ('0' + second) : second,
  555. };
  556. this.$set(this.listObj[i].goods_list[j], 'miaosha_string', `${timeDaily.h + ':' + timeDaily.m + ':' + timeDaily.s}`);
  557. }
  558. if (data[i].goods_list[j].sign === 'flash_sale' && (data[i].goods_list[j].flash_sale_status === 1 || data[i].goods_list[j].flash_sale_status === 2)) {
  559. is_spike = true;
  560. data[i].goods_list[j].flash_sale_time--;
  561. let second = parseInt(data[i].goods_list[j].flash_sale_time);
  562. let minute = 0;
  563. let hour = 0;
  564. if (second > 60) {
  565. minute = parseInt(second / 60);
  566. second = parseInt(second % 60);
  567. if (minute > 60) {
  568. hour = parseInt(minute / 60);
  569. minute = parseInt(minute % 60);
  570. }
  571. }
  572. let timeDaily = {
  573. h: hour < 10 ? ('0' + hour) : hour,
  574. m: minute < 10 ? ('0' + minute) : minute,
  575. s: second < 10 ? ('0' + second) : second,
  576. };
  577. this.$set(this.listObj[i].goods_list[j], 'flash_sale_string', `${timeDaily.h + ':' + timeDaily.m + ':' + timeDaily.s}`);
  578. }
  579. }
  580. }
  581. return is_spike;
  582. },
  583. spikeTime(data) {
  584. clearInterval(this.spike);
  585. let is_spike = this.setTime(data);
  586. if (!is_spike) return;
  587. this.spike = setInterval(() => {
  588. let is_spike = this.setTime(data);
  589. if (!is_spike) {
  590. clearInterval(this.spike);
  591. }
  592. }, 1000);
  593. }
  594. },
  595. onShow() {
  596. this.submitDis = true;
  597. this.listObj = [];
  598. setTimeout(() => {
  599. this.getProductList();
  600. }, 1000);
  601. this.all = false;
  602. },
  603. onHide() {
  604. this.editNum();
  605. clearInterval(this.spike);
  606. },
  607. onUnload() {
  608. this.editNum();
  609. clearInterval(this.spike);
  610. },
  611. watch:{
  612. listObj: {
  613. handler(listObj) {
  614. this.priceNum = 0;
  615. let listNum = 0;
  616. let activeIndex = 0;
  617. let check = true;
  618. for (let i = 0; i < listObj.length; i++) {
  619. if(listObj[i].new_status == 0) {
  620. listNum += listObj[i].goods_list.length;
  621. let status = listObj[i].goods_list.length;
  622. let newStatus = 0;
  623. for (let j = 0; j < listObj[i].goods_list.length;j++) {
  624. if (listObj[i].goods_list[j].new_status !== 0) {
  625. newStatus++;
  626. }
  627. if (this.editStatus === false && listObj[i].goods_list[j].new_status !== 0) {
  628. listNum --;
  629. }
  630. if (listObj[i].goods_list[j].is_active) {
  631. if(listObj[i].goods_list[j].sign === 'wholesale') {
  632. listNum += listObj[i].goods_list[j].attr_arr.length - 1;
  633. for(let item of listObj[i].goods_list[j].attr_arr) {
  634. if (!this.editStatus) {
  635. if(listObj[i].goods_list[j].plugin_data.discount_type == 0) {
  636. let discount = listObj[i].goods_list[j].discount ? listObj[i].goods_list[j].discount : 10;
  637. item.price = (+item.attrs.price*(+discount/10)).toFixed(2);
  638. }else {
  639. let discount = listObj[i].goods_list[j].discount ? listObj[i].goods_list[j].discount : 0;
  640. item.price = (+item.attrs.price - +discount).toFixed(2);
  641. }
  642. }
  643. if(item.is_active) {
  644. if (!this.editStatus) {
  645. let num = Number(item.price) * Number(item.num);
  646. this.priceNum += num;
  647. if(!(listObj[i].goods_list[j].choose_num < listObj[i].goods_list[j].plugin_data.up_num)) {
  648. activeIndex++;
  649. }
  650. }else {
  651. activeIndex++;
  652. }
  653. }
  654. }
  655. }else {
  656. if (!this.editStatus) {
  657. let num = Number(listObj[i].goods_list[j].attrs.price) * Number(listObj[i].goods_list[j].num);
  658. this.priceNum += num;
  659. }
  660. activeIndex++;
  661. }
  662. }else {
  663. if(listObj[i].goods_list[j].sign === 'wholesale' && listObj[i].goods_list[j].new_status !== 3) {
  664. listNum += listObj[i].goods_list[j].attr_arr.length - 1;
  665. for(let item of listObj[i].goods_list[j].attr_arr) {
  666. if(listObj[i].goods_list[j].plugin_data.discount_type == 0) {
  667. let discount = listObj[i].goods_list[j].discount ? listObj[i].goods_list[j].discount : 10;
  668. item.price = (+item.attrs.price*(+discount/10)).toFixed(2);
  669. }else {
  670. let discount = listObj[i].goods_list[j].discount ? listObj[i].goods_list[j].discount : 0;
  671. item.price = (+item.attrs.price - +discount).toFixed(2);
  672. }
  673. if(item.is_active) {
  674. if (!this.editStatus) {
  675. let num = Number(item.price) * Number(item.num);
  676. this.priceNum += num;
  677. if(!(listObj[i].goods_list[j].choose_num < listObj[i].goods_list[j].plugin_data.up_num)) {
  678. activeIndex++;
  679. }else {
  680. check = false;
  681. }
  682. }else {
  683. activeIndex++;
  684. }
  685. }
  686. }
  687. }
  688. }
  689. }
  690. if (status === newStatus) {
  691. this.listObj[i].new_status = this.listObj[i].new_status == 0 ? 1 : this.listObj[i].new_status;
  692. }
  693. }
  694. }
  695. if (activeIndex === listNum) {
  696. if (listNum === 0 && activeIndex === 0) {
  697. this.all = false;
  698. } else {
  699. this.all = true;
  700. }
  701. } else {
  702. this.all = false;
  703. }
  704. if (activeIndex > 0 && check) {
  705. this.submitDis = false;
  706. } else {
  707. this.submitDis = true;
  708. }
  709. this.priceNum = this.priceNum.toFixed(2);
  710. },
  711. deep: true,
  712. },
  713. tabBarNavs: {
  714. handler: function() {
  715. this.b();
  716. },
  717. immediate: true,
  718. }
  719. }
  720. }
  721. </script>
  722. <style lang="scss" scoped>
  723. .bd-fixed-bottom {
  724. width: 100%;
  725. z-index: 1500;
  726. position: fixed;
  727. left: 0;
  728. bottom: 0;
  729. }
  730. .safe-area-inset-bottom {
  731. padding-bottom: 0;
  732. padding-bottom: constant(safe-area-inset-bottom);
  733. padding-bottom: env(safe-area-inset-bottom);
  734. }
  735. .bd-bottom-height-0 {
  736. width:100%;
  737. height: 110upx;
  738. }
  739. .app-cart {
  740. background-color: #f7f7f7;
  741. position: absolute;
  742. top: 0;
  743. left: 0;
  744. width: #{750rpx};
  745. .app-announcement {
  746. width: 100%;
  747. height: #{72rpx};
  748. background-color: #ffffff;
  749. .app-announcement-text {
  750. font-size: #{26rpx};
  751. color: #999999;
  752. margin-left: #{24rpx};
  753. }
  754. .app-edit-text {
  755. font-size: #{26rpx};
  756. color: #353535;
  757. margin-right: #{32rpx};
  758. }
  759. }
  760. .app-settlement {
  761. width: 100%;
  762. height: #{110rpx};
  763. border-top: #{1rpx} solid #e2e2e2;
  764. background-color: white;
  765. padding: 15upx 24upx;
  766. .app-radio {
  767. padding-left: #{23rpx};
  768. .app-price {
  769. margin-left: #{24rpx};
  770. font-size: #{28rpx};
  771. }
  772. }
  773. .app-all-text {
  774. margin-left: #{9rpx};
  775. font-size: #{25rpx};
  776. color: #3f3f3f;
  777. }
  778. .app-delete {
  779. width: #{140rpx};
  780. height: #{64rpx};
  781. line-height: #{64rpx};
  782. text-align: center;
  783. background-color: white;
  784. border-radius: #{32rpx};
  785. border: #{1rpx} solid ;
  786. font-size: #{28rpx};
  787. margin: #{0 24rpx 0 0};
  788. padding: 0;
  789. }
  790. .delete-disabled {
  791. color: #989898;
  792. border: #{1rpx} solid #989898;
  793. }
  794. .app-settlement-button {
  795. height: #{82rpx};
  796. width: #{250rpx};
  797. color: #ffffff;
  798. font-size: #{30rpx};
  799. line-height: #{82rpx};
  800. text-align: center;
  801. margin: 0;
  802. padding: 0;
  803. border-radius: 41upx;
  804. border: none;
  805. }
  806. }
  807. .no-cart {
  808. width: 100%;
  809. .cart-icon {
  810. width: #{160rpx};
  811. height: #{160rpx};
  812. border-radius: 50%;
  813. background-color: rgba(0, 0, 0, 0.1);
  814. margin: #{150rpx auto 40rpx};
  815. .cart-image {
  816. height: #{80rpx};
  817. width: #{80rpx};
  818. margin: #{40rpx};
  819. }
  820. }
  821. .cart-text {
  822. font-size: #{30rpx};
  823. color: #888;
  824. text-align: center;
  825. }
  826. }
  827. }
  828. .send-dialog {
  829. position: fixed;
  830. top: 0;
  831. left: 0;
  832. width: 100%;
  833. height: 100%;
  834. background-color: rgba(0,0,0,.3);
  835. z-index: 1700;
  836. .send-content {
  837. position: absolute;
  838. bottom: 0;
  839. left: 0;
  840. background-color: #fff;
  841. border-top-left-radius: 16rpx;
  842. border-top-right-radius: 16rpx;
  843. padding: 24rpx;
  844. .send-close {
  845. position: absolute;
  846. top: 24rpx;
  847. right: 24rpx;
  848. width: 30rpx;
  849. height: 30rpx;
  850. }
  851. .send-title {
  852. font-size: 32rpx;
  853. margin: 16rpx 0 36rpx;
  854. text-align: center;
  855. color: #000000;
  856. }
  857. .send-tip {
  858. font-size: 24rpx;
  859. color: #999999;
  860. }
  861. .send-type {
  862. margin-top: 32rpx;
  863. .send-type-name {
  864. height: 42rpx;
  865. font-size: 28rpx;
  866. color: #353535;
  867. image {
  868. width: 42rpx;
  869. height: 42rpx;
  870. margin-right: 18rpx;
  871. }
  872. }
  873. .send-type-item {
  874. margin-top: 15rpx;
  875. height: 226rpx;
  876. border-radius: 16rpx;
  877. background-color: #f2f2f2;
  878. padding: 20rpx;
  879. padding-left: 0;
  880. padding-bottom: 0;
  881. width: 702rpx;
  882. position: relative;
  883. .send-goods {
  884. white-space: nowrap;
  885. .send-goods-list {
  886. white-space: nowrap;
  887. margin-left: 0;
  888. }
  889. view {
  890. height: 110rpx;
  891. margin-left: 20rpx;
  892. display: inline-block;
  893. image {
  894. width: 110rpx;
  895. height: 110rpx;
  896. border-radius: 16rpx;
  897. }
  898. }
  899. }
  900. .send-count {
  901. height: 96rpx;
  902. line-height: 96rpx;
  903. width: 500rpx;
  904. font-size: 22rpx;
  905. color: #353535;
  906. position: absolute;
  907. bottom: 0;
  908. left: 30rpx;
  909. text {
  910. color: #ff4544;
  911. }
  912. }
  913. .send-count-btn {
  914. position: absolute;
  915. bottom: 22rpx;
  916. right: 28rpx;
  917. height: 54rpx;
  918. border-radius: 27rpx;
  919. width: 128rpx;
  920. text-align: center;
  921. line-height: 54rpx;
  922. background-color: #ff4544;
  923. color: #fff;
  924. font-size: 28rpx;
  925. }
  926. }
  927. }
  928. }
  929. }
  930. </style>