index.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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 v-for="item in test">
  7. <tm-checkbox @change="choose" style="float: left;padding:2px !important;margin-top:9%;"
  8. v-model="item.checked" label=""></tm-checkbox>
  9. <tm-cartCellListFood @change="shuliangjia(item)" class="shuliang" :typeclick="typeclick"
  10. :mdata="item" :cart-num.sync="item.buy"></tm-cartCellListFood>
  11. </view>
  12. </tm-sheet>
  13. </view>
  14. <view class="dibu">
  15. <tm-listitem class="liebiao" value="免费" :round="24" :shadow="12" title="邮费" :show-right-icon="false">
  16. </tm-listitem>
  17. <tm-listitem class="liebiao jiageList" :value="'¥'+zongjia" :round="24" :shadow="12" title="价格"
  18. :show-right-icon="false"></tm-listitem>
  19. <view class="text-align-center">
  20. <!-- <tm-button theme="red" @click="qingkong()" :round="24" class="mt-50 logincla">清空</tm-button> -->
  21. <tm-button theme="red" @click="shanchu" :round="24" class="mt-50 logincla">删除</tm-button>
  22. <tm-button theme="primary" :round="24" class="mt-50 logincla" @click="goPay">立即付款</tm-button>
  23. </view>
  24. </view>
  25. <!-- 弹出层消息 -->
  26. <tm-message ref="toast"></tm-message>
  27. </view>
  28. </template>
  29. <script>
  30. import {
  31. myRequest
  32. } from '@/api/request.js'
  33. export default {
  34. data() {
  35. return {
  36. zongjia: 0,
  37. test: [],
  38. typeclick: 2, //1加入购物车,2购物车
  39. };
  40. },
  41. onLoad() {
  42. },
  43. created() {
  44. if (!uni.getStorageSync("token")) {
  45. uni.navigateTo({
  46. url: "/pages/login/index",
  47. })
  48. }
  49. this.sys = uni.getSystemInfoSync();
  50. this.getList()
  51. },
  52. methods: {
  53. // 清空
  54. qingkong() {
  55. let that = this;
  56. myRequest({
  57. url: '/api/ShopCart/deleteAllGoods',
  58. method: 'post',
  59. data: {}
  60. }).then(res => {
  61. if (res.data.code == 200) {
  62. console.log(res.data.data, '33');
  63. that.$refs.toast.show({
  64. model: 'success',
  65. label: res.data.msg
  66. })
  67. this.getList()
  68. } else {
  69. that.$refs.toast.show({
  70. model: 'error',
  71. label: res.data.msg
  72. })
  73. }
  74. })
  75. },
  76. goPay() {
  77. var that = this,
  78. data = this.test,
  79. goods = [],
  80. gw_id = [];
  81. for (let i = 0; i < data.length; i++) {
  82. if (data[i].checked) {
  83. console.log(that.zongjia, 'ss');
  84. goods.push(
  85. {
  86. order_remark: '',
  87. order_money:data[i].buy*data[i].price,
  88. pay_money:data[i].buy*data[i].price,
  89. buy_num: data[i].buy,
  90. goods_id: data[i].goods_id,
  91. }
  92. )
  93. gw_id.push(data[i].id)
  94. console.log(goods, gw_id, '下单数据');
  95. }
  96. }
  97. if (goods.length == 0) {
  98. that.$refs.toast.show({
  99. model: 'warn',
  100. label: '请选择商品'
  101. })
  102. return
  103. } else {
  104. myRequest({
  105. url: "/api/Order/addOrder",
  106. method: 'post',
  107. data: {
  108. gw_id: gw_id,
  109. good: goods
  110. }
  111. }).then(res => {
  112. if (res.data.code == 200) {
  113. that.$refs.toast.show({
  114. model: 'success',
  115. label: res.data.msg
  116. })
  117. this.getList()
  118. } else {
  119. that.$refs.toast.show({
  120. model: 'error',
  121. label: res.data.msg
  122. })
  123. }
  124. })
  125. }
  126. },
  127. shanchu() {
  128. var that = this,
  129. data = this.test,
  130. ids = [];
  131. for (let i = 0; i < data.length; i++) {
  132. if (data[i].checked) {
  133. ids.push(data[i].id)
  134. console.log(ids);
  135. }
  136. }
  137. console.log(data, '数据');
  138. if (ids.length == 0) {
  139. that.$refs.toast.show({
  140. model: 'warn',
  141. label: '请选择商品'
  142. })
  143. return
  144. }
  145. myRequest({
  146. url: "/api/ShopCart/deleteOneGoods",
  147. method: 'post',
  148. data: {
  149. id: ids
  150. }
  151. }).then(res => {
  152. if (res.data.code == 200) {
  153. that.$refs.toast.show({
  154. model: 'success',
  155. label: res.data.msg
  156. })
  157. this.getList()
  158. } else {
  159. that.$refs.toast.show({
  160. model: 'error',
  161. label: res.data.msg
  162. })
  163. }
  164. })
  165. },
  166. shuliangjia(num) {
  167. this.jiage();
  168. },
  169. choose() {
  170. this.jiage()
  171. },
  172. jiage() {
  173. var data = this.test,
  174. jiage = 0;
  175. for (let i = 0; i < data.length; i++) {
  176. if (data[i].checked) {
  177. var danjia = JSON.parse(data[i].price);
  178. var shuliang = data[i].buy;
  179. jiage = jiage + (danjia * shuliang);
  180. }
  181. }
  182. this.zongjia = jiage;
  183. },
  184. getList() {
  185. var that = this;
  186. myRequest({
  187. url: "/api/ShopCart/shopCartList",
  188. method: 'post',
  189. data: {}
  190. }).then(res => {
  191. if (res.data.code == 200) {
  192. that.test = [];
  193. for (let i = 0; i < res.data.data.length; i++) {
  194. var obj = {
  195. img: res.data.data[i].goods_image,
  196. title: res.data.data[i].goods_name,
  197. // label: '黑色 - 6518/320',
  198. // size:'S',
  199. price: res.data.data[i].goods_price,
  200. id: res.data.data[i].id,
  201. buy: res.data.data[i].goods_num,
  202. itemId: res.data.data[i].id,
  203. checked: false,
  204. goods_id: res.data.data[i].goods_id
  205. };
  206. that.test.push(obj)
  207. }
  208. that.jiage()
  209. } else {
  210. that.test = [];
  211. }
  212. })
  213. },
  214. },
  215. }
  216. </script>
  217. <style lang="scss">
  218. /deep/ .tm-menubars .body {
  219. background-color: #1b1b1b !important;
  220. }
  221. /deep/ .jiaoxi {
  222. margin: 0 !important;
  223. padding: 8px !important;
  224. margin-bottom: 200px !important;
  225. }
  226. /deep/ .shangpin .white.bk {
  227. background-color: #1b1b1b !important;
  228. }
  229. /deep/ .shangpin .tm-cartCellListFood {
  230. padding: 0px 0px 15px 0px !important;
  231. margin-top: 5px !important;
  232. margin-bottom: 20px !important;
  233. border-bottom: 1px solid #303030;
  234. }
  235. /deep/ .shangpin .border-t-1.bk {
  236. border-top: 1px solid #1b1b1b !important;
  237. }
  238. /deep/ .shangpin .title {
  239. color: white !important;
  240. }
  241. /deep/ .shangpin .text-red {
  242. color: white !important;
  243. }
  244. /deep/ .shangpin .round-3 {
  245. width: 90px !important;
  246. height: 90px !important;
  247. }
  248. /deep/ .shangpin .tm-cartCellListFood-img {
  249. width: 90px !important;
  250. height: 90px !important;
  251. }
  252. /deep/ .shuliang .text-size-n {
  253. color: white !important;
  254. }
  255. .dibu {
  256. background: #0D0D0D;
  257. position: fixed;
  258. bottom: 0px;
  259. width: 100%;
  260. }
  261. /deep/ .liebiao .grey-darken-4.bk {
  262. background: #0D0D0D !important;
  263. padding: 0px;
  264. margin: 0px;
  265. width: 100%;
  266. border-radius: 0px !important;
  267. }
  268. .logincla {
  269. width: 40%;
  270. margin: 0 auto;
  271. margin-top: 20px;
  272. margin-bottom: 30px;
  273. }
  274. /deep/ .jiageList .d-inline-block {
  275. font-size: 18px !important;
  276. color: white !important;
  277. }
  278. </style>