cart.vue 38 KB

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