[javascript] PPOBProviderAddProduct.vue

Viewer

copydownloadembedprintName: PPOBProviderAddProduct.vue
  1. <template>
  2.   <v-layout column fill-height justify-start>
  3.     <!-- TITLE ADD PRODUCT -->
  4.     <v-snackbar
  5.       :color="snackbar.color"
  6.       v-model="snackbar.value"
  7.       multi-line
  8.       top
  9.     >
  10.       {{snackbar.text}}
  11.       <v-btn dark flat @click.native="snackbar.value = false">Close</v-btn>
  12.     </v-snackbar>
  13.     <v-flex>
  14.       <v-layout row>
  15.         <v-flex>
  16.           <div class="title font-weight-bold">
  17.             Add Product {{ this.pageTitle }}
  18.           </div>
  19.         </v-flex>
  20.       </v-layout>
  21.     </v-flex>
  22.     <!-- END TITLE ADD PRODUCT  -->
  23.  
  24.     <!-- V-card -->
  25.     <v-flex xs12 md12 pt-3>
  26.       <v-layout row>
  27.         <v-flex>
  28.           <v-stepper v-model="stepper" class="elevation-2">
  29.             <v-stepper-header class="elevation-0">
  30.               <v-stepper-step :complete="stepper > 1" step="1">Product Information</v-stepper-step>
  31.               <v-divider></v-divider>
  32.               <v-stepper-step step="2">Unit Information</v-stepper-step>
  33.             </v-stepper-header>
  34.             <v-divider></v-divider>
  35.             <v-stepper-items>
  36.               <v-stepper-content step="1">
  37.                 <v-form v-model="valid" ref="pricelistForm">
  38.                   <v-flex class="py-2 mb-5" lg12 md12 sm12 xs12>
  39.                     <v-container grid-list-md fluid pa-0>
  40.                       <v-layout column>
  41.                         <v-flex>
  42.                           <v-layout row wrap>
  43.                             <v-flex xs12 sm3 class="subheading font-weight-bold">
  44.                               Product Information
  45.                             </v-flex>
  46.                             <v-flex xs12 sm4>
  47.                               <label for="business_unit" class="subheading">Product ID<span class="red--text">*</span></label>
  48.                               <v-text-field required v-model="idProduct" :rules="[idRules(idProduct)]" label="Product Id Klikdaily" solo class="solo-outline" :disabled="isEditMode"></v-text-field>
  49.                             </v-flex>
  50.                             <v-flex xs12 offset-sm3 sm6>
  51.                               <label id="product-name" for="distribution_centre" class="subheading">Product Name</label>
  52.                               <v-text-field required v-model="productName" label="(ex. Pulsa Telkomsel 20.000)" solo class="solo-outline"></v-text-field>
  53.                             </v-flex>
  54.                             <v-flex xs12 offset-sm3 sm6>
  55.                               <label class="subheading">Description</label>
  56.                               <vueditor ref="descriptionEditor"></vueditor>
  57.                             </v-flex>
  58.                           </v-layout>
  59.                         </v-flex>
  60.                       </v-layout>
  61.                     </v-container>
  62.                   </v-flex>
  63.                 </v-form>
  64.                 <v-divider class="pt-3"></v-divider>
  65.                 <v-card-actions class="pb-4 pr-4">
  66.                   <v-spacer></v-spacer>
  67.                   <v-btn @click="cancel()" flat color="secondary">Cancel</v-btn>
  68.                   <v-btn :disabled="isNextButtonDisabled" @click="stepper = 2" depressed color="success">Next</v-btn>
  69.                 </v-card-actions>
  70.               </v-stepper-content>
  71.               <v-stepper-content step="2">
  72.                 <v-flex class="py-2 mb-5" lg12 md12 sm12 xs12>
  73.                   <v-container grid-list-md fluid pa-0>
  74.                     <v-layout column>
  75.                       <v-flex>
  76.                         <v-layout row wrap>
  77.                           <v-flex xs12 sm3 class="subheading font-weight-bold">
  78.                             Product Prices
  79.                           </v-flex>
  80.                           <v-flex xs12 sm9>
  81.                             <label for="business_unit" class="subheading font-weight-bold">KDR101 - {{ productName }}<span class="red--text">*</span></label>
  82.                             <v-layout row wrap>
  83.                               <v-flex sm3>
  84.                                 <label for="business_unit" class="subheading">Select Vendor</label>
  85.                                 <v-autocomplete
  86.                                   solo
  87.                                   class="solo-outline"
  88.                                   :items="vendors"
  89.                                   return-object
  90.                                   v-model="vendorSelected"
  91.                                   item-value="id"
  92.                                   @change="fetchProductIdVendor(vendorSelected)"
  93.                                   :filter="autocompleteFilter"
  94.                                 >
  95.                                   <template v-slot:selection="data">
  96.                                     {{ data.item.name }}
  97.                                   </template>
  98.                                   <template v-slot:item="data">
  99.                                     {{ data.item.name }}
  100.                                   </template>
  101.                                 </v-autocomplete>
  102.                               </v-flex>
  103.                               <v-flex sm3>
  104.                                 <label for="business_unit" class="subheading">Product Id Vendor<span class="red--text">*</span></label>
  105.                                 <v-autocomplete
  106.                                   :loading="fetchVendorLoading"
  107.                                   solo
  108.                                   class="solo-outline"
  109.                                   :items="vendorDetailProducts"
  110.                                   return-object
  111.                                   v-model="vendorDetailProductSelected"
  112.                                   item-value="id"
  113.                                   :filter="autocompleteFilter"
  114.                                 >
  115.                                   <template v-slot:selection="data">
  116.                                     {{ data.item.name }}
  117.                                   </template>
  118.                                   <template v-slot:item="data">
  119.                                     {{ data.item.name }}
  120.                                   </template>
  121.                                 </v-autocomplete>
  122.                               </v-flex>
  123.                               <v-flex sm3>
  124.                                 <label for="business_unit" class="subheading">Buying Price</label>
  125.                                 <v-currency-field
  126.                                   solo
  127.                                   class="solo-outline"
  128.                                   :prefix="'Rp'"
  129.                                   type="number"
  130.                                   disabled
  131.                                   :decimal-length="0"
  132.                                   v-model.number="vendorDetailProductSelected.purchase_price"
  133.                                   label="Price"
  134.                                 ></v-currency-field>
  135.                               </v-flex>
  136.                               <v-flex sm3>
  137.                                 <label for="business_unit" class="subheading">Price Status</label>
  138.                                 <v-switch
  139.                                   v-model="priceStatus"
  140.                                   :label="`${priceStatus ? 'Active' : 'Inactive'}`"
  141.                                   color="primary"
  142.                                 ></v-switch>
  143.                               </v-flex>
  144.                               <v-flex sm3>
  145.                                 <v-btn color="warning" @click="addNewProduct()">Assign New Product</v-btn>
  146.                               </v-flex>
  147.                             </v-layout>
  148.                           </v-flex>
  149.                           <v-flex xs12 sm12>
  150.                             <v-divider></v-divider>
  151.                           </v-flex>
  152.                           <v-flex>
  153.                             <v-layout row wrap>
  154.                               <v-flex xs12 sm3 class="subheading font-weight-bold">
  155.                                 Selling Price
  156.                               </v-flex>
  157.                               <v-flex xs12 sm9>
  158.                                <label for="business_unit" class="subheading">Selling Price</label>
  159.                                 <v-layout row wrap>
  160.                                   <v-flex sm3>
  161.                                     <v-currency-field
  162.                                       solo
  163.                                       class="solo-outline"
  164.                                       :prefix="'Rp'"
  165.                                       type="number"
  166.                                       :decimal-length="0"
  167.                                       v-model.number="sellingPrice"
  168.                                       label="Price"
  169.                                     ></v-currency-field>
  170.                                   </v-flex>
  171.                                 </v-layout>
  172.                               </v-flex>
  173.                             </v-layout>
  174.                           </v-flex>
  175.                         </v-layout>
  176.                       </v-flex>
  177.                     </v-layout>
  178.                   </v-container>
  179.                 </v-flex>
  180.                 <v-divider class="mb-3"></v-divider>
  181.                 <v-card-actions class="pb-4 pr-4">
  182.                   <v-spacer></v-spacer>
  183.                   <v-btn @click="stepper = 1" flat color="secondary">Previous</v-btn>
  184.                   <v-btn @click="confirmModal()" depressed color="success">Confirm</v-btn>
  185.                 </v-card-actions>
  186.               </v-stepper-content>
  187.             </v-stepper-items>
  188.           </v-stepper>
  189.         </v-flex>
  190.       </v-layout>
  191.     </v-flex>
  192.     <!-- end v-card -->
  193.   </v-layout>
  194. </template>
  195.  
  196. <script>
  197. import Vue from 'vue'
  198. import VeeValidate from 'vee-validate'
  199. import Vuex from 'vuex'
  200. // import 'vueditor/dist/style/vueditor.min.css'
  201. import Vueditor from 'vueditor'
  202.  
  203. let config = {
  204.   // for vueeditor
  205.   toolbar: [
  206.     'bold', 'italic', 'underline', '|',
  207.     'justifyLeft', 'justifyCenter', 'justifyRight', '|',
  208.     'insertOrderedList', 'insertUnorderedList', '|',
  209.     'undo', 'redo', '|',
  210.     'link'
  211.   ]
  212. }
  213.  
  214. Vue.use(VeeValidate, {fieldsBagName: 'vvFields'})
  215. Vue.use(Vuex)
  216. Vue.use(Vueditor, config)
  217.  
  218. export default {
  219.   $_veeValidate: {
  220.     validator: 'new'
  221.   },
  222.   components: {
  223.     ValidationProvider: VeeValidate.ValidationProvider
  224.   },
  225.   data: () => ({
  226.     vendorSelected: {},
  227.     pageTitle: '',
  228.     priceStatus: false,
  229.     idProduct: '',
  230.     productName: '',
  231.     description: '',
  232.     stepper: 0,
  233.     valid: true,
  234.     sellingPrice: '',
  235.     fetchVendorLoading: false,
  236.     vendors: [],
  237.     vendorDetailProducts: [],
  238.     vendorDetailProductSelected: {},
  239.     snackbar: {
  240.       value: false,
  241.       text: '',
  242.       color: 'primary'
  243.     }
  244.   }),
  245.   created () {
  246.     this.definePageTitle()
  247.     this.fetchPPOBVendors()
  248.   },
  249.   watch: {
  250.     descriptionEditorContent (newValue) {
  251.       this.description = newValue
  252.     }
  253.   },
  254.   computed: {
  255.     descriptionEditorContent: {
  256.       get () {
  257.         if (`${this.mode}`.length > 0) {
  258.           return this.$refs.descriptionEditor.getContent()
  259.         }
  260.         return null
  261.       },
  262.       set (newContent) {
  263.         this.$refs.descriptionEditor.setContent(newContent)
  264.       }
  265.     },
  266.     isEditMode () {
  267.       return this.mode === 'edit'
  268.     },
  269.     isNextButtonDisabled () {
  270.       if (!this.idProduct) {
  271.         return true
  272.       } else return false
  273.     }
  274.   },
  275.   methods: {
  276.     autocompleteFilter (item, queryText, itemText) {
  277.       const actualItemName = item.name || item.category_name
  278.       const mainText = actualItemName.toLowerCase()
  279.       const searchText = queryText.toLowerCase()
  280.  
  281.       return mainText.indexOf(searchText) > -1
  282.     },
  283.     addNewProduct () {
  284.       console.log('test')
  285.     },
  286.     definePageTitle () {
  287.       if (this.$route.params.type === 'mobile_credit') this.pageTitle = 'Pulsa'
  288.       else if (this.$route.params.type === 'mobile_package') this.pageTitle = 'Paket Data'
  289.       else if (this.$route.params.type === 'prepaid_electricity') this.pageTitle = 'Listrik'
  290.     },
  291.     cancel () {
  292.       this.$router.push(`/ppob-list/${this.$route.params.type}/detail/${this.$route.params.id}/products`)
  293.     },
  294.     confirmModal () {
  295.       console.log('confirm')
  296.     },
  297.     idRules (idProduct) {
  298.       if (idProduct) {
  299.         return true
  300.       } else {
  301.         return 'This field is required'
  302.       }
  303.     },
  304.     async fetchPPOBVendors () {
  305.       this.loading = true
  306.       await this.$store.dispatch('ppob/fetchPPOBVendors').then(result => {
  307.         if (result.status === 200) {
  308.           this.$set(this, 'vendors', result.data)
  309.           this.loading = false
  310.         } else {
  311.           this.snackbar.value = true
  312.           this.snackbar.text = result.message
  313.           this.snackbar.color = 'error'
  314.           this.loading = false
  315.         }
  316.       }).catch(error => {
  317.         this.snackbar.value = true
  318.         this.snackbar.text = error.message
  319.         this.snackbar.color = 'error'
  320.         this.loading = false
  321.       })
  322.     },
  323.     async fetchProductIdVendor (vendorProductSelected) {
  324.       console.log('vendor Product Selected', vendorProductSelected)
  325.       this.fetchVendorLoading = true
  326.       let params = {
  327.         idvendor: vendorProductSelected.id
  328.       }
  329.       await this.$store.dispatch('ppob/fetchPPOBVendorProducts', params).then(result => {
  330.         if (result.status === 200) {
  331.           this.$set(this, 'vendorDetailProducts', result.data)
  332.           this.loading = false
  333.         } else {
  334.           this.snackbar.value = true
  335.           this.snackbar.text = result.message
  336.           this.snackbar.color = 'error'
  337.           this.loading = false
  338.         }
  339.         this.fetchVendorLoading = false
  340.       }).catch(error => {
  341.         this.snackbar.value = true
  342.         this.snackbar.text = error.message
  343.         this.snackbar.color = 'error'
  344.         this.loading = false
  345.       })
  346.     }
  347.   }
  348. }
  349. </script>
  350.  

Editor

You can edit this paste and save as new:


File Description
  • PPOBProviderAddProduct.vue
  • Paste Code
  • 14 Jun-2021
  • 13.79 Kb
You can Share it: