index.vue 12 KB

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