CardCase.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. <template>
  2. <div class="case">
  3. <van-cell :border="false" class="bottom-show" @click="init" is-link>
  4. <div slot="title">
  5. <div class="text1" v-if="chooseIds.length > 0">
  6. 已选<span>{{ chooseIds.length }}</span
  7. >包,共<span>{{ money }}</span
  8. >元,邮费{{ cardCaseInfo.postage || 0 }}元
  9. </div>
  10. <div v-else>请选择卡包</div>
  11. </div>
  12. </van-cell>
  13. <van-popup :show="show" round position="bottom" @close="show = false">
  14. <div class="box">
  15. <div class="top">
  16. <span>选择卡包</span>
  17. <div class="right">
  18. <div class="tool-item">
  19. 可选
  20. </div>
  21. <div class="tool-item used">
  22. 已售
  23. </div>
  24. </div>
  25. </div>
  26. <div class="content">
  27. <div class="card" v-for="(card, index) in cardList" :key="index">
  28. <div class="card-title">第{{ index + 1 }}组</div>
  29. <div class="card-list">
  30. <div
  31. v-for="(item, itemIndex) in card"
  32. :key="item.id"
  33. class="card-item"
  34. :class="{
  35. used: !canChoose(item),
  36. active: nowChoose.includes(item.id)
  37. }"
  38. @click="choose(item.id, !canChoose(item))"
  39. >
  40. {{ itemIndex + 1 }}
  41. </div>
  42. </div>
  43. </div>
  44. </div>
  45. <div class="bottom">
  46. <span class="text"
  47. >已选{{ nowChoose.length }}包,共{{ money }}元,邮费{{ cardCaseInfo.postage || 0 }}元</span
  48. >
  49. <van-button size="medium" @click="submit" class="submit" :radius="0" type="primary"
  50. >确认购买</van-button
  51. >
  52. </div>
  53. </div>
  54. </van-popup>
  55. </div>
  56. </template>
  57. <script>
  58. export default {
  59. name: 'CardCase',
  60. props: {
  61. detailsList: {
  62. type: Object,
  63. default: () => {
  64. return {};
  65. }
  66. },
  67. cardCaseInfo: {
  68. type: Object,
  69. default: () => {
  70. return {};
  71. }
  72. },
  73. chooseIds: {
  74. type: Array,
  75. default: () => {
  76. return [];
  77. }
  78. }
  79. },
  80. computed: {
  81. cardList() {
  82. let boxMap = { ...this.detailsList };
  83. return Object.keys(boxMap).map(item => {
  84. return boxMap[item];
  85. });
  86. },
  87. allCards() {
  88. return [...this.cardList].flat();
  89. },
  90. money() {
  91. let choose = this.show ? this.nowChoose : this.chooseIds;
  92. let list = [...this.allCards].filter(item => {
  93. return [...choose].includes(item.id);
  94. });
  95. return list.reduce((prev, cur) => {
  96. var r1, r2, m;
  97. try {
  98. r1 = prev.toString().split('.')[1].length;
  99. } catch (e) {
  100. r1 = 0;
  101. }
  102. try {
  103. r2 = cur.money.toString().split('.')[1].length;
  104. } catch (e) {
  105. r2 = 0;
  106. }
  107. m = Math.pow(10, Math.max(r1, r2));
  108. return (prev * m + cur.money * m) / m;
  109. }, 0);
  110. }
  111. },
  112. data() {
  113. return {
  114. show: false,
  115. nowChoose: [],
  116. buy: false
  117. };
  118. },
  119. methods: {
  120. canChoose(info) {
  121. let status = ['WAIT', 'PROGRESS'];
  122. return status.includes(info.caseStatus) && !info.sold;
  123. },
  124. init(type) {
  125. this.nowChoose = [...this.chooseIds];
  126. this.show = true;
  127. this.buy = type === 'buy';
  128. },
  129. choose(id, used = false) {
  130. if (used) {
  131. return;
  132. }
  133. let list = [...this.nowChoose];
  134. if (list.includes(id)) {
  135. list.splice(list.indexOf(id), 1);
  136. } else {
  137. list.push(id);
  138. }
  139. this.nowChoose = list;
  140. },
  141. submit() {
  142. console.log(this.cardCaseInfo);
  143. // console.log(this.cardList);
  144. if (this.nowChoose.length === 0) {
  145. this.toast('请选择卡牌');
  146. return;
  147. }
  148. let caseId = this.cardCaseInfo.cardCaseId;
  149. let boxIds = this.nowChoose.join(',');
  150. this.$http
  151. .get('/orderInfo/checkBox', {
  152. caseId,
  153. boxIds
  154. })
  155. .then(res => {
  156. let checkResult = false;
  157. checkResult = res;
  158. if (!checkResult) {
  159. wx.showToast({
  160. icon: 'none',
  161. title: '该卡箱需要两个卡包组选择数量一样',
  162. duration: 4000
  163. });
  164. return Promise.reject('提示');
  165. } else {
  166. return Promise.resolve();
  167. }
  168. })
  169. .then(res => {
  170. this.$emit('update:chooseIds', this.nowChoose);
  171. this.show = false;
  172. if (this.buy) {
  173. this.$emit('buy');
  174. }
  175. })
  176. .catch(e => {
  177. if (e.error) {
  178. wx.showToast({
  179. icon: 'none',
  180. title: e.error
  181. });
  182. }
  183. });
  184. }
  185. }
  186. };
  187. </script>
  188. <style lang="less" scoped>
  189. /deep/ .van-cell {
  190. --cell-horizontal-padding: 0px;
  191. --cell-vertical-padding: 20px;
  192. .van-cell__title {
  193. font-size: 16px;
  194. font-weight: bold;
  195. color: #000000;
  196. line-height: 28px;
  197. span {
  198. color: @prim;
  199. }
  200. }
  201. }
  202. .box {
  203. max-height: 70vh;
  204. min-height: 50vh;
  205. padding: 0 20px 0;
  206. .flex-col();
  207. padding-bottom: 6px;
  208. }
  209. .content {
  210. flex-grow: 1;
  211. overflow: auto;
  212. padding: 0 0 12px;
  213. }
  214. .top {
  215. .flex();
  216. justify-content: space-between;
  217. padding: 20px 0;
  218. flex-shrink: 0;
  219. span {
  220. font-size: 16px;
  221. font-weight: bold;
  222. color: #000000;
  223. line-height: 26px;
  224. }
  225. .right {
  226. .flex();
  227. .tool-item {
  228. font-size: 14px;
  229. color: #000000;
  230. line-height: 24px;
  231. .flex();
  232. margin-left: 30px;
  233. &::before {
  234. content: '';
  235. flex-shrink: 0;
  236. width: 16px;
  237. height: 16px;
  238. background: #ffffff;
  239. border-radius: 4px;
  240. border: 1px solid #f5f7fa;
  241. margin-right: 4px;
  242. }
  243. &.used {
  244. &::before {
  245. background-color: #939599;
  246. }
  247. }
  248. }
  249. }
  250. }
  251. .card + .card {
  252. margin-top: 12px;
  253. }
  254. .card-title {
  255. font-size: 14px;
  256. color: #939599;
  257. line-height: 24px;
  258. }
  259. .card {
  260. background-color: @bg;
  261. padding: 12px 16px;
  262. border-radius: 8px;
  263. .card-list {
  264. .flex();
  265. flex-wrap: wrap;
  266. .card-item {
  267. width: 42px;
  268. height: 42px;
  269. background: #ffffff;
  270. border-radius: 8px;
  271. font-size: 16px;
  272. font-weight: bold;
  273. text-align: center;
  274. color: #000000;
  275. line-height: 42px;
  276. margin-top: 10px;
  277. &.used {
  278. background-color: #939599;
  279. color: #ffffff;
  280. }
  281. &.active {
  282. background-color: @prim;
  283. color: #ffffff;
  284. }
  285. &:active {
  286. opacity: 0.8;
  287. }
  288. &:nth-child(6n + 1) {
  289. margin-left: 0 !important;
  290. }
  291. }
  292. .card-item + .card-item {
  293. margin-left: 10px;
  294. }
  295. }
  296. }
  297. .bottom {
  298. margin-top: 6px;
  299. border-radius: 12px;
  300. overflow: hidden;
  301. flex-shrink: 0;
  302. .flex();
  303. .text {
  304. padding: 0 16px;
  305. flex-grow: 1;
  306. font-size: 13px;
  307. font-family: PingFangSC-Medium, PingFang SC;
  308. font-weight: 500;
  309. color: #ffffff;
  310. line-height: 48px;
  311. height: 48px;
  312. background-color: lighten(@prim, 10);
  313. }
  314. }
  315. /deep/ .submit {
  316. .van-button {
  317. height: 48px;
  318. border-radius: 0px;
  319. min-width: 98px;
  320. max-width: 98px;
  321. }
  322. }
  323. </style>