payment_groupbuy.js 26 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205
  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/groupbuy"
  17. import {
  18. getArea
  19. } from "@/api/address"
  20. import {
  21. mapGetters
  22. } from "vuex"
  23. export default {
  24. name: "groupbuy_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. groupbuy_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: 0,
  139. balance_show: 1
  140. }
  141. },
  142. computed: {
  143. ...mapGetters(["groupbuyOrderCreateData", "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: 0,
  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.groupbuyOrderCreateData
  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. // if (data.shop_goods_list.express_type != undefined && data.shop_goods_list.express_type[0] != undefined) {
  810. // var express_type = data.shop_goods_list.express_type
  811. // this.orderCreateData.delivery.delivery_type = express_type[0].name
  812. // this.orderCreateData.delivery.delivery_type_name = express_type[0].title
  813. // this.orderCreateData.delivery.store_id = 0
  814. // // 如果默认配送方式是门店配送
  815. // if (express_type[0].name == "store") {
  816. // if (express_type[0].store_list[0] != undefined) {
  817. // this.orderCreateData.delivery.store_id = express_type[0].store_list[0].store_id
  818. // }
  819. // }
  820. // }
  821. if (data.shop_goods_list.coupon_list != undefined && data.shop_goods_list.coupon_list[0] != undefined) {
  822. var coupon_list = data.shop_goods_list.coupon_list
  823. this.orderCreateData.coupon.coupon_id = coupon_list[0].coupon_id
  824. this.orderCreateData.coupon.coupon_money = coupon_list[0].money
  825. }
  826. if (this.orderPaymentData.is_virtual) {
  827. this.orderCreateData.member_address = {
  828. mobile: ""
  829. }
  830. }
  831. Object.assign(this.orderPaymentData, this.orderCreateData)
  832. this.orderCalculate()
  833. },
  834. /**
  835. * 订单计算
  836. */
  837. orderCalculate() {
  838. this.fullscreenLoading = true
  839. var data = this.$util.deepClone(this.orderCreateData)
  840. data.delivery = JSON.stringify(data.delivery)
  841. data.coupon = JSON.stringify(data.coupon)
  842. data.member_address = JSON.stringify(data.member_address)
  843. calculate(data)
  844. .then(res => {
  845. const {
  846. code,
  847. message,
  848. data
  849. } = res
  850. if (code >= 0) {
  851. this.orderPaymentData.delivery_money = res.data.delivery_money
  852. this.orderPaymentData.coupon_money = res.data.coupon_money
  853. this.orderPaymentData.invoice_money = res.data.invoice_money
  854. this.orderPaymentData.promotion_money = res.data.promotion_money
  855. this.orderPaymentData.order_money = res.data.order_money
  856. this.orderPaymentData.balance_money = res.data.balance_money
  857. this.orderPaymentData.pay_money = res.data.pay_money
  858. this.orderPaymentData.goods_money = res.data.goods_money
  859. } else {
  860. this.$message({
  861. message: message, //提示的信息
  862. type: "warning",
  863. offset: 225,
  864. duration: 3000,
  865. onClose: () => {
  866. this.$router.go(-1)
  867. return false
  868. }
  869. })
  870. return
  871. }
  872. this.fullscreenLoading = false
  873. })
  874. .catch(err => {
  875. const {
  876. code,
  877. message,
  878. data
  879. } = err
  880. this.$message.error(message)
  881. this.fullscreenLoading = false
  882. })
  883. },
  884. /**
  885. * 选择配送方式
  886. */
  887. selectDeliveryType(data) {
  888. this.orderCreateData.delivery.delivery_type = data.name
  889. this.orderCreateData.delivery.delivery_type_name = data.title
  890. this.orderCreateData.delivery_type = data.name
  891. this.orderCreateData.delivery_type_name = data.title
  892. // 如果是门店配送
  893. if (data.name == "store") {
  894. data.store_list.forEach(function(e, i) {
  895. data.store_list[i]["store_address"] = e.full_address + e.address
  896. })
  897. if (data.store_list[0] != undefined) {
  898. this.orderCreateData.delivery.store_id = data.store_list[0].store_id
  899. }
  900. this.dialogStore = true
  901. this.storeList = data.store_list
  902. } else if (data.name == "local") {
  903. this.deliveryTime = true
  904. }
  905. Object.assign(this.orderPaymentData, this.orderCreateData)
  906. this.orderCalculate()
  907. this.$forceUpdate()
  908. },
  909. /**
  910. * 选择自提点
  911. * @param {Object} item
  912. */
  913. selectStore(item) {
  914. console.log(item, 'selectStore')
  915. if (!item) return;
  916. let store_id = item.store_id
  917. this.dialogStore = false
  918. this.orderCreateData.delivery.store_id = store_id
  919. this.orderCreateData.delivery.store_name = item.store_name
  920. Object.assign(this.orderPaymentData, this.orderCreateData)
  921. this.storeRadio = item
  922. this.orderCalculate()
  923. this.$forceUpdate()
  924. },
  925. /**
  926. * 显示店铺优惠信息
  927. * @param {Object} data
  928. */
  929. openSitePromotion(data) {
  930. this.sitePromotion = data
  931. if (this.promotionInfo) {
  932. this.promotionInfo = false
  933. } else {
  934. this.promotionInfo = true
  935. }
  936. },
  937. /**
  938. * 是否使用余额
  939. */
  940. useBalance(type) {
  941. if (this.orderCreateData.is_balance) this.orderCreateData.is_balance = 0
  942. else this.orderCreateData.is_balance = 1
  943. this.orderCalculate()
  944. this.$forceUpdate()
  945. },
  946. orderCreate() {
  947. if (this.verify()) {
  948. if (this.isSub) return
  949. this.isSub = true
  950. var loading = this.$loading({
  951. lock: true,
  952. text: "订单提交中...",
  953. spinner: "el-icon-loading",
  954. background: "rgba(0, 0, 0, 0.7)"
  955. })
  956. let siteId = this.orderPaymentData.shop_goods_list.site_id
  957. var deliveryObj = this.orderCreateData.delivery
  958. var messageObj = this.orderCreateData.buyer_message
  959. var data = this.$util.deepClone(this.orderCreateData)
  960. data.delivery = JSON.stringify(deliveryObj)
  961. data.buyer_message = messageObj
  962. data.member_address = JSON.stringify(data.member_address)
  963. data.forceLogin = true
  964. orderCreate(data)
  965. .then(res => {
  966. const {
  967. code,
  968. message,
  969. data
  970. } = res
  971. loading.close()
  972. if (code >= 0) {
  973. this.$store.dispatch("order/removeGroupbuyOrderCreateData", "")
  974. if (this.orderPaymentData.pay_money == 0) {
  975. this.$router.push({
  976. path: "/result",
  977. query: {
  978. code: data
  979. }
  980. })
  981. } else {
  982. this.$router.push({
  983. path: "/pay",
  984. query: {
  985. code: data
  986. }
  987. })
  988. }
  989. } else {
  990. this.$message({
  991. message: message,
  992. type: "warning"
  993. })
  994. }
  995. })
  996. .catch(err => {
  997. loading.close()
  998. this.isSub = false
  999. const {
  1000. code,
  1001. message,
  1002. data
  1003. } = err
  1004. this.$message.error(message)
  1005. })
  1006. }
  1007. },
  1008. /**
  1009. * 订单验证
  1010. */
  1011. verify() {
  1012. if (this.orderPaymentData.is_virtual == 1) {
  1013. if (!this.orderCreateData.member_address.mobile.length) {
  1014. this.$message({
  1015. message: "请输入您的手机号码",
  1016. type: "warning"
  1017. })
  1018. return false
  1019. }
  1020. if (!this.$util.verifyMobile(this.orderCreateData.member_address.mobile)) {
  1021. this.$message({
  1022. message: "请输入正确的手机号码",
  1023. type: "warning"
  1024. })
  1025. return false
  1026. }
  1027. }
  1028. if (this.orderPaymentData.is_virtual == 0) {
  1029. if (!this.orderPaymentData.member_address) {
  1030. this.$message({
  1031. message: "请先选择您的收货地址",
  1032. type: "warning"
  1033. })
  1034. return false
  1035. }
  1036. let deliveryVerify = true
  1037. for (let key in this.orderCreateData.delivery) {
  1038. if (JSON.stringify(this.orderCreateData.delivery[key]) == "{}") {
  1039. deliveryVerify = false
  1040. this.$message({
  1041. message: '店铺"' + this.orderPaymentData.shop_goods_list[key].site_name + '"未设置配送方式',
  1042. type: "warning"
  1043. })
  1044. break
  1045. }
  1046. if (this.orderCreateData.delivery[key].delivery_type == "store" && this.orderCreateData.delivery[key].store_id ==
  1047. 0) {
  1048. deliveryVerify = false
  1049. this.$message({
  1050. message: '店铺"' + this.orderPaymentData.shop_goods_list[key].site_name + '"没有可提货的门店,请选择其他配送方式',
  1051. type: "warning"
  1052. })
  1053. break
  1054. }
  1055. }
  1056. if (!deliveryVerify) return false
  1057. }
  1058. console.log(this.orderPaymentData.delivery_type)
  1059. console.log(this.orderCreateData.delivery.store_name)
  1060. if (this.orderPaymentData.delivery_type == 'store') {
  1061. if (!this.orderCreateData.delivery.store_name) {
  1062. this.$message({
  1063. message: '请选择自提门店',
  1064. type: "warning"
  1065. })
  1066. return false
  1067. }
  1068. }
  1069. // if (this.orderCreateData.is_balance == 1 && this.orderCreateData.pay_password == "") {
  1070. // this.dialogpay = true
  1071. // return false
  1072. // }
  1073. return true
  1074. },
  1075. /**
  1076. * 支付密码输入
  1077. */
  1078. input() {
  1079. if (this.password.length == 6) {
  1080. var loading = this.$loading({
  1081. lock: true,
  1082. text: "支付中",
  1083. spinner: "el-icon-loading",
  1084. background: "rgba(0, 0, 0, 0.7)"
  1085. })
  1086. checkpaypassword({
  1087. pay_password: this.password
  1088. })
  1089. .then(res => {
  1090. const {
  1091. code,
  1092. message,
  1093. data
  1094. } = res
  1095. loading.close()
  1096. if (code >= 0) {
  1097. this.orderCreateData.pay_password = this.password
  1098. this.orderCreate()
  1099. this.dialogpay = false
  1100. } else {
  1101. this.$message({
  1102. message: message,
  1103. type: "warning"
  1104. })
  1105. }
  1106. })
  1107. .catch(err => {
  1108. loading.close()
  1109. const {
  1110. code,
  1111. message,
  1112. data
  1113. } = err
  1114. this.$message.error(message)
  1115. })
  1116. }
  1117. },
  1118. textarea() {
  1119. this.$forceUpdate()
  1120. },
  1121. bindTimeChange(time) {
  1122. this.time = time
  1123. this.orderCreateData.delivery.buyer_ask_delivery_time = this.time
  1124. },
  1125. setDeliveryTime() {
  1126. this.deliveryTime = false
  1127. this.orderCreateData.delivery.buyer_ask_delivery_time = this.time
  1128. },
  1129. imageError(index) {
  1130. this.orderPaymentData.shop_goods_list.goods_list[index].sku_image = this.defaultGoodsImage
  1131. },
  1132. setPayPassword() {
  1133. this.$util.pushToTab("/member/security");
  1134. }
  1135. }
  1136. }