index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. <template>
  2. <view :style="{ minHeight: sys.windowHeight + 'px' }" :class="[$tm.vx.state().tmVuetify.black ? 'black' : ' ']">
  3. <tm-menubars title="购物车列表" :shadow="0" :showback="true"></tm-menubars>
  4. <view class="zhuti shangpin" v-if="test.length>0">
  5. <tm-sheet :padding="[0, 0]" class="jiaoxi xiao">
  6. <view class="" style="width:100%;">
  7. <tm-checkbox @change="chooseAll" v-model="checked"></tm-checkbox>{{checked?'取消全选':'全选'}}
  8. </view>
  9. <view v-for="item in test">
  10. <tm-checkbox @change="choose" style="float: left;padding:2px !important;margin-top:9%;"
  11. v-model="item.checked" label=""></tm-checkbox>
  12. <tm-cartCellListFood @change="shuliangjia(item)" v-on:jian="jian(item)" v-on:jia="jia(item)"
  13. class="shuliang" :typeclick="typeclick" :mdata="item" :cart-num.sync="item.buy">
  14. </tm-cartCellListFood>
  15. </view>
  16. </tm-sheet>
  17. </view>
  18. <view class="dibu">
  19. <tm-listitem class="liebiao" value="免费" :round="24" :shadow="12" title="邮费" :show-right-icon="false">
  20. </tm-listitem>
  21. <tm-listitem class="liebiao jiageList" :value="'¥'+zongjia" :round="24" :shadow="12" title="价格"
  22. :show-right-icon="false"></tm-listitem>
  23. <view class="text-align-center">
  24. <!-- <tm-button theme="red" @click="qingkong()" :round="24" class="mt-50 logincla">清空</tm-button> -->
  25. <tm-button theme="red" @click="shanchu" :round="24" class="mt-50 logincla">删除</tm-button>
  26. <tm-button theme="primary" :round="24" class="mt-50 logincla" @click="goPay">立即付款</tm-button>
  27. </view>
  28. </view>
  29. <!-- 弹出层消息 -->
  30. <tm-message ref="toast"></tm-message>
  31. </view>
  32. </template>
  33. <script>
  34. import {
  35. myRequest
  36. } from '@/api/request.js'
  37. export default {
  38. data() {
  39. return {
  40. zongjia: 0,
  41. test: [],
  42. typeclick: 2, //1加入购物车,2购物车
  43. // 全选状态
  44. checked: false,
  45. // 数量默认为1
  46. number: 1,
  47. // 是否全选
  48. isAll: true
  49. };
  50. },
  51. onLoad() {
  52. },
  53. created() {
  54. if (!uni.getStorageSync("token")) {
  55. uni.navigateTo({
  56. url: "/pages/login/index",
  57. })
  58. }
  59. this.sys = uni.getSystemInfoSync();
  60. this.getList()
  61. },
  62. methods: {
  63. // 全选
  64. chooseAll() {
  65. if (this.checked) {
  66. this.test.forEach(item => {
  67. item.checked = true
  68. })
  69. } else {
  70. if (this.isAll) {
  71. this.checked = false
  72. } else {
  73. this.test.forEach(item => {
  74. item.checked = false
  75. })
  76. }
  77. }
  78. this.jiage()
  79. },
  80. // 单选
  81. choose() {
  82. let status = []
  83. this.test.forEach(item => {
  84. status.push(item.checked)
  85. })
  86. // console.log(status, '单选状态数组');
  87. if (status.includes(false)) {
  88. this.checked = false;
  89. this.isAll = true;
  90. } else {
  91. this.checked = true;
  92. this.isAll = false;
  93. }
  94. this.jiage()
  95. },
  96. // 清空
  97. qingkong() {
  98. let that = this;
  99. myRequest({
  100. url: '/api/ShopCart/deleteAllGoods',
  101. method: 'post',
  102. data: {}
  103. }).then(res => {
  104. if (res.data.code == 200) {
  105. console.log(res.data.data, '33');
  106. that.$refs.toast.show({
  107. model: 'success',
  108. label: res.data.msg
  109. })
  110. this.getList()
  111. } else {
  112. that.$refs.toast.show({
  113. model: 'error',
  114. label: res.data.msg
  115. })
  116. }
  117. })
  118. },
  119. goPay() {
  120. var that = this,
  121. data = this.test,
  122. goods = [],
  123. gw_id = [];
  124. for (let i = 0; i < data.length; i++) {
  125. if (data[i].checked) {
  126. console.log(that.zongjia, 'ss');
  127. goods.push({
  128. order_remark: '',
  129. order_money: data[i].buy * data[i].price,
  130. pay_money: data[i].buy * data[i].price,
  131. buy_num: data[i].buy,
  132. goods_id: data[i].goods_id,
  133. })
  134. gw_id.push(data[i].id)
  135. console.log(goods, gw_id, '下单数据');
  136. }
  137. }
  138. if (goods.length == 0) {
  139. that.$refs.toast.show({
  140. model: 'warn',
  141. label: '请选择商品'
  142. })
  143. return
  144. } else {
  145. myRequest({
  146. url: "/api/Order/addOrder",
  147. method: 'post',
  148. data: {
  149. gw_id: gw_id,
  150. good: goods
  151. }
  152. }).then(res => {
  153. if (res.data.code == 200) {
  154. that.$refs.toast.show({
  155. model: 'success',
  156. label: res.data.msg
  157. })
  158. this.getList()
  159. } else {
  160. that.$refs.toast.show({
  161. model: 'error',
  162. label: res.data.msg
  163. })
  164. }
  165. })
  166. }
  167. },
  168. // /删除
  169. shanchu() {
  170. var that = this,
  171. data = this.test,
  172. ids = [];
  173. for (let i = 0; i < data.length; i++) {
  174. if (data[i].checked) {
  175. ids.push(data[i].id)
  176. console.log(ids);
  177. }
  178. }
  179. if (ids.length == data.length) {
  180. console.log(ids.length, data.length);
  181. this.checked = true;
  182. }
  183. console.log(data, '数据');
  184. if (ids.length == 0) {
  185. that.$refs.toast.show({
  186. model: 'warn',
  187. label: '请选择商品'
  188. })
  189. return
  190. }
  191. myRequest({
  192. url: "/api/ShopCart/deleteOneGoods",
  193. method: 'post',
  194. data: {
  195. id: ids
  196. }
  197. }).then(res => {
  198. if (res.data.code == 200) {
  199. that.$refs.toast.show({
  200. model: 'success',
  201. label: res.data.msg
  202. })
  203. this.getList()
  204. } else {
  205. that.$refs.toast.show({
  206. model: 'error',
  207. label: res.data.msg
  208. })
  209. }
  210. })
  211. },
  212. // 按钮减
  213. jian(data) {
  214. console.log(data);
  215. if (data.buy <= 1) {
  216. this.$refs.toast.show({
  217. model: 'warn',
  218. label: '该商品不能减少了哟~'
  219. })
  220. return
  221. }
  222. this.number = -1;
  223. },
  224. // 按钮加
  225. jia() {
  226. this.number = 1;
  227. },
  228. // 数量增减
  229. shuliangjia(num) {
  230. var that = this;
  231. myRequest({
  232. url: "/api/ShopCart/addShopCart",
  233. method: 'post',
  234. data: {
  235. goods_id: num.goods_id,
  236. goods_num: that.number
  237. }
  238. }).then(res => {
  239. if (res.data.code == 200) {} else {
  240. that.$refs.toast.show({
  241. model: 'error',
  242. label: res.data.msg
  243. })
  244. }
  245. })
  246. this.jiage();
  247. },
  248. // 总价
  249. jiage() {
  250. var data = this.test,
  251. jiage = 0;
  252. for (let i = 0; i < data.length; i++) {
  253. if (data[i].checked) {
  254. var danjia = JSON.parse(data[i].price);
  255. var shuliang = data[i].buy;
  256. jiage = jiage + (danjia * shuliang);
  257. }
  258. }
  259. this.zongjia = jiage;
  260. },
  261. // /获取购物车列表
  262. getList() {
  263. var that = this;
  264. myRequest({
  265. url: "/api/ShopCart/shopCartList",
  266. method: 'post',
  267. data: {}
  268. }).then(res => {
  269. if (res.data.code == 200) {
  270. that.test = [];
  271. for (let i = 0; i < res.data.data.length; i++) {
  272. var obj = {
  273. img: res.data.data[i].goods_image,
  274. title: res.data.data[i].goods_name,
  275. // label: '黑色 - 6518/320',
  276. // size:'S',
  277. price: res.data.data[i].goods_price,
  278. id: res.data.data[i].id,
  279. buy: res.data.data[i].goods_num,
  280. itemId: res.data.data[i].id,
  281. checked: false,
  282. goods_id: res.data.data[i].goods_id
  283. };
  284. that.test.push(obj)
  285. }
  286. that.jiage()
  287. } else {
  288. that.test = [];
  289. }
  290. })
  291. },
  292. },
  293. }
  294. </script>
  295. <style lang="scss">
  296. /deep/ .tm-menubars .body {
  297. background-color: #1b1b1b !important;
  298. }
  299. /deep/ .jiaoxi {
  300. margin: 0 !important;
  301. padding: 8px !important;
  302. margin-bottom: 200px !important;
  303. }
  304. /deep/ .shangpin .white.bk {
  305. background-color: #1b1b1b !important;
  306. }
  307. /deep/ .shangpin .tm-cartCellListFood {
  308. padding: 0px 0px 15px 0px !important;
  309. margin-top: 5px !important;
  310. margin-bottom: 20px !important;
  311. border-bottom: 1px solid #303030;
  312. }
  313. /deep/ .shangpin .border-t-1.bk {
  314. border-top: 1px solid #1b1b1b !important;
  315. }
  316. /deep/ .shangpin .title {
  317. color: white !important;
  318. }
  319. /deep/ .shangpin .text-red {
  320. color: white !important;
  321. }
  322. /deep/ .shangpin .round-3 {
  323. width: 90px !important;
  324. height: 90px !important;
  325. }
  326. /deep/ .shangpin .tm-cartCellListFood-img {
  327. width: 90px !important;
  328. height: 90px !important;
  329. }
  330. /deep/ .shuliang .text-size-n {
  331. color: white !important;
  332. }
  333. .dibu {
  334. background: #0D0D0D;
  335. position: fixed;
  336. bottom: 0px;
  337. width: 100%;
  338. }
  339. /deep/ .liebiao .grey-darken-4.bk {
  340. background: #0D0D0D !important;
  341. padding: 0px;
  342. margin: 0px;
  343. width: 100%;
  344. border-radius: 0px !important;
  345. }
  346. .logincla {
  347. width: 40%;
  348. margin: 0 auto;
  349. margin-top: 20px;
  350. margin-bottom: 30px;
  351. }
  352. /deep/ .jiageList .d-inline-block {
  353. font-size: 18px !important;
  354. color: white !important;
  355. }
  356. </style>