index.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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. checked: false,
  44. number: 0
  45. };
  46. },
  47. onLoad() {
  48. },
  49. created() {
  50. if (!uni.getStorageSync("token")) {
  51. uni.navigateTo({
  52. url: "/pages/login/index",
  53. })
  54. }
  55. this.sys = uni.getSystemInfoSync();
  56. this.getList()
  57. },
  58. methods: {
  59. // ’
  60. chooseAll() {
  61. var data = this.test;
  62. for (let i = 0; i < data.length; i++) {
  63. if (this.checked) {
  64. data[i].checked = true;
  65. } else {
  66. data[i].checked = false;
  67. }
  68. }
  69. this.jiage()
  70. },
  71. // 清空
  72. qingkong() {
  73. let that = this;
  74. myRequest({
  75. url: '/api/ShopCart/deleteAllGoods',
  76. method: 'post',
  77. data: {}
  78. }).then(res => {
  79. if (res.data.code == 200) {
  80. console.log(res.data.data, '33');
  81. that.$refs.toast.show({
  82. model: 'success',
  83. label: res.data.msg
  84. })
  85. this.getList()
  86. } else {
  87. that.$refs.toast.show({
  88. model: 'error',
  89. label: res.data.msg
  90. })
  91. }
  92. })
  93. },
  94. goPay() {
  95. var that = this,
  96. data = this.test,
  97. goods = [],
  98. gw_id = [];
  99. for (let i = 0; i < data.length; i++) {
  100. if (data[i].checked) {
  101. console.log(that.zongjia, 'ss');
  102. goods.push({
  103. order_remark: '',
  104. order_money: data[i].buy * data[i].price,
  105. pay_money: data[i].buy * data[i].price,
  106. buy_num: data[i].buy,
  107. goods_id: data[i].goods_id,
  108. })
  109. gw_id.push(data[i].id)
  110. console.log(goods, gw_id, '下单数据');
  111. }
  112. }
  113. if (goods.length == 0) {
  114. that.$refs.toast.show({
  115. model: 'warn',
  116. label: '请选择商品'
  117. })
  118. return
  119. } else {
  120. myRequest({
  121. url: "/api/Order/addOrder",
  122. method: 'post',
  123. data: {
  124. gw_id: gw_id,
  125. good: goods
  126. }
  127. }).then(res => {
  128. if (res.data.code == 200) {
  129. that.$refs.toast.show({
  130. model: 'success',
  131. label: res.data.msg
  132. })
  133. this.getList()
  134. } else {
  135. that.$refs.toast.show({
  136. model: 'error',
  137. label: res.data.msg
  138. })
  139. }
  140. })
  141. }
  142. },
  143. shanchu() {
  144. var that = this,
  145. data = this.test,
  146. ids = [];
  147. for (let i = 0; i < data.length; i++) {
  148. if (data[i].checked) {
  149. ids.push(data[i].id)
  150. console.log(ids);
  151. }
  152. }
  153. if (ids.length == data.length) {
  154. console.log(ids.length, data.length);
  155. this.checked = true;
  156. }
  157. console.log(data, '数据');
  158. if (ids.length == 0) {
  159. that.$refs.toast.show({
  160. model: 'warn',
  161. label: '请选择商品'
  162. })
  163. return
  164. }
  165. myRequest({
  166. url: "/api/ShopCart/deleteOneGoods",
  167. method: 'post',
  168. data: {
  169. id: ids
  170. }
  171. }).then(res => {
  172. if (res.data.code == 200) {
  173. that.$refs.toast.show({
  174. model: 'success',
  175. label: res.data.msg
  176. })
  177. this.getList()
  178. } else {
  179. that.$refs.toast.show({
  180. model: 'error',
  181. label: res.data.msg
  182. })
  183. }
  184. })
  185. },
  186. jian(data) {
  187. console.log(data, 'data');
  188. if (data.buy >= 1) {
  189. this.number = -1;
  190. } else {
  191. this.number = 1;
  192. }
  193. },
  194. jia(data) {
  195. this.number = 1;
  196. },
  197. // 数量增减
  198. shuliangjia(num) {
  199. console.log(num);
  200. var that = this;
  201. myRequest({
  202. url: "/api/ShopCart/addShopCart",
  203. method: 'post',
  204. data: {
  205. goods_id: num.goods_id,
  206. goods_num: that.number
  207. }
  208. }).then(res => {
  209. if (res.data.code == 200) {} else {
  210. that.$refs.toast.show({
  211. model: 'error',
  212. label: res.data.msg
  213. })
  214. }
  215. })
  216. this.jiage();
  217. },
  218. choose() {
  219. this.jiage()
  220. },
  221. // 总价
  222. jiage() {
  223. var data = this.test,
  224. jiage = 0;
  225. for (let i = 0; i < data.length; i++) {
  226. if (data[i].checked) {
  227. var danjia = JSON.parse(data[i].price);
  228. var shuliang = data[i].buy;
  229. jiage = jiage + (danjia * shuliang);
  230. }
  231. }
  232. this.zongjia = jiage;
  233. },
  234. // /获取购物车列表
  235. getList() {
  236. var that = this;
  237. myRequest({
  238. url: "/api/ShopCart/shopCartList",
  239. method: 'post',
  240. data: {}
  241. }).then(res => {
  242. if (res.data.code == 200) {
  243. that.test = [];
  244. for (let i = 0; i < res.data.data.length; i++) {
  245. var obj = {
  246. img: res.data.data[i].goods_image,
  247. title: res.data.data[i].goods_name,
  248. // label: '黑色 - 6518/320',
  249. // size:'S',
  250. price: res.data.data[i].goods_price,
  251. id: res.data.data[i].id,
  252. buy: res.data.data[i].goods_num,
  253. itemId: res.data.data[i].id,
  254. checked: false,
  255. goods_id: res.data.data[i].goods_id
  256. };
  257. that.test.push(obj)
  258. }
  259. that.jiage()
  260. } else {
  261. that.test = [];
  262. }
  263. })
  264. },
  265. },
  266. }
  267. </script>
  268. <style lang="scss">
  269. /deep/ .tm-menubars .body {
  270. background-color: #1b1b1b !important;
  271. }
  272. /deep/ .jiaoxi {
  273. margin: 0 !important;
  274. padding: 8px !important;
  275. margin-bottom: 200px !important;
  276. }
  277. /deep/ .shangpin .white.bk {
  278. background-color: #1b1b1b !important;
  279. }
  280. /deep/ .shangpin .tm-cartCellListFood {
  281. padding: 0px 0px 15px 0px !important;
  282. margin-top: 5px !important;
  283. margin-bottom: 20px !important;
  284. border-bottom: 1px solid #303030;
  285. }
  286. /deep/ .shangpin .border-t-1.bk {
  287. border-top: 1px solid #1b1b1b !important;
  288. }
  289. /deep/ .shangpin .title {
  290. color: white !important;
  291. }
  292. /deep/ .shangpin .text-red {
  293. color: white !important;
  294. }
  295. /deep/ .shangpin .round-3 {
  296. width: 90px !important;
  297. height: 90px !important;
  298. }
  299. /deep/ .shangpin .tm-cartCellListFood-img {
  300. width: 90px !important;
  301. height: 90px !important;
  302. }
  303. /deep/ .shuliang .text-size-n {
  304. color: white !important;
  305. }
  306. .dibu {
  307. background: #0D0D0D;
  308. position: fixed;
  309. bottom: 0px;
  310. width: 100%;
  311. }
  312. /deep/ .liebiao .grey-darken-4.bk {
  313. background: #0D0D0D !important;
  314. padding: 0px;
  315. margin: 0px;
  316. width: 100%;
  317. border-radius: 0px !important;
  318. }
  319. .logincla {
  320. width: 40%;
  321. margin: 0 auto;
  322. margin-top: 20px;
  323. margin-bottom: 30px;
  324. }
  325. /deep/ .jiageList .d-inline-block {
  326. font-size: 18px !important;
  327. color: white !important;
  328. }
  329. </style>