payment_combo.js 27 KB

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