景徳镇旅游微信小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

279 lines
6.0 KiB

8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
  1. <template>
  2. <view class="page">
  3. <navbar title="购物车" leftClick @leftClick="$utils.navigateBack" />
  4. <view class="user">
  5. <!-- <uv-checkbox-group
  6. shape="circle"
  7. v-model="cartCheckboxValue"> -->
  8. <uv-radio-group v-model="radiovalue">
  9. <uv-swipe-action>
  10. <view
  11. v-for="(item, index) in cartList"
  12. :key="index">
  13. <view style="margin-top: 20rpx;"></view>
  14. <uv-swipe-action-item
  15. :options="options"
  16. @click="delCart(item, index)">
  17. <view class="item">
  18. <view class="checkbox">
  19. <!-- <uv-checkbox
  20. :name="item.shopcar.id"
  21. activeColor="#FA5A0A"
  22. size="40rpx"
  23. icon-size="35rpx"
  24. ></uv-checkbox> -->
  25. <uv-radio
  26. :name="item.shopcar.id"
  27. activeColor="#FA5A0A"
  28. size="40rpx"
  29. icon-size="35rpx">
  30. </uv-radio>
  31. </view>
  32. <image
  33. class="image"
  34. :src="item.wares.waresImage"
  35. mode=""></image>
  36. <view class="info">
  37. <view class="title">
  38. <view class="">
  39. {{ item.wares.waresTitle }}
  40. </view>
  41. <view class="">
  42. <uv-number-box v-model="item.shopcar.shopcarNumber"
  43. @change="e => valChange(item, e)"></uv-number-box>
  44. </view>
  45. </view>
  46. <!-- <view class="unit">
  47. 规格{{ item.unit }}
  48. <uv-icon name="arrow-down"></uv-icon>
  49. </view> -->
  50. <view class="price">
  51. <text>{{ item.wares.waresPrice }}</text>
  52. </view>
  53. </view>
  54. </view>
  55. </uv-swipe-action-item>
  56. </view>
  57. </uv-swipe-action>
  58. <!-- </uv-checkbox-group> -->
  59. </uv-radio-group>
  60. <cartAction
  61. :price="totalPrice"
  62. :num="num"
  63. @submit="$refs.addressPopup.open('bottom')"/>
  64. </view>
  65. <!-- 地址弹框 -->
  66. <uv-popup ref="addressPopup" :round="30">
  67. <addressList ref="addressList" height="60vh" @select="selectAddress" />
  68. </uv-popup>
  69. <tabber select="3" />
  70. </view>
  71. </template>
  72. <script>
  73. import cartAction from '../components/product/cartAction.vue'
  74. import { mapState } from 'vuex'
  75. import addressList from '../components/address/addressList.vue'
  76. export default {
  77. components: {
  78. cartAction,
  79. addressList,
  80. },
  81. data() {
  82. return {
  83. radiovalue : 0,
  84. options: [
  85. {
  86. text: '删除',
  87. style: {
  88. backgroundColor: '#FA5A0A'
  89. }
  90. },
  91. ],
  92. addressTotal: 0,
  93. address: {
  94. name: '请选择联系人',
  95. addressDetail: ''
  96. },
  97. }
  98. },
  99. computed: {
  100. ...mapState(['cartList', 'cartCheckboxValue']),
  101. totalPrice() {
  102. if (!this.radiovalue) {
  103. return '0'
  104. }
  105. let price = 0
  106. this.cartList.forEach(n => {
  107. if (this.radiovalue == n.shopcar.id) {
  108. price += n.wares.waresPrice * (n.shopcar.shopcarNumber || 1)
  109. }
  110. })
  111. return price
  112. },
  113. num(){
  114. if (!this.radiovalue) {
  115. return '0'
  116. }
  117. let num = 0
  118. this.cartList.forEach(n => {
  119. if (this.radiovalue == n.shopcar.id) {
  120. num += (n.shopcar.shopcarNumber || 1)
  121. }
  122. })
  123. return num
  124. },
  125. },
  126. onShow() {
  127. this.$store.commit('getCartList')
  128. this.getAddressListA()
  129. },
  130. methods: {
  131. // 选择地址
  132. selectAddress(e) {
  133. this.address = e
  134. this.$refs.addressPopup.close()
  135. this.submit()
  136. },
  137. // 获取地址列表
  138. getAddressListA() {
  139. this.$refs.addressList.getAddressList().then(res => {
  140. this.addressTotal = res.total
  141. if (this.addressTotal != 0) {
  142. this.address = res.records[0]
  143. }
  144. })
  145. },
  146. valChange(item, e){
  147. this.$api('updateShopcar', {
  148. id : item.shopcar.id,
  149. shopcarNumber : e.value,
  150. })
  151. },
  152. // 删除购物车
  153. delCart(item, index){
  154. this.$api('deleteShopcar', {
  155. shopcarId : item.shopcar.id
  156. }, res => {
  157. if(res.code == 200){
  158. this.$store.commit('getCartList')
  159. uni.showToast({
  160. title: '删除成功',
  161. });
  162. }
  163. })
  164. },
  165. submit(){
  166. let data = {}
  167. this.cartList.forEach(n => {
  168. if (this.radiovalue == n.shopcar.id) {
  169. data.waresId = n.shopcar.waresId
  170. data.number = n.shopcar.shopcarNumber
  171. data.addressId = this.address.id
  172. }
  173. })
  174. if(this.$utils.verificationAll(data, {
  175. addressId : '请选择地址',
  176. waresId : '请选择商品',
  177. number : '请选择数量',
  178. })){
  179. return
  180. }
  181. this.$api('addWaresOrder', data, res => {
  182. if(res.code == 200){
  183. uni.redirectTo({
  184. url: '/pages_order/order/order'
  185. })
  186. // uni.requestPayment({
  187. // provider: 'wxpay', // 服务提提供商
  188. // timeStamp: res.result.timeStamp, // 时间戳
  189. // nonceStr: res.result.nonceStr, // 随机字符串
  190. // package: res.result.packageValue,
  191. // signType: res.result.signType, // 签名算法
  192. // paySign: res.result.paySign, // 签名
  193. // success: function (res) {
  194. // console.log('支付成功',res);
  195. // uni.redirectTo({
  196. // url: '/pages/index/order'
  197. // })
  198. // },
  199. // fail: function (err) {
  200. // console.log('支付失败',err);
  201. // uni.showToast({
  202. // icon:'none',
  203. // title:"支付失败"
  204. // })
  205. // }
  206. // });
  207. }
  208. })
  209. },
  210. }
  211. }
  212. </script>
  213. <style scoped lang="scss">
  214. .page {
  215. padding-bottom: 200rpx;
  216. /deep/ .uv-swipe-action{
  217. width: 100%;
  218. }
  219. }
  220. .user {
  221. .item{
  222. background-color: #fff;
  223. display: flex;
  224. padding: 30rpx;
  225. .checkbox{
  226. display: flex;
  227. justify-content: center;
  228. align-items: center;
  229. }
  230. .image{
  231. width: 200rpx;
  232. height: 200rpx;
  233. border-radius: 20rpx;
  234. }
  235. .info{
  236. flex: 1;
  237. .title{
  238. display: flex;
  239. padding: 10rpx 20rpx;
  240. justify-content: space-between;
  241. }
  242. .unit{
  243. font-size: 24rpx;
  244. padding: 10rpx 20rpx;
  245. color: #717171;
  246. display: flex;
  247. align-items: center;
  248. }
  249. .price{
  250. color: $uni-color;
  251. font-size: 28rpx;
  252. padding: 10rpx 20rpx;
  253. text{
  254. font-size: 36rpx;
  255. font-weight: 900;
  256. }
  257. }
  258. }
  259. }
  260. }
  261. </style>