Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Step from "~/components/Step";
  2. import Postcode from "~/components/inputs/Postcode";
  3. import { mapState, mapActions } from "vuex";
  4. import * as frMutations from "~/mutations/franchises";
  5.  
  6. export default {
  7.   name: "BoxRental",
  8.   data: function() {
  9.     return {
  10.       nextButtonIsActive: true,
  11.       movingFrom: {
  12.         label: "Moving from",
  13.         required: true,
  14.         valueName: "movingFrom",
  15.         placeholder: "Current Zip/Postal Code",
  16.         errorMessage: "",
  17.         value: ""
  18.       },
  19.       movingTo: {
  20.         label: "Moving to",
  21.         required: true,
  22.         valueName: "movingTo",
  23.         placeholder: "New Zip/Postal Code",
  24.         errorMessage: "",
  25.         value: ""
  26.       }
  27.     };
  28.   },
  29.   components: {
  30.     Step,
  31.     Postcode
  32.   },
  33.   methods: {
  34.     bindAction(data) {
  35.       this[data.valueName].value = data.value;
  36.     },
  37.     async goNext() {
  38.       if (!this.canContinue) {
  39.         return;
  40.       }
  41.       this.nextButtonIsActive = false;
  42.  
  43.       await this.save();
  44.  
  45.       this.nextButtonIsActive = true;
  46.  
  47.       // this.movingTo.errorMessage === "" &&
  48.       // this.movingFrom.errorMessage === ""
  49.       //   ) {
  50.       //     this.nextButtonIsActive = true;
  51.       //     // this.$router.push("/box-rental/what");
  52.       //   } else {
  53.       //     this.nextButtonIsActive = true;
  54.       //   }
  55.       // })
  56.       // .catch(() => {
  57.       //   this.nextButtonIsActive = true;
  58.       // });
  59.     },
  60.     async save() {
  61.       await this.checkSecurityToken();
  62.  
  63.       try {
  64.         this.setMovingFrom(this.movingFrom.value);
  65.         // change store franchise id
  66.         await this.updateLocalFranchiseByZip({
  67.           zip: this.movingFrom.value,
  68.           mutation: frMutations.SET_FRANCHISE_ID_FROM
  69.         });
  70.       } catch (e) {
  71.         this.movingFrom.errorMessage = await e.message;
  72.       }
  73.       try {
  74.         await this.changeAPIFranchise(this.stateFranchiseId);
  75.       } catch (e) {}
  76.  
  77.       try {
  78.         this.setMovingTo(this.movingTo.value);
  79.         await this.updateLocalFranchiseByZip({
  80.           zip: this.movingFrom.value,
  81.           mutation: frMutations.SET_FRANCHISE_ID_TO
  82.         });
  83.       } catch (e) {
  84.         this.movingTo.errorMessage = e.message;
  85.       }
  86.     },
  87.     ...mapActions({
  88.       setMoveType: "userInfo/setMoveType",
  89.       setMovingFrom: "userInfo/setMovingFrom",
  90.       setMovingTo: "userInfo/setMovingTo",
  91.       updateLocalFranchiseByZip: "franchises/updateFranchiseByZip",
  92.       changeAPIFranchise: "franchises/changeFranchise",
  93.       checkSecurityToken: "service/checkSecurityToken"
  94.     })
  95.   },
  96.   computed: {
  97.     canContinue: function() {
  98.       return (
  99.         this.movingFrom.value !== "" &&
  100.         this.movingTo.value !== "" &&
  101.         this.nextButtonIsActive
  102.       );
  103.     },
  104.     ...mapState({
  105.       stateMovingFrom: state => state.userInfo.movingFrom,
  106.       stateMovingTo: state => state.userInfo.movingTo,
  107.       stateFranchiseId: state => state.franchises.franchiseIDFrom
  108.     })
  109.   },
  110.   created: function() {
  111.     this.movingFrom.value = this.stateMovingFrom;
  112.     this.movingTo.value = this.stateMovingTo;
  113.     this.setMoveType("BOX_RENTAL");
  114.   }
  115. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement