index.vue 5.8 KB

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