index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. <template>
  2. <mobile-frame :frameStyle="frameStyle" @toPath="toPath">
  3. <view class="main">
  4. <view class="top" v-if="list.length !=0">
  5. <view class="text_1">
  6. <checkbox class="checkbox" @click="selectAll(false)" :checked="isAll">全选</checkbox>
  7. </view>
  8. <view class="text_2" v-if="num==0" @click="edit(1)">编辑</view>
  9. <view class="text_2" v-if="num==1" @click="edit(0)">完成</view>
  10. </view>
  11. <view class="one" v-if="!user._id">
  12. <view class="logo">
  13. <text class="iconfont icon-gouwuche"></text>
  14. </view>
  15. <view class="one_1">
  16. 您还没有登录
  17. </view>
  18. <view class="btn">
  19. <button type="primary" size="mini" @click="toCommon('/pages/login/index')">去登录</button>
  20. </view>
  21. </view>
  22. <view class="one" v-if="list.length==0">
  23. <view class="logo">
  24. <text class="iconfont icon-gouwuche"></text>
  25. </view>
  26. <view class="one_1">
  27. 购物车空空如也~
  28. </view>
  29. <view class="btn">
  30. <button type="primary" size="mini" @click="toCommon('/pages/home/index')">去逛逛</button>
  31. </view>
  32. </view>
  33. <view class="two">
  34. <scroll-view scroll-y="true" class="scroll-view">
  35. <view class="list-scroll-view">
  36. <checkbox-group name="checkbox" @change="marketChange">
  37. <view class="lists" v-for="(item, index) in list" :key="index">
  38. <view class="list">
  39. <view class="title">
  40. <checkbox :value="item.id" :checked="item.check">
  41. {{item.title}}
  42. </checkbox>
  43. </view>
  44. <checkbox-group name="checkbox" @change="goodsChange">
  45. <view class="content" v-for="(item, indexs) in item.goods" :key="indexs">
  46. <view class="box">
  47. <checkbox :value="item.id" :checked="item.check" />
  48. </view>
  49. <view class="img">
  50. <image src="../../static/logo.png"></image>
  51. </view>
  52. <view class=" one_1" v-if="num==0">
  53. <view class="name">{{item.name}}</view>
  54. <view class="info">
  55. <view class="title_1" v-if="item.kg">
  56. <text>规格:{{item.kg}}</text>
  57. </view>
  58. </view>
  59. </view>
  60. <view class="money" v-if="num==0">
  61. <view>¥{{item.money}}</view>
  62. <view>x{{item.num}}</view>
  63. </view>
  64. <view class="num" v-if="num==1">
  65. <uni-number-box @change="changeValue(item)" name="num" value="item"
  66. :min="1" v-model="item.num" />
  67. </view>
  68. <view class="del" v-if="num==1">
  69. <text class="iconfont icon-del-copy" @click="toDel(item)"></text>
  70. </view>
  71. </view>
  72. </checkbox-group>
  73. </view>
  74. </view>
  75. </checkbox-group>
  76. </view>
  77. </scroll-view>
  78. </view>
  79. <view class="foot" v-if="list.length !=0">
  80. <view class="total">总价:<text>¥{{totalMoney}}(不含运费)</text></view>
  81. <view class="btn">
  82. <button type="primary" size="mini" @click="toSettle()" v-if="num==0">提交订单</button>
  83. <button type="primary" size="mini" @click="toDel()" v-if="num==1">删除</button>
  84. </view>
  85. </view>
  86. </view>
  87. </mobile-frame>
  88. </template>
  89. <script>
  90. export default {
  91. data() {
  92. return {
  93. frameStyle: {
  94. useBar: true
  95. },
  96. user: {
  97. _id: '001'
  98. },
  99. list: [{
  100. id: '001',
  101. title: '商品1店铺',
  102. goods: [{
  103. id: '00001',
  104. name: '商品商品商品商品商品1',
  105. money: 50.00,
  106. num: 2,
  107. kg: '1.5L',
  108. }, {
  109. id: '00002',
  110. name: '商品商品商品商品商品2',
  111. money: 150.00,
  112. num: 2,
  113. kg: '13.5L',
  114. }, ]
  115. }, {
  116. id: '002',
  117. title: '商品1店铺',
  118. goods: [{
  119. id: '00003',
  120. name: '商品商品商品商品商品1',
  121. money: 50.00,
  122. num: 2,
  123. kg: '1.5L',
  124. }, {
  125. id: '00004',
  126. name: '商品商品商品商品商品2',
  127. money: 150.00,
  128. num: 2,
  129. kg: '13.5L',
  130. }, ]
  131. }, ],
  132. isAll: false,
  133. // 编辑/完成按钮传的数字
  134. num: 0,
  135. totalMoney: 0,
  136. };
  137. },
  138. onShow: function() {
  139. },
  140. methods: {
  141. toPath(e) {
  142. if (e && e.route) uni.redirectTo({
  143. url: `/${e.route}`
  144. })
  145. },
  146. // 转换金额
  147. showMoney(money) {
  148. const that = this;
  149. let moneys = `${money}`.split(".");
  150. if (moneys.length == 1) {
  151. money = money + ".00";
  152. } else if (moneys.length == 2) {
  153. money = money + "0";
  154. }
  155. return money;
  156. },
  157. // 编辑
  158. edit(num) {
  159. const that = this;
  160. that.$set(that, `num`, num)
  161. },
  162. //全选
  163. selectAll(e) {
  164. const that = this;
  165. const list = that.list;
  166. const isAll = that.isAll;
  167. let data = [];
  168. for (const val of list) {
  169. let a = isAll ? false : true;
  170. val.check = a;
  171. for (let s of val.goods) {
  172. s.check = a
  173. }
  174. data.push(val);
  175. }
  176. that.$set(that, `list`, data)
  177. // 计算总额
  178. that.countMoney();
  179. // 赋值是否全选
  180. that.$set(that, `isAll`, isAll ? false : true)
  181. },
  182. // 选择店铺
  183. marketChange(e) {
  184. const that = this;
  185. const list = this.list;
  186. const {
  187. value
  188. } = e.detail;
  189. for (const p1 of list) {
  190. let p2 = value.find((i) => i == p1.id);
  191. let a = p2 ? true : false;
  192. p1.check = a;
  193. for (let s of p1.goods) {
  194. s.check = a
  195. }
  196. }
  197. that.$set(that, `list`, list);
  198. that.marketAllChange();
  199. // 计算总额
  200. that.countMoney();
  201. },
  202. //店铺全部选择true,全选自动选择,
  203. marketAllChange() {
  204. const that = this;
  205. let list = that.list;
  206. for (let val of list) {
  207. if (val.check == true) {
  208. that.$set(that, `isAll`, true)
  209. } else {
  210. that.$set(that, `isAll`, false)
  211. }
  212. }
  213. that.$set(that, `list`, list)
  214. // 计算总额
  215. that.countMoney();
  216. },
  217. //选择商品
  218. goodsChange(e) {
  219. const that = this;
  220. let list = that.list;
  221. const {
  222. value
  223. } = e.detail;
  224. let shop = list.find(f => f.goods.find(i => value.find(s => s == i.id)))
  225. if (shop) {
  226. for (let val of shop.goods) {
  227. let p2 = value.find((i) => i == val.id);
  228. if (p2) val.check = true;
  229. else val.check = false;
  230. }
  231. } else {
  232. list = list.map(i => {
  233. i.goods = i.goods.map(g => ({
  234. ...g,
  235. check: false
  236. }))
  237. return i;
  238. })
  239. }
  240. that.$set(that, `list`, list)
  241. that.goodsAllChange(value);
  242. // 计算总额
  243. that.countMoney();
  244. },
  245. //商品全部选择true,店铺自动选择,
  246. goodsAllChange(value) {
  247. const that = this;
  248. let list = that.list;
  249. let shop = list.find(f => f.goods.find(i => value.find(s => s == i.id)))
  250. if (shop) {
  251. for (let val of shop.goods) {
  252. if (val.check == true) {
  253. shop.check = true;
  254. } else {
  255. shop.check = false;
  256. }
  257. }
  258. } else {
  259. list = list.map(i => {
  260. i.goods = i.goods.map(g => ({
  261. ...g,
  262. check: false
  263. }))
  264. return i;
  265. })
  266. }
  267. // 计算总额
  268. that.countMoney();
  269. },
  270. // 加减商品数量
  271. changeValue(value) {
  272. const that = this;
  273. const list = that.list;
  274. for (const val of list) {
  275. for (let s of val.goods) {
  276. if (s.id == value.id) {
  277. s.num = value.num
  278. }
  279. }
  280. }
  281. that.$set(that, `list`, list)
  282. // 计算总额
  283. that.countMoney(list);
  284. },
  285. // 删除
  286. toDel(e) {
  287. const that = this;
  288. const list = that.list;
  289. let shop = list.find(f => f.goods.find(i => i.check == true))
  290. if (shop) {
  291. uni.showModal({
  292. title: '提示',
  293. content: '确认要删除这些商品吗?',
  294. success: async function(res) {
  295. if (res.confirm) {}
  296. }
  297. });
  298. } else if (e.id) {
  299. uni.showModal({
  300. title: '提示',
  301. content: '是否确认删除该商品',
  302. success: async function(res) {
  303. if (res.confirm) {}
  304. }
  305. });
  306. } else {
  307. uni.showModal({
  308. title: '提示',
  309. content: '请选择要删除的商品',
  310. success: async function(res) {
  311. if (res.confirm) {}
  312. }
  313. });
  314. }
  315. },
  316. // 计算总额
  317. countMoney() {
  318. const that = this;
  319. const list = this.list;
  320. let totalMoney = 0;
  321. // 渲染结束执行下面方法
  322. that.$nextTick(() => {
  323. for (const val of list) {
  324. for (let s of val.goods) {
  325. if (s.check == true) {
  326. let total = Number(s.money) * Number(s.num);
  327. totalMoney += Number(total);
  328. }
  329. }
  330. }
  331. that.$set(that, `totalMoney`, totalMoney.toFixed(2))
  332. })
  333. },
  334. // 去结算
  335. toSettle() {},
  336. }
  337. }
  338. </script>
  339. <style lang="scss">
  340. .main {
  341. display: flex;
  342. flex-direction: column;
  343. width: 100vw;
  344. height: 92vh;
  345. background-color: var(--footColor);
  346. .top {
  347. display: flex;
  348. flex-direction: row;
  349. background-color: var(--mainColor);
  350. height: 35px;
  351. margin: 0 0 4px 0;
  352. padding: 5px 4vw;
  353. .text_1 {
  354. flex-grow: 1;
  355. line-height: 30px;
  356. }
  357. .text_2 {
  358. line-height: 35px;
  359. }
  360. }
  361. .one {
  362. text-align: center;
  363. margin: 2vw 0;
  364. .logo {
  365. margin: 10vw 0 2vw 0;
  366. .iconfont {
  367. font-size: 35vw;
  368. }
  369. }
  370. .one_1 {
  371. margin: 3vw 0;
  372. }
  373. button {
  374. background-color: var(--ff0Color);
  375. }
  376. }
  377. .two {
  378. position: relative;
  379. flex-grow: 1;
  380. margin: 0 2vw;
  381. .list {
  382. background-color: var(--mainColor);
  383. margin: 2vw 0 2vw 0;
  384. padding: 2vw 3vw;
  385. border-radius: 4px;
  386. .title {
  387. border-bottom: 1px solid var(--fcColor);
  388. padding: 0 0 2vw 0;
  389. font-size: var(--font18Size);
  390. }
  391. .content {
  392. display: flex;
  393. flex-direction: row;
  394. padding: 3vw 0;
  395. font-size: var(--font16Size);
  396. border-bottom: 1px dashed var(--fcColor);
  397. .box {
  398. line-height: 20vw;
  399. }
  400. .img {
  401. width: 20vw;
  402. height: 20vw;
  403. border-radius: 2vw;
  404. border: 1px solid var(--fcColor);
  405. image {
  406. width: 20vw;
  407. height: 20vw;
  408. }
  409. }
  410. .one_1 {
  411. margin: 2.5vw;
  412. flex-grow: 1;
  413. .info {
  414. width: 100%;
  415. display: flex;
  416. flex-direction: row;
  417. .title_1 {
  418. font-size: 12px;
  419. color: #666;
  420. margin-top: 10px;
  421. text {
  422. background-color: #eee;
  423. padding: 5px;
  424. }
  425. }
  426. }
  427. }
  428. .money {
  429. margin-top: 2vw;
  430. text-align: right;
  431. flex-grow: 1;
  432. }
  433. .num {
  434. margin: 6vw 4vw;
  435. font-size: 20px;
  436. }
  437. .del {
  438. margin: 6vw 0;
  439. text-align: right;
  440. flex-grow: 1;
  441. }
  442. }
  443. }
  444. }
  445. .foot {
  446. background-color: var(--fffColor);
  447. display: flex;
  448. flex-direction: row;
  449. justify-content: space-between;
  450. height: 44px;
  451. padding: 0 0 0 6vw;
  452. border-right: 1px solid var(--f99Color);
  453. .total {
  454. flex-grow: 1;
  455. display: flex;
  456. align-content: flex-end;
  457. line-height: 40px;
  458. text {
  459. color: var(--ff0Color);
  460. }
  461. }
  462. .btn {
  463. button {
  464. width: 30vw;
  465. height: 44px;
  466. line-height: 44px;
  467. border-radius: 0px;
  468. background-color: var(--ff0Color);
  469. text-align: center;
  470. font-weight: normal;
  471. font-size: var(--font15Size);
  472. color: var(--fffColor);
  473. }
  474. }
  475. }
  476. }
  477. .scroll-view {
  478. position: absolute;
  479. top: 0;
  480. left: 0;
  481. right: 0;
  482. bottom: 0;
  483. .list-scroll-view {
  484. display: flex;
  485. flex-direction: column;
  486. }
  487. }
  488. // 复选框样式
  489. checkbox .wx-checkbox-input {
  490. width: 40rpx;
  491. height: 40rpx;
  492. border-radius: 50%;
  493. border-color: var(--f99Color);
  494. background-color: var(--mainColor);
  495. }
  496. // 复选框选中样式
  497. checkbox .wx-checkbox-input.wx-checkbox-input-checked {
  498. border-color: var(--ff0Color);
  499. background-color: var(--ff0Color);
  500. }
  501. // 复选框选中之后对号的样式
  502. checkbox .wx-checkbox-input.wx-checkbox-input-checked::before {
  503. color: var(--fffColor);
  504. }
  505. </style>