index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  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. let data = {
  205. address: that.address._id,
  206. shop: that.shopInfo._id,
  207. goods: that.orderInfo._id,
  208. buy_num: that.buy_num,
  209. remarks: that.remarks
  210. }
  211. const arr = await that.$api(`/zrOrder`, `POST`, data, `integral`)
  212. if (arr.errcode == '0') {
  213. uni.hideLoading();
  214. uni.showToast({
  215. title: arr.data.errmsg || '兑换成功',
  216. icon: 'none'
  217. })
  218. uni.reLaunch({
  219. url: `/pagesIntegral/record/index`
  220. })
  221. } else {
  222. uni.showToast({
  223. title: arr.data.errmsg || '兑换失败!',
  224. icon: 'none'
  225. })
  226. }
  227. } else {
  228. uni.showToast({
  229. title: `没有收货地址`,
  230. icon: 'none'
  231. })
  232. }
  233. },
  234. // 监听用户是否登录
  235. watchLogin() {
  236. const that = this;
  237. uni.getStorage({
  238. key: 'token',
  239. success: function(res) {
  240. let user = that.$jwt(res.data);
  241. that.$set(that, `user`, user);
  242. that.search()
  243. },
  244. fail: function(err) {
  245. uni.reLaunch({
  246. url: `/pages/login/index`
  247. })
  248. }
  249. })
  250. },
  251. // 查询列表
  252. async search() {
  253. const that = this;
  254. let user = that.user;
  255. const res = await that.$api(`/address`, 'GET', {
  256. customer: user._id
  257. })
  258. if (res.errcode == '0') {
  259. that.$set(that, `addressList`, res.data.reverse());
  260. }
  261. const arr = await that.$api(`/zrOrder/toMakeOrder`, 'POST', {
  262. key: that.key
  263. }, `integral`)
  264. if (arr.errcode == '0') {
  265. that.$set(that, `address`, arr.data.address);
  266. that.$set(that, `orderInfo`, arr.data.goods);
  267. that.$set(that, `costTotal`, arr.data.costTotal);
  268. that.$set(that, `shopInfo`, arr.data.shop);
  269. that.$set(that, `buy_num`, arr.data.buy_num);
  270. // this.computedTotal();
  271. }
  272. },
  273. async computedTotal() {
  274. const total_detail = this.total_detail;
  275. let total = this.$plus(total_detail.freight_total, total_detail.goods_total)
  276. if (this.coupon.length > 0) {
  277. let discount = 0;
  278. for (const coupon of this.coupon) {
  279. const r = this.couponList.find(f => f._id === coupon)
  280. if (!r) continue;
  281. const {
  282. discount_config,
  283. discount_type
  284. } = r;
  285. if (discount_type === 'min') {
  286. const min = discount_config.min;
  287. discount = this.$plus(discount, min)
  288. } else if (discount_type === 'discount') {
  289. const min = discount_config.min || 0;
  290. let discount_money = 0;
  291. const max = discount_config.max || 0;
  292. // TODO 现在是平台发放的优惠券,所以可以直接用总价*折扣,如果是店铺的折扣券,则需要将金额分开,对应店铺计算折扣
  293. // const dm = min / 10 * total;
  294. const dm = this.$multiply(this.divide(min, 10), total)
  295. if (max !== 0) {
  296. if (max > dm) discount_money = dm;
  297. else discount_money = max
  298. }
  299. discount += discount_money
  300. }
  301. }
  302. total = this.$minus(total, discount)
  303. }
  304. if (total >= 0) {
  305. this.$set(this, `goods_total`, total);
  306. } else {
  307. uni.showToast({
  308. title: `实付金额不能为负数 不能使用该优惠劵`,
  309. icon: 'none'
  310. })
  311. }
  312. }
  313. }
  314. }
  315. </script>
  316. <style lang="scss">
  317. .main {
  318. display: flex;
  319. flex-direction: column;
  320. width: 100vw;
  321. height: 100vh;
  322. .one {
  323. position: relative;
  324. flex-grow: 1;
  325. background-color: var(--f1Color);
  326. .one_1 {
  327. display: flex;
  328. justify-content: space-between;
  329. align-items: center;
  330. width: 100vw;
  331. padding: 2vw;
  332. border-bottom: 1vw dashed var(--fcColor);
  333. .address {
  334. flex-grow: 1;
  335. margin: 0 0 0 2vw;
  336. font-size: var(--font14Size);
  337. color: var(--f85Color);
  338. }
  339. .iconfont {
  340. font-size: var(--font20Szie);
  341. }
  342. .other {
  343. width: 82vw;
  344. padding: 0 2vw;
  345. .name {
  346. font-size: var(--font16Size);
  347. }
  348. .other_1 {
  349. font-size: var(--font14Size);
  350. color: var(--f85Color);
  351. text {
  352. margin: 0 1vw 0 0;
  353. }
  354. }
  355. }
  356. }
  357. .one_2 {
  358. margin: 2vw 0 0 0;
  359. .list {
  360. width: 100vw;
  361. margin: 2vw 0;
  362. .list_1 {
  363. padding: 2vw;
  364. background-color: var(--mainColor);
  365. border-bottom: 0.1vw solid var(--fcColor);
  366. text {
  367. padding: 0 0 0 1vw;
  368. }
  369. }
  370. .list_2 {
  371. padding: 2vw;
  372. display: flex;
  373. background-color: var(--mainColor);
  374. .l {
  375. width: 20vw;
  376. .image {
  377. width: 100%;
  378. height: 20vw;
  379. border-radius: 5px;
  380. }
  381. }
  382. .c {
  383. width: 60vw;
  384. padding: 0 2vw;
  385. }
  386. .r {
  387. width: 15vw;
  388. text-align: right;
  389. }
  390. }
  391. .list_3 {
  392. width: 96vw;
  393. padding: 2vw;
  394. background-color: var(--mainColor);
  395. .other {
  396. display: flex;
  397. justify-content: space-between;
  398. border-bottom: 0.1vw solid var(--fcColor);
  399. margin: 0 0 2vw 0;
  400. padding: 2vw 0;
  401. .other_1 {
  402. font-size: var(--font16Size);
  403. color: var(--f85Color);
  404. }
  405. .other_3 {
  406. flex-grow: 1;
  407. margin: 0 0 0 2vw;
  408. font-size: var(--font12Size);
  409. }
  410. text {
  411. padding: 0 1vw 0 0;
  412. font-size: var(--font20Szie);
  413. }
  414. }
  415. }
  416. }
  417. .other {
  418. display: flex;
  419. justify-content: space-between;
  420. background-color: var(--mainColor);
  421. border-bottom: 0.1vw solid var(--fcColor);
  422. margin: 0 0 2vw 0;
  423. width: 96vw;
  424. padding: 2vw;
  425. .other_1 {
  426. font-size: var(--font16Size);
  427. color: var(--f85Color);
  428. }
  429. .other_3 {
  430. flex-grow: 1;
  431. margin: 0 0 0 2vw;
  432. font-size: var(--font12Size);
  433. }
  434. text {
  435. padding: 0 1vw 0 0;
  436. font-size: var(--font20Szie);
  437. }
  438. }
  439. }
  440. }
  441. .two {
  442. display: flex;
  443. justify-content: space-between;
  444. border-top: 0.1vw solid var(--fcColor);
  445. .two_1 {
  446. display: flex;
  447. align-items: center;
  448. padding: 0 2vw;
  449. font-size: var(--font16Size);
  450. view:last-child {
  451. margin: 0 0 0 2vw;
  452. color: var(--ff0Color);
  453. font-weight: bold;
  454. }
  455. }
  456. .two_2 {
  457. padding: 3vw 4vw;
  458. color: var(--mainColor);
  459. font-size: var(--font16Size);
  460. background-color: #6A5ACD;
  461. }
  462. }
  463. }
  464. .scroll-view {
  465. position: absolute;
  466. top: 0;
  467. left: 0;
  468. right: 0;
  469. bottom: 0;
  470. .list-scroll-view {
  471. display: flex;
  472. flex-direction: row;
  473. flex-wrap: wrap;
  474. }
  475. }
  476. .popup {
  477. display: flex;
  478. flex-direction: column;
  479. height: 100vw;
  480. overflow-x: hidden;
  481. background-color: var(--f5Color);
  482. padding: 2vw;
  483. .list {
  484. .one {
  485. display: flex;
  486. justify-content: space-between;
  487. margin: 2vw 0 0 0;
  488. padding: 2vw;
  489. background-color: var(--mainColor);
  490. .name {
  491. font-size: var(--font16Size);
  492. }
  493. .address {
  494. font-size: var(--font14Size);
  495. }
  496. .iconfont {
  497. line-height: 15vw;
  498. font-size: var(--font20Szie);
  499. }
  500. }
  501. .two {
  502. display: flex;
  503. justify-content: space-between;
  504. border-top: 0.1vw solid var(--fcColor);
  505. padding: 2vw;
  506. background-color: var(--mainColor);
  507. font-size: var(--font14Size);
  508. .text {
  509. margin: 0 2vw 0 0;
  510. border: 0.1vw solid var(--fFB1Color);
  511. padding: 1vw;
  512. font-size: var(--font12Size);
  513. border-radius: 2vw;
  514. color: var(--fFB1Color);
  515. }
  516. }
  517. }
  518. }
  519. </style>