青蛙卖大米小程序2024-11-24
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.

384 lines
7.5 KiB

6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
  1. <template>
  2. <view class="page">
  3. <navbar title="下单支付" leftClick @leftClick="$utils.navigateBack" />
  4. <view class="box">
  5. <!-- 地址 -->
  6. <view class="address" @click="openAddress">
  7. <image src="../static/address/icon1.png" mode=""></image>
  8. <view class="">
  9. {{ address.name }}
  10. </view>
  11. <view class="">
  12. {{ address.address }}
  13. </view>
  14. <view class="icon">
  15. <uv-icon size="30rpx" name="arrow-right"></uv-icon>
  16. </view>
  17. </view>
  18. <view class="productList">
  19. <view class="item"
  20. :key="index"
  21. v-for="(item, index) in productList">
  22. <view class="item-image">
  23. <image :src="item.image &&
  24. item.image.split(',')[0]"
  25. mode="aspectFill"></image>
  26. </view>
  27. <view class="info">
  28. <view class="title">
  29. {{ item.title }}
  30. </view>
  31. <view class="desc">
  32. {{ item.sku }}
  33. </view>
  34. <view class="price-box">
  35. <view class="">
  36. <uv-number-box
  37. v-model="item.num"
  38. v-if="[1, 2].includes(item.type)"
  39. ></uv-number-box>
  40. </view>
  41. <!-- 会员价普通商品并且是会员的时候显示 -->
  42. <view class="price"
  43. v-if="[2].includes(item.type) && [1].includes(userInfo.isPay)">
  44. 会员价{{ item.vipPrice }}
  45. </view>
  46. <!-- 零售价价格 -->
  47. <view class="price"
  48. v-else>
  49. {{ item.price }}
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. <view class="submit-box">
  56. <view class="peis">
  57. <view class="">
  58. 配送方式
  59. </view>
  60. <view class="">
  61. 商家自行配送
  62. </view>
  63. </view>
  64. <view class="priceInfo">
  65. <view class="">
  66. 付款金额
  67. </view>
  68. <view class="totalPrice">
  69. {{ totalPrice }}
  70. </view>
  71. </view>
  72. <view class="remark">
  73. <input type="text"
  74. placeholder="请输入备注"
  75. v-model="remark"/>
  76. </view>
  77. </view>
  78. <view class="uni-color-btn"
  79. @click="submit">
  80. 确认下单
  81. </view>
  82. </view>
  83. <!-- 地址选择 -->
  84. <uv-popup ref="addressPopup" :round="30">
  85. <addressList ref="addressList" height="60vh" @select="selectAddress" />
  86. </uv-popup>
  87. </view>
  88. </template>
  89. <script>
  90. import addressList from '../components/address/addressList.vue'
  91. import { mapState } from 'vuex'
  92. export default {
  93. components: {
  94. addressList,
  95. },
  96. data() {
  97. return {
  98. productList: [],
  99. address: {
  100. name: '请选择地址',
  101. address: '',
  102. },
  103. addressTotal: 0,
  104. remark : '',
  105. num : 1,
  106. }
  107. },
  108. computed : {
  109. totalPrice(){
  110. let price = 0
  111. this.productList.forEach(n => {
  112. if([2].includes(n.type) &&
  113. [1].includes(this.userInfo.isPay)){
  114. // 普通商品的同时用户是会员就计算会员价
  115. price += n.vipPrice * n.num
  116. }else{
  117. // 普通价格
  118. price += n.price * n.num
  119. }
  120. })
  121. return Number(price).toFixed(2)
  122. },
  123. ...mapState(['payOrderProduct', 'userInfo']),
  124. },
  125. onLoad() {
  126. this.getRiceProductDetail()
  127. this.$store.commit('getUserInfo')
  128. },
  129. onShow() {
  130. this.getAddressList()
  131. },
  132. methods: {
  133. // 获取商品
  134. getRiceProductDetail() {
  135. this.productList = JSON.parse(JSON.stringify(this.payOrderProduct))
  136. },
  137. // 打开
  138. getAddressList() {
  139. // 获取地址列表
  140. this.$refs.addressList.getAddressList().then(res => {
  141. this.addressTotal = res.total
  142. if (this.addressTotal != 0) {
  143. this.address = res.records[0]
  144. }
  145. })
  146. },
  147. // 打开选择地址
  148. openAddress() {
  149. if (this.addressTotal == 0) {
  150. return uni.navigateTo({
  151. url: '/pages_order/mine/address?type=back'
  152. })
  153. }
  154. this.$refs.addressPopup.open('bottom')
  155. },
  156. // 选择地址
  157. selectAddress(e) {
  158. this.address = e
  159. this.$refs.addressPopup.close()
  160. },
  161. // 确认下单
  162. // submit(){
  163. // this.$api('createOrder', {
  164. // productId : this.productList[0].id,
  165. // num : 1,
  166. // }, res => {
  167. // if(res.code == 200){
  168. // uni.showToast({
  169. // title: '购买成功',
  170. // icon: 'none'
  171. // })
  172. // setInterval(uni.navigateTo, 1000, {
  173. // url : '/pages/index/order'
  174. // })
  175. // }
  176. // })
  177. // },
  178. submit(){
  179. let addressId = this.address.id
  180. if(!addressId){
  181. uni.showToast({
  182. title: '请选择地址',
  183. icon: 'none'
  184. })
  185. return
  186. }
  187. let data = {}
  188. let api = ''
  189. if(this.productList[0].type == 2){//普通商品
  190. let list = []
  191. this.productList.forEach(n => {
  192. list.push({
  193. num : n.num,
  194. shopId : n.shopId || n.id,
  195. })
  196. })
  197. data = {
  198. addressId,
  199. list : JSON.stringify(list),
  200. }
  201. api = 'createSumOrder'
  202. }else{//体验、常规商品
  203. data = {
  204. addressId,
  205. num : this.productList[0].num,
  206. productId : this.productList[0].id,
  207. }
  208. api = 'createOrder'
  209. }
  210. this.$api(api, data, res => {
  211. if(res.code == 200){
  212. uni.requestPaymentWxPay(res)
  213. .then(res => {
  214. uni.showToast({
  215. title: '下单成功',
  216. icon: 'none'
  217. })
  218. setTimeout(uni.redirectTo, 700, {
  219. url: '/pages/index/order'
  220. })
  221. }).catch(n => {
  222. setTimeout(uni.redirectTo, 700, {
  223. url: '/pages/index/order'
  224. })
  225. })
  226. }
  227. })
  228. },
  229. }
  230. }
  231. </script>
  232. <style scoped lang="scss">
  233. .page {
  234. .box {
  235. padding: 20rpx;
  236. .address {
  237. display: flex;
  238. padding: 20rpx;
  239. background-color: #fff;
  240. align-items: center;
  241. border-radius: 20rpx;
  242. image {
  243. width: 60rpx;
  244. height: 40rpx;
  245. margin: 20rpx;
  246. }
  247. view {
  248. margin: 20rpx;
  249. overflow: hidden; //超出的文本隐藏
  250. text-overflow: ellipsis; //溢出用省略号显示
  251. white-space: nowrap; //溢出不换行
  252. }
  253. .icon {
  254. margin-left: auto;
  255. }
  256. }
  257. .productList {
  258. margin-top: 20rpx;
  259. background-color: #fff;
  260. border-radius: 20rpx;
  261. .item {
  262. padding: 10rpx 20rpx;
  263. align-items: center;
  264. margin-bottom: 20rpx;
  265. display: flex;
  266. width: 100%;
  267. box-sizing: border-box;
  268. .item-image {
  269. width: 140rpx;
  270. height: 140rpx;
  271. flex-shrink: 0;
  272. image {
  273. height: 100%;
  274. width: 100%;
  275. border-radius: 20rpx;
  276. }
  277. }
  278. .info {
  279. padding: 20rpx;
  280. color: #555;
  281. flex: 1;
  282. .title {
  283. font-size: 28rpx;
  284. font-weight: 900;
  285. }
  286. .desc {
  287. font-size: 22rpx;
  288. color: #777;
  289. margin-top: 10rpx;
  290. }
  291. .price-box {
  292. display: flex;
  293. justify-content: space-between;
  294. color: #f40;
  295. font-size: 30rpx;
  296. font-weight: 900;
  297. .price{
  298. &>view:nth-child(2){
  299. font-size: 22rpx;
  300. color: #777;
  301. text{
  302. font-size: 26rpx;
  303. font-weight: 900;
  304. }
  305. }
  306. }
  307. }
  308. }
  309. }
  310. }
  311. .submit-box{
  312. background-color: #fff;
  313. padding: 20rpx;
  314. border-radius: 20rpx;
  315. &>view:nth-child(2){
  316. margin-top: 20rpx;
  317. }
  318. &>view{
  319. display: flex;
  320. justify-content: space-between;
  321. align-items: center;
  322. font-size: 28rpx;
  323. &>view:nth-child(1){
  324. font-weight: 900;
  325. }
  326. &>view:nth-child(2){
  327. color: #999;
  328. font-size: 24rpx;
  329. }
  330. .totalPrice{
  331. color: #f40 !important;
  332. font-size: 34rpx !important;
  333. font-weight: 900;
  334. }
  335. }
  336. .remark{
  337. margin-top: 30rpx;
  338. input{
  339. background-color: #f3f3f3;
  340. padding: 14rpx 20rpx;
  341. border-radius: 20rpx;
  342. flex: 1;
  343. }
  344. }
  345. }
  346. }
  347. }
  348. </style>