普兆健康管家前端代码仓库
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.

388 lines
9.1 KiB

4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
  1. <template>
  2. <view class="page__view">
  3. <navbar title="确认订单" leftClick @leftClick="$utils.navigateBack" color="#191919" bgColor="#F3F2F7" />
  4. <view class="main">
  5. <view class="flex address" @click="jumpToSelectAddress">
  6. <addressView :data="addressData" :showIcon="true"></addressView>
  7. <uv-icon name="arrow-right" color="#C6C6C6" size="32rpx"></uv-icon>
  8. </view>
  9. <view class="card" v-for="(item, index) in productList" :key="item.id">
  10. <productCard :data="item" @change="onChange(index, $event)"></productCard>
  11. </view>
  12. <view class="order" v-if="orderData">
  13. <view class="order-header">
  14. 订单信息
  15. </view>
  16. <view class="flex row">
  17. <view class="row-label">订单编号</view>
  18. <view class="row-content">{{ orderData.number }}</view>
  19. </view>
  20. <view class="flex row">
  21. <view class="row-label">下单时间</view>
  22. <view class="row-content">{{ $dayjs(orderData.createTime).format('YYYY-MM-DD HH:mm') }}</view>
  23. </view>
  24. </view>
  25. <view class="notice">
  26. <view class="notice-header">下单须知</view>
  27. <view class="notice-content">
  28. <!-- todo: 替换配置项key -->
  29. <uv-parse :content="configList['config_agreement']"></uv-parse>
  30. </view>
  31. </view>
  32. </view>
  33. <view class="bottom">
  34. <view class="agreement">
  35. <uv-checkbox-group
  36. v-model="checkboxValue"
  37. shape="circle"
  38. >
  39. <uv-checkbox
  40. size="40rpx"
  41. icon-size="40rpx"
  42. activeColor="#7451DE"
  43. :name="1"
  44. ></uv-checkbox>
  45. </uv-checkbox-group>
  46. <view class="desc">
  47. 我已阅读并同意
  48. <!-- todo: 替换配置项key -->
  49. <text class="highlight" @click="$refs.modal.open('config_agreement', '用户协议')">用户协议</text>
  50. <!-- todo: 替换配置项key -->
  51. <text class="highlight" @click="$refs.modal.open('config_privacy', '隐私协议')">隐私协议</text>
  52. <!-- todo: 替换配置项key -->
  53. <text class="highlight" @click="$refs.modal.open('config_privacy', '消费者告知')">消费者告知</text>
  54. </view>
  55. </view>
  56. <view class="flex bar">
  57. <view class="flex col price">
  58. <view class="price-label">合计</view>
  59. <view class="price-unit">¥</view><view class="price-value">{{ totalPrice }}</view>
  60. </view>
  61. <button class="col btn" @click="onPay">立即支付</button>
  62. </view>
  63. </view>
  64. <agreementModal ref="modal" @confirm="onConfirmAgreement"></agreementModal>
  65. <payPopup ref="payPopup" @submitted="onPaySuccess"></payPopup>
  66. </view>
  67. </template>
  68. <script>
  69. import { mapState } from 'vuex'
  70. import addressView from '@/pages_order/address/addressView.vue'
  71. import productCard from './productCard.vue'
  72. import agreementModal from '@/pages_order/components/agreementModal.vue'
  73. import payPopup from '@/pages_order/order/payPopup.vue'
  74. export default {
  75. components: {
  76. addressView,
  77. productCard,
  78. agreementModal,
  79. payPopup,
  80. },
  81. data() {
  82. return {
  83. id: null,
  84. defaultAddressInfo: null,
  85. orderData: null,
  86. productList: [],
  87. checkboxValue: [],
  88. }
  89. },
  90. computed: {
  91. ...mapState(['configList', 'userInfo', 'payOrderProduct', 'addressInfo']),
  92. totalPrice() {
  93. return this.productList.reduce((price, item) => {
  94. // return price + item.price * (item.count || 1)
  95. return price + item.currentPrice
  96. }, 0)
  97. },
  98. addressData() {
  99. return this.addressInfo || this.defaultAddressInfo || null
  100. },
  101. },
  102. async onShow() {
  103. console.log('onShow')
  104. console.log('address', this.addressInfo)
  105. this.fetchDefaultAddress()
  106. },
  107. onLoad(arg) {
  108. console.log('onLoad')
  109. console.log('payOrderProduct', this.payOrderProduct)
  110. this.productList = JSON.parse(JSON.stringify(this.payOrderProduct))
  111. // todo: check include Overseas Product ?
  112. // this.$utils.navigateTo('/pages_order/order/userInfo/infoFill')
  113. return
  114. this.orderData = {
  115. id: '001',
  116. number: 'BH872381728321983929',
  117. createTime: '2025-04-28 08:14',
  118. }
  119. console.log('orderData', this.orderData)
  120. },
  121. onUnload() {
  122. this.$store.commit('setAddressInfo', null)
  123. },
  124. methods: {
  125. async fetchDefaultAddress() {
  126. try {
  127. const params = {
  128. pageNo: 1,
  129. pageSize: 1,
  130. userId: this.userInfo.id,
  131. defaultFlag: 1,
  132. }
  133. let { records, total } = await this.$fetch('getAddressList', params)
  134. this.defaultAddressInfo = total ? records[0] : null
  135. } catch (err) {
  136. this.defaultAddressInfo = null
  137. }
  138. },
  139. jumpToSelectAddress() {
  140. this.$utils.navigateTo('/pages_order/address/addressList')
  141. },
  142. onChange(index, obj) {
  143. console.log('onChange', index, obj)
  144. // todo: check skuId? currentPrice ?
  145. this.list[index].skuId = obj.id
  146. this.list[index].specName = obj.specName
  147. },
  148. onConfirmAgreement(confirm) {
  149. if (confirm) {
  150. this.checkboxValue = [1]
  151. } else {
  152. this.checkboxValue = []
  153. }
  154. },
  155. async onPay() {
  156. if(!this.checkboxValue.length){
  157. return uni.showToast({
  158. title: '请先同意《用户协议》《隐私协议》《消费者告知》',
  159. icon:'none'
  160. })
  161. }
  162. if (!this.addressData?.id) {
  163. return uni.showToast({
  164. title: '请选择地址',
  165. icon:'none'
  166. })
  167. }
  168. // const { id } = this.orderData
  169. const obj = {
  170. // todo: check title
  171. title: '营养套餐消费',
  172. // orderId: id,
  173. list: this.productList,
  174. addressId: this.addressData.id,
  175. amount: this.totalPrice,
  176. }
  177. this.$refs.payPopup.open(obj)
  178. },
  179. onPaySuccess() {
  180. uni.reLaunch({
  181. url: '/pages/order/orderList/index'
  182. })
  183. },
  184. },
  185. }
  186. </script>
  187. <style scoped lang="scss">
  188. .page__view {
  189. width: 100vw;
  190. min-height: 100vh;
  191. background-color: $uni-bg-color;
  192. position: relative;
  193. /deep/ .nav-bar__view {
  194. position: fixed;
  195. top: 0;
  196. left: 0;
  197. }
  198. }
  199. .main {
  200. padding: calc(var(--status-bar-height) + 144rpx) 32rpx 310rpx 32rpx;
  201. }
  202. .address {
  203. margin-bottom: 40rpx;
  204. justify-content: space-between;
  205. padding: 24rpx 32rpx;
  206. background: #FFFFFF;
  207. border-radius: 24rpx;
  208. }
  209. .card {
  210. & + & {
  211. margin-top: 32rpx;
  212. }
  213. }
  214. .order {
  215. margin-top: 40rpx;
  216. padding: 32rpx;
  217. background: #FAFAFF;
  218. border: 2rpx solid #FFFFFF;
  219. border-radius: 32rpx;
  220. &-header {
  221. font-family: PingFang SC;
  222. font-weight: 500;
  223. font-size: 36rpx;
  224. line-height: 1.4;
  225. color: #252545;
  226. }
  227. .row {
  228. margin-top: 32rpx;
  229. justify-content: space-between;
  230. font-family: PingFang SC;
  231. font-weight: 400;
  232. line-height: 1.4;
  233. &-label {
  234. font-size: 26rpx;
  235. color: #8B8B8B;
  236. }
  237. &-content {
  238. font-size: 28rpx;
  239. color: #393939;
  240. }
  241. }
  242. }
  243. .notice {
  244. margin-top: 40rpx;
  245. font-family: PingFang SC;
  246. font-weight: 400;
  247. &-header {
  248. font-size: 28rpx;
  249. line-height: 1.4;
  250. color: #393939;
  251. }
  252. &-content {
  253. margin-top: 24rpx;
  254. font-size: 24rpx;
  255. line-height: 1.3;
  256. color: #BABABA;
  257. }
  258. }
  259. .bottom {
  260. position: fixed;
  261. left: 0;
  262. bottom: 0;
  263. width: 100vw;
  264. height: 270rpx;
  265. background: #FFFFFF;
  266. box-sizing: border-box;
  267. .agreement {
  268. display: flex;
  269. padding: 16rpx 40rpx;
  270. background: #EFEAFF;
  271. box-sizing: border-box;
  272. /deep/ .uv-checkbox-group {
  273. flex: none;
  274. }
  275. .desc {
  276. flex: 1;
  277. font-family: PingFang SC;
  278. font-size: 24rpx;
  279. font-weight: 400;
  280. line-height: 40rpx;
  281. color: #8B8B8B;
  282. }
  283. .highlight {
  284. color: $uni-color;
  285. }
  286. }
  287. .bar {
  288. padding: 24rpx 40rpx;
  289. box-sizing: border-box;
  290. column-gap: 30rpx;
  291. .col {
  292. flex: 1;
  293. }
  294. .price {
  295. justify-content: flex-start;
  296. &-label {
  297. font-family: PingFang SC;
  298. font-weight: 400;
  299. font-size: 24rpx;
  300. line-height: 1.4;
  301. color: #626262;
  302. }
  303. &-unit {
  304. margin: 0 8rpx;
  305. font-family: PingFang SC;
  306. font-weight: 500;
  307. font-size: 24rpx;
  308. line-height: 1.4;
  309. color: #7451DE;
  310. }
  311. &-value {
  312. font-family: PingFang SC;
  313. font-weight: 500;
  314. font-size: 40rpx;
  315. line-height: 1.4;
  316. color: #7451DE;
  317. }
  318. }
  319. .btn {
  320. width: 100%;
  321. padding: 16rpx 0;
  322. box-sizing: border-box;
  323. font-family: PingFang SC;
  324. font-weight: 500;
  325. font-size: 36rpx;
  326. line-height: 1;
  327. color: #FFFFFF;
  328. background-image: linear-gradient(to right, #4B348F, #845CFA);
  329. border-radius: 41rpx;
  330. }
  331. }
  332. }
  333. </style>