index.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. <template>
  2. <view class="cart-pages">
  3. <view v-if="!userInfo.receiveAddress" @click="editAddress" class="noAddress">
  4. <view>请输入收货地址</view>
  5. <u-icon name="arrow-right" size="36"></u-icon>
  6. </view>
  7. <view v-else class="cart-bar">
  8. <view>
  9. <u-image height="40rpx" width="40rpx" src="/static/position.png"></u-image>
  10. </view>
  11. <view class="position">
  12. <view class="address">{{userInfo.receiveAddress}}</view>
  13. <view>{{userInfo.receiverName +'&nbsp;&nbsp;&nbsp;' + userInfo.receiverPhone}}</view>
  14. </view>
  15. <view @click="editAddress">
  16. <u-image height="50rpx" width="50rpx" src="/static/edit.png"></u-image>
  17. </view>
  18. </view>
  19. <view class="goods-list">
  20. <!-- 商品列表 -->
  21. <view class="goods-item" v-for="(item,index) in goodsList" :key="item.id">
  22. <view class="goods-imgs">
  23. <u-image border-radius="12" width="158rpx" height="140rpx" :src="item.goods.homeImage"></u-image>
  24. </view>
  25. <view class="goods-info">
  26. <view class="good-name">{{item.goods.name}}</view>
  27. <view class="goods-price">
  28. <view>
  29. <text>{{item.goods.sellGold}}</text>
  30. <u-image mode="scaleToFill" width="30rpx" height="30rpx" src="/static/ledou.png"></u-image>
  31. </view>
  32. <view>×{{item.buyQty}}</view>
  33. </view>
  34. </view>
  35. </view>
  36. <!-- 总计 -->
  37. <view class="goods-heji">
  38. <view>
  39. <view>商品合计:</view>
  40. <view class="heji">
  41. <text>{{totalPrice}}</text>
  42. <u-image mode="scaleToFill" width="35rpx" height="35rpx" src="/static/ledou.png"></u-image>
  43. </view>
  44. </view>
  45. <view>
  46. <view>运费:</view>
  47. <view>免运费</view>
  48. </view>
  49. </view>
  50. </view>
  51. <view class="cart-submit">
  52. <view>
  53. <view>总计:<text>{{totalPrice}}</text></view>
  54. <u-image mode="scaleToFill" width="40rpx" height="40rpx" src="/static/ledou.png"></u-image>
  55. </view>
  56. <view>
  57. <u-button size="mini" :loading="btnLoading" :custom-style="toOrderButton" type="error" @click="toSave">确认支付</u-button>
  58. </view>
  59. </view>
  60. <!-- 提示用户设置支付密码 -->
  61. <u-modal v-model="showSetPswModal"
  62. content="请先设置支付密码,才能使用乐豆"
  63. show-cancel-button
  64. confirm-text="去设置"
  65. cancel-text="暂时放弃"
  66. @confirm="toSetPwd"
  67. @cancel="showSetPswModal=false"
  68. ></u-modal>
  69. <!-- 确认取消弹窗 -->
  70. <u-modal v-model="showLeavePsw"
  71. title="确认放弃支付吗?"
  72. content="您的订单在30分钟内未支付将被取消"
  73. show-cancel-button
  74. confirm-text="确认放弃"
  75. cancel-text="继续支付"
  76. @confirm="canclePay"
  77. @cancel="payAgain"
  78. ></u-modal>
  79. <!-- 确认支付弹窗 -->
  80. <u-popup mode="center" closeable @close="showLeavePsw=true" v-model="showInputPsw" width="500rpx" >
  81. <view class="slot-content">
  82. <view>确认支付</view>
  83. <view class="text-cont">
  84. <text class="num-big">{{totalPrice}}</text>乐豆
  85. </view>
  86. <view class="footer">
  87. <u-input v-model="password" maxlength="30" input-align="center" type="password" placeholder="请输入支付密码" />
  88. </view>
  89. </view>
  90. </u-popup>
  91. </view>
  92. </template>
  93. <script>
  94. import { saveOrder, signPay, existPayPwd} from '@/api/order.js'
  95. import {
  96. findAddressBycustomerNo
  97. } from '@/api/receiveAddress.js'
  98. export default {
  99. data() {
  100. return {
  101. toOrderButton: {
  102. borderRadius:'100rpx',
  103. fontSize:'30rpx',
  104. width: '180rpx',
  105. height: '60rpx'
  106. },
  107. goodsList: [], // 商品列表
  108. // 用户信息
  109. userInfo: {
  110. receiveAddress: '陕西省西安市未央区华帝金座',
  111. receiverName: '王明',
  112. receiverPhone: '14564654551',
  113. },
  114. btnLoading: false, // 提交按钮加载圈
  115. orderId: '', // 订单id
  116. password: '', // 支付密码
  117. showSetPswModal: false, // 设置支付密码弹窗
  118. showInputPsw: false, // 打开输入密码弹窗
  119. showLeavePsw: false, // 打开确定放弃弹窗
  120. };
  121. },
  122. onShow() {
  123. this.getLocation()
  124. },
  125. onLoad() {
  126. this.goodsList = this.$store.state.vuex_toOrderList
  127. // 监听设置密码是否成功
  128. uni.$once('setPswSuccess', this.setPsw)
  129. },
  130. computed: {
  131. totalPrice() {
  132. let total = 0
  133. this.goodsList.map(item => {
  134. total = total + item.buyQty * item.goods.sellGold
  135. })
  136. return total
  137. }
  138. },
  139. methods: {
  140. // 获取用户位置
  141. getLocation() {
  142. findAddressBycustomerNo({}).then(res => {
  143. console.log(res)
  144. if (res.status == 200) {
  145. this.userInfo = res.data[0] || {}
  146. } else {
  147. this.userInfo = {}
  148. uni.showToast({
  149. title: res.message,
  150. icon: 'none'
  151. })
  152. }
  153. })
  154. },
  155. //新增/修改收货地址信息
  156. editAddress(){
  157. this.$u.vuex("vuex_OrderAddress",this.userInfo)
  158. uni.navigateTo({
  159. url:"/pages/toOrder/editAddress?"
  160. })
  161. },
  162. // 跳转到设置支付密码页
  163. toSetPwd () {
  164. uni.navigateTo({
  165. url:"/pages/userCenter/userInfo/paymentPwd"
  166. })
  167. },
  168. // 设置密码成功, 打开输入密码弹窗
  169. setPsw (e) {
  170. if (e.success) {
  171. this.showInputPsw = true
  172. }
  173. },
  174. //确认放弃
  175. canclePay() {
  176. this.showLeavePsw = false
  177. this.showInputPsw = false
  178. },
  179. // 继续支付
  180. payAgain () {
  181. this.showLeavePsw = false
  182. this.showInputPsw = true
  183. },
  184. // 支付 保存订单
  185. toSave(){
  186. existPayPwd().then(res=>{
  187. console.log(res,'rrrrrr')
  188. if(res.status == 200) {
  189. }
  190. })
  191. return
  192. // this.showSetPswModal = true
  193. // return
  194. let orderGoodsList = []
  195. this.goodsList.map((item,index)=>{
  196. orderGoodsList[index] = {
  197. goodsNo: item.goodsNo,
  198. buyQty: item.buyQty
  199. }
  200. })
  201. this.btnLoading = true
  202. let params = {
  203. receiveAddress: this.userInfo.receiveAddress,
  204. receiverName: this.userInfo.receiverName,
  205. receiverPhone: this.userInfo.receiverPhone,
  206. orderGoodsList: orderGoodsList
  207. }
  208. saveOrder(params).then(res=>{
  209. console.log(res,'rrrrrrr')
  210. if(res.status==200) {
  211. this.orderId = res.data.id
  212. this.toPay(this.orderId)
  213. } else {
  214. this.btnLoading = false
  215. uni.showToast({
  216. title: res.message,
  217. icon: 'none'
  218. })
  219. }
  220. })
  221. },
  222. // 支付
  223. toPay(id) {
  224. signPay({id:id}).then(res=>{
  225. this.btnLoading = false
  226. if(res.status == 200) {
  227. // 跳转到支付完成界面
  228. uni.navigateTo({
  229. url:"/pages/toOrder/payFinish?id=" + this.orderId
  230. })
  231. } else{
  232. uni.showToast({
  233. title: res.message,
  234. icon: 'none'
  235. })
  236. }
  237. })
  238. }
  239. },
  240. }
  241. </script>
  242. <style lang="scss">
  243. page{
  244. height: 100%;
  245. }
  246. .cart-pages{
  247. width: 100%;
  248. height: 100%;
  249. display: flex;
  250. flex-direction: column;
  251. .cart-bar{
  252. background: #FFFFFF;
  253. border-bottom: 1px solid #F8F8F8;
  254. border-top: 10upx solid #F8F8F8;
  255. display: flex;
  256. align-items: center;
  257. padding:15upx 20upx;
  258. .position{
  259. flex-grow: 1;
  260. }
  261. > view{
  262. padding: 10upx;
  263. .address{
  264. padding: 5upx 0;
  265. }
  266. &:last-child{
  267. padding: 0 20upx;
  268. }
  269. }
  270. }
  271. .noAddress{
  272. background: #FFFFFF;
  273. border-bottom: 1px solid #F8F8F8;
  274. border-top: 10upx solid #F8F8F8;
  275. display: flex;
  276. align-items: center;
  277. justify-content: space-between;
  278. padding:30upx 20upx;
  279. font-size: 30upx;
  280. }
  281. .goods-list{
  282. padding: 20upx 0;
  283. flex-grow: 1;
  284. overflow: auto;
  285. .goods-class-box{
  286. background: #FFFFFF;
  287. box-shadow: 1px 1px 3px #eee;
  288. margin-bottom: 20upx;
  289. }
  290. .goods-item{
  291. padding: 20upx 40upx;
  292. display: flex;
  293. align-items: center;
  294. border-bottom: 1px solid #F8F8F8;
  295. background: #fff;
  296. &:last-child{
  297. border: 0;
  298. }
  299. .goods-imgs{
  300. position: relative;
  301. }
  302. .goods-info{
  303. flex-grow: 1;
  304. padding-left: 20upx;
  305. .good-name{
  306. font-weight: bold;
  307. word-break: break-all;
  308. }
  309. }
  310. .goods-price{
  311. display: flex;
  312. align-items: center;
  313. justify-content: space-between;
  314. padding-top: 20upx;
  315. >view{
  316. &:first-child{
  317. display: flex;
  318. align-items: center;
  319. text{
  320. color: red;
  321. font-size: 35upx;
  322. margin-right: 6upx;
  323. font-weight: bold;
  324. }
  325. }
  326. }
  327. }
  328. }
  329. }
  330. .goods-heji{
  331. padding: 20upx 40upx;
  332. background: #FFFFFF;
  333. box-shadow: 1px 1px 3px #eee;
  334. margin-top: 20upx;
  335. >view{
  336. display: flex;
  337. align-items: center;
  338. justify-content: space-between;
  339. padding: 10upx 0;
  340. .heji{
  341. display: flex;
  342. align-items: center;
  343. text{
  344. color: red;
  345. margin-right: 6upx;
  346. font-size: 35upx;
  347. font-weight: bold;
  348. }
  349. }
  350. }
  351. }
  352. .cart-submit{
  353. padding: 20upx 30upx;
  354. background: #FFFFFF;
  355. box-shadow: 1px 1px 3px #eee;
  356. border-top: 1px solid #eee;
  357. display: flex;
  358. align-items: center;
  359. justify-content: space-between;
  360. > view{
  361. &:first-child{
  362. display: flex;
  363. align-items: center;
  364. text{
  365. color: red;
  366. font-size: 40upx;
  367. margin-right: 6upx;
  368. font-weight: bold;
  369. }
  370. }
  371. }
  372. }
  373. // 支付密码弹窗
  374. .slot-content{
  375. padding: 30upx 0;
  376. display: flex;
  377. flex-direction: column;
  378. align-items: center;
  379. justify-content: space-between;
  380. .text-cont{
  381. width: 100%;
  382. padding: 60upx 0;
  383. text-align: center;
  384. .num-big{
  385. font-size: 40upx;
  386. color: red;
  387. }
  388. }
  389. .footer{
  390. width: 80%;
  391. border-bottom: 1px solid #b1b1b1;
  392. }
  393. }
  394. }
  395. </style>