index.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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%;" v-model="item.checked"
  11. label=""></tm-checkbox>
  12. <tm-cartCellListFood @change="shuliangjia(item)" v-on:jian="jian(item)" v-on:jia="jia(item)" class="shuliang"
  13. :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. shanchu() {
  169. var that = this,
  170. data = this.test,
  171. ids = [];
  172. for (let i = 0; i < data.length; i++) {
  173. if (data[i].checked) {
  174. ids.push(data[i].id)
  175. console.log(ids);
  176. }
  177. }
  178. if (ids.length == data.length) {
  179. console.log(ids.length, data.length);
  180. this.checked = true;
  181. }
  182. console.log(data, '数据');
  183. if (ids.length == 0) {
  184. that.$refs.toast.show({
  185. model: 'warn',
  186. label: '请选择商品'
  187. })
  188. return
  189. }
  190. myRequest({
  191. url: "/api/ShopCart/deleteOneGoods",
  192. method: 'post',
  193. data: {
  194. id: ids
  195. }
  196. }).then(res => {
  197. if (res.data.code == 200) {
  198. that.$refs.toast.show({
  199. model: 'success',
  200. label: res.data.msg
  201. })
  202. this.getList()
  203. } else {
  204. that.$refs.toast.show({
  205. model: 'error',
  206. label: res.data.msg
  207. })
  208. }
  209. })
  210. },
  211. // 按钮减
  212. jian() {
  213. this.number = -1;
  214. },
  215. // 按钮加
  216. jia() {
  217. this.number = 1;
  218. },
  219. // 数量增减
  220. shuliangjia(num) {
  221. var that = this;
  222. myRequest({
  223. url: "/api/ShopCart/addShopCart",
  224. method: 'post',
  225. data: {
  226. goods_id: num.goods_id,
  227. goods_num: that.number
  228. }
  229. }).then(res => {
  230. if (res.data.code == 200) {} else {
  231. that.$refs.toast.show({
  232. model: 'error',
  233. label: res.data.msg
  234. })
  235. }
  236. })
  237. this.jiage();
  238. },
  239. // 总价
  240. jiage() {
  241. var data = this.test,
  242. jiage = 0;
  243. for (let i = 0; i < data.length; i++) {
  244. if (data[i].checked) {
  245. var danjia = JSON.parse(data[i].price);
  246. var shuliang = data[i].buy;
  247. jiage = jiage + (danjia * shuliang);
  248. }
  249. }
  250. this.zongjia = jiage;
  251. },
  252. // /获取购物车列表
  253. getList() {
  254. var that = this;
  255. myRequest({
  256. url: "/api/ShopCart/shopCartList",
  257. method: 'post',
  258. data: {}
  259. }).then(res => {
  260. if (res.data.code == 200) {
  261. that.test = [];
  262. for (let i = 0; i < res.data.data.length; i++) {
  263. var obj = {
  264. img: res.data.data[i].goods_image,
  265. title: res.data.data[i].goods_name,
  266. // label: '黑色 - 6518/320',
  267. // size:'S',
  268. price: res.data.data[i].goods_price,
  269. id: res.data.data[i].id,
  270. buy: res.data.data[i].goods_num,
  271. itemId: res.data.data[i].id,
  272. checked: false,
  273. goods_id: res.data.data[i].goods_id
  274. };
  275. that.test.push(obj)
  276. }
  277. that.jiage()
  278. } else {
  279. that.test = [];
  280. }
  281. })
  282. },
  283. },
  284. }
  285. </script>
  286. <style lang="scss">
  287. /deep/ .tm-menubars .body {
  288. background-color: #1b1b1b !important;
  289. }
  290. /deep/ .jiaoxi {
  291. margin: 0 !important;
  292. padding: 8px !important;
  293. margin-bottom: 200px !important;
  294. }
  295. /deep/ .shangpin .white.bk {
  296. background-color: #1b1b1b !important;
  297. }
  298. /deep/ .shangpin .tm-cartCellListFood {
  299. padding: 0px 0px 15px 0px !important;
  300. margin-top: 5px !important;
  301. margin-bottom: 20px !important;
  302. border-bottom: 1px solid #303030;
  303. }
  304. /deep/ .shangpin .border-t-1.bk {
  305. border-top: 1px solid #1b1b1b !important;
  306. }
  307. /deep/ .shangpin .title {
  308. color: white !important;
  309. }
  310. /deep/ .shangpin .text-red {
  311. color: white !important;
  312. }
  313. /deep/ .shangpin .round-3 {
  314. width: 90px !important;
  315. height: 90px !important;
  316. }
  317. /deep/ .shangpin .tm-cartCellListFood-img {
  318. width: 90px !important;
  319. height: 90px !important;
  320. }
  321. /deep/ .shuliang .text-size-n {
  322. color: white !important;
  323. }
  324. .dibu {
  325. background: #0D0D0D;
  326. position: fixed;
  327. bottom: 0px;
  328. width: 100%;
  329. }
  330. /deep/ .liebiao .grey-darken-4.bk {
  331. background: #0D0D0D !important;
  332. padding: 0px;
  333. margin: 0px;
  334. width: 100%;
  335. border-radius: 0px !important;
  336. }
  337. .logincla {
  338. width: 40%;
  339. margin: 0 auto;
  340. margin-top: 20px;
  341. margin-bottom: 30px;
  342. }
  343. /deep/ .jiageList .d-inline-block {
  344. font-size: 18px !important;
  345. color: white !important;
  346. }
  347. </style>