payment_seckill.js 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240
  1. import {
  2. checkpaypassword,
  3. balanceConfig
  4. } from "@/api/order/payment"
  5. import {
  6. addressList,
  7. saveAddress,
  8. setDefault,
  9. deleteAddress,
  10. addressInfo
  11. } from "@/api/member/member"
  12. import {
  13. payment,
  14. calculate,
  15. orderCreate
  16. } from "@/api/seckill"
  17. import {
  18. getArea
  19. } from "@/api/address"
  20. import {
  21. mapGetters
  22. } from "vuex"
  23. export default {
  24. name: "seckill_payment",
  25. components: {},
  26. data: () => {
  27. var checkMobile = (rule, value, callback) => {
  28. if (value === "") {
  29. callback(new Error("请输入手机号"))
  30. } else if (!/^\d{11}$/.test(value)) {
  31. callback(new Error("手机号格式错误"))
  32. } else {
  33. callback()
  34. }
  35. }
  36. return {
  37. dialogVisible: false,
  38. memberAddress: {}, //收货地址列表
  39. addressId: 0, //收货地址
  40. addressForm: {
  41. id: 0,
  42. name: "",
  43. mobile: "",
  44. telephone: "",
  45. province_id: "",
  46. city_id: "",
  47. district_id: "",
  48. community_id: "",
  49. address: "",
  50. full_address: "",
  51. is_default: "",
  52. longitude: "",
  53. latitude: ""
  54. },
  55. pickerValueArray: {},
  56. cityArr: {},
  57. districtArr: {},
  58. addressRules: {
  59. name: [{
  60. required: true,
  61. message: "请输入收货人",
  62. trigger: "blur"
  63. },
  64. {
  65. min: 1,
  66. max: 20,
  67. message: "长度在 1 到 20 个字符",
  68. trigger: "blur"
  69. }
  70. ],
  71. mobile: [{
  72. required: true,
  73. validator: checkMobile,
  74. trigger: "change"
  75. }],
  76. province: [{
  77. required: true,
  78. message: "请选择省",
  79. trigger: "change"
  80. }],
  81. city: [{
  82. required: true,
  83. message: "请选择市",
  84. trigger: "change"
  85. }],
  86. district: [{
  87. required: true,
  88. message: "请选择区/县",
  89. trigger: "change"
  90. }],
  91. address: [{
  92. required: true,
  93. message: "请输入详细地址",
  94. trigger: "change"
  95. }]
  96. },
  97. isSend: false,
  98. orderCreateData: {
  99. is_balance: 0,
  100. pay_password: ""
  101. },
  102. orderPaymentData: {
  103. goods_money: 0,
  104. pay_money: 0,
  105. shop_goods_list: {
  106. site_name: "",
  107. express_type: [],
  108. coupon_list: []
  109. },
  110. seckill_info: {
  111. name: ""
  112. },
  113. member_account: {
  114. balance: 0,
  115. is_pay_password: 0
  116. }
  117. },
  118. siteCoupon: {
  119. site_id: 0,
  120. data: []
  121. },
  122. siteDelivery: {
  123. site_id: 0,
  124. data: []
  125. },
  126. dialogStore: false,
  127. promotionInfo: false,
  128. storeList: {},
  129. sitePromotion: [],
  130. isSub: false,
  131. dialogpay: false,
  132. password: "",
  133. fullscreenLoading: true,
  134. deliveryTime: false,
  135. timeTip: "选择配送时间",
  136. time: null,
  137. addressShow: false,
  138. storeRadio: false,
  139. balance_show : 1
  140. }
  141. },
  142. computed: {
  143. ...mapGetters(["seckillOrderCreateData", "defaultGoodsImage", "city"])
  144. },
  145. middleware: 'auth',
  146. mounted() {},
  147. created() {
  148. this.getMemberAddress()
  149. this.getOrderPaymentData()
  150. this.getBalanceConfig()
  151. },
  152. filters: {
  153. /**
  154. * 金额格式化输出
  155. * @param {Object} money
  156. */
  157. moneyFormat(money) {
  158. return parseFloat(money).toFixed(2)
  159. },
  160. /**
  161. * 店铺优惠摘取
  162. */
  163. promotion(data) {
  164. let promotion = ""
  165. if (data) {
  166. Object.keys(data).forEach(key => {
  167. promotion += data[key].content + " "
  168. })
  169. }
  170. return promotion
  171. }
  172. },
  173. methods: {
  174. //获取余额支付配置
  175. getBalanceConfig() {
  176. balanceConfig()
  177. .then(res => {
  178. const {
  179. code,
  180. message,
  181. data
  182. } = res
  183. if (code >= 0) {
  184. this.balance_show = data.balance_show;
  185. }
  186. })
  187. .catch(err => {
  188. const {
  189. code,
  190. message,
  191. data
  192. } = err
  193. // this.$message.error(message)
  194. })
  195. },
  196. //获取收货地址
  197. getMemberAddress() {
  198. addressList({
  199. page_size: 0
  200. })
  201. .then(res => {
  202. const {
  203. code,
  204. message,
  205. data
  206. } = res
  207. if (data && data.list) {
  208. let that = this
  209. this.memberAddress = data.list
  210. data.list.forEach(function(e) {
  211. if (e.is_default == 1) {
  212. that.addressId = e.id
  213. }
  214. })
  215. }
  216. })
  217. .catch(err => {
  218. const {
  219. code,
  220. message,
  221. data
  222. } = err
  223. this.$message.error(message)
  224. })
  225. },
  226. //设置会员收货地址
  227. setMemberAddress(params) {
  228. this.addressId = params
  229. setDefault({
  230. id: params
  231. })
  232. .then(res => {
  233. const {
  234. code,
  235. message,
  236. data
  237. } = res
  238. this.orderCalculate()
  239. })
  240. .catch(err => {
  241. const {
  242. code,
  243. message,
  244. data
  245. } = err
  246. this.$message.error(message)
  247. })
  248. },
  249. //删除会员收货地址
  250. deleteMemberAddress(params) {
  251. deleteAddress({
  252. id: params
  253. })
  254. .then(res => {
  255. const {
  256. code,
  257. message,
  258. data
  259. } = res
  260. if (data) {
  261. this.$message({
  262. message: message,
  263. type: "success"
  264. })
  265. this.getMemberAddress()
  266. } else {
  267. this.$message({
  268. message: message,
  269. type: "warning"
  270. })
  271. }
  272. })
  273. .catch(err => {
  274. this.$message.error(err.message)
  275. })
  276. },
  277. //打开添加收货地址弹出层
  278. addAddressShow() {
  279. this.dialogVisible = true
  280. this.addressForm.id = 0
  281. this.addressForm.name = ""
  282. this.addressForm.mobile = ""
  283. this.addressForm.telephone = ""
  284. this.addressForm.province_id = ""
  285. this.addressForm.city_id = ""
  286. this.addressForm.district_id = ""
  287. this.addressForm.community_id = ""
  288. this.addressForm.address = ""
  289. this.addressForm.full_address = ""
  290. this.addressForm.is_default = ""
  291. this.addressForm.longitude = ""
  292. this.addressForm.latitude = ""
  293. this.$nextTick(() => {
  294. this.$refs.form.resetFields()
  295. })
  296. this.cityArr = {}
  297. this.districtArr = {}
  298. this.getAddress(0)
  299. },
  300. //获取地址
  301. getAddress(type) {
  302. let pid = 0
  303. let that = this
  304. switch (type) {
  305. case 0:
  306. //加载省
  307. pid = 0
  308. break
  309. case 1:
  310. //加载市
  311. pid = this.addressForm.province_id
  312. that.cityArr = {}
  313. that.districtArr = {}
  314. this.addressForm.city_id = ""
  315. this.addressForm.district_id = ""
  316. break
  317. case 2:
  318. //加载区县
  319. pid = this.addressForm.city_id
  320. that.districtArr = {}
  321. this.addressForm.district_id = ""
  322. break
  323. }
  324. getArea({
  325. pid: pid
  326. })
  327. .then(res => {
  328. const {
  329. code,
  330. message,
  331. data
  332. } = res
  333. if (data) {
  334. switch (type) {
  335. case 0:
  336. that.pickerValueArray = data
  337. break
  338. case 1:
  339. //加载市
  340. that.cityArr = data
  341. break
  342. case 2:
  343. //加载区县
  344. that.districtArr = data
  345. break
  346. }
  347. }
  348. })
  349. .catch(err => {
  350. const {
  351. code,
  352. message,
  353. data
  354. } = err
  355. this.$message.error(message)
  356. })
  357. },
  358. //编辑地址 初始化
  359. initAddress(type) {
  360. let pid = 0
  361. let that = this
  362. switch (type) {
  363. case 0:
  364. //加载省
  365. pid = 0
  366. break
  367. case 1:
  368. //加载市
  369. pid = this.addressForm.province_id
  370. that.cityArr = {}
  371. that.districtArr = {}
  372. break
  373. case 2:
  374. //加载区县
  375. pid = this.addressForm.city_id
  376. that.districtArr = {}
  377. break
  378. }
  379. getArea({
  380. pid: pid
  381. })
  382. .then(res => {
  383. const {
  384. code,
  385. message,
  386. data
  387. } = res
  388. if (data) {
  389. switch (type) {
  390. case 0:
  391. that.pickerValueArray = data
  392. break
  393. case 1:
  394. //加载市
  395. that.cityArr = data
  396. break
  397. case 2:
  398. //加载区县
  399. that.districtArr = data
  400. break
  401. }
  402. }
  403. })
  404. .catch(err => {
  405. const {
  406. code,
  407. message,
  408. data
  409. } = err
  410. this.$message.error(message)
  411. })
  412. },
  413. //新增/编辑收货地址
  414. saveAddress(formName) {
  415. this.$refs[formName].validate(valid => {
  416. if (valid) {
  417. if (this.isSend) {
  418. return false
  419. }
  420. if (!this.addressForm.id) {
  421. this.addressForm.full_address = this.$refs.province.selectedLabel + "-" + this.$refs.city.selectedLabel + "-" +
  422. this.$refs.district.selectedLabel
  423. let data = {
  424. name: this.addressForm.name,
  425. mobile: this.addressForm.mobile,
  426. telephone: this.addressForm.telephone,
  427. province_id: this.addressForm.province_id,
  428. city_id: this.addressForm.city_id,
  429. district_id: this.addressForm.district_id,
  430. community_id: "",
  431. address: this.addressForm.address,
  432. full_address: this.addressForm.full_address,
  433. longitude: this.addressForm.longitude,
  434. latitude: this.addressForm.latitude,
  435. is_default: this.addressForm.is_default,
  436. url: "add"
  437. }
  438. if (!data.province_id) {
  439. this.$message({
  440. message: "请选择省",
  441. type: "warning"
  442. })
  443. return false
  444. }
  445. if (!data.city_id) {
  446. this.$message({
  447. message: "请选择市",
  448. type: "warning"
  449. })
  450. return false
  451. }
  452. if (!data.district_id) {
  453. this.$message({
  454. message: "请选择区/县",
  455. type: "warning"
  456. })
  457. return false
  458. }
  459. this.isSend = true
  460. addMemberAddress(data)
  461. .then(res => {
  462. const {
  463. code,
  464. message,
  465. data
  466. } = res
  467. if (data) {
  468. this.setMemberAddress(data)
  469. this.$message({
  470. message: message,
  471. type: "success"
  472. })
  473. this.dialogVisible = false
  474. this.getMemberAddress()
  475. this.getOrderPaymentData()
  476. } else {
  477. this.$message({
  478. message: message,
  479. type: "warning"
  480. })
  481. }
  482. this.isSend = false
  483. })
  484. .catch(err => {
  485. const {
  486. code,
  487. message,
  488. data
  489. } = err
  490. this.$message.error(message)
  491. })
  492. } else {
  493. this.addressForm.full_address = this.$refs.province.selectedLabel + "-" + this.$refs.city.selectedLabel + "-" +
  494. this.$refs.district.selectedLabel
  495. let data = this.addressForm
  496. if (!data.province_id) {
  497. this.$message({
  498. message: "请选择省",
  499. type: "warning"
  500. })
  501. return false
  502. }
  503. if (!data.city_id) {
  504. this.$message({
  505. message: "请选择市",
  506. type: "warning"
  507. })
  508. return false
  509. }
  510. if (!data.district_id) {
  511. this.$message({
  512. message: "请选择区/县",
  513. type: "warning"
  514. })
  515. return false
  516. }
  517. this.isSend = true
  518. this.setMemberAddress(data.id);
  519. data.url = "edit";
  520. saveAddress(data)
  521. .then(res => {
  522. const {
  523. code,
  524. message,
  525. data
  526. } = res
  527. if (data) {
  528. this.$message({
  529. message: message,
  530. type: "success"
  531. })
  532. this.dialogVisible = false
  533. this.getMemberAddress()
  534. this.getOrderPaymentData()
  535. } else {
  536. this.$message({
  537. message: message,
  538. type: "warning"
  539. })
  540. }
  541. this.isSend = false
  542. })
  543. .catch(err => {
  544. const {
  545. code,
  546. message,
  547. data
  548. } = err
  549. this.$message.error(message)
  550. })
  551. }
  552. } else {
  553. return false
  554. }
  555. })
  556. },
  557. addmemberAddress(formName) {
  558. this.$refs[formName].validate(valid => {
  559. if (valid) {
  560. if (this.isSend) {
  561. return false
  562. }
  563. if (!this.addressForm.id) {
  564. this.addressForm.full_address = this.$refs.province.selectedLabel + "-" + this.$refs.city.selectedLabel + "-" +
  565. this.$refs.district.selectedLabel
  566. let data = {
  567. name: this.addressForm.name,
  568. mobile: this.addressForm.mobile,
  569. telephone: this.addressForm.telephone,
  570. province_id: this.addressForm.province_id,
  571. city_id: this.addressForm.city_id,
  572. district_id: this.addressForm.district_id,
  573. community_id: "",
  574. address: this.addressForm.address,
  575. full_address: this.addressForm.full_address,
  576. longitude: this.addressForm.longitude,
  577. latitude: this.addressForm.latitude,
  578. is_default: this.addressForm.is_default,
  579. url: 'add'
  580. }
  581. if (!data.province_id || data.province_id <= 0 ) {
  582. this.$message({
  583. message: "请正确选择省",
  584. type: "warning"
  585. })
  586. return false
  587. }
  588. if (!data.city_id || data.city_id <= 0) {
  589. this.$message({
  590. message: "请正确选择市",
  591. type: "warning"
  592. })
  593. return false
  594. }
  595. if (!data.district_id || data.district_id <= 0) {
  596. this.$message({
  597. message: "请正确选择区/县",
  598. type: "warning"
  599. })
  600. return false
  601. }
  602. this.isSend = true
  603. saveAddress(data)
  604. .then(res => {
  605. const {
  606. code,
  607. message,
  608. data
  609. } = res
  610. if (data) {
  611. this.setMemberAddress(data)
  612. this.$message({
  613. message: message,
  614. type: "success"
  615. })
  616. this.dialogVisible = false
  617. this.getMemberAddress()
  618. this.getOrderPaymentData()
  619. } else {
  620. this.$message({
  621. message: message,
  622. type: "warning"
  623. })
  624. }
  625. this.isSend = false
  626. })
  627. .catch(err => {
  628. const {
  629. code,
  630. message,
  631. data
  632. } = err
  633. this.$message.error(message)
  634. })
  635. } else {
  636. this.addressForm.full_address = this.$refs.province.selectedLabel + "-" + this.$refs.city.selectedLabel + "-" +
  637. this.$refs.district.selectedLabel
  638. let data = this.addressForm
  639. if (!data.province_id) {
  640. this.$message({
  641. message: "请选择省",
  642. type: "warning"
  643. })
  644. return false
  645. }
  646. if (!data.city_id) {
  647. this.$message({
  648. message: "请选择市",
  649. type: "warning"
  650. })
  651. return false
  652. }
  653. if (!data.district_id) {
  654. this.$message({
  655. message: "请选择区/县",
  656. type: "warning"
  657. })
  658. return false
  659. }
  660. this.isSend = true
  661. this.setMemberAddress(data.id);
  662. data.url = "edit";
  663. saveAddress(data)
  664. .then(res => {
  665. const {
  666. code,
  667. message,
  668. data
  669. } = res
  670. if (data) {
  671. this.$message({
  672. message: message,
  673. type: "success"
  674. })
  675. this.dialogVisible = false
  676. this.getMemberAddress()
  677. this.getOrderPaymentData()
  678. } else {
  679. this.$message({
  680. message: message,
  681. type: "warning"
  682. })
  683. }
  684. this.isSend = false
  685. })
  686. .catch(err => {
  687. const {
  688. code,
  689. message,
  690. data
  691. } = err
  692. this.$message.error(message)
  693. })
  694. }
  695. } else {
  696. return false
  697. }
  698. })
  699. },
  700. //编辑收货地址
  701. editAddress(id) {
  702. addressInfo({
  703. id: id
  704. })
  705. .then(res => {
  706. const {
  707. code,
  708. message,
  709. data
  710. } = res
  711. this.addressForm = {
  712. id: data.id,
  713. name: data.name,
  714. mobile: data.mobile,
  715. telephone: data.telephone,
  716. province_id: data.province_id,
  717. city_id: "",
  718. district_id: "",
  719. community_id: "",
  720. address: data.address,
  721. full_address: data.full_address,
  722. is_default: data.is_default,
  723. longitude: data.longitude,
  724. latitude: data.latitude
  725. }
  726. this.initAddress(0)
  727. this.initAddress(1)
  728. this.addressForm.city_id = data.city_id
  729. this.initAddress(2)
  730. this.addressForm.district_id = data.district_id
  731. this.dialogVisible = true
  732. })
  733. .catch(err => {
  734. const {
  735. code,
  736. message,
  737. data
  738. } = err
  739. this.$message.error(message)
  740. })
  741. },
  742. /**
  743. * 获取订单初始化数据
  744. */
  745. getOrderPaymentData() {
  746. this.orderCreateData = this.seckillOrderCreateData
  747. if (!this.orderCreateData) {
  748. this.$message({
  749. message: "未获取到创建订单所需数据!", //提示的信息
  750. type: "warning",
  751. offset: 225,
  752. duration: 3000,
  753. onClose: () => {
  754. this.$router.go(-1)
  755. return false
  756. }
  757. })
  758. return
  759. }
  760. this.orderCreateData.web_city = this.city ? this.city.id : 0
  761. payment(this.orderCreateData)
  762. .then(res => {
  763. const {
  764. code,
  765. message,
  766. data
  767. } = res
  768. if (code >= 0) {
  769. this.orderPaymentData = res.data
  770. this.handlePaymentData()
  771. } else {
  772. this.$message({
  773. message: "未获取到创建订单所需数据!", //提示的信息
  774. type: "warning",
  775. offset: 225,
  776. duration: 3000,
  777. onClose: () => {
  778. this.$router.go(-1)
  779. return false
  780. }
  781. })
  782. return
  783. }
  784. })
  785. .catch(err => {
  786. const {
  787. code,
  788. message,
  789. data
  790. } = err
  791. this.$message.error(message)
  792. })
  793. },
  794. /**
  795. * 处理结算订单数据
  796. */
  797. handlePaymentData() {
  798. this.orderCreateData.delivery = {}
  799. this.orderCreateData.coupon = {}
  800. this.orderCreateData.is_balance = 0
  801. this.orderCreateData.pay_password = ""
  802. var data = this.orderPaymentData
  803. console.log(this.orderPaymentData.shop_goods_list.express_type)
  804. if (this.orderPaymentData.shop_goods_list.express_type.length > 1) {
  805. console.log(this.orderPaymentData.shop_goods_list.express_type, '配送方式')
  806. this.orderCreateData.delivery_type = 'express'
  807. this.orderCreateData.delivery_type_name = '物流配送'
  808. }
  809. let h = new Date().getHours().toString()
  810. let m = new Date().getMinutes().toString()
  811. if (h.length == 1) {
  812. h = "0" + h
  813. }
  814. if (m.length == 1) {
  815. m = "0" + m
  816. }
  817. let nowTime = h + ":" + m
  818. if (data.shop_goods_list.local_config) {
  819. if (data.shop_goods_list.local_config.info && data.shop_goods_list.local_config.info.time_is_open == 1) {
  820. this.orderCreateData.delivery.showTimeBar = true
  821. this.orderCreateData.delivery.buyer_ask_delivery_time = nowTime
  822. } else {
  823. this.orderCreateData.delivery.showTimeBar = false
  824. }
  825. }
  826. // if (data.shop_goods_list.express_type != undefined && data.shop_goods_list.express_type[0] != undefined) {
  827. // var express_type = data.shop_goods_list.express_type
  828. // this.orderCreateData.delivery.delivery_type = express_type[0].name
  829. // this.orderCreateData.delivery.delivery_type_name = express_type[0].title
  830. // this.orderCreateData.delivery.store_id = 0
  831. // // 如果默认配送方式是门店配送
  832. // if (express_type[0].name == "store") {
  833. // if (express_type[0].store_list[0] != undefined) {
  834. // this.orderCreateData.delivery.store_id = express_type[0].store_list[0].store_id
  835. // }
  836. // }
  837. // }
  838. if (data.shop_goods_list.coupon_list != undefined && data.shop_goods_list.coupon_list[0] != undefined) {
  839. var coupon_list = data.shop_goods_list.coupon_list
  840. this.orderCreateData.coupon.coupon_id = coupon_list[0].coupon_id
  841. this.orderCreateData.coupon.coupon_money = coupon_list[0].money
  842. }
  843. if (this.orderPaymentData.is_virtual) {
  844. this.orderCreateData.member_address = {
  845. mobile: ""
  846. }
  847. }
  848. Object.assign(this.orderPaymentData, this.orderCreateData)
  849. this.orderPaymentData.shop_goods_list.goods_list.forEach((v) => {
  850. if (v.sku_spec_format) {
  851. console.log(v)
  852. v.sku_spec_format = JSON.parse(v.sku_spec_format);
  853. } else {
  854. v.sku_spec_format = [];
  855. }
  856. });
  857. this.orderCalculate()
  858. },
  859. /**
  860. * 订单计算
  861. */
  862. orderCalculate() {
  863. this.fullscreenLoading = true
  864. let siteId = this.orderPaymentData.shop_goods_list.site_id
  865. var deliveryObj = {}
  866. deliveryObj[siteId] = this.orderCreateData.delivery
  867. var messageObj = {}
  868. messageObj[siteId] = this.orderCreateData.buyer_message
  869. var data = this.$util.deepClone(this.orderCreateData)
  870. data.delivery = JSON.stringify(deliveryObj)
  871. data.buyer_message = JSON.stringify(messageObj)
  872. data.member_address = JSON.stringify(data.member_address)
  873. calculate(data)
  874. .then(res => {
  875. const {
  876. code,
  877. message,
  878. data
  879. } = res
  880. if (code >= 0) {
  881. this.orderPaymentData.delivery_money = res.data.delivery_money
  882. this.orderPaymentData.coupon_money = res.data.coupon_money
  883. this.orderPaymentData.invoice_money = res.data.invoice_money
  884. this.orderPaymentData.promotion_money = res.data.promotion_money
  885. this.orderPaymentData.order_money = res.data.order_money
  886. this.orderPaymentData.balance_money = res.data.balance_money
  887. this.orderPaymentData.pay_money = res.data.pay_money
  888. this.orderPaymentData.goods_money = res.data.goods_money
  889. } else {
  890. this.$message({
  891. message: message, //提示的信息
  892. type: "warning",
  893. offset: 225,
  894. duration: 3000,
  895. onClose: () => {
  896. this.$router.go(-1)
  897. return false
  898. }
  899. })
  900. return
  901. }
  902. this.fullscreenLoading = false
  903. })
  904. .catch(err => {
  905. const {
  906. code,
  907. message,
  908. data
  909. } = err
  910. this.$message.error(message)
  911. this.fullscreenLoading = false
  912. })
  913. },
  914. /**
  915. * 选择配送方式
  916. */
  917. selectDeliveryType(data) {
  918. this.orderCreateData.delivery.delivery_type = data.name
  919. this.orderCreateData.delivery.delivery_type_name = data.title
  920. this.orderCreateData.delivery_type = data.name
  921. this.orderCreateData.delivery_type_name = data.title
  922. // 如果是门店配送
  923. if (data.name == "store") {
  924. data.store_list.forEach(function(e, i) {
  925. data.store_list[i]["store_address"] = e.full_address + e.address
  926. })
  927. if (data.store_list[0] != undefined) {
  928. this.orderCreateData.delivery.store_id = data.store_list[0].store_id
  929. }
  930. this.dialogStore = true
  931. this.storeList = data.store_list
  932. } else if (data.name == "local") {
  933. this.deliveryTime = true
  934. }
  935. Object.assign(this.orderPaymentData, this.orderCreateData)
  936. this.orderCalculate()
  937. this.$forceUpdate()
  938. },
  939. /**
  940. * 选择自提点
  941. * @param {Object} item
  942. */
  943. selectStore(item) {
  944. console.log(item, 'selectStore')
  945. if (!item) return;
  946. let store_id = item.store_id
  947. this.dialogStore = false
  948. this.orderCreateData.delivery.store_id = store_id
  949. this.orderCreateData.delivery.store_name = item.store_name
  950. Object.assign(this.orderPaymentData, this.orderCreateData)
  951. this.storeRadio = item
  952. this.orderCalculate()
  953. this.$forceUpdate()
  954. },
  955. /**
  956. * 显示店铺优惠信息
  957. * @param {Object} data
  958. */
  959. openSitePromotion(data) {
  960. this.sitePromotion = data
  961. if (this.promotionInfo) {
  962. this.promotionInfo = false
  963. } else {
  964. this.promotionInfo = true
  965. }
  966. },
  967. /**
  968. * 是否使用余额
  969. */
  970. useBalance(type) {
  971. if (this.orderCreateData.is_balance) this.orderCreateData.is_balance = 0
  972. else this.orderCreateData.is_balance = 1
  973. this.orderCalculate()
  974. this.$forceUpdate()
  975. },
  976. orderCreate() {
  977. if (this.verify()) {
  978. if (this.isSub) return
  979. this.isSub = true
  980. var loading = this.$loading({
  981. lock: true,
  982. text: "订单提交中...",
  983. spinner: "el-icon-loading",
  984. background: "rgba(0, 0, 0, 0.7)"
  985. })
  986. let siteId = this.orderPaymentData.shop_goods_list.site_id
  987. var deliveryObj = this.orderCreateData.delivery
  988. var messageObj = this.orderCreateData.buyer_message
  989. var data = this.$util.deepClone(this.orderCreateData)
  990. data.delivery = JSON.stringify(deliveryObj)
  991. data.buyer_message = messageObj
  992. data.member_address = JSON.stringify(data.member_address)
  993. orderCreate(data)
  994. .then(res => {
  995. const {
  996. code,
  997. message,
  998. data
  999. } = res
  1000. loading.close()
  1001. if (code >= 0) {
  1002. this.$store.dispatch("order/removeSeckillOrderCreateData", "")
  1003. if (this.orderPaymentData.pay_money == 0) {
  1004. this.$router.push({
  1005. path: "/result",
  1006. query: {
  1007. code: data
  1008. }
  1009. })
  1010. } else {
  1011. this.$router.push({
  1012. path: "/pay",
  1013. query: {
  1014. code: data
  1015. }
  1016. })
  1017. }
  1018. } else {
  1019. this.$message({
  1020. message: message,
  1021. type: "warning"
  1022. })
  1023. }
  1024. })
  1025. .catch(err => {
  1026. loading.close()
  1027. this.isSub = false
  1028. const {
  1029. code,
  1030. message,
  1031. data
  1032. } = err
  1033. this.$message.error(message)
  1034. })
  1035. }
  1036. },
  1037. /**
  1038. * 订单验证
  1039. */
  1040. verify() {
  1041. if (this.orderPaymentData.is_virtual == 1) {
  1042. if (!this.orderCreateData.member_address.mobile.length) {
  1043. this.$message({
  1044. message: "请输入您的手机号码",
  1045. type: "warning"
  1046. })
  1047. return false
  1048. }
  1049. if (!this.$util.verifyMobile(this.orderCreateData.member_address.mobile)) {
  1050. this.$message({
  1051. message: "请输入正确的手机号码",
  1052. type: "warning"
  1053. })
  1054. return false
  1055. }
  1056. }
  1057. if (this.orderPaymentData.is_virtual == 0) {
  1058. if (!this.orderPaymentData.member_address) {
  1059. this.$message({
  1060. message: "请先选择您的收货地址",
  1061. type: "warning"
  1062. })
  1063. return false
  1064. }
  1065. let deliveryVerify = true
  1066. for (let key in this.orderCreateData.delivery) {
  1067. if (JSON.stringify(this.orderCreateData.delivery[key]) == "{}") {
  1068. deliveryVerify = false
  1069. this.$message({
  1070. message: '店铺"' + this.orderPaymentData.shop_goods_list[key].site_name + '"未设置配送方式',
  1071. type: "warning"
  1072. })
  1073. break
  1074. }
  1075. if (this.orderCreateData.delivery[key].delivery_type == "store" && this.orderCreateData.delivery[key].store_id ==
  1076. 0) {
  1077. deliveryVerify = false
  1078. this.$message({
  1079. message: '店铺"' + this.orderPaymentData.shop_goods_list[key].site_name + '"没有可提货的门店,请选择其他配送方式',
  1080. type: "warning"
  1081. })
  1082. break
  1083. }
  1084. }
  1085. if (!deliveryVerify) return false
  1086. }
  1087. console.log(this.orderPaymentData.delivery_type)
  1088. console.log(this.orderCreateData.delivery.store_name)
  1089. if (this.orderPaymentData.delivery_type == 'store') {
  1090. if (!this.orderCreateData.delivery.store_name) {
  1091. this.$message({
  1092. message: '请选择自提门店',
  1093. type: "warning"
  1094. })
  1095. return false
  1096. }
  1097. }
  1098. // if (this.orderCreateData.is_balance == 1 && this.orderCreateData.pay_password == "") {
  1099. // this.dialogpay = true
  1100. // return false
  1101. // }
  1102. return true
  1103. },
  1104. /**
  1105. * 支付密码输入
  1106. */
  1107. input() {
  1108. if (this.password.length == 6) {
  1109. var loading = this.$loading({
  1110. lock: true,
  1111. text: "支付中",
  1112. spinner: "el-icon-loading",
  1113. background: "rgba(0, 0, 0, 0.7)"
  1114. })
  1115. checkpaypassword({
  1116. pay_password: this.password
  1117. })
  1118. .then(res => {
  1119. const {
  1120. code,
  1121. message,
  1122. data
  1123. } = res
  1124. loading.close()
  1125. if (code >= 0) {
  1126. this.orderCreateData.pay_password = this.password
  1127. this.orderCreate()
  1128. this.dialogpay = false
  1129. } else {
  1130. this.$message({
  1131. message: message,
  1132. type: "warning"
  1133. })
  1134. }
  1135. })
  1136. .catch(err => {
  1137. loading.close()
  1138. const {
  1139. code,
  1140. message,
  1141. data
  1142. } = err
  1143. this.$message.error(message)
  1144. })
  1145. }
  1146. },
  1147. textarea() {
  1148. this.$forceUpdate()
  1149. },
  1150. bindTimeChange(time) {
  1151. this.time = time
  1152. this.orderCreateData.delivery.buyer_ask_delivery_time = this.time
  1153. },
  1154. setDeliveryTime() {
  1155. this.deliveryTime = false
  1156. this.orderCreateData.delivery.buyer_ask_delivery_time = this.time
  1157. },
  1158. imageError(index) {
  1159. this.orderPaymentData.shop_goods_list.goods_list[index].sku_image = this.defaultGoodsImage
  1160. },
  1161. setPayPassword() {
  1162. this.$util.pushToTab("/member/security");
  1163. }
  1164. }
  1165. }