order_confirm.vue 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. <!-- 订单确认页 -->
  2. <template>
  3. <view class="order_confirm" :style="{ background: 'url(' + bgImg + ') #F4F5F9' }">
  4. <view class="all">
  5. <view class="title">您选择的{{ setData.packageName }}</view>
  6. <view class="menu">
  7. <view class="amounts flex jcsb">
  8. <view class="amontl">
  9. <view class="now flex aife">
  10. <text class="dw fs40">¥</text>
  11. <text class="num">{{ setData.currentPrice }}</text>
  12. <text class="unit">/条</text>
  13. </view>
  14. <view class="past flex aic">
  15. <text class="past_text fs28">原价</text>
  16. <text class="past_num fs32">¥{{ setData.originalPrice }}/条</text>
  17. </view>
  18. </view>
  19. <view class="amontr">
  20. <text class="num">{{ strip }}</text>
  21. <text class="unit">条</text>
  22. </view>
  23. </view>
  24. <view class="choose">
  25. <view v-for="(item, index) in setData.selectContents" :key="index"
  26. class="choose_item-box flex aic jcsb">
  27. <view class="choose_item flex aic">
  28. <image :src="guoxuanImg"></image>
  29. <text>{{ item.configKey }}可选 {{ item.count || 0 }} 个</text>
  30. </view>
  31. <view v-if="index == 0" class="choose_item-more flex aic" @click="toDetail">
  32. <text>查看更多</text>
  33. <image :src="moreBImg"></image>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. <view class="choosion">
  39. <view class="name">选择内容</view>
  40. <view class="content">
  41. <view v-for="(item, index) in orderContents" :key="index" class="content_item flex aic jcsb"
  42. @click="chooseScene(item, index)">
  43. <view class="aic flex">
  44. <view class="item_label">{{ item.name }}</view>
  45. <view v-if="item.scenes.length > 0" class="item_num">{{ item.scenes.join('; ') }}</view>
  46. <view v-else class="item_text">{{ setData.packageName }}可选 {{ item.count || 0 }} 个{{
  47. item.name
  48. }}</view>
  49. </view>
  50. <image class="more_img" :src="moreImg"></image>
  51. </view>
  52. </view>
  53. </view>
  54. <view class="choosion">
  55. <view class="name">支付方式</view>
  56. <view class="content">
  57. <view class="content_item flex aic jcsb">
  58. <view class="aic flex">
  59. <image class="icon_img" :src="weixinImg"></image>
  60. <view class="item_name">微信支付</view>
  61. </view>
  62. <image class="icon_img" :src="guoyuanImg"></image>
  63. </view>
  64. </view>
  65. </view>
  66. <view class="choosion">
  67. <view class="name">收件方式</view>
  68. <view class="content">
  69. <view class="content_item flex aic jcsb">
  70. <view class="aic flex">
  71. <view class="item_label">收件人</view>
  72. <u--input v-model="formData.recipientName" placeholder="输入收件人姓名" fontSize="14"
  73. :customStyle="{ 'margin-left': '48rpx', 'padding': 0 }"></u--input>
  74. </view>
  75. </view>
  76. <view class="content_item flex aic jcsb">
  77. <view class="aic flex">
  78. <view class="item_label">联系电话</view>
  79. <u--input v-model="formData.contactPhone" placeholder="输入手机号码" fontSize="14"
  80. :customStyle="{ 'margin-left': '48rpx', 'padding': 0 }"></u--input>
  81. </view>
  82. </view>
  83. <view class="content_item flex aic jcsb">
  84. <view class="aic flex">
  85. <view class="item_label">收件地址</view>
  86. <u--input v-model="formData.email" placeholder="输入电子邮箱或网盘" fontSize="14"
  87. :customStyle="{ 'margin-left': '48rpx', 'padding': 0 }"></u--input>
  88. </view>
  89. </view>
  90. </view>
  91. </view>
  92. <view class="choosion">
  93. <view class="name">需求相关</view>
  94. <view class="content">
  95. <view class="content_item flex aic jcsb">
  96. <view class="flex">
  97. <view class="item_label">以往案例</view>
  98. <u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple
  99. :maxCount="5">
  100. <view class="item_updata">
  101. <image :src="upImg"></image>
  102. <text>上传案例</text>
  103. </view>
  104. </u-upload>
  105. </view>
  106. </view>
  107. <view class="content_item flex aic jcsb">
  108. <view class="flex w100">
  109. <view class="item_label pt18">拍摄需求</view>
  110. <u--textarea v-model="formData.shootingRequirements" placeholder="简单描述您的拍摄需求" count
  111. maxlength="200"></u--textarea>
  112. </view>
  113. </view>
  114. </view>
  115. </view>
  116. <view class="agree">
  117. <text>点击“确认支付”,即代表您已阅读并同意</text>
  118. <text class="agree_text">《用户购买协议》</text>
  119. </view>
  120. </view>
  121. <view class="btom">
  122. <view class="sum">
  123. <text>应付款:</text>
  124. <text class="money"><text class="unit">¥</text>{{ numMultiR }}</text>
  125. </view>
  126. <view class="btn" :style="{ background: 'url(' + buybtnBg + ')' }" @click="submitOrder">立即购买</view>
  127. </view>
  128. <u-popup ref="uPicker" mode="bottom" :loading="loading" :show="isSelect" round="12" @close="close" @open="open"
  129. :customStyle="{ height: '100px' }">
  130. <view class="popup_content safe-area-inset-bottom">
  131. <view class="checkbox">
  132. <u-checkbox-group v-model="checked" placement="column" iconPlacement="right"
  133. @change="checkboxChange">
  134. <u-checkbox v-for="(item, index) in configData" :key="index" :label="item" :name="item"
  135. :customStyle="{ marginBottom: '24px' }" :disabled="isDisabled(item)"></u-checkbox>
  136. </u-checkbox-group>
  137. </view>
  138. <view class="btns flex aic jcsb">
  139. <view class="cancel" @click="close">取消</view>
  140. <view class="confirm" @click="confirm">确认</view>
  141. </view>
  142. </view>
  143. </u-popup>
  144. </view>
  145. </template>
  146. <script>
  147. import { getPackageById, getConfigById, upload, save } from '@/apis/index';
  148. import { baseUrl } from "@/config"
  149. import { numMulti } from '@/utils/calculate'
  150. export default {
  151. components: {},
  152. data() {
  153. return {
  154. type: '',
  155. fileList1: [],
  156. count: '', //可选数量
  157. strip: '',//条数
  158. packageId: '', //套餐id
  159. setData: {}, // 套餐数据
  160. configData: [], //选择内容数据
  161. loading: false,
  162. isSelect: false,
  163. name: '',
  164. phone: '',
  165. checked: [], //多选
  166. orderContents: [], //选中后的内容
  167. configKey: '',//内容标题
  168. bgImg: "https://ovp-shop.oss-cn-hangzhou.aliyuncs.com/static/9dshop/bg_top%403x.png",
  169. guoxuanImg: 'https://ovp-shop.oss-cn-hangzhou.aliyuncs.com/static/9dshop/ic_guoxuan.png',
  170. guoyuanImg: 'https://ovp-shop.oss-cn-hangzhou.aliyuncs.com/static/9dshop/ic_guoxuanyuan.png',
  171. moreBImg: 'https://ovp-shop.oss-cn-hangzhou.aliyuncs.com/static/9dshop/ic_more_black.png',
  172. moreImg: 'https://ovp-shop.oss-cn-hangzhou.aliyuncs.com/static/9dshop/ic_more%403x.png',
  173. weixinImg: 'https://ovp-shop.oss-cn-hangzhou.aliyuncs.com/static/9dshop/ic_weixinzhifu.png',
  174. upImg: 'https://ovp-shop.oss-cn-hangzhou.aliyuncs.com/static/9dshop/ic_up.png',
  175. buybtnBg: 'https://ovp-shop.oss-cn-hangzhou.aliyuncs.com/static/9dshop/ic_buy.png',
  176. formData: {
  177. recipientName: '',
  178. contactPhone: '',
  179. email: '',
  180. shootingRequirements: '',
  181. }
  182. };
  183. },
  184. computed: {
  185. numMultiR() {
  186. return numMulti(Number(this.setData.currentPrice), Number(this.strip))
  187. }
  188. },
  189. watch: {},
  190. onLoad(options) {
  191. if (options.id) this.packageId = options.id
  192. if (options.strip) this.strip = options.strip
  193. if (options.type) this.type = options.type
  194. this.getPackage()
  195. },
  196. methods: {
  197. toDetail(){
  198. uni.navigateTo({
  199. url: '/pages/index/detail?type='+this.type
  200. })
  201. },
  202. // 判断当前选项是否应该禁用
  203. isDisabled(value) {
  204. // 已选中6个且当前选项未被选中时禁用
  205. return this.checked.length >= this.count &&
  206. !this.checked.includes(value)
  207. },
  208. // 选择变化时的处理
  209. checkboxChange(values) {
  210. if (values.length > this.count) {
  211. // 如果超过6个,自动截断并提示
  212. this.checked = values.slice(0, thsi.count);
  213. uni.showToast({
  214. title: '最多只能选择6个选项',
  215. icon: 'none'
  216. });
  217. }
  218. },
  219. // 获取套餐内容
  220. getPackage() {
  221. getPackageById({ packageId: this.packageId }).then(res => {
  222. this.setData = res
  223. this.orderContents = res.selectContents.map(item => {
  224. return {
  225. name: item.configKey,
  226. configId: item.configId,
  227. count: item.count,
  228. scenes: []
  229. }
  230. })
  231. console.log('orderContents', this.orderContents);
  232. })
  233. },
  234. open() {
  235. console.log('打开');
  236. },
  237. // 选择内容
  238. chooseScene(item, index) {
  239. if (!item.count) {
  240. uni.showToast({
  241. title: '无可选内容',
  242. icon: 'none'
  243. });
  244. return
  245. }
  246. this.loading = true
  247. getConfigById({
  248. packageId: this.packageId,
  249. configId: item.configId
  250. }).then(res => {
  251. this.loading = false
  252. this.count = item.count
  253. console.log(this.checked, this.count, '数量');
  254. this.configData = res
  255. this.configKey = item.name
  256. this.orderContents.map(itm => {
  257. if (itm.name === this.configKey && itm.scenes.length !== 0) {
  258. this.checked = itm.scenes
  259. }
  260. })
  261. this.isSelect = true
  262. })
  263. },
  264. confirm() {
  265. if (this.checked.length < this.count) {
  266. uni.showToast({
  267. title: '至少选择' + this.count + '个选项',
  268. icon: 'none',
  269. });
  270. return
  271. }
  272. this.orderContents.map(item => {
  273. if (item.name === this.configKey) {
  274. item.scenes = this.checked
  275. }
  276. })
  277. this.checked = []
  278. this.isSelect = false
  279. },
  280. close() {
  281. this.isSelect = false
  282. this.checked = []
  283. },
  284. // 删除图片
  285. deletePic(event) {
  286. this[`fileList${event.name}`].splice(event.index, 1);
  287. },
  288. // 新增图片
  289. async afterRead(event) {
  290. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  291. let lists = [].concat(event.file);
  292. let fileListLen = this[`fileList${event.name}`].length;
  293. lists.map((item) => {
  294. this[`fileList${event.name}`].push({
  295. ...item,
  296. status: "uploading",
  297. message: "上传中",
  298. });
  299. });
  300. for (let i = 0; i < lists.length; i++) {
  301. const result = await this.uploadFilePromise(lists[i].url);
  302. let item = this[`fileList${event.name}`][fileListLen];
  303. this[`fileList${event.name}`].splice(
  304. fileListLen,
  305. 1,
  306. Object.assign({
  307. // status: "success",
  308. // message: "",
  309. url: result,
  310. })
  311. );
  312. fileListLen++;
  313. }
  314. console.log(this.fileList1, 'fileList1');
  315. },
  316. uploadFilePromise(url) {
  317. console.log(url, upload, 'url');
  318. return new Promise((resolve, reject) => {
  319. let a = uni.uploadFile({
  320. url: baseUrl + '/sys/oss/upload', // 仅为示例,非真实的接口地址
  321. filePath: url,
  322. name: "file",
  323. formData: {
  324. user: "test",
  325. },
  326. success: (res) => {
  327. let data = JSON.parse(res.data);
  328. setTimeout(() => {
  329. resolve(data.data.src);
  330. }, 1000);
  331. },
  332. fail: (err) => {
  333. console.log(err, 'err');
  334. reject(err);
  335. },
  336. });
  337. });
  338. },
  339. // 校验选择内容
  340. checkContents() {
  341. // for (const item of this.orderContents){
  342. // if (item.scenes.length === 0) {
  343. // uni.showToast({
  344. // title: '请选择' + item.name,
  345. // icon: 'none',
  346. // });
  347. // return false
  348. // }
  349. // }
  350. // // this.orderContents.map(item => {
  351. // // if (item.scenes.length === 0) {
  352. // // uni.showToast({
  353. // // title: '请选择' + item.name,
  354. // // icon: 'none',
  355. // // });
  356. // // return false
  357. // // }
  358. // // })
  359. // return true
  360. for (const item of this.orderContents) {
  361. if (!item.scenes || item.scenes.length === 0) {
  362. uni.showToast({
  363. title: `请选择${item.name}`,
  364. icon: 'none',
  365. duration: 2000
  366. });
  367. return false; // 校验失败
  368. }
  369. }
  370. return true; // 校验成功
  371. },
  372. // 校验表单
  373. checkForm() {
  374. if (this.formData.recipientName === '' || this.formData.contactPhone === '' || this.formData.email === '') {
  375. uni.showToast({
  376. title: '请填写完整收件方式',
  377. icon: 'none',
  378. });
  379. return false
  380. }
  381. return true; // 校验成功
  382. },
  383. // 提交订单
  384. submitOrder() {
  385. // this.checkContents()
  386. if (!this.checkContents()) {
  387. return; // 如果校验失败,停止提交
  388. }
  389. // this.checkForm()
  390. if (!this.checkForm()) {
  391. return; // 如果校验失败,停止提交
  392. }
  393. let params = {
  394. packageId: this.packageId,
  395. quantity: this.strip,
  396. unitPrice: this.setData.currentPrice,
  397. totalAmount: this.numMultiR,
  398. packageName: this.setData.packageName,
  399. ...this.formData,
  400. caseFileUrls: this.fileList1.map(item => {
  401. return item.url
  402. }),
  403. orderContents: JSON.stringify(this.orderContents),
  404. }
  405. save(params).then(res => {
  406. console.log(res, 'res');
  407. })
  408. }
  409. },
  410. created() {
  411. },
  412. mounted() {
  413. },
  414. }
  415. </script>
  416. <style lang="scss">
  417. uni-toast {
  418. z-index: 99999 !important;
  419. }
  420. </style>
  421. <style lang='scss' scoped>
  422. .order_confirm {
  423. width: 100%;
  424. position: absolute;
  425. top: 0;
  426. bottom: 0;
  427. display: flex;
  428. flex-direction: column;
  429. background-size: contain !important;
  430. background-repeat: no-repeat !important;
  431. background-position: top;
  432. .all {
  433. padding: 0 24rpx;
  434. flex: 1;
  435. overflow: auto;
  436. .title {
  437. font-weight: 500;
  438. font-size: 36rpx;
  439. color: #0D121A;
  440. margin: 48rpx 0 40rpx;
  441. text-align: center;
  442. }
  443. .menu {
  444. width: 100%;
  445. background: linear-gradient(180deg, #E4F8FF 0%, #FFFFFF 100%);
  446. border-radius: 24rpx;
  447. border: 2rpx solid #FFFFFF;
  448. padding: 64rpx 48rpx;
  449. .amounts {
  450. .now {
  451. font-size: 32rpx;
  452. color: #0D121A;
  453. .dw {
  454. line-height: 40rpx;
  455. }
  456. .limit {
  457. margin-left: 24rpx;
  458. width: 72rpx;
  459. height: 40rpx;
  460. background: linear-gradient(144deg, #00C1FF 0%, #2FFFFC 100%);
  461. border-radius: 8rpx;
  462. font-weight: 500;
  463. font-size: 24rpx;
  464. color: #0D121A;
  465. text-align: center;
  466. line-height: 40rpx;
  467. }
  468. }
  469. .num {
  470. font-size: 72rpx;
  471. line-height: 56rpx;
  472. font-weight: bold;
  473. }
  474. .unit {
  475. margin-left: 8px;
  476. }
  477. .past {
  478. color: #0D121A;
  479. margin-top: 34rpx;
  480. .past_text {
  481. margin-right: 8rpx;
  482. }
  483. }
  484. }
  485. .choose {
  486. margin-top: 64rpx;
  487. .choose_item-box {
  488. margin-top: 16rpx;
  489. image {
  490. width: 48rpx;
  491. height: 48rpx;
  492. margin-right: 24rpx;
  493. }
  494. text {
  495. color: #0D121A;
  496. font-size: 28rpx;
  497. }
  498. }
  499. .choose_item-more {
  500. text {
  501. font-size: 28rpx;
  502. color: #0D121A;
  503. }
  504. image {
  505. width: 32rpx;
  506. height: 32rpx;
  507. margin-left: 12rpx;
  508. }
  509. }
  510. .choose_item-box:nth-child(1) {
  511. margin-top: 0;
  512. }
  513. }
  514. }
  515. .choosion {
  516. .name {
  517. font-weight: 400;
  518. font-size: 28rpx;
  519. color: #9EA3B1;
  520. margin: 32rpx 0 20rpx 32rpx;
  521. }
  522. .content {
  523. background-color: #FFFFFF;
  524. border-radius: 24rpx;
  525. .content_item {
  526. padding: 36rpx 32rpx;
  527. .item_updata {
  528. width: 168rpx;
  529. height: 168rpx;
  530. background: #F4F5F9;
  531. border-radius: 16rpx;
  532. display: flex;
  533. flex-direction: column;
  534. align-items: center;
  535. justify-content: center;
  536. // margin-left: 48rpx;
  537. image {
  538. width: 56rpx;
  539. height: 56rpx;
  540. }
  541. text {
  542. color: #9EA3B1;
  543. font-weight: 400;
  544. font-size: 24rpx;
  545. }
  546. }
  547. .item_label {
  548. font-weight: 500;
  549. font-size: 28rpx;
  550. color: #0D121A;
  551. min-width: 150rpx;
  552. white-space: nowrap;
  553. }
  554. .item_num {
  555. font-size: 28rpx;
  556. margin-left: 48rpx;
  557. }
  558. .item_text {
  559. font-size: 28rpx;
  560. color: #9EA3B1;
  561. margin-left: 48rpx;
  562. }
  563. .item_name {
  564. font-size: 28rpx;
  565. color: #0D121A;
  566. margin-left: 16rpx;
  567. }
  568. .more_img {
  569. width: 32rpx;
  570. height: 32rpx;
  571. flex-shrink: 0;
  572. }
  573. .icon_img {
  574. width: 48rpx;
  575. height: 48rpx;
  576. }
  577. input {
  578. height: 0;
  579. }
  580. }
  581. .content_item_input {}
  582. }
  583. }
  584. .agree {
  585. display: flex;
  586. justify-content: center;
  587. align-items: center;
  588. font-size: 24rpx;
  589. color: #9EA3B1;
  590. padding: 48rpx 0 32rpx;
  591. .agree_text {
  592. color: #0D121A;
  593. }
  594. }
  595. }
  596. .btom {
  597. background: #FFFFFF;
  598. flex-shrink: 1;
  599. display: flex;
  600. justify-content: space-between;
  601. align-items: center;
  602. padding: 16rpx 24rpx;
  603. padding-bottom: calc(16rpx + constant(safe-area-inset-bottom)) !important;
  604. padding-bottom: calc(16rpx + env(safe-area-inset-bottom)) !important;
  605. .sum {
  606. font-weight: 400;
  607. font-size: 30rpx;
  608. color: #0D121A;
  609. .money {
  610. font-size: 56rpx;
  611. color: #0D121A;
  612. }
  613. .unit {
  614. font-size: 40rpx;
  615. }
  616. }
  617. .btn {
  618. width: 312rpx;
  619. height: 84rpx;
  620. display: flex;
  621. justify-content: center;
  622. align-items: center;
  623. font-weight: bold;
  624. font-size: 32rpx;
  625. color: #0D121A;
  626. background-size: 100% 100% !important;
  627. }
  628. }
  629. .pt18 {
  630. padding-top: 18rpx;
  631. }
  632. .popup_content {
  633. padding: 32rpx;
  634. max-height: 1000rpx;
  635. display: flex;
  636. flex-direction: column;
  637. .checkbox {
  638. flex: 1;
  639. overflow: auto;
  640. }
  641. .btns {
  642. flex-shrink: 1;
  643. }
  644. }
  645. .btns {
  646. padding: 0 0 16rpx;
  647. color: #0D121A;
  648. .cancel {
  649. width: 45%;
  650. height: 84rpx;
  651. background: #FFFFFF;
  652. border-radius: 16rpx;
  653. display: flex;
  654. justify-content: center;
  655. align-items: center;
  656. border: #9EA3B1 1px solid;
  657. }
  658. .confirm {
  659. width: 45%;
  660. height: 84rpx;
  661. border-radius: 16rpx;
  662. display: flex;
  663. justify-content: center;
  664. align-items: center;
  665. background: linear-gradient(144deg, #00C1FF 0%, #2FFFFC 100%);
  666. }
  667. }
  668. .u-popup {
  669. flex: 0;
  670. z-index: 999;
  671. }
  672. }
  673. </style>