index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  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. methods: {
  140. // 公共跳转
  141. toCommon(route, e) {
  142. const that = this;
  143. uni.navigateTo({
  144. url: `${route}?id=${e && e._id ? e._id : ''}`
  145. })
  146. },
  147. toPath(e) {
  148. if (e && e.route) uni.redirectTo({
  149. url: `/${e.route}`
  150. })
  151. },
  152. // 转换金额
  153. showMoney(money) {
  154. const that = this;
  155. let moneys = `${money}`.split(".");
  156. if (moneys.length == 1) {
  157. money = money + ".00";
  158. } else if (moneys.length == 2) {
  159. money = money + "0";
  160. }
  161. return money;
  162. },
  163. // 编辑
  164. edit(num) {
  165. const that = this;
  166. that.$set(that, `num`, num)
  167. },
  168. //全选
  169. selectAll(e) {
  170. const that = this;
  171. const list = that.list;
  172. const isAll = that.isAll;
  173. let data = [];
  174. for (const val of list) {
  175. let a = isAll ? false : true;
  176. val.check = a;
  177. for (let s of val.goods) {
  178. s.check = a
  179. }
  180. data.push(val);
  181. }
  182. that.$set(that, `list`, data)
  183. // 计算总额
  184. that.countMoney();
  185. // 赋值是否全选
  186. that.$set(that, `isAll`, isAll ? false : true)
  187. },
  188. // 选择店铺
  189. marketChange(e) {
  190. const that = this;
  191. const list = that.list;
  192. const {
  193. value
  194. } = e.detail;
  195. let data = [];
  196. for (const p1 of list) {
  197. let p2 = value.find((i) => i == p1.id);
  198. let a = p2 ? true : false;
  199. p1.check = a;
  200. for (let s of p1.goods) {
  201. s.check = a
  202. }
  203. data.push(p1);
  204. }
  205. that.$set(that, `list`, data)
  206. // 计算总额
  207. that.countMoney();
  208. },
  209. //选择商品
  210. goodsChange(e) {
  211. const that = this;
  212. const list = that.list;
  213. const {
  214. value
  215. } = e.detail;
  216. let data = [];
  217. console.log(value);
  218. console.log(list);
  219. let shop = list.find(f => f.goods.find(i => value.find(s => s == i.id)))
  220. console.log(shop);
  221. for (let val of shop.goods) {
  222. let p2 = value.find((i) => i == val.id);
  223. if (p2) val.check = true;
  224. else val.check = false;
  225. }
  226. // 计算总额
  227. that.countMoney();
  228. },
  229. // 加减商品数量
  230. changeValue(value) {
  231. const that = this;
  232. const list = that.list;
  233. let data = [];
  234. for (const val of list) {
  235. for (let s of val.goods) {
  236. if (s.id == value.id) {
  237. s.num = value.num
  238. }
  239. }
  240. }
  241. // 计算总额
  242. that.countMoney();
  243. },
  244. toDel(e) {
  245. const that = this;
  246. const list = that.list;
  247. let shop = list.find(f => f.goods.find(i => i.check == true))
  248. if (shop) {
  249. uni.showModal({
  250. title: '提示',
  251. content: '确认要删除这些商品吗?',
  252. success: async function(res) {
  253. if (res.confirm) {}
  254. }
  255. });
  256. } else if (e.id) {
  257. uni.showModal({
  258. title: '提示',
  259. content: '是否确认删除该商品',
  260. success: async function(res) {
  261. if (res.confirm) {}
  262. }
  263. });
  264. } else {
  265. uni.showModal({
  266. title: '提示',
  267. content: '请选择要删除的商品',
  268. success: async function(res) {
  269. if (res.confirm) {}
  270. }
  271. });
  272. }
  273. },
  274. // 计算总额
  275. countMoney() {
  276. const that = this;
  277. const list = that.list;
  278. let totalMoney = 0;
  279. for (const val of list) {
  280. for (let s of val.goods) {
  281. if (s.check == true) {
  282. let total = Number(s.money) * Number(s.num);
  283. totalMoney += Number(total);
  284. }
  285. }
  286. }
  287. that.$set(that, `totalMoney`, totalMoney.toFixed(2))
  288. },
  289. }
  290. }
  291. </script>
  292. <style lang="scss">
  293. .main {
  294. display: flex;
  295. flex-direction: column;
  296. width: 100vw;
  297. height: 92vh;
  298. background-color: var(--footColor);
  299. .top {
  300. display: flex;
  301. flex-direction: row;
  302. background-color: var(--mainColor);
  303. height: 35px;
  304. margin: 0 0 4px 0;
  305. padding: 5px 4vw;
  306. .text_1 {
  307. flex-grow: 1;
  308. line-height: 30px;
  309. }
  310. .text_2 {
  311. line-height: 35px;
  312. }
  313. }
  314. .one {
  315. text-align: center;
  316. margin: 2vw 0;
  317. .logo {
  318. margin: 10vw 0 2vw 0;
  319. .iconfont {
  320. font-size: 35vw;
  321. }
  322. }
  323. .one_1 {
  324. margin: 3vw 0;
  325. }
  326. button {
  327. background-color: var(--ff0Color);
  328. }
  329. }
  330. .two {
  331. position: relative;
  332. flex-grow: 1;
  333. margin: 0 2vw;
  334. .list {
  335. background-color: var(--mainColor);
  336. margin: 2vw 0 2vw 0;
  337. padding: 2vw 3vw;
  338. border-radius: 4px;
  339. .title {
  340. border-bottom: 1px solid var(--fcColor);
  341. padding: 0 0 2vw 0;
  342. font-size: var(--font18Size);
  343. }
  344. .content {
  345. display: flex;
  346. flex-direction: row;
  347. padding: 3vw 0;
  348. font-size: var(--font16Size);
  349. border-bottom: 1px dashed var(--fcColor);
  350. .box {
  351. line-height: 20vw;
  352. }
  353. .img {
  354. width: 20vw;
  355. height: 20vw;
  356. border-radius: 2vw;
  357. border: 1px solid var(--fcColor);
  358. image {
  359. width: 20vw;
  360. height: 20vw;
  361. }
  362. }
  363. .one_1 {
  364. margin: 2.5vw;
  365. flex-grow: 1;
  366. .info {
  367. width: 100%;
  368. display: flex;
  369. flex-direction: row;
  370. .title_1 {
  371. font-size: 12px;
  372. color: #666;
  373. margin-top: 10px;
  374. text {
  375. background-color: #eee;
  376. padding: 5px;
  377. }
  378. }
  379. }
  380. }
  381. .money {
  382. margin-top: 2vw;
  383. text-align: right;
  384. flex-grow: 1;
  385. }
  386. .num {
  387. margin: 6vw 4vw;
  388. font-size: 20px;
  389. }
  390. .del {
  391. margin: 6vw 0;
  392. text-align: right;
  393. flex-grow: 1;
  394. }
  395. }
  396. }
  397. }
  398. .foot {
  399. background-color: var(--fffColor);
  400. display: flex;
  401. flex-direction: row;
  402. justify-content: space-between;
  403. height: 44px;
  404. padding: 0 0 0 6vw;
  405. border-right: 1px solid var(--f99Color);
  406. .total {
  407. flex-grow: 1;
  408. display: flex;
  409. align-content: flex-end;
  410. line-height: 40px;
  411. text {
  412. color: var(--ff0Color);
  413. }
  414. }
  415. .btn {
  416. button {
  417. width: 30vw;
  418. height: 44px;
  419. line-height: 44px;
  420. border-radius: 0px;
  421. background-color: var(--ff0Color);
  422. text-align: center;
  423. font-weight: normal;
  424. font-size: var(--font15Size);
  425. color: var(--fffColor);
  426. }
  427. }
  428. }
  429. }
  430. .scroll-view {
  431. position: absolute;
  432. top: 0;
  433. left: 0;
  434. right: 0;
  435. bottom: 0;
  436. .list-scroll-view {
  437. display: flex;
  438. flex-direction: column;
  439. }
  440. }
  441. // 复选框样式
  442. checkbox .wx-checkbox-input {
  443. width: 40rpx;
  444. height: 40rpx;
  445. border-radius: 50%;
  446. border-color: var(--f99Color);
  447. background-color: var(--mainColor);
  448. }
  449. // 复选框选中样式
  450. checkbox .wx-checkbox-input.wx-checkbox-input-checked {
  451. border-color: var(--ff0Color);
  452. background-color: var(--ff0Color);
  453. }
  454. // 复选框选中之后对号的样式
  455. checkbox .wx-checkbox-input.wx-checkbox-input-checked::before {
  456. color: var(--fffColor);
  457. }
  458. </style>