cart.vue 55 KB

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