cart.vue 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834
  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. if (good.new_status === 0) {
  261. if(good.is_active) {
  262. if (good.sign === 'miaosha') is_miaosha = true;
  263. if(good.sign === 'wholesale') {
  264. for(let item of good.attr_arr) {
  265. if(item.num > 0 && item.is_active) {
  266. let product = {
  267. id: item.attr_info.goods_id,
  268. attr: [],
  269. num: item.num,
  270. cart_id: item.id,
  271. goods_attr_id: item.attr_id
  272. }
  273. for(let attr of item.attrs.attr) {
  274. let para = {
  275. attr_id: attr.attr_id,
  276. attr_group_id: attr.attr_group_id
  277. }
  278. product.attr.push(para)
  279. }
  280. mch.goods_list.push(product);
  281. }
  282. }
  283. }else {
  284. let product = {
  285. id: good.goods_id,
  286. attr: [
  287. ],
  288. num: good.num,
  289. cart_id: good.id,
  290. goods_attr_id: good.attr_id,
  291. };
  292. for (let n in good.attrs.attr) {
  293. let attr = {
  294. attr_id: good.attrs.attr[n].attr_id,
  295. attr_group_id: good.attrs.attr[n].attr_group_id,
  296. };
  297. product.attr.push(attr);
  298. }
  299. mch.goods_list.push(product);
  300. }
  301. }else {
  302. if(good.sign === 'wholesale') {
  303. for(let item of good.attr_arr) {
  304. if(item.num > 0 && item.is_active) {
  305. let product = {
  306. id: item.attr_info.goods_id,
  307. attr: [],
  308. num: item.num,
  309. cart_id: item.id,
  310. goods_attr_id: item.attr_id
  311. }
  312. for(let attr of item.attrs.attr) {
  313. let para = {
  314. attr_id: attr.attr_id,
  315. attr_group_id: attr.attr_group_id
  316. }
  317. product.attr.push(para)
  318. }
  319. mch.goods_list.push(product);
  320. }
  321. }
  322. }
  323. }
  324. }
  325. }
  326. if (mch.goods_list.length > 0) {
  327. all_product.push(mch);
  328. }
  329. }
  330. let jump_url = `/pages/order-submit/order-submit?mch_list=${JSON.stringify(all_product)}`;
  331. if (is_miaosha) {
  332. jump_url += `&preview_url=${encodeURIComponent(this.$api.miaosha.order_preview)}&submit_url=${encodeURIComponent(this.$api.miaosha.order_submit)}`;
  333. }
  334. this.$jump({
  335. open_type: 'navigate',
  336. url: jump_url,
  337. });
  338. setTimeout(()=> {
  339. this.listObj = [];
  340. }, 1000);
  341. },
  342. editNum() {
  343. let editList = [];
  344. for (let i = 0; i < this.listObj.length; i++) {
  345. let goods = this.listObj[i].goods_list;
  346. for (let j = 0; j < goods.length; j++) {
  347. if (goods[j].new_status === 0) {
  348. if(goods[j].sign === 'wholesale') {
  349. for(let attr of goods[j].attr_arr) {
  350. editList.push({
  351. goods_id: attr.attr_info.goods_id,
  352. num: attr.num,
  353. attr: attr.attr_id,
  354. })
  355. }
  356. }else {
  357. editList.push({
  358. goods_id: goods[j].goods_id,
  359. num: goods[j].num,
  360. attr: goods[j].attr_id,
  361. })
  362. }
  363. }
  364. }
  365. }
  366. this.$request({
  367. method: 'post',
  368. url: this.$api.cart.edit,
  369. data: {
  370. list: JSON.stringify(editList)
  371. }
  372. }).then(() => {
  373. this.$store.dispatch('cart/is_edit', false);
  374. })
  375. },
  376. // 删除商品
  377. async deleteProduct() {
  378. let product_list = [];
  379. for (let i = 0 ; i < this.listObj.length; i++) {
  380. let goods = this.listObj[i].goods_list;
  381. for (let j = 0 ; j < goods.length; j++) {
  382. if (goods[j].is_active) {
  383. if(goods[j].sign == 'wholesale') {
  384. for(let item of goods[j].attr_arr) {
  385. product_list.push({
  386. mch_id: goods[j].mch_id,
  387. id: item.id,
  388. })
  389. }
  390. }else {
  391. product_list.push({
  392. mch_id: goods[j].mch_id,
  393. id: goods[j].id,
  394. })
  395. }
  396. }else {
  397. if(goods[j].sign == 'wholesale') {
  398. for(let item of goods[j].attr_arr) {
  399. if(item.is_active) {
  400. product_list.push({
  401. mch_id: goods[j].mch_id,
  402. id: item.id,
  403. })
  404. }
  405. }
  406. }
  407. }
  408. }
  409. }
  410. if (!product_list.length) return;
  411. const res = await this.$request({
  412. method: 'post',
  413. url: this.$api.cart.delete,
  414. data: {
  415. cart_id_list: JSON.stringify(product_list),
  416. }
  417. });
  418. if (res.code === 0) {
  419. this.editStatus = false;
  420. for (let j = 0; j < this.listObj.length; j++) {
  421. for (let i = 0; i < product_list.length; i++) {
  422. if (this.listObj[j].mch_id == product_list[i].mch_id) {
  423. for (let k = 0; k < this.listObj[j].goods_list.length; k++) {
  424. if(this.listObj[j].goods_list[k].sign === 'wholesale') {
  425. for(let index in this.listObj[j].goods_list[k].attr_arr) {
  426. if (this.listObj[j].goods_list[k].attr_arr[index].id == product_list[i].id) {
  427. this.$delete(this.listObj[j].goods_list[k].attr_arr, index);
  428. if(this.listObj[j].goods_list[k].attr_arr.length == 0) {
  429. this.$delete(this.listObj[j].goods_list, k);
  430. }
  431. }
  432. }
  433. this.count();
  434. }else {
  435. if (this.listObj[j].goods_list[k].id == product_list[i].id) {
  436. this.$delete(this.listObj[j].goods_list, k);
  437. }
  438. }
  439. }
  440. if (this.listObj[j].goods_list.length === 0) {
  441. this.$delete(this.listObj, j);
  442. }
  443. }
  444. }
  445. }
  446. }
  447. },
  448. b() {
  449. let currentRoute = this.currentRoute;
  450. for (let i = 0; i < this.tabBarNavs.length; i++) {
  451. if(currentRoute.includes(this.tabBarNavs[i].url.split('?')[0])) {
  452. return this.tabbarbool = true;
  453. }
  454. }
  455. return this.tabbarbool = false;
  456. },
  457. change(number, id, mch_id) {
  458. for (let i = 0; i < this.listObj.length; i++) {
  459. if (this.listObj[i].mch_id === mch_id) {
  460. for (let j = 0; j < this.listObj[i].goods_list.length; j++) {
  461. if(this.listObj[i].goods_list[j].sign === 'wholesale' && this.listObj[i].goods_list[j].new_status != 3) {
  462. for (let x = 0; x < this.listObj[i].goods_list[j].attr_arr.length; x++) {
  463. if (this.listObj[i].goods_list[j].attr_arr[x].id == id) {
  464. this.listObj[i].goods_list[j].attr_arr[x].num = Number(number);
  465. this.count();
  466. return;
  467. }
  468. }
  469. }else {
  470. if (this.listObj[i].goods_list[j].id === id) {
  471. this.listObj[i].goods_list[j].num = Number(number);
  472. return;
  473. }
  474. }
  475. }
  476. }
  477. }
  478. },
  479. count() {
  480. let that = this;
  481. for(let item of that.listObj) {
  482. for(let goods of item.goods_list) {
  483. goods.price = 0;
  484. if(goods.sign === 'wholesale' && (goods.new_status == 0 || goods.new_status == 6)) {
  485. if(goods.plugin_data.discount_type == 0) {
  486. goods.attrs.discount = 10
  487. }else {
  488. goods.attrs.discount = 0;
  489. }
  490. goods.attrs.num = 0;
  491. let price = 0;
  492. goods.choose_num = 0;
  493. for(let attr of goods.attr_arr) {
  494. price += (+attr.num * +attr.attrs.price)
  495. goods.attrs.num += +attr.num
  496. if(attr.is_active) {
  497. goods.choose_num += +attr.num
  498. }
  499. }
  500. let chooseNum = 0;
  501. for(let item of goods.attr_arr) {
  502. if(item.is_active) {
  503. chooseNum += +item.num
  504. }
  505. }
  506. for(let i of goods.plugin_data.discount_rules) {
  507. if(!(+goods.attrs.num < +i.num)) {
  508. goods.attrs.discount = i.discount
  509. }
  510. if(!(+chooseNum < +i.num)) {
  511. goods.discount = i.discount
  512. }
  513. }
  514. if(goods.plugin_data.discount_type == 0) {
  515. goods.price = (price*(goods.attrs.discount/10)).toFixed(2);
  516. }else {
  517. goods.price = (price - (goods.attrs.discount*goods.attrs.num)).toFixed(2);
  518. }
  519. if(goods.attrs.num < goods.plugin_data.up_num) {
  520. goods.new_status = 6;
  521. }else {
  522. goods.new_status = 0;
  523. }
  524. }
  525. }
  526. }
  527. },
  528. setTime(data) {
  529. let is_spike = false;
  530. for (let i = 0; i < data.length; i++) {
  531. for (let j = 0; j < data[i].goods_list.length; j++) {
  532. if (data[i].goods_list[j].sign === 'miaosha' && data[i].goods_list[j].miaosha_status === 1) {
  533. is_spike = true;
  534. data[i].goods_list[j].miaosha_time--;
  535. let second = parseInt(data[i].goods_list[j].miaosha_time);
  536. let minute = 0;
  537. let hour = 0;
  538. if (second > 60) {
  539. minute = parseInt(second / 60);
  540. second = parseInt(second % 60);
  541. if (minute > 60) {
  542. hour = parseInt(minute / 60);
  543. minute = parseInt(minute % 60);
  544. }
  545. }
  546. let timeDaily = {
  547. h: hour < 10 ? ('0' + hour) : hour,
  548. m: minute < 10 ? ('0' + minute) : minute,
  549. s: second < 10 ? ('0' + second) : second,
  550. };
  551. this.$set(this.listObj[i].goods_list[j], 'miaosha_string', `${timeDaily.h + ':' + timeDaily.m + ':' + timeDaily.s}`);
  552. }
  553. 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)) {
  554. is_spike = true;
  555. data[i].goods_list[j].flash_sale_time--;
  556. let second = parseInt(data[i].goods_list[j].flash_sale_time);
  557. let minute = 0;
  558. let hour = 0;
  559. if (second > 60) {
  560. minute = parseInt(second / 60);
  561. second = parseInt(second % 60);
  562. if (minute > 60) {
  563. hour = parseInt(minute / 60);
  564. minute = parseInt(minute % 60);
  565. }
  566. }
  567. let timeDaily = {
  568. h: hour < 10 ? ('0' + hour) : hour,
  569. m: minute < 10 ? ('0' + minute) : minute,
  570. s: second < 10 ? ('0' + second) : second,
  571. };
  572. this.$set(this.listObj[i].goods_list[j], 'flash_sale_string', `${timeDaily.h + ':' + timeDaily.m + ':' + timeDaily.s}`);
  573. }
  574. }
  575. }
  576. return is_spike;
  577. },
  578. spikeTime(data) {
  579. clearInterval(this.spike);
  580. let is_spike = this.setTime(data);
  581. if (!is_spike) return;
  582. this.spike = setInterval(() => {
  583. let is_spike = this.setTime(data);
  584. if (!is_spike) {
  585. clearInterval(this.spike);
  586. }
  587. }, 1000);
  588. }
  589. },
  590. onShow() {
  591. this.submitDis = true;
  592. this.listObj = [];
  593. setTimeout(() => {
  594. this.getProductList();
  595. }, 1000);
  596. this.all = false;
  597. },
  598. onHide() {
  599. this.editNum();
  600. clearInterval(this.spike);
  601. },
  602. onUnload() {
  603. this.editNum();
  604. clearInterval(this.spike);
  605. },
  606. watch:{
  607. listObj: {
  608. handler(listObj) {
  609. this.priceNum = 0;
  610. let listNum = 0;
  611. let activeIndex = 0;
  612. let check = true;
  613. for (let i = 0; i < listObj.length; i++) {
  614. if(listObj[i].new_status == 0) {
  615. listNum += listObj[i].goods_list.length;
  616. let status = listObj[i].goods_list.length;
  617. let newStatus = 0;
  618. for (let j = 0; j < listObj[i].goods_list.length;j++) {
  619. if (listObj[i].goods_list[j].new_status !== 0) {
  620. newStatus++;
  621. }
  622. if (this.editStatus === false && listObj[i].goods_list[j].new_status !== 0) {
  623. listNum --;
  624. }
  625. if (listObj[i].goods_list[j].is_active) {
  626. if(listObj[i].goods_list[j].sign === 'wholesale') {
  627. listNum += listObj[i].goods_list[j].attr_arr.length - 1;
  628. for(let item of listObj[i].goods_list[j].attr_arr) {
  629. if (!this.editStatus) {
  630. if(listObj[i].goods_list[j].plugin_data.discount_type == 0) {
  631. let discount = listObj[i].goods_list[j].discount ? listObj[i].goods_list[j].discount : 10;
  632. item.price = (+item.attrs.price*(+discount/10)).toFixed(2);
  633. }else {
  634. let discount = listObj[i].goods_list[j].discount ? listObj[i].goods_list[j].discount : 0;
  635. item.price = (+item.attrs.price - +discount).toFixed(2);
  636. }
  637. }
  638. if(item.is_active) {
  639. if (!this.editStatus) {
  640. let num = Number(item.price) * Number(item.num);
  641. this.priceNum += num;
  642. if(!(listObj[i].goods_list[j].choose_num < listObj[i].goods_list[j].plugin_data.up_num)) {
  643. activeIndex++;
  644. }
  645. }else {
  646. activeIndex++;
  647. }
  648. }
  649. }
  650. }else {
  651. if (!this.editStatus) {
  652. let num = Number(listObj[i].goods_list[j].attrs.price) * Number(listObj[i].goods_list[j].num);
  653. this.priceNum += num;
  654. }
  655. activeIndex++;
  656. }
  657. }else {
  658. if(listObj[i].goods_list[j].sign === 'wholesale' && listObj[i].goods_list[j].new_status !== 3) {
  659. listNum += listObj[i].goods_list[j].attr_arr.length - 1;
  660. for(let item of listObj[i].goods_list[j].attr_arr) {
  661. if(listObj[i].goods_list[j].plugin_data.discount_type == 0) {
  662. let discount = listObj[i].goods_list[j].discount ? listObj[i].goods_list[j].discount : 10;
  663. item.price = (+item.attrs.price*(+discount/10)).toFixed(2);
  664. }else {
  665. let discount = listObj[i].goods_list[j].discount ? listObj[i].goods_list[j].discount : 0;
  666. item.price = (+item.attrs.price - +discount).toFixed(2);
  667. }
  668. if(item.is_active) {
  669. if (!this.editStatus) {
  670. let num = Number(item.price) * Number(item.num);
  671. this.priceNum += num;
  672. if(!(listObj[i].goods_list[j].choose_num < listObj[i].goods_list[j].plugin_data.up_num)) {
  673. activeIndex++;
  674. }else {
  675. check = false;
  676. }
  677. }else {
  678. activeIndex++;
  679. }
  680. }
  681. }
  682. }
  683. }
  684. }
  685. if (status === newStatus) {
  686. this.listObj[i].new_status = this.listObj[i].new_status == 0 ? 1 : this.listObj[i].new_status;
  687. }
  688. }
  689. }
  690. if (activeIndex === listNum) {
  691. if (listNum === 0 && activeIndex === 0) {
  692. this.all = false;
  693. } else {
  694. this.all = true;
  695. }
  696. } else {
  697. this.all = false;
  698. }
  699. if (activeIndex > 0 && check) {
  700. this.submitDis = false;
  701. } else {
  702. this.submitDis = true;
  703. }
  704. this.priceNum = this.priceNum.toFixed(2);
  705. },
  706. deep: true,
  707. },
  708. tabBarNavs: {
  709. handler: function() {
  710. this.b();
  711. },
  712. immediate: true,
  713. }
  714. }
  715. }
  716. </script>
  717. <style lang="scss" scoped>
  718. .app-cart {
  719. background-color: #f7f7f7;
  720. position: absolute;
  721. top: 0;
  722. left: 0;
  723. width: #{750rpx};
  724. .app-announcement {
  725. width: 100%;
  726. height: #{72rpx};
  727. background-color: #ffffff;
  728. .app-announcement-text {
  729. font-size: #{26rpx};
  730. color: #999999;
  731. margin-left: #{24rpx};
  732. }
  733. .app-edit-text {
  734. font-size: #{26rpx};
  735. color: #353535;
  736. margin-right: #{32rpx};
  737. }
  738. }
  739. .app-settlement {
  740. width: 100%;
  741. height: #{100rpx};
  742. z-index: 1500;
  743. position: fixed;
  744. left: 0;
  745. border-top: #{1rpx} solid #e2e2e2;
  746. background-color: white;
  747. .app-radio {
  748. padding-left: #{23rpx};
  749. .app-price {
  750. margin-left: #{24rpx};
  751. font-size: #{28rpx};
  752. }
  753. }
  754. .app-all-text {
  755. margin-left: #{9rpx};
  756. font-size: #{25rpx};
  757. color: #3f3f3f;
  758. }
  759. .app-delete {
  760. width: #{140rpx};
  761. height: #{64rpx};
  762. line-height: #{64rpx};
  763. text-align: center;
  764. background-color: white;
  765. border-radius: #{32rpx};
  766. border: #{1rpx} solid ;
  767. font-size: #{28rpx};
  768. margin: #{0 24rpx 0 0};
  769. padding: 0;
  770. }
  771. .delete-disabled {
  772. color: #989898;
  773. border: #{1rpx} solid #989898;
  774. }
  775. .app-settlement-button {
  776. height: #{100rpx};
  777. width: #{250rpx};
  778. color: #ffffff;
  779. font-size: #{30rpx};
  780. line-height: #{100rpx};
  781. text-align: center;
  782. border-radius: 0;
  783. margin: 0;
  784. padding: 0;
  785. border: none;
  786. }
  787. .disabled-background {
  788. background-color: #989898;
  789. }
  790. }
  791. .no-cart {
  792. width: 100%;
  793. .cart-icon {
  794. width: #{160rpx};
  795. height: #{160rpx};
  796. border-radius: 50%;
  797. background-color: rgba(0, 0, 0, 0.1);
  798. margin: #{150rpx auto 40rpx};
  799. .cart-image {
  800. height: #{80rpx};
  801. width: #{80rpx};
  802. margin: #{40rpx};
  803. }
  804. }
  805. .cart-text {
  806. font-size: #{30rpx};
  807. color: #888;
  808. text-align: center;
  809. }
  810. }
  811. }
  812. </style>