payment.js 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504
  1. import {
  2. checkpaypassword,
  3. payment,
  4. calculate,
  5. orderCreate,
  6. balanceConfig
  7. } from "@/api/order/payment"
  8. import {
  9. addressList,
  10. saveAddress,
  11. setDefault,
  12. deleteAddress,
  13. addressInfo
  14. } from "@/api/member/member"
  15. import {
  16. getArea
  17. } from "@/api/address"
  18. import {
  19. mapGetters
  20. } from "vuex"
  21. export default {
  22. name: "payment",
  23. components: {},
  24. middleware: 'auth',
  25. data: () => {
  26. var checkMobile = (rule, value, callback) => {
  27. if (value === "") {
  28. callback(new Error("请输入手机号"))
  29. } else if (!/^\d{11}$/.test(value)) {
  30. callback(new Error("手机号格式错误"))
  31. } else {
  32. callback()
  33. }
  34. }
  35. return {
  36. dialogVisible: false,
  37. memberAddress: [], //收货地址列表
  38. addressId: 0, //收货地址
  39. addressForm: {
  40. id: 0,
  41. name: "",
  42. mobile: "",
  43. telephone: "",
  44. province_id: "",
  45. city_id: "",
  46. district_id: "",
  47. community_id: "",
  48. address: "",
  49. full_address: "",
  50. is_default: "",
  51. longitude: "",
  52. latitude: ""
  53. },
  54. pickerValueArray: {},
  55. cityArr: {},
  56. districtArr: {},
  57. addressRules: {
  58. name: [{
  59. required: true,
  60. message: "请输入收货人",
  61. trigger: "blur"
  62. },
  63. {
  64. min: 1,
  65. max: 20,
  66. message: "长度在 1 到 20 个字符",
  67. trigger: "blur"
  68. }
  69. ],
  70. mobile: [{
  71. required: true,
  72. validator: checkMobile,
  73. trigger: "change"
  74. }],
  75. province: [{
  76. required: true,
  77. message: "请选择省",
  78. trigger: "change"
  79. }],
  80. city: [{
  81. required: true,
  82. message: "请选择市",
  83. trigger: "change"
  84. }],
  85. district: [{
  86. required: true,
  87. message: "请选择区/县",
  88. trigger: "change"
  89. }],
  90. address: [{
  91. required: true,
  92. message: "请输入详细地址",
  93. trigger: "change"
  94. }]
  95. },
  96. isSend: false,
  97. orderCreateData: {
  98. is_balance: 0,
  99. is_point: 1,
  100. pay_password: '',
  101. // 发票
  102. is_invoice: 0, // 是否需要发票 0 无发票 1 有发票
  103. invoice_type: 1, // 发票类型 1 纸质 2 电子
  104. invoice_title_type: 1, // 抬头类型 1 个人 2 企业
  105. is_tax_invoice: 0, // 是否需要增值税专用发票 0 不需要 1 需要
  106. invoice_title: '', // 发票抬头
  107. taxpayer_number: '', // 纳税人识别号
  108. invoice_content: '', // 发票内容
  109. invoice_full_address: '', // 发票邮寄地址
  110. invoice_email: '', //发票邮箱
  111. member_address: {
  112. mobile: ''
  113. },
  114. is_open_card: 0,
  115. member_card_unit: ''
  116. },
  117. orderPaymentData: {
  118. shop_goods_list: {
  119. site_name: '',
  120. express_type: [],
  121. coupon_list: [],
  122. invoice: {
  123. invoice_content_array: []
  124. }
  125. },
  126. member_account: {
  127. balance: 0,
  128. is_pay_password: 0
  129. },
  130. delivery: {
  131. delivery_type: ''
  132. },
  133. member_address: {
  134. mobile: ''
  135. },
  136. local_config: {
  137. info: {
  138. start_time: 0,
  139. end_time: 0,
  140. time_week: []
  141. }
  142. }
  143. },
  144. dialogCoupon: false,
  145. siteCoupon: {
  146. site_id: 0,
  147. data: []
  148. },
  149. siteDelivery: {
  150. site_id: 0,
  151. data: []
  152. },
  153. dialogStore: false,
  154. promotionInfo: false,
  155. storeList: {},
  156. sitePromotion: [],
  157. isSub: false,
  158. dialogpay: false,
  159. password: "",
  160. fullscreenLoading: true,
  161. deliveryTime: false,
  162. timeTip: "选择配送时间",
  163. time: null,
  164. addressShow: false,
  165. couponRadio: 0,
  166. storeRadio: 0,
  167. dialogPlatcoupon: false,
  168. platformCouponRadio: 0,
  169. // 门店信息
  170. storeInfo: {
  171. storeList: [], //门店列表
  172. currStore: {} //当前选择门店
  173. },
  174. // 自提地址
  175. member_address: {
  176. mobile: ''
  177. },
  178. // 当前时间
  179. timeInfo: {
  180. week: 0,
  181. start_time: 0,
  182. end_time: 0,
  183. showTime: false,
  184. showTimeBar: false
  185. },
  186. balance_show: 1,
  187. addresNextType: true
  188. }
  189. },
  190. computed: {
  191. ...mapGetters(["orderCreateGoodsData", "defaultGoodsImage", "city"])
  192. },
  193. mounted() {},
  194. created() {
  195. this.getMemberAddress()
  196. this.getOrderPaymentData()
  197. this.getBalanceConfig()
  198. },
  199. filters: {
  200. /**
  201. * 金额格式化输出
  202. * @param {Object} money
  203. */
  204. moneyFormat(money) {
  205. return parseFloat(money).toFixed(2)
  206. },
  207. /**
  208. * 店铺优惠摘取
  209. */
  210. promotion(data) {
  211. let promotion = ""
  212. if (data) {
  213. Object.keys(data).forEach(key => {
  214. promotion += data[key].content + " "
  215. })
  216. }
  217. return promotion
  218. }
  219. },
  220. methods: {
  221. //获取余额支付配置
  222. getBalanceConfig() {
  223. balanceConfig()
  224. .then(res => {
  225. const {
  226. code,
  227. message,
  228. data
  229. } = res
  230. if (code >= 0) {
  231. this.balance_show = data.balance_show;
  232. }
  233. })
  234. .catch(err => {
  235. const {
  236. code,
  237. message,
  238. data
  239. } = err
  240. // this.$message.error(message)
  241. })
  242. },
  243. //获取收货地址
  244. getMemberAddress() {
  245. addressList({
  246. page_size: 0
  247. })
  248. .then(res => {
  249. const {
  250. code,
  251. message,
  252. data
  253. } = res
  254. if (data && data.list) {
  255. let that = this
  256. this.memberAddress = data.list
  257. data.list.forEach(function(e) {
  258. if (e.is_default == 1) {
  259. that.addressId = e.id
  260. }
  261. })
  262. }
  263. })
  264. .catch(err => {
  265. const {
  266. code,
  267. message,
  268. data
  269. } = err
  270. this.$message.error(message)
  271. })
  272. },
  273. //设置会员收货地址
  274. setMemberAddress(params) {
  275. this.addressId = params
  276. setDefault({
  277. id: params
  278. })
  279. .then(res => {
  280. const {
  281. code,
  282. message,
  283. data
  284. } = res
  285. this.orderCalculate()
  286. })
  287. .catch(err => {
  288. const {
  289. code,
  290. message,
  291. data
  292. } = err
  293. this.$message.error(message)
  294. })
  295. },
  296. //删除会员收货地址
  297. deleteMemberAddress(params) {
  298. deleteAddress({
  299. id: params
  300. })
  301. .then(res => {
  302. const {
  303. code,
  304. message,
  305. data
  306. } = res
  307. if (data) {
  308. this.$message({
  309. message: message,
  310. type: "success"
  311. })
  312. this.getMemberAddress()
  313. } else {
  314. this.$message({
  315. message: message,
  316. type: "warning"
  317. })
  318. }
  319. })
  320. .catch(err => {
  321. this.$message.error(err.message)
  322. })
  323. },
  324. //打开添加收货地址弹出层
  325. addAddressShow() {
  326. this.dialogVisible = true
  327. this.addressForm.id = 0
  328. this.addressForm.name = ""
  329. this.addressForm.mobile = ""
  330. this.addressForm.telephone = ""
  331. this.addressForm.province_id = ""
  332. this.addressForm.city_id = ""
  333. this.addressForm.district_id = ""
  334. this.addressForm.community_id = ""
  335. this.addressForm.address = ""
  336. this.addressForm.full_address = ""
  337. this.addressForm.is_default = ""
  338. this.addressForm.longitude = ""
  339. this.addressForm.latitude = ""
  340. // this.$nextTick(() => {
  341. // this.$refs.form.resetFields();
  342. // });
  343. this.cityArr = {}
  344. this.districtArr = {}
  345. this.getAddress(0)
  346. },
  347. //获取地址
  348. getAddress(type) {
  349. let pid = 0
  350. let that = this
  351. switch (type) {
  352. case 0:
  353. //加载省
  354. pid = 0
  355. break
  356. case 1:
  357. //加载市
  358. pid = this.addressForm.province_id
  359. that.cityArr = {}
  360. that.districtArr = {}
  361. this.addressForm.city_id = ""
  362. this.addressForm.district_id = ""
  363. break
  364. case 2:
  365. //加载区县
  366. pid = this.addressForm.city_id
  367. that.districtArr = {}
  368. this.addressForm.district_id = ""
  369. break
  370. }
  371. getArea({
  372. pid: pid
  373. })
  374. .then(res => {
  375. const {
  376. code,
  377. message,
  378. data
  379. } = res
  380. if (data) {
  381. switch (type) {
  382. case 0:
  383. that.pickerValueArray = data
  384. break
  385. case 1:
  386. //加载市
  387. that.cityArr = data
  388. break
  389. case 2:
  390. //加载区县
  391. that.districtArr = data
  392. break
  393. }
  394. }
  395. if (data.length == 0) {
  396. this.addresNextType = false;
  397. }
  398. })
  399. .catch(err => {
  400. const {
  401. code,
  402. message,
  403. data
  404. } = err
  405. this.$message.error(message)
  406. })
  407. },
  408. //编辑地址 初始化
  409. initAddress(type) {
  410. let pid = 0
  411. let that = this
  412. switch (type) {
  413. case 0:
  414. //加载省
  415. pid = 0
  416. break
  417. case 1:
  418. //加载市
  419. pid = this.addressForm.province_id
  420. that.cityArr = {}
  421. that.districtArr = {}
  422. break
  423. case 2:
  424. //加载区县
  425. pid = this.addressForm.city_id
  426. that.districtArr = {}
  427. break
  428. }
  429. getArea({
  430. pid: pid
  431. })
  432. .then(res => {
  433. const {
  434. code,
  435. message,
  436. data
  437. } = res
  438. if (data) {
  439. switch (type) {
  440. case 0:
  441. that.pickerValueArray = data
  442. break
  443. case 1:
  444. //加载市
  445. that.cityArr = data
  446. break
  447. case 2:
  448. //加载区县
  449. that.districtArr = data
  450. break
  451. }
  452. }
  453. if (data.length == 0) {
  454. this.addresNextType = false;
  455. }
  456. })
  457. .catch(err => {
  458. const {
  459. code,
  460. message,
  461. data
  462. } = err
  463. this.$message.error(message)
  464. })
  465. },
  466. //新增/编辑收货地址
  467. addmemberAddress(formName) {
  468. this.$refs[formName].validate(valid => {
  469. if (valid) {
  470. if (this.isSend) {
  471. return false
  472. }
  473. if (!this.addressForm.id) {
  474. this.addressForm.full_address = this.$refs.province.selectedLabel + "-" + this.$refs.city
  475. .selectedLabel + "-" +
  476. this.$refs.district.selectedLabel
  477. let data = {
  478. name: this.addressForm.name,
  479. mobile: this.addressForm.mobile,
  480. telephone: this.addressForm.telephone,
  481. province_id: this.addressForm.province_id,
  482. city_id: this.addressForm.city_id,
  483. district_id: this.addressForm.district_id,
  484. community_id: "",
  485. address: this.addressForm.address,
  486. full_address: this.addressForm.full_address,
  487. longitude: this.addressForm.longitude,
  488. latitude: this.addressForm.latitude,
  489. is_default: this.addressForm.is_default,
  490. url: 'add'
  491. }
  492. if (!data.province_id || data.province_id <= 0) {
  493. this.$message({
  494. message: "请正确选择省",
  495. type: "warning"
  496. })
  497. return false
  498. }
  499. if (!data.city_id || data.city_id <= 0) {
  500. this.$message({
  501. message: "请正确选择市",
  502. type: "warning"
  503. })
  504. return false
  505. }
  506. if ((!data.district_id || data.district_id <= 0) && this.addresNextType == true) {
  507. this.$message({
  508. message: "请正确选择区/县",
  509. type: "warning"
  510. })
  511. return false
  512. }
  513. this.isSend = true
  514. saveAddress(data)
  515. .then(res => {
  516. const {
  517. code,
  518. message,
  519. data
  520. } = res
  521. if (data) {
  522. this.setMemberAddress(data)
  523. this.$message({
  524. message: message,
  525. type: "success"
  526. })
  527. this.dialogVisible = false
  528. this.getMemberAddress()
  529. this.getOrderPaymentData()
  530. } else {
  531. this.$message({
  532. message: message,
  533. type: "warning"
  534. })
  535. }
  536. this.isSend = false
  537. })
  538. .catch(err => {
  539. const {
  540. code,
  541. message,
  542. data
  543. } = err
  544. this.$message.error(message)
  545. })
  546. } else {
  547. this.addressForm.full_address = this.$refs.province.selectedLabel + "-" + this.$refs.city
  548. .selectedLabel + "-" +
  549. this.$refs.district.selectedLabel
  550. let data = this.addressForm
  551. if (!data.province_id) {
  552. this.$message({
  553. message: "请选择省",
  554. type: "warning"
  555. })
  556. return false
  557. }
  558. if (!data.city_id) {
  559. this.$message({
  560. message: "请选择市",
  561. type: "warning"
  562. })
  563. return false
  564. }
  565. if (!data.district_id) {
  566. this.$message({
  567. message: "请选择区/县",
  568. type: "warning"
  569. })
  570. return false
  571. }
  572. this.isSend = true
  573. this.setMemberAddress(data.id);
  574. data.url = "edit";
  575. saveAddress(data)
  576. .then(res => {
  577. const {
  578. code,
  579. message,
  580. data
  581. } = res
  582. if (data) {
  583. this.$message({
  584. message: message,
  585. type: "success"
  586. })
  587. this.dialogVisible = false
  588. this.getMemberAddress()
  589. this.getOrderPaymentData()
  590. } else {
  591. this.$message({
  592. message: message,
  593. type: "warning"
  594. })
  595. }
  596. this.isSend = false
  597. })
  598. .catch(err => {
  599. const {
  600. code,
  601. message,
  602. data
  603. } = err
  604. this.$message.error(message)
  605. })
  606. }
  607. } else {
  608. return false
  609. }
  610. })
  611. },
  612. //编辑收货地址
  613. editAddress(id) {
  614. addressInfo({
  615. id: id
  616. })
  617. .then(res => {
  618. const {
  619. code,
  620. message,
  621. data
  622. } = res
  623. this.addressForm = {
  624. id: data.id,
  625. name: data.name,
  626. mobile: data.mobile,
  627. telephone: data.telephone,
  628. province_id: data.province_id,
  629. city_id: "",
  630. district_id: "",
  631. community_id: "",
  632. address: data.address,
  633. full_address: data.full_address,
  634. is_default: data.is_default,
  635. longitude: data.longitude,
  636. latitude: data.latitude
  637. }
  638. this.initAddress(0)
  639. this.initAddress(1)
  640. this.addressForm.city_id = data.city_id
  641. this.initAddress(2)
  642. this.addressForm.district_id = data.district_id
  643. this.dialogVisible = true
  644. })
  645. .catch(err => {
  646. const {
  647. code,
  648. message,
  649. data
  650. } = err
  651. this.$message.error(message)
  652. })
  653. },
  654. /**
  655. * 获取订单初始化数据
  656. */
  657. getOrderPaymentData() {
  658. this.orderCreateData = this.orderCreateGoodsData
  659. if (!this.orderCreateData) {
  660. this.$message({
  661. message: "未获取到创建订单所需数据!", //提示的信息
  662. type: "warning",
  663. offset: 225,
  664. duration: 3000,
  665. onClose: () => {
  666. this.$router.go(-1)
  667. return false
  668. }
  669. })
  670. return
  671. }
  672. this.orderCreateData.web_city = this.city ? this.city.id : 0
  673. payment(this.orderCreateData)
  674. .then(res => {
  675. const {
  676. code,
  677. message,
  678. data
  679. } = res
  680. if (code >= 0) {
  681. this.orderPaymentData = data
  682. this.handlePaymentData()
  683. } else {
  684. this.$message({
  685. message: "未获取到创建订单所需数据!", //提示的信息
  686. type: "warning",
  687. offset: 225,
  688. duration: 3000,
  689. onClose: () => {
  690. this.$router.go(-1)
  691. return false
  692. }
  693. })
  694. return
  695. }
  696. })
  697. .catch(err => {
  698. const {
  699. code,
  700. message,
  701. data
  702. } = err
  703. // this.$message.error(message)
  704. })
  705. },
  706. /**
  707. * 处理结算订单数据
  708. */
  709. handlePaymentData() {
  710. this.orderCreateData.delivery = {}
  711. this.orderCreateData.coupon = {}
  712. this.orderCreateData.buyer_message = ""
  713. this.orderCreateData.is_balance = 0
  714. this.orderCreateData.pay_password = ""
  715. this.orderCreateData.is_point = 1;
  716. this.orderCreateData.is_invoice = 0; // 是否需要发票 0 无发票 1 有发票
  717. this.orderCreateData.invoice_type = 1; // 发票类型 1 纸质 2 电子
  718. this.orderCreateData.invoice_title_type = 1; // 发票抬头类型 1 个人 2企业
  719. this.orderCreateData.is_tax_invoice = 0; // 是否需要增值税专用发票 0 不需要 1 需要
  720. this.orderCreateData.invoice_title = '';
  721. var data = this.orderPaymentData
  722. if (data.recommend_member_card) {
  723. this.orderCreateData.member_card_unit = Object.keys(data.recommend_member_card.charge_rule)[0];
  724. }
  725. // 店铺的配送
  726. if (data.shop_goods_list.express_type.length > 1) {
  727. this.orderCreateData.delivery_type = 'express'
  728. this.orderCreateData.delivery_type_name = '物流配送'
  729. }
  730. // 店铺优惠券
  731. if (data.shop_goods_list.coupon_list != undefined && data.shop_goods_list.coupon_list[0] != undefined) {
  732. var coupon_list = data.shop_goods_list.coupon_list;
  733. this.orderCreateData.coupon.coupon_id = coupon_list[0].coupon_id;
  734. this.orderCreateData.coupon.coupon_money = coupon_list[0].money;
  735. }
  736. // 满减送
  737. if (data.shop_goods_list.promotion != undefined && data.shop_goods_list.promotion.manjian != undefined) {
  738. this.manjian = data.shop_goods_list.promotion.manjian;
  739. }
  740. if (this.orderPaymentData.is_virtual) this.orderCreateData.member_address = {
  741. mobile: ''
  742. };
  743. if (this.orderPaymentData.shop_goods_list.invoice) {
  744. var invoice_content_array = this.orderPaymentData.shop_goods_list.invoice.invoice_content_array;
  745. if (invoice_content_array.length) this.orderCreateData.invoice_content = invoice_content_array[0];
  746. }
  747. if (this.orderPaymentData.is_virtual == 0) {
  748. // 是否显示时间选择
  749. if (this.orderPaymentData.shop_goods_list.local_config.info && this.orderPaymentData
  750. .shop_goods_list.local_config.info.time_is_open == 1) {
  751. this.timeInfo.showTimeBar = true;
  752. // 当日是否支持配送
  753. if (this.orderPaymentData.shop_goods_list.local_config.info.time_week.length == 0 ||
  754. this.orderPaymentData.shop_goods_list.local_config.info.time_week.length == 7 ||
  755. this.orderPaymentData.shop_goods_list.local_config.info.time_week.indexOf(this.timeInfo.week) > -1) {
  756. this.canLocalDelicery = true;
  757. } else {
  758. this.canLocalDelicery = false;
  759. }
  760. if (this.orderPaymentData.shop_goods_list.local_config.info.time_type == 0) {
  761. this.deliveryWeek = "全天";
  762. } else if (this.orderPaymentData.shop_goods_list.local_config.info.time_week.length > 0) {
  763. if (this.orderPaymentData.shop_goods_list.local_config.info.time_week.length == 7) {
  764. this.deliveryWeek = "全天";
  765. } else {
  766. this.timeInfo.showTime = true;
  767. // 判断配送时间是连续还是间隔
  768. var timeWeek = this.orderPaymentData.shop_goods_list.local_config.info.time_week;
  769. var is_interval = false; // 是否间隔
  770. for (var i = 0; i < timeWeek.length; i++) {
  771. if ((i + 1) < timeWeek.length) {
  772. var difference = timeWeek[i + 1] - timeWeek[i];
  773. if (difference > 1) {
  774. is_interval = true;
  775. break;
  776. }
  777. }
  778. }
  779. var weeks = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
  780. if (is_interval) {
  781. var temp = [];
  782. for (var i = 0; i < timeWeek.length; i++) {
  783. temp.push(weeks[timeWeek[i]]);
  784. }
  785. this.deliveryWeek = temp.join("、");
  786. } else {
  787. this.deliveryWeek = weeks[timeWeek[0]] + "至" + weeks[timeWeek[timeWeek.length - 1]];
  788. }
  789. }
  790. } else {
  791. this.deliveryWeek = "店铺未设置配送时间";
  792. }
  793. // 将timepicker选中当前时间
  794. var h = new Date().getHours().toString();
  795. var m = new Date().getMinutes().toString();
  796. if (h.length == 1) {
  797. h = '0' + h;
  798. }
  799. if (m.length == 1) {
  800. m = '0' + m;
  801. }
  802. this.orderCreateData.buyer_ask_delivery_time = h + ':' + m;
  803. // picker组件时间起始
  804. let start_time = this.orderPaymentData.shop_goods_list.local_config.info.start_time;
  805. this.timeInfo.start_time = this.getTimeStr(start_time);
  806. let end_time = this.orderPaymentData.shop_goods_list.local_config.info.end_time;
  807. this.timeInfo.end_time = this.getTimeStr(end_time);
  808. var current_time = new Date(this.$util.timeStampTurnTime(this.orderPaymentData.timestamp));
  809. var hour = current_time.getHours();
  810. var minute = current_time.getMinutes();
  811. var start_hour = parseInt(this.timeInfo.start_time.split(":")[0]);
  812. var start_minute = parseInt(this.timeInfo.start_time.split(":")[1]);
  813. var end_hour = parseInt(this.timeInfo.end_time.split(":")[0]);
  814. var end_minute = parseInt(this.timeInfo.end_time.split(":")[1]);
  815. // 检测当天是否能够配送,然后判断送达时间。不在配送时间当日不能下单,例:配送时间是周一到周五,那么周末不能下单,周一到周五可以下单
  816. if (this.canLocalDelicery) {
  817. // 判断是否全天
  818. if (!(start_hour == end_hour && start_minute == end_minute)) {
  819. // 当前时间早于配送时间,送达时间:开始时间~结束时间
  820. if ((hour < start_hour) || (hour == start_hour && minute < start_minute)) {
  821. this.orderCreateData.buyer_ask_delivery_time = (start_hour.toString().length == 1 ? "0" + start_hour :
  822. start_hour) + ':' +
  823. (start_minute.toString().length == 1 ? "0" + start_minute : start_minute);
  824. }
  825. // if (((hour > start_hour && hour < end_hour) || (hour == start_hour && minute > start_minute) || (hour ==
  826. // start_hour && minute >= start_minute && hour < end_hour))) {
  827. // }
  828. // 当前时间晚于配送时间,送达时间隐藏,不能下单
  829. if ((hour > end_hour) || (hour == end_hour && minute > end_minute)) {
  830. this.canLocalDelicery = false;
  831. }
  832. }
  833. }
  834. } else {
  835. this.deliveryWeek = "店铺未开启配送时间";
  836. }
  837. }
  838. Object.assign(this.orderPaymentData, this.orderCreateData);
  839. this.orderPaymentData.shop_goods_list.goods_list.forEach((v) => {
  840. if (v.sku_spec_format) {
  841. v.sku_spec_format = JSON.parse(v.sku_spec_format);
  842. } else {
  843. v.sku_spec_format = [];
  844. }
  845. });
  846. this.orderCalculate()
  847. },
  848. // 转化时间字符串
  849. getTimeStr(val) {
  850. var h = parseInt(val / 3600).toString();
  851. var m = parseInt((val % 3600) / 60).toString();
  852. if (m.length == 1) {
  853. m = '0' + m;
  854. }
  855. if (h.length == 1) {
  856. h = '0' + h;
  857. }
  858. return h + ':' + m;
  859. },
  860. clickType(type) {
  861. this.orderCreateData.invoice_type = type;
  862. this.orderCalculate();
  863. this.$forceUpdate();
  864. },
  865. clickTitleType(type) {
  866. this.orderCreateData.invoice_title_type = type;
  867. this.orderCalculate();
  868. this.$forceUpdate();
  869. },
  870. // 选择发票内容
  871. changeInvoiceContent(invoice_content) {
  872. this.orderCreateData.invoice_content = invoice_content;
  873. this.$forceUpdate();
  874. },
  875. // 切换发票开关
  876. changeIsInvoice() {
  877. if (this.orderCreateData.is_invoice == 0) {
  878. this.orderCreateData.is_invoice = 1;
  879. } else {
  880. this.orderCreateData.is_invoice = 0;
  881. }
  882. this.orderCalculate();
  883. this.$forceUpdate();
  884. },
  885. // 发票验证
  886. invoiceVerify() {
  887. if (!this.orderCreateData.invoice_title) {
  888. this.$message({
  889. message: "请填写发票抬头",
  890. type: "warning"
  891. })
  892. return false;
  893. }
  894. if (!this.orderCreateData.taxpayer_number && this.orderCreateData.invoice_title_type == 2) {
  895. this.$message({
  896. message: "请填写纳税人识别号",
  897. type: "warning"
  898. })
  899. return false;
  900. }
  901. if (this.orderCreateData.invoice_type == 1 && !this.orderCreateData.invoice_full_address) {
  902. this.$message({
  903. message: "请填写发票邮寄地址",
  904. type: "warning"
  905. })
  906. return false;
  907. }
  908. if (this.orderCreateData.invoice_type == 2 && !this.orderCreateData.invoice_email) {
  909. this.$message({
  910. message: "请填写邮箱",
  911. type: "warning"
  912. })
  913. return false;
  914. }
  915. if (this.orderCreateData.invoice_type == 2) {
  916. var reg = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
  917. if (!reg.test(this.orderCreateData.invoice_email)) {
  918. this.$message({
  919. message: "请填写正确的邮箱",
  920. type: "warning"
  921. })
  922. return false;
  923. }
  924. }
  925. if (!this.orderCreateData.invoice_content) {
  926. this.$message({
  927. message: "请选择发票内容",
  928. type: "warning"
  929. })
  930. return false;
  931. }
  932. return true;
  933. },
  934. /**
  935. * 订单计算
  936. */
  937. orderCalculate() {
  938. this.fullscreenLoading = true
  939. var data = this.$util.deepClone(this.orderCreateData)
  940. data.delivery = JSON.stringify(data.delivery)
  941. data.coupon = JSON.stringify(data.coupon)
  942. if (this.orderPaymentData.delivery_type == 'store') {
  943. data.member_address = JSON.stringify(this.member_address);
  944. } else {
  945. data.member_address = JSON.stringify(data.member_address);
  946. }
  947. calculate(data)
  948. .then(res => {
  949. const {
  950. code,
  951. message,
  952. data
  953. } = res
  954. if (code >= 0) {
  955. this.orderPaymentData.member_address = res.data.member_address;
  956. this.orderPaymentData.delivery_money = res.data.delivery_money;
  957. this.orderPaymentData.coupon_money = res.data.coupon_money;
  958. this.orderPaymentData.invoice_money = res.data.invoice_money;
  959. this.orderPaymentData.invoice_delivery_money = res.data.shop_goods_list.invoice_delivery_money;
  960. this.orderPaymentData.promotion_money = res.data.promotion_money;
  961. this.orderPaymentData.order_money = res.data.order_money;
  962. this.orderPaymentData.balance_money = res.data.balance_money;
  963. this.orderPaymentData.pay_money = res.data.pay_money;
  964. this.orderPaymentData.goods_money = res.data.goods_money;
  965. this.orderPaymentData.point_money = res.data.point_money;
  966. this.orderPaymentData.member_card_money = res.data.member_card_money;
  967. this.orderPaymentData.shop_goods_list.promotion = res.data.shop_goods_list.promotion;
  968. this.orderPaymentData.shop_goods_list.coupon_list = res.data.shop_goods_list.coupon_list;
  969. this.orderPaymentData.shop_goods_list.goods_list = res.data.shop_goods_list.goods_list;
  970. this.orderPaymentData.shop_goods_list.max_usable_point = res.data.shop_goods_list.max_usable_point;
  971. // 针对优惠券特殊处理
  972. // if (this.orderPaymentData.shop_goods_list.coupon_list.length == 0) {
  973. // this.orderCreateData.coupon = {};
  974. // } else if (!this.orderCreateData.coupon.coupon_id) {
  975. // var coupon_list = res.data.shop_goods_list.coupon_list;
  976. // this.orderCreateData.coupon.coupon_id = coupon_list[0].coupon_id;
  977. // this.orderCreateData.coupon.coupon_money = coupon_list[0].money;
  978. // // this.orderCalculate();
  979. // }
  980. this.orderPaymentData.shop_goods_list.goods_list.forEach((v) => {
  981. if (v.sku_spec_format) {
  982. v.sku_spec_format = JSON.parse(v.sku_spec_format);
  983. } else {
  984. v.sku_spec_format = [];
  985. }
  986. });
  987. } else {
  988. this.$message({
  989. message: message, //提示的信息
  990. type: "warning",
  991. offset: 225,
  992. duration: 3000,
  993. onClose: () => {
  994. this.$router.go(-1)
  995. return false
  996. }
  997. })
  998. return
  999. }
  1000. this.fullscreenLoading = false
  1001. })
  1002. .catch(err => {
  1003. const {
  1004. code,
  1005. message,
  1006. data
  1007. } = err
  1008. this.$message.error(message)
  1009. this.fullscreenLoading = false
  1010. })
  1011. },
  1012. /**
  1013. * 选择配送方式
  1014. */
  1015. selectDeliveryType(data, siteId, deliveryData) {
  1016. this.tempData = {
  1017. delivery: this.$util.deepClone(this.orderPaymentData.delivery)
  1018. }
  1019. this.siteDelivery.site_id = siteId
  1020. this.siteDelivery.data = deliveryData
  1021. this.orderCreateData.delivery_type = data.name
  1022. this.orderCreateData.delivery_type_name = data.title
  1023. if (data.name == "store") {
  1024. // 如果是门店配送
  1025. // let row = '';
  1026. let that = this;
  1027. data.store_list.forEach(function(e, i) {
  1028. data.store_list[i]["store_address"] = e.full_address + e.address
  1029. })
  1030. this.dialogStore = true
  1031. this.storeList = data.store_list
  1032. this.orderPaymentData.delivery.delivery_type = 'store'
  1033. this.orderPaymentData.delivery.delivery_type_name = '门店自提'
  1034. Object.assign(this.orderPaymentData, this.orderCreateData)
  1035. if (this.orderPaymentData.delivery.store_id) {
  1036. this.orderCalculate()
  1037. } else {
  1038. this.orderPaymentData.delivery.store_id = 0;
  1039. }
  1040. } else if (data.name == "local") {
  1041. this.deliveryTime = true
  1042. this.time = this.orderCreateData.delivery[siteId].buyer_ask_delivery_time;
  1043. } else {
  1044. this.orderPaymentData.delivery.delivery_type = 'express'
  1045. this.orderPaymentData.delivery.delivery_type_name = '物流配送'
  1046. Object.assign(this.orderPaymentData, this.orderCreateData)
  1047. this.orderCalculate()
  1048. }
  1049. this.$forceUpdate()
  1050. },
  1051. /**
  1052. * 设置选择自提点
  1053. * @param {Object} item
  1054. */
  1055. setStore(row) {
  1056. this.$refs.singleTable.setCurrentRow(row)
  1057. },
  1058. /**
  1059. * 选择自提点
  1060. * @param {Object} item
  1061. */
  1062. selectStore(item) {
  1063. if (!item) return;
  1064. let store_id = item.store_id
  1065. this.dialogStore = false
  1066. this.orderCreateData.delivery.store_id = store_id
  1067. this.orderCreateData.delivery.delivery_type = this.orderCreateData.delivery_type
  1068. this.orderCreateData.delivery.store_name = item.store_name
  1069. Object.assign(this.orderPaymentData, this.orderCreateData)
  1070. this.storeRadio = item
  1071. this.orderCalculate()
  1072. this.$forceUpdate()
  1073. },
  1074. /**
  1075. * 显示优惠券信息
  1076. * @param {Object} siteId
  1077. * @param {Object} couponData
  1078. */
  1079. openPlatformCoupon() {
  1080. let row = 0
  1081. let that = this;
  1082. this.dialogPlatcoupon = true
  1083. this.orderPaymentData.shop_goods_list.coupon_list.forEach(function(e, i) {
  1084. if (e.coupon_id == that.orderPaymentData.coupon.coupon_id) {
  1085. row = e
  1086. }
  1087. })
  1088. setTimeout(function() {
  1089. that.setPlatformCurrent(row)
  1090. that.platformCouponRadio = row;
  1091. }, 50)
  1092. },
  1093. /**
  1094. * 取消选择优惠券
  1095. * @param {Object} item
  1096. */
  1097. setPlatformCurrent(row) {
  1098. this.$refs.platformCouponTable.setCurrentRow(row)
  1099. if (row == undefined) {
  1100. this.orderCalculate()
  1101. }
  1102. },
  1103. /**
  1104. * 确认选择优惠券
  1105. * @param {Object} item
  1106. */
  1107. savePlatformCoupon() {
  1108. this.dialogPlatcoupon = false
  1109. this.orderCalculate()
  1110. },
  1111. /**
  1112. * 选择优惠券
  1113. * @param {Object} item
  1114. */
  1115. selectPlatformCoupon(item) {
  1116. if (this.orderCreateData.coupon.coupon_id != item.coupon_id) {
  1117. this.orderCreateData.coupon.coupon_id = item.coupon_id;
  1118. this.orderCreateData.coupon.coupon_money = item.money;
  1119. this.platformCouponRadio = item;
  1120. } else {
  1121. this.orderCreateData.coupon.coupon_id = 0;
  1122. this.orderCreateData.coupon.coupon_money = '0.00';
  1123. this.platformCouponRadio = '';
  1124. }
  1125. Object.assign(this.orderPaymentData, this.orderCreateData);
  1126. this.$forceUpdate()
  1127. },
  1128. /**
  1129. * 显示店铺优惠券信息
  1130. * @param {Object} siteId
  1131. * @param {Object} couponData
  1132. */
  1133. // openSiteCoupon(siteId, couponData) {
  1134. // this.tempData = {
  1135. // coupon: this.$util.deepClone(this.orderPaymentData.coupon)
  1136. // }
  1137. // let row = 0
  1138. // let that = this
  1139. // this.siteCoupon.site_id = siteId
  1140. // couponData.forEach(function(e, i) {
  1141. // if (e.at_least > 0) {
  1142. // couponData[i]["use"] = "满" + e.at_least + "可用"
  1143. // } else {
  1144. // couponData[i]["use"] = "任意金额可用"
  1145. // }
  1146. // couponData[i]["time"] = timeStampTurnTime(e.end_time)
  1147. // if (e.coupon_id == that.orderCreateData.coupon[that.siteCoupon.site_id].coupon_id) {
  1148. // row = e
  1149. // }
  1150. // })
  1151. // this.siteCoupon.data = couponData
  1152. // this.dialogCoupon = true
  1153. // setTimeout(function() {
  1154. // that.setCurrent(row)
  1155. // that.couponRadio = row;
  1156. // }, 50)
  1157. // },
  1158. /**
  1159. * 选择优惠券
  1160. * @param {Object} item
  1161. */
  1162. selectCoupon(item) {
  1163. if (!item) {
  1164. this.orderCreateData.coupon[this.siteCoupon.site_id].coupon_id = 0
  1165. this.orderCreateData.coupon[this.siteCoupon.site_id].coupon_money = "0.00"
  1166. this.couponRadio = '';
  1167. } else {
  1168. if (this.orderCreateData.coupon[this.siteCoupon.site_id].coupon_id != item.coupon_id) {
  1169. this.orderCreateData.coupon[this.siteCoupon.site_id].coupon_id = item.coupon_id
  1170. this.orderCreateData.coupon[this.siteCoupon.site_id].coupon_money = item.money
  1171. this.couponRadio = item;
  1172. } else {
  1173. this.couponRadio = '';
  1174. this.orderCreateData.coupon[this.siteCoupon.site_id].coupon_id = 0
  1175. this.orderCreateData.coupon[this.siteCoupon.site_id].coupon_money = "0.00"
  1176. }
  1177. }
  1178. Object.assign(this.orderPaymentData, this.orderCreateData)
  1179. this.$forceUpdate()
  1180. },
  1181. /**
  1182. * 取消选择优惠券
  1183. * @param {Object} item
  1184. */
  1185. setCurrent(row) {
  1186. this.$refs.couponTable.setCurrentRow(row)
  1187. if (row == undefined) {
  1188. this.orderCalculate()
  1189. }
  1190. },
  1191. /**
  1192. * 确认选择优惠券
  1193. * @param {Object} item
  1194. */
  1195. saveCoupon() {
  1196. this.dialogCoupon = false
  1197. this.orderCalculate()
  1198. },
  1199. /**
  1200. * 显示店铺优惠信息
  1201. * @param {Object} data
  1202. */
  1203. openSitePromotion(data) {
  1204. this.sitePromotion = data
  1205. if (this.promotionInfo) {
  1206. this.promotionInfo = false
  1207. } else {
  1208. this.promotionInfo = true
  1209. }
  1210. },
  1211. /**
  1212. * 是否使用余额
  1213. */
  1214. useBalance(type) {
  1215. if (this.orderCreateData.is_balance) this.orderCreateData.is_balance = 0
  1216. else this.orderCreateData.is_balance = 1
  1217. this.orderCalculate()
  1218. this.$forceUpdate()
  1219. },
  1220. // 使用积分
  1221. usePoint(type) {
  1222. if (this.orderCreateData.is_point) this.orderCreateData.is_point = 0;
  1223. else this.orderCreateData.is_point = 1;
  1224. this.orderCalculate();
  1225. this.$forceUpdate();
  1226. },
  1227. orderCreate() {
  1228. if (this.verify()) {
  1229. if (this.isSub) return
  1230. if (this.orderCreateData.is_invoice == 1) {
  1231. if (this.invoiceVerify() === false) return;
  1232. }
  1233. this.isSub = true
  1234. var loading = this.$loading({
  1235. lock: true,
  1236. text: "订单提交中...",
  1237. spinner: "el-icon-loading",
  1238. background: "rgba(0, 0, 0, 0.7)"
  1239. })
  1240. var data = this.$util.deepClone(this.orderCreateData);
  1241. data.delivery = JSON.stringify(data.delivery);
  1242. data.coupon = JSON.stringify(data.coupon);
  1243. if (this.orderCreateData.delivery.delivery_type == 'store') {
  1244. data.member_address = JSON.stringify(this.member_address);
  1245. } else {
  1246. data.member_address = JSON.stringify(data.member_address);
  1247. }
  1248. orderCreate(data)
  1249. .then(res => {
  1250. const {
  1251. code,
  1252. message,
  1253. data
  1254. } = res
  1255. loading.close()
  1256. if (code >= 0) {
  1257. this.$store.dispatch("order/removeOrderCreateData", "")
  1258. if (this.orderPaymentData.pay_money == 0) {
  1259. this.$router.push({
  1260. path: "/pay/result",
  1261. query: {
  1262. code: data
  1263. }
  1264. })
  1265. } else {
  1266. this.$router.push({
  1267. path: "/pay",
  1268. query: {
  1269. code: data
  1270. }
  1271. })
  1272. }
  1273. } else {
  1274. this.$message({
  1275. message: message,
  1276. type: "warning"
  1277. })
  1278. }
  1279. })
  1280. .catch(err => {
  1281. loading.close()
  1282. this.isSub = false
  1283. const {
  1284. code,
  1285. message,
  1286. data
  1287. } = err
  1288. this.$message.error(message)
  1289. })
  1290. }
  1291. },
  1292. /**
  1293. * 订单验证
  1294. */
  1295. verify() {
  1296. if (this.orderPaymentData.is_virtual == 1) {
  1297. if (!this.orderCreateData.member_address.mobile.length) {
  1298. this.$message({
  1299. message: "请输入您的手机号码",
  1300. type: "warning"
  1301. })
  1302. return false
  1303. }
  1304. if (!this.$util.verifyMobile(this.orderCreateData.member_address.mobile)) {
  1305. this.$message({
  1306. message: "请输入正确的手机号码",
  1307. type: "warning"
  1308. })
  1309. return false
  1310. }
  1311. }
  1312. if (this.orderPaymentData.is_virtual == 0) {
  1313. if (!this.orderPaymentData.member_address) {
  1314. this.$message({
  1315. message: "请先选择您的收货地址",
  1316. type: "warning"
  1317. })
  1318. return false
  1319. }
  1320. let deliveryVerify = true
  1321. for (let key in this.orderCreateData.delivery) {
  1322. if (JSON.stringify(this.orderCreateData.delivery[key]) == "{}") {
  1323. deliveryVerify = false
  1324. this.$message({
  1325. message: '店铺"' + this.orderPaymentData.shop_goods_list[key].site_name + '"未设置配送方式',
  1326. type: "warning"
  1327. })
  1328. break
  1329. }
  1330. if (this.orderCreateData.delivery[key].delivery_type == "store" && this.orderCreateData.store_id ==
  1331. 0) {
  1332. deliveryVerify = false
  1333. this.$message({
  1334. message: '店铺"' + this.orderPaymentData.shop_goods_list[key].site_name + '"没有可提货的门店,请选择其他配送方式',
  1335. type: "warning"
  1336. })
  1337. break
  1338. }
  1339. }
  1340. if (!deliveryVerify) return false
  1341. }
  1342. if (this.orderPaymentData.delivery_type == 'store') {
  1343. if (JSON.stringify(this.orderPaymentData.delivery) == "{}" || !this.orderPaymentData.delivery.store_id) {
  1344. this.$message({
  1345. message: '请选择自提门店',
  1346. type: "warning"
  1347. })
  1348. return false
  1349. }
  1350. }
  1351. // if (this.orderCreateData.is_balance == 1 && this.orderCreateData.pay_password == "") {
  1352. // this.dialogpay = true
  1353. // return false
  1354. // }
  1355. return true
  1356. },
  1357. /**
  1358. * 支付密码输入
  1359. */
  1360. input() {
  1361. if (this.password.length == 6) {
  1362. var loading = this.$loading({
  1363. lock: true,
  1364. text: "支付中",
  1365. spinner: "el-icon-loading",
  1366. background: "rgba(0, 0, 0, 0.7)"
  1367. })
  1368. checkpaypassword({
  1369. pay_password: this.password
  1370. })
  1371. .then(res => {
  1372. const {
  1373. code,
  1374. message,
  1375. data
  1376. } = res
  1377. loading.close()
  1378. if (code >= 0) {
  1379. this.orderCreateData.pay_password = this.password
  1380. this.orderCreate()
  1381. this.dialogpay = false
  1382. } else {
  1383. this.$message({
  1384. message: message,
  1385. type: "warning"
  1386. })
  1387. }
  1388. })
  1389. .catch(err => {
  1390. loading.close()
  1391. const {
  1392. code,
  1393. message,
  1394. data
  1395. } = err
  1396. this.$message.error(message)
  1397. })
  1398. }
  1399. },
  1400. textarea() {
  1401. this.$forceUpdate()
  1402. },
  1403. bindTimeChange(time) {
  1404. this.time = time
  1405. },
  1406. setDeliveryTime(site_id) {
  1407. this.deliveryTime = false
  1408. this.orderCreateData.delivery[site_id].buyer_ask_delivery_time = this.time;
  1409. },
  1410. imageError(index) {
  1411. this.orderPaymentData.shop_goods_list.goods_list[index].sku_image = this.defaultGoodsImage
  1412. },
  1413. setPayPassword() {
  1414. this.$util.pushToTab("/member/security");
  1415. }
  1416. }
  1417. }