index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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. }
  221. this.number = -1;
  222. },
  223. // 按钮加
  224. jia() {
  225. this.number = 1;
  226. },
  227. // 数量增减
  228. shuliangjia(num) {
  229. var that = this;
  230. myRequest({
  231. url: "/api/ShopCart/addShopCart",
  232. method: 'post',
  233. data: {
  234. goods_id: num.goods_id,
  235. goods_num: that.number
  236. }
  237. }).then(res => {
  238. if (res.data.code == 200) {} else {
  239. that.$refs.toast.show({
  240. model: 'error',
  241. label: res.data.msg
  242. })
  243. }
  244. })
  245. this.jiage();
  246. },
  247. // 总价
  248. jiage() {
  249. var data = this.test,
  250. jiage = 0;
  251. for (let i = 0; i < data.length; i++) {
  252. if (data[i].checked) {
  253. var danjia = JSON.parse(data[i].price);
  254. var shuliang = data[i].buy;
  255. jiage = jiage + (danjia * shuliang);
  256. }
  257. }
  258. this.zongjia = jiage;
  259. },
  260. // /获取购物车列表
  261. getList() {
  262. var that = this;
  263. myRequest({
  264. url: "/api/ShopCart/shopCartList",
  265. method: 'post',
  266. data: {}
  267. }).then(res => {
  268. if (res.data.code == 200) {
  269. that.test = [];
  270. for (let i = 0; i < res.data.data.length; i++) {
  271. var obj = {
  272. img: res.data.data[i].goods_image,
  273. title: res.data.data[i].goods_name,
  274. // label: '黑色 - 6518/320',
  275. // size:'S',
  276. price: res.data.data[i].goods_price,
  277. id: res.data.data[i].id,
  278. buy: res.data.data[i].goods_num,
  279. itemId: res.data.data[i].id,
  280. checked: false,
  281. goods_id: res.data.data[i].goods_id
  282. };
  283. that.test.push(obj)
  284. }
  285. that.jiage()
  286. } else {
  287. that.test = [];
  288. }
  289. })
  290. },
  291. },
  292. }
  293. </script>
  294. <style lang="scss">
  295. /deep/ .tm-menubars .body {
  296. background-color: #1b1b1b !important;
  297. }
  298. /deep/ .jiaoxi {
  299. margin: 0 !important;
  300. padding: 8px !important;
  301. margin-bottom: 200px !important;
  302. }
  303. /deep/ .shangpin .white.bk {
  304. background-color: #1b1b1b !important;
  305. }
  306. /deep/ .shangpin .tm-cartCellListFood {
  307. padding: 0px 0px 15px 0px !important;
  308. margin-top: 5px !important;
  309. margin-bottom: 20px !important;
  310. border-bottom: 1px solid #303030;
  311. }
  312. /deep/ .shangpin .border-t-1.bk {
  313. border-top: 1px solid #1b1b1b !important;
  314. }
  315. /deep/ .shangpin .title {
  316. color: white !important;
  317. }
  318. /deep/ .shangpin .text-red {
  319. color: white !important;
  320. }
  321. /deep/ .shangpin .round-3 {
  322. width: 90px !important;
  323. height: 90px !important;
  324. }
  325. /deep/ .shangpin .tm-cartCellListFood-img {
  326. width: 90px !important;
  327. height: 90px !important;
  328. }
  329. /deep/ .shuliang .text-size-n {
  330. color: white !important;
  331. }
  332. .dibu {
  333. background: #0D0D0D;
  334. position: fixed;
  335. bottom: 0px;
  336. width: 100%;
  337. }
  338. /deep/ .liebiao .grey-darken-4.bk {
  339. background: #0D0D0D !important;
  340. padding: 0px;
  341. margin: 0px;
  342. width: 100%;
  343. border-radius: 0px !important;
  344. }
  345. .logincla {
  346. width: 40%;
  347. margin: 0 auto;
  348. margin-top: 20px;
  349. margin-bottom: 30px;
  350. }
  351. /deep/ .jiageList .d-inline-block {
  352. font-size: 18px !important;
  353. color: white !important;
  354. }
  355. </style>