index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. for (let i = 0; i < data.length; i++) {
  81. if (data[i].checked) {
  82. goods.push(data[i])
  83. console.log(data, goods, '数据');
  84. }
  85. }
  86. if (goods.length == 0) {
  87. that.$refs.toast.show({
  88. model: 'success',
  89. label: '请选择商品'
  90. })
  91. return
  92. } else if (goods.length == 1) {
  93. myRequest({
  94. url: "/api/Order/addOrder",
  95. method: 'post',
  96. data: {
  97. order_remark: '',
  98. order_money: that.zongjia,
  99. pay_money: that.zongjia,
  100. buy_num: goods[0].buy,
  101. goods_id: goods[0].goods_id
  102. }
  103. }).then(res => {
  104. if (res.data.code == 200) {
  105. that.$refs.toast.show({
  106. model: 'success',
  107. label: res.data.msg
  108. })
  109. this.shanchu()
  110. } else {
  111. that.$refs.toast.show({
  112. model: 'error',
  113. label: res.data.msg
  114. })
  115. }
  116. })
  117. } else {
  118. console.log('不止一个');
  119. }
  120. },
  121. shanchu() {
  122. var that = this,
  123. data = this.test,
  124. ids = [];
  125. for (let i = 0; i < data.length; i++) {
  126. if (data[i].checked) {
  127. ids.push(data[i].id)
  128. console.log(ids);
  129. }
  130. }
  131. console.log(data, '数据');
  132. if (ids.length == 0) {
  133. that.$refs.toast.show({
  134. model: 'success',
  135. label: '请选择商品'
  136. })
  137. return
  138. }
  139. myRequest({
  140. url: "/api/ShopCart/deleteOneGoods",
  141. method: 'post',
  142. data: {
  143. id: ids
  144. }
  145. }).then(res => {
  146. if (res.data.code == 200) {
  147. that.$refs.toast.show({
  148. model: 'success',
  149. label: res.data.msg
  150. })
  151. this.getList()
  152. } else {
  153. that.$refs.toast.show({
  154. model: 'error',
  155. label: res.data.msg
  156. })
  157. }
  158. })
  159. },
  160. shuliangjia(num) {
  161. this.jiage();
  162. },
  163. choose() {
  164. this.jiage()
  165. },
  166. jiage() {
  167. var data = this.test,
  168. jiage = 0;
  169. for (let i = 0; i < data.length; i++) {
  170. if (data[i].checked) {
  171. var danjia = JSON.parse(data[i].price);
  172. var shuliang = data[i].buy;
  173. jiage = jiage + (danjia * shuliang);
  174. }
  175. }
  176. this.zongjia = jiage;
  177. },
  178. getList() {
  179. var that = this;
  180. myRequest({
  181. url: "/api/ShopCart/shopCartList",
  182. method: 'post',
  183. data: {}
  184. }).then(res => {
  185. if (res.data.code == 200) {
  186. that.test = [];
  187. for (let i = 0; i < res.data.data.length; i++) {
  188. var obj = {
  189. img: res.data.data[i].goods_image,
  190. title: res.data.data[i].goods_name,
  191. // label: '黑色 - 6518/320',
  192. // size:'S',
  193. price: res.data.data[i].goods_price,
  194. id: res.data.data[i].id,
  195. buy: res.data.data[i].goods_num,
  196. itemId: res.data.data[i].id,
  197. checked: false,
  198. goods_id:res.data.data[i].goods_id
  199. };
  200. that.test.push(obj)
  201. }
  202. that.jiage()
  203. } else {
  204. that.test = [];
  205. }
  206. })
  207. },
  208. },
  209. }
  210. </script>
  211. <style lang="scss">
  212. /deep/ .tm-menubars .body {
  213. background-color: #1b1b1b !important;
  214. }
  215. /deep/ .jiaoxi {
  216. margin: 0 !important;
  217. padding: 8px !important;
  218. margin-bottom: 200px !important;
  219. }
  220. /deep/ .shangpin .white.bk {
  221. background-color: #1b1b1b !important;
  222. }
  223. /deep/ .shangpin .tm-cartCellListFood {
  224. padding: 0px 0px 15px 0px !important;
  225. margin-top: 5px !important;
  226. margin-bottom: 20px !important;
  227. border-bottom: 1px solid #303030;
  228. }
  229. /deep/ .shangpin .border-t-1.bk {
  230. border-top: 1px solid #1b1b1b !important;
  231. }
  232. /deep/ .shangpin .title {
  233. color: white !important;
  234. }
  235. /deep/ .shangpin .text-red {
  236. color: white !important;
  237. }
  238. /deep/ .shangpin .round-3 {
  239. width: 90px !important;
  240. height: 90px !important;
  241. }
  242. /deep/ .shangpin .tm-cartCellListFood-img {
  243. width: 90px !important;
  244. height: 90px !important;
  245. }
  246. /deep/ .shuliang .text-size-n {
  247. color: white !important;
  248. }
  249. .dibu {
  250. background: #0D0D0D;
  251. position: fixed;
  252. bottom: 0px;
  253. width: 100%;
  254. }
  255. /deep/ .liebiao .grey-darken-4.bk {
  256. background: #0D0D0D !important;
  257. padding: 0px;
  258. margin: 0px;
  259. width: 100%;
  260. border-radius: 0px !important;
  261. }
  262. .logincla {
  263. width: 40%;
  264. margin: 0 auto;
  265. margin-top: 20px;
  266. margin-bottom: 30px;
  267. }
  268. /deep/ .jiageList .d-inline-block {
  269. font-size: 18px !important;
  270. color: white !important;
  271. }
  272. </style>