index.vue 12 KB

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