pond.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. <template>
  2. <app-layout>
  3. <view class="pond">
  4. <view class="bulletin dir-left-nowrap">
  5. <text class="bulletin-text">结算规则:选购商品数等于任选商品数的倍数</text>
  6. <view class="edit" v-if="!edit" @click="setEdit(true)">编辑</view>
  7. <view class="edit" v-else @click="setEdit(false)">完成</view>
  8. </view>
  9. <view class="list">
  10. <view class="empty" v-if="pond.length === 0">
  11. <view class="cart">
  12. <image src="/static/image/icon/nav-icon-cart.png"></image>
  13. </view>
  14. <text>凑单池还是空的哦</text>
  15. </view>
  16. <view class="item dir-left-nowrap" v-for="(item) in pond" :key="item.id" v-else>
  17. <view class="radio dir-top-nowrap main-center cross-center" @click="changeActive(item)" v-if="item.pick_activity_id == pick_activity_id && !edit">
  18. <view class="radio-single" v-if="!item.is_active"></view>
  19. <view class="radio-single-active" v-else :class="getTheme + '-m-back ' + getTheme"></view>
  20. </view>
  21. <view class="radio dir-top-nowrap main-center cross-center" @click="changeActive(item)" v-if="edit">
  22. <view class="radio-single" v-if="!item.is_active"></view>
  23. <view class="radio-single-active" v-else :class="getTheme + '-m-back ' + getTheme"></view>
  24. </view>
  25. <view class="radio dir-top-nowrap main-center cross-center" v-else-if="item.pick_activity_id != pick_activity_id && !edit">
  26. <view class="radio-lapse">
  27. 失效
  28. </view>
  29. </view>
  30. <view class="content dir-left-nowrap">
  31. <image class="cover-pic" :src="item.attrs.pic_url ? item.attrs.pic_url : item.goods.cover_pic "></image>
  32. <view class="text dir-top-nowrap main-between">
  33. <text class="name t-omit-two">
  34. {{item.goods.name}}
  35. </text>
  36. <view class="it-attr">
  37. <text v-for="(it, i) in item.attrs.attr" :key="i">
  38. {{it.attr_group_name}}:{{it.attr_name}}<text class="empty-nbsp"></text>
  39. </text>
  40. </view>
  41. <view class="dir-left-nowrap main-between cross-center">
  42. <template v-if="item.pick_activity_id == pick_activity_id">
  43. <text class="price" :class="getTheme + '-m-text ' + getTheme">{{item.attrs.price}}</text>
  44. <view class="aob dir-left-nowrap main-around cross-center">
  45. <view class="icon" @click="_calcValue(item, 'minus')" :class="{'app-unreducible': item.num == 1, 'app-can-be-reduced': item.num > 1}"></view>
  46. <input v-model="item.num" @change="editInput(item)" type="number">
  47. <view class="icon" @click="_calcValue(item, 'plus')" :class="[{'app-not-add': item.num >= item.attrs.stock, 'app-can-add': item.num < item.attrs.stock}, getTheme+ '-m-back', getTheme]"></view>
  48. </view>
  49. </template>
  50. <view v-else style="font-size: 25rpx;">
  51. 此活动已过期,无法购买
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. </view>
  58. <view class="safe-area-inset-bottom u-bottom-fixed">
  59. <view class="settlement dir-left-nowrap">
  60. <view class="all-price dir-left-nowrap">
  61. <view class="all-select dir-left-nowrap main-center cross-center" @click="selectAll">
  62. <view class="all-radio">
  63. <view class="radio-single" v-if="!is_active"></view>
  64. <view class="radio-single-active" :class="getTheme + '-m-back ' + getTheme" v-else></view>
  65. </view>
  66. <text class="all-text">全选</text>
  67. </view>
  68. <view class="red-text dir-top-nowrap main-center" v-if="!edit">
  69. <text class="all-price-text" :class="getTheme + '-m-text ' + getTheme">总计:¥{{all_price}}</text>
  70. <text class="other-good" :class="getTheme + '-m-text ' + getTheme" v-if="stillNeed !== 0">还需添加{{stillNeed}}件商品</text>
  71. </view>
  72. </view>
  73. <view class="button" :class="[{'disabled': stillNeed !== 0 , 'disabled': all_num === 0}, getTheme + '-m-back', getTheme]" @click="buy" v-if="!edit">
  74. 去结算
  75. </view>
  76. <view class="delete" :class="getTheme + '-m-text ' + getTheme" @click="del()" v-else>
  77. <view>
  78. 删除
  79. </view>
  80. </view>
  81. </view>
  82. </view>
  83. </view>
  84. </app-layout>
  85. </template>
  86. <script>
  87. import {mapGetters} from "vuex";
  88. export default {
  89. name: "pond",
  90. data() {
  91. return {
  92. pond: [],
  93. step: 1,
  94. pick_activity_id: 0,
  95. pay_pond: [],
  96. all_price: 0,
  97. is_active: false,
  98. rule_num: 0,
  99. edit: false,
  100. stillNeed: 0,
  101. buy_goods_list: [],
  102. all_num: 0
  103. }
  104. },
  105. computed: {
  106. ...mapGetters('mallConfig', {
  107. getTheme: 'getTheme',
  108. }),
  109. },
  110. onLoad(options) {
  111. this.pick_activity_id = options.pick_activity_id;
  112. this.rule_num = options.rule_num;
  113. },
  114. onShow() {
  115. this.getCart();
  116. },
  117. methods: {
  118. changeActive(item) {
  119. item.is_active = !item.is_active;
  120. },
  121. _calcValue(item, type) {
  122. const scale = this._getDecimalScale();
  123. let value = item.num * scale;
  124. let step = this.step * scale;
  125. if (type === "minus") {
  126. value -= step;
  127. } else if (type === "plus") {
  128. value += step;
  129. }
  130. if (value < 1 || value > item.attrs.stock) {
  131. return;
  132. }
  133. item.num = String(value / scale);
  134. this.editList();
  135. // this.$storage.setStorageSync('PICK', this.pond);
  136. },
  137. editInput() {
  138. this.editList();
  139. },
  140. _getDecimalScale() {
  141. let scale = 1;
  142. // 浮点型
  143. if (~~this.step !== this.step) {
  144. scale = Math.pow(10, (this.step + "").split(".")[1].length);
  145. }
  146. return scale;
  147. },
  148. selectAll() {
  149. this.is_active = !this.is_active;
  150. for (let i = 0; i < this.pond.length; i++) {
  151. if (this.pond[i].pick_activity_id == this.pick_activity_id && !this.edit) {
  152. this.pond[i].is_active = this.is_active;
  153. } else if (this.edit) {
  154. this.pond[i].is_active = this.is_active;
  155. }
  156. }
  157. },
  158. buy() {
  159. let data = [];
  160. this.buy_goods_list = [];
  161. let obj = {
  162. mch_id: '0',
  163. goods_list: this.buy_goods_list,
  164. pick_activity_id: this.pick_activity_id
  165. };
  166. data.push(obj);
  167. for (let i = 0; i < this.pay_pond.length; i++) {
  168. this.buy_goods_list.push({
  169. id: this.pay_pond[i].goods_id,
  170. attr: this.pay_pond[i].attrs.attr,
  171. num: this.pay_pond[i].num,
  172. cat_id:0,
  173. cart_id: this.pay_pond[i].id,
  174. goods_attr_id: this.pay_pond[i].attrs.id
  175. });
  176. }
  177. if (this.stillNeed !== 0) {
  178. return;
  179. }
  180. if (this.buy_goods_list.length === 0) {
  181. return;
  182. }
  183. let str = `/pages/order-submit/order-submit?mch_list=${JSON.stringify(data)}&preview_url=${encodeURIComponent(this.$api.pick.order_preview)}&submit_url=${encodeURIComponent(this.$api.pick.order_submit)}`;
  184. uni.navigateTo({
  185. url: str
  186. });
  187. },
  188. setEdit(boolean) {
  189. if (boolean === false) {
  190. for (let i = 0; i < this.pond.length; i++) {
  191. this.pond[i].is_active = false;
  192. }
  193. }
  194. this.is_active = false;
  195. this.edit = boolean;
  196. },
  197. async del() {
  198. let data = JSON.parse(JSON.stringify(this.pay_pond));
  199. let list = [];
  200. for (let i = 0; i < data.length; i++) {
  201. list.push( data[i].id);
  202. }
  203. const e = await this.$request({
  204. url: this.$api.pick.delete,
  205. method: 'post',
  206. data: {
  207. cart_id_list: JSON.stringify(list),
  208. }
  209. });
  210. if (e.code === 0) {
  211. this.is_active = false;
  212. this.getCart();
  213. }
  214. },
  215. async getCart() {
  216. const e = await this.$request({
  217. url: this.$api.pick.list
  218. });
  219. if (e.code === 0) {
  220. let list = e.data.list;
  221. for (let i = 0; i < list.length; i++) {
  222. list[i].is_active = false;
  223. }
  224. this.pond = list;
  225. }
  226. },
  227. async editList() {
  228. let data = JSON.parse(JSON.stringify(this.pond));
  229. let list = [];
  230. for (let i = 0; i < data.length; i++) {
  231. list.push({
  232. attr: data[i].attr_id,
  233. goods_id: data[i].goods_id,
  234. num: data[i].num
  235. })
  236. }
  237. const e = await this.$request({
  238. url: this.$api.pick.edit,
  239. method: 'post',
  240. data: {
  241. list: JSON.stringify(list),
  242. }
  243. });
  244. }
  245. },
  246. watch: {
  247. pond: {
  248. handler(data) {
  249. this.pay_pond = [];
  250. let all_price = 0;
  251. let all_active = 0;
  252. this.all_num = 0;
  253. for (let i = 0; i < data.length; i++) {
  254. if (data[i].is_active) {
  255. this.pay_pond.push(data[i]);
  256. all_active++;
  257. this.all_num += Number(data[i].num);
  258. all_price += data[i].num*data[i].attrs.price;
  259. }
  260. }
  261. if (all_active === data.length) {
  262. this.is_active = true;
  263. if (data.length === 0) {
  264. this.is_active = false;
  265. }
  266. }
  267. if (this.all_num%this.rule_num === 0) {
  268. this.stillNeed = 0;
  269. } else {
  270. this.stillNeed = this.rule_num - (this.all_num%this.rule_num);
  271. }
  272. this.all_price = all_price.toFixed(2);
  273. },
  274. deep: true
  275. }
  276. },
  277. }
  278. </script>
  279. <style scoped lang="scss">
  280. .pond {
  281. padding-bottom: #{100upx};
  282. }
  283. .settlement {
  284. height: #{110upx};
  285. width: #{750upx};
  286. background-color: #ffffff;
  287. border-top: #{1upx} solid #e2e2e2;
  288. }
  289. .button {
  290. width: #{250upx};
  291. height: #{100upx};
  292. font-size: #{32upx};
  293. color: #ffffff;
  294. text-align: center;
  295. line-height: #{100upx};
  296. }
  297. .all-price {
  298. width: #{500upx};
  299. height: #{100upx};
  300. }
  301. .bulletin {
  302. height: #{70upx};
  303. width: #{750upx};
  304. background-color: #ffffff;
  305. position: fixed;
  306. top: 0;
  307. }
  308. .edit {
  309. width: #{116upx};
  310. height: #{70upx};
  311. line-height: #{70upx};
  312. font-size: #{25upx};
  313. text-align: center;
  314. }
  315. .bulletin-text {
  316. font-size: #{25upx};
  317. line-height: #{70upx};
  318. width: #{610upx};
  319. color: #999999;
  320. margin-left: #{24upx};
  321. }
  322. .list {
  323. margin-top: #{100upx};
  324. background-color: #ffffff;
  325. }
  326. .item {
  327. width: #{750upx};
  328. border-bottom: #{1upx} solid #e2e2e2;
  329. height: #{218upx};
  330. padding: #{30upx 0 15upx 0};
  331. }
  332. .radio {
  333. width: #{85upx};
  334. height: #{156upx};
  335. }
  336. .radio-single {
  337. width: #{40rpx};
  338. height: #{40rpx};
  339. border-radius: 50%;
  340. background-color: white;
  341. border: #{1rpx} solid #e2e2e2;
  342. }
  343. .radio-single-active {
  344. width: #{40rpx};
  345. height: #{40rpx};
  346. border-radius: 50%;
  347. background-repeat: repeat;
  348. background-size: 100% 100%;
  349. background-image: url("../../../static/image/icon/icon-checkbox-checked.png");
  350. }
  351. .content {
  352. width: #{665upx};
  353. padding-right: #{25upx};
  354. }
  355. .cover-pic {
  356. width: #{156upx};
  357. height: #{156upx};
  358. }
  359. .text {
  360. margin-left: #{20upx};
  361. height: #{171upx};
  362. width: #{440upx};
  363. }
  364. .text>view {
  365. width: 100%;
  366. }
  367. .name {
  368. font-size: #{28upx};
  369. color: #3f3f3f;
  370. }
  371. .price {
  372. font-size: #{32upx};
  373. }
  374. .price:before {
  375. content: '¥';
  376. font-size: #{24upx};
  377. }
  378. .aob {
  379. height: #{60upx};
  380. input {
  381. height: #{60rpx};
  382. width: #{88rpx};
  383. font-size: #{21rpx};
  384. color: #353535;
  385. text-align: center;
  386. }
  387. }
  388. .app-unreducible {
  389. background-image: url("../../../static/image/cart/unreducible.png");
  390. }
  391. .app-not-add {
  392. background-image: url("../../../static/image/cart/can-add.png");
  393. }
  394. .app-can-add {
  395. background-image: url("../../../static/image/icon/add-but.png");
  396. }
  397. .app-can-be-reduced {
  398. background-image: url("../../../static/image/icon/subtract.png");
  399. }
  400. .all-select {
  401. width: #{150upx};
  402. height: 100%;
  403. }
  404. .all-text {
  405. font-size: #{26upx};
  406. color: #3f3f3f;
  407. margin-left: #{5upx};
  408. }
  409. .all-radio {
  410. margin-right: #{5upx};
  411. }
  412. .all-price-text {
  413. font-size: #{26upx};
  414. line-height: 1;
  415. }
  416. .red-text {
  417. width: #{350upx};
  418. }
  419. .other-good {
  420. font-size: #{21upx};
  421. margin-top: #{10upx};
  422. line-height: 1;
  423. }
  424. .delete {
  425. width: #{250upx};
  426. height: #{100upx};
  427. position: relative;
  428. >view {
  429. font-size: #{24upx};
  430. text-align: center;
  431. width: #{140upx};
  432. height: #{64upx};
  433. line-height: #{64upx};
  434. border-radius: #{28upx};
  435. border: #{1upx} solid;
  436. position: absolute;
  437. right: #{24upx};
  438. top: #{18upx};
  439. }
  440. }
  441. .it-attr {
  442. font-size: #{22upx};
  443. color: #999999;
  444. }
  445. .disabled {
  446. background-color: #999999;
  447. }
  448. .empty {
  449. margin-top: #{150upx};
  450. width: #{750upx};
  451. /*position: relative;*/
  452. text-align: center;
  453. >text {
  454. color: #999999;
  455. font-size: #{26upx};
  456. position: absolute;
  457. top: #{325upx};
  458. transform: translateX(-50%);
  459. }
  460. }
  461. .cart {
  462. width: #{160upx};
  463. height: #{160upx};
  464. border-radius: 50%;
  465. background-color: #dedede;
  466. position: absolute;
  467. left: 50%;
  468. transform: translateX(-50%);
  469. >image {
  470. width: #{59upx};
  471. height: #{59upx};
  472. position: absolute;
  473. left: 50%;
  474. top:50%;
  475. transform: translate(-50%, -50%);
  476. }
  477. }
  478. .empty-nbsp {
  479. width: #{10upx};
  480. display: inline-block;
  481. }
  482. .radio-lapse {
  483. height: #{32upx};
  484. width: #{64upx};
  485. border-radius: #{16upx};
  486. background-color: #cdcdcd;
  487. font-size: #{23upx};
  488. color: #ffffff;
  489. line-height: #{32upx};
  490. text-align: center;
  491. }
  492. .icon {
  493. height: #{44rpx};
  494. width: #{44rpx};
  495. background-size: 100% 100%;
  496. background-repeat: no-repeat;
  497. }
  498. .u-bottom-fixed {
  499. position: fixed;
  500. bottom: 0;
  501. left: 0;
  502. width: 100%;
  503. z-index: 1602;
  504. background-color: #ffffff;
  505. }
  506. </style>