index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. <template>
  2. <mobile-frame>
  3. <view class="main">
  4. <view class="one">
  5. <scroll-view scroll-y="true" class="scroll-view">
  6. <view class="list-scroll-view">
  7. <view class="one_1" @click="toChoose">
  8. <text class="localicon iconfont icon-dingweixiao"></text>
  9. <view class="other" v-if="address._id">
  10. <view class="name">
  11. <text>{{address.name}},</text>{{address.phone}}
  12. </view>
  13. <view class="other_1">
  14. <text>{{address.province}}</text><text>{{address.city}}</text>
  15. <text>{{address.area}}</text><text>{{address.address}}</text>
  16. </view>
  17. </view>
  18. <view class="address" v-else><text>请选择一个收货地址</text></view>
  19. <text class="iconfont icon-jiantouyou"></text>
  20. </view>
  21. <view class="one_2">
  22. <view class="list">
  23. <view class="list_1">
  24. <view class="l">
  25. <text class="iconfont icon-shangdian"></text>
  26. <text>{{shopInfo.name}}</text>
  27. </view>
  28. </view>
  29. <view class="list_2">
  30. <view class="l">
  31. <image class="image"
  32. :src="orderInfo.file&&orderInfo.file.length>0?orderInfo.file[0].url:''"
  33. mode=""></image>
  34. </view>
  35. <view class="c">
  36. <view class="name">
  37. {{orderInfo.name}}
  38. </view>
  39. </view>
  40. <view class="r">
  41. <view class="price">
  42. {{orderInfo.cost}}
  43. </view>
  44. <view class="num">
  45. ×{{buy_num}}
  46. </view>
  47. </view>
  48. </view>
  49. <view class="list_3">
  50. <view class="other">
  51. <view class="other_1">配送方式</view>
  52. <view class="other_2"><text class="iconfont icon-duihao"></text>快递配送</view>
  53. </view>
  54. <view class="other">
  55. <view class="other_1">运费</view>
  56. <view class="other_2">包邮</view>
  57. </view>
  58. <view class="other">
  59. <view class="other_1">订单备注</view>
  60. <view class="other_3">
  61. <input type="text" v-model="remarks" placeholder="选填,可填写您与卖家达成一致的要求" />
  62. </view>
  63. </view>
  64. </view>
  65. </view>
  66. </view>
  67. </view>
  68. </scroll-view>
  69. </view>
  70. <view class="two">
  71. <view class="two_1">
  72. <view>尊荣:</view>
  73. <view>{{costTotal}}</view>
  74. </view>
  75. <view class="two_2">
  76. <text @click="toSubmit">尊荣支付</text>
  77. </view>
  78. </view>
  79. </view>
  80. <uni-popup ref="popup" background-color="#fff" type="bottom">
  81. <view class="popup">
  82. <scroll-view scroll-y="true" class="scroll-view">
  83. <view class="list" v-for="(item,index) in addressList" :key="index">
  84. <view class="one">
  85. <view class="one_1">
  86. <view class="name">
  87. <text>{{item.name}},</text>{{item.phone}}
  88. </view>
  89. <view class="address">
  90. <text>{{item.province}}</text><text>{{item.city}}</text>
  91. <text>{{item.area}}</text><text>{{item.address}}</text>
  92. </view>
  93. </view>
  94. <text class="iconfont icon-jiantouyou"></text>
  95. </view>
  96. <view class="two">
  97. <view class="two_1">
  98. <checkbox-group @change="toCheckbox">
  99. <label>
  100. <checkbox :value="item._id" :checked="item.checked"
  101. style="transform:scale(0.7)" />
  102. 选择地址
  103. </label>
  104. </checkbox-group>
  105. </view>
  106. <view class="two_2">
  107. <text class="text" v-if="item.is_default=='1'">默认</text>
  108. <text @click="toDel(item)" class="iconfont icon-del"></text>
  109. </view>
  110. </view>
  111. </view>
  112. </scroll-view>
  113. </view>
  114. </uni-popup>
  115. </mobile-frame>
  116. </template>
  117. <script>
  118. export default {
  119. data() {
  120. return {
  121. Style: {
  122. btn: true
  123. },
  124. user: {},
  125. key: '',
  126. address: {},
  127. // 商品详情
  128. orderInfo: {},
  129. // 店铺详情
  130. shopInfo: {},
  131. // 总尊荣
  132. costTotal: 0,
  133. // 购买数量
  134. buy_num: 0,
  135. // 收货地址
  136. addressList: [],
  137. // 备注
  138. remarks: '',
  139. };
  140. },
  141. onLoad: async function(e) {
  142. const that = this;
  143. that.$set(that, `key`, e.key || '');
  144. that.watchLogin()
  145. },
  146. methods: {
  147. // 选择收货地址
  148. toChoose() {
  149. const that = this;
  150. if (that.addressList.length > 0) {
  151. that.$refs.popup.open();
  152. } else {
  153. uni.showToast({
  154. title: `暂无收货地址`,
  155. icon: 'none'
  156. })
  157. }
  158. },
  159. // 是否选中
  160. toCheckbox(e) {
  161. const that = this;
  162. var addressList = that.addressList;
  163. var values = e.detail.value;
  164. for (var i = 0, lenI = addressList.length; i < lenI; ++i) {
  165. const item = addressList[i]
  166. if (values.includes(item._id)) {
  167. that.$set(item, 'checked', true)
  168. that.$set(that, `address`, item);
  169. } else {
  170. that.$set(item, 'checked', false)
  171. }
  172. }
  173. that.$refs.popup.close();
  174. },
  175. // 删除收货地址
  176. toDel(e) {
  177. const that = this;
  178. uni.showModal({
  179. title: '提示',
  180. content: '确定删除该地址吗?',
  181. success: async function(res) {
  182. if (res.confirm) {
  183. const arr = await that.$api(`/address/${e._id}`, 'DELETE');
  184. if (arr.errcode == '0') {
  185. uni.showToast({
  186. title: '删除信息成功',
  187. icon: 'none'
  188. })
  189. that.search();
  190. } else {
  191. uni.showToast({
  192. title: arr.errmsg,
  193. icon: 'none'
  194. })
  195. }
  196. }
  197. }
  198. });
  199. },
  200. // 提交订单
  201. async toSubmit() {
  202. const that = this;
  203. if (that.address) {
  204. uni.showModal({
  205. title: '提示',
  206. content: '确定兑换该商品吗?',
  207. success: async function(res) {
  208. if (res.confirm) {
  209. let data = {
  210. address: that.address._id,
  211. shop: that.shopInfo._id,
  212. goods: that.orderInfo._id,
  213. buy_num: that.buy_num,
  214. remarks: that.remarks
  215. }
  216. const arr = await that.$api(`/zrOrder`, `POST`, data, `integral`)
  217. if (arr.errcode == '0') {
  218. uni.hideLoading();
  219. uni.showToast({
  220. title: arr.data.errmsg || '兑换成功',
  221. icon: 'none'
  222. })
  223. uni.reLaunch({
  224. url: `/pagesIntegral/record/index`
  225. })
  226. } else {
  227. uni.showToast({
  228. title: arr.data.errmsg || '兑换失败!',
  229. icon: 'none'
  230. })
  231. }
  232. }
  233. }
  234. });
  235. } else {
  236. uni.showToast({
  237. title: `没有收货地址`,
  238. icon: 'none'
  239. })
  240. }
  241. },
  242. // 监听用户是否登录
  243. watchLogin() {
  244. const that = this;
  245. uni.getStorage({
  246. key: 'token',
  247. success: function(res) {
  248. let user = that.$jwt(res.data);
  249. that.$set(that, `user`, user);
  250. that.search()
  251. },
  252. fail: function(err) {
  253. uni.reLaunch({
  254. url: `/pages/login/index`
  255. })
  256. }
  257. })
  258. },
  259. // 查询列表
  260. async search() {
  261. const that = this;
  262. let user = that.user;
  263. const res = await that.$api(`/address`, 'GET', {
  264. customer: user._id
  265. })
  266. if (res.errcode == '0') {
  267. that.$set(that, `addressList`, res.data.reverse());
  268. }
  269. const arr = await that.$api(`/zrOrder/toMakeOrder`, 'POST', {
  270. key: that.key
  271. }, `integral`)
  272. if (arr.errcode == '0') {
  273. that.$set(that, `address`, arr.data.address);
  274. that.$set(that, `orderInfo`, arr.data.goods);
  275. that.$set(that, `costTotal`, arr.data.costTotal);
  276. that.$set(that, `shopInfo`, arr.data.shop);
  277. that.$set(that, `buy_num`, arr.data.buy_num);
  278. // this.computedTotal();
  279. }
  280. },
  281. async computedTotal() {
  282. const total_detail = this.total_detail;
  283. let total = this.$plus(total_detail.freight_total, total_detail.goods_total)
  284. if (this.coupon.length > 0) {
  285. let discount = 0;
  286. for (const coupon of this.coupon) {
  287. const r = this.couponList.find(f => f._id === coupon)
  288. if (!r) continue;
  289. const {
  290. discount_config,
  291. discount_type
  292. } = r;
  293. if (discount_type === 'min') {
  294. const min = discount_config.min;
  295. discount = this.$plus(discount, min)
  296. } else if (discount_type === 'discount') {
  297. const min = discount_config.min || 0;
  298. let discount_money = 0;
  299. const max = discount_config.max || 0;
  300. // TODO 现在是平台发放的优惠券,所以可以直接用总价*折扣,如果是店铺的折扣券,则需要将金额分开,对应店铺计算折扣
  301. // const dm = min / 10 * total;
  302. const dm = this.$multiply(this.divide(min, 10), total)
  303. if (max !== 0) {
  304. if (max > dm) discount_money = dm;
  305. else discount_money = max
  306. }
  307. discount += discount_money
  308. }
  309. }
  310. total = this.$minus(total, discount)
  311. }
  312. if (total >= 0) {
  313. this.$set(this, `goods_total`, total);
  314. } else {
  315. uni.showToast({
  316. title: `实付金额不能为负数 不能使用该优惠劵`,
  317. icon: 'none'
  318. })
  319. }
  320. }
  321. }
  322. }
  323. </script>
  324. <style lang="scss">
  325. .main {
  326. display: flex;
  327. flex-direction: column;
  328. width: 100vw;
  329. height: 100vh;
  330. .one {
  331. position: relative;
  332. flex-grow: 1;
  333. background-color: var(--f1Color);
  334. .one_1 {
  335. display: flex;
  336. justify-content: space-between;
  337. align-items: center;
  338. width: 100vw;
  339. padding: 2vw;
  340. border-bottom: 1vw dashed var(--fcColor);
  341. .address {
  342. flex-grow: 1;
  343. margin: 0 0 0 2vw;
  344. font-size: var(--font14Size);
  345. color: var(--f85Color);
  346. }
  347. .iconfont {
  348. font-size: var(--font20Szie);
  349. }
  350. .other {
  351. width: 82vw;
  352. padding: 0 2vw;
  353. .name {
  354. font-size: var(--font16Size);
  355. }
  356. .other_1 {
  357. font-size: var(--font14Size);
  358. color: var(--f85Color);
  359. text {
  360. margin: 0 1vw 0 0;
  361. }
  362. }
  363. }
  364. }
  365. .one_2 {
  366. margin: 2vw 0 0 0;
  367. .list {
  368. width: 100vw;
  369. margin: 2vw 0;
  370. .list_1 {
  371. padding: 2vw;
  372. background-color: var(--mainColor);
  373. border-bottom: 0.1vw solid var(--fcColor);
  374. text {
  375. padding: 0 0 0 1vw;
  376. }
  377. }
  378. .list_2 {
  379. padding: 2vw;
  380. display: flex;
  381. background-color: var(--mainColor);
  382. .l {
  383. width: 20vw;
  384. .image {
  385. width: 100%;
  386. height: 20vw;
  387. border-radius: 5px;
  388. }
  389. }
  390. .c {
  391. width: 60vw;
  392. padding: 0 2vw;
  393. }
  394. .r {
  395. width: 15vw;
  396. text-align: right;
  397. .price{
  398. color: var(--ff0Color);
  399. }
  400. }
  401. }
  402. .list_3 {
  403. width: 96vw;
  404. padding: 2vw;
  405. background-color: var(--mainColor);
  406. .other {
  407. display: flex;
  408. justify-content: space-between;
  409. border-bottom: 0.1vw solid var(--fcColor);
  410. margin: 0 0 2vw 0;
  411. padding: 2vw 0;
  412. .other_1 {
  413. font-size: var(--font16Size);
  414. color: var(--f85Color);
  415. }
  416. .other_3 {
  417. flex-grow: 1;
  418. margin: 0 0 0 2vw;
  419. font-size: var(--font12Size);
  420. }
  421. text {
  422. padding: 0 1vw 0 0;
  423. font-size: var(--font20Szie);
  424. }
  425. }
  426. }
  427. }
  428. .other {
  429. display: flex;
  430. justify-content: space-between;
  431. background-color: var(--mainColor);
  432. border-bottom: 0.1vw solid var(--fcColor);
  433. margin: 0 0 2vw 0;
  434. width: 96vw;
  435. padding: 2vw;
  436. .other_1 {
  437. font-size: var(--font16Size);
  438. color: var(--f85Color);
  439. }
  440. .other_3 {
  441. flex-grow: 1;
  442. margin: 0 0 0 2vw;
  443. font-size: var(--font12Size);
  444. }
  445. text {
  446. padding: 0 1vw 0 0;
  447. font-size: var(--font20Szie);
  448. }
  449. }
  450. }
  451. }
  452. .two {
  453. display: flex;
  454. justify-content: space-between;
  455. border-top: 0.1vw solid var(--fcColor);
  456. .two_1 {
  457. display: flex;
  458. align-items: center;
  459. padding: 0 2vw;
  460. font-size: var(--font16Size);
  461. view:last-child {
  462. margin: 0 0 0 2vw;
  463. color: var(--ff0Color);
  464. font-weight: bold;
  465. }
  466. }
  467. .two_2 {
  468. padding: 3vw 4vw;
  469. color: var(--mainColor);
  470. font-size: var(--font16Size);
  471. background-color: #6A5ACD;
  472. }
  473. }
  474. }
  475. .scroll-view {
  476. position: absolute;
  477. top: 0;
  478. left: 0;
  479. right: 0;
  480. bottom: 0;
  481. .list-scroll-view {
  482. display: flex;
  483. flex-direction: row;
  484. flex-wrap: wrap;
  485. }
  486. }
  487. .popup {
  488. display: flex;
  489. flex-direction: column;
  490. height: 100vw;
  491. overflow-x: hidden;
  492. background-color: var(--f5Color);
  493. padding: 2vw;
  494. .list {
  495. .one {
  496. display: flex;
  497. justify-content: space-between;
  498. margin: 2vw 0 0 0;
  499. padding: 2vw;
  500. background-color: var(--mainColor);
  501. .name {
  502. font-size: var(--font16Size);
  503. }
  504. .address {
  505. font-size: var(--font14Size);
  506. }
  507. .iconfont {
  508. line-height: 15vw;
  509. font-size: var(--font20Szie);
  510. }
  511. }
  512. .two {
  513. display: flex;
  514. justify-content: space-between;
  515. border-top: 0.1vw solid var(--fcColor);
  516. padding: 2vw;
  517. background-color: var(--mainColor);
  518. font-size: var(--font14Size);
  519. .text {
  520. margin: 0 2vw 0 0;
  521. border: 0.1vw solid var(--fFB1Color);
  522. padding: 1vw;
  523. font-size: var(--font12Size);
  524. border-radius: 2vw;
  525. color: var(--fFB1Color);
  526. }
  527. }
  528. }
  529. }
  530. </style>