| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526 |
- <template>
- <div class="container">
- <el-form
- ref="form"
- :model="form"
- :rules="rules"
- label-width="150px"
- label-position="top">
- <div class="content">
- <div class="section-title">Rate Config</div>
- <div class="flexcr">
- <el-form-item
- label="Name:"
- prop="rateName"
- class="add-input">
- <el-input
- v-model="form.rateName"/>
- </el-form-item>
- <el-form-item
- label="Country:"
- prop="countryCode"
- class="add-input">
- <el-select
- v-model="form.countryCode">
- <el-option
- v-for="item in options.country"
- :key="item.name"
- :label="item.name"
- :value="item.value" />
- </el-select>
- </el-form-item>
- <!-- <el-form-item
- label="Rate Type:"
- prop="rateType"
- class="add-input">
- <el-input
- v-model="form.rateType"/>
- </el-form-item> -->
- </div>
- <div class="flexcr">
- <label class="el-form-item__label">Repeat:</label>
- <div class="repeat-view">
- (
- <div
- class="link-type"
- v-for="(item, index) in options.shortcut"
- :key="index"
- @click="handleShortcut(item)">
- <span>{{item.name}}</span>
- </div>
- )
- <el-tooltip
- effect="dark"
- content="This is an items for quickly selecting the repeats"
- placement="right">
- <i class="el-icon-question icon-help"></i>
- </el-tooltip>
- </div>
- </div>
- <div style="margin-bottom: 10px;">
- <el-checkbox-group
- v-model="form.repeats">
- <el-checkbox-button
- v-for="(item, index) in options.repeat"
- :label="item.value"
- :key="index">
- {{item.name}}
- </el-checkbox-button>
- </el-checkbox-group>
- </div>
- <div class="flexcr">
- <el-form-item
- label="All Day:"
- class="add-input">
- <el-switch
- v-model="form.allDay"
- @change="changeAllday"/>
- </el-form-item>
- <template v-if="form.allDay">
- <el-form-item
- label="Start Time:"
- class="add-input">
- <el-input disabled/>
- </el-form-item>
- <el-form-item
- label="End Time:"
- class="add-input">
- <el-input disabled/>
- </el-form-item>
- </template>
- <template v-else>
- <el-form-item
- label="Start Time:"
- class="add-input"
- prop="startTime">
- <el-time-picker
- v-model="form.startTime"
- format="HH:mm"
- value-format="HH:mm"
- clearable/>
- </el-form-item>
- <el-form-item
- label="End Time:"
- class="add-input"
- prop="endTime">
- <el-time-picker
- v-model="form.endTime"
- format="HH:mm"
- value-format="HH:mm"
- clearable/>
- </el-form-item>
- </template>
- </div>
- </div>
- <div class="content">
- <div class="section-title flexcr">
- CHARGE SITE RATE
- <div class="section-sub-title">(Currency Used: {{currencyData[form.countryCode]}})</div>
- </div>
- <charge-rate
- v-model="ratesForm.chargeRates"/>
- </div>
- <div class="content" v-if="false">
- <div class="section-title flexcr">
- SPECIAL CHARGE RATE
- <div class="section-sub-title">(Currency Used: {{currencyData[form.countryCode]}})</div>
- </div>
- <charge-rate
- isSpecial
- v-model="ratesForm.specialChargeRates"/>
- </div>
- <div class="content flexcr">
- <div class="buttons">
- <el-button
- @click="onBack"
- type="primary"
- class="cancel-button">
- Cancel
- </el-button>
- <el-button
- @click="onClickSave"
- type="primary"
- :loading="loadingSave">
- Save
- </el-button>
- </div>
- <div class="update-by" v-if="isEdit">
- <span
- class="add-text"
- :title='"CREATED BY " + form.createdBy + " ON " + form.createdOn'>
- LAST UPDATED BY {{form.updatedBy}} TIMESTAMP: {{form.updatedOn}}
- </span>
- </div>
- </div>
- </el-form>
- </div>
- </template>
- <script>
- import site from '../../http/api/site'
- import api from '../../http/api/rates'
- import settings from '../../settings.js'
- import ChargeRate from './components/ChargeRate'
- export default {
- data() {
- return {
- loading: false,
- loadingSave: false,
- isEdit: false,
- form: {
- dynamicRateId: "",
- rateName: "",
- countryCode: settings.defaultCountry,
- repeats: [],
- allDay: false,
- startTime: "",
- endTime: "",
- rates: [],
- specialRates: []
- },
- options: {
- country: [],
- repeat: [],
- shortcut: [{
- name: "Daily",
- value: [],
- all: true
- },{
- name: "Weekday",
- value: ["Mon","Tue","Wed","Thu","Fri"]
- },{
- name: "Weekend",
- value: ["Sat","Sun"]
- }, {
- name: "None",
- value: []
- }]
- },
- currencyData: {
- SG: "S$"
- },
- ratesForm: {
- chargeRates: [{
- rate: '',
- rateType: '',
- chargeTypePk: '',
- dynamicRateItemId: ''
- }],
- specialChargeRates: [{
- rate: '',
- rateType: '',
- chargeTypePk: '',
- groupPk: ''
- }]
- },
- rules: {
- rateName: {
- required: true,
- trigger: "blur",
- message: "Please input rate name"
- },
- startTime: {
- required: true,
- trigger: "change",
- message: "Please select start time"
- },
- endTime: {
- required: true,
- trigger: "change",
- message: "Please select end time"
- }
- },
-
- }
- },
- components: {ChargeRate},
- created() {
- this.loading = true;
- this.getCountryOptions();
- this.getRepeatOptions();
- if (this.$route.params.id) {
- this.isEdit = true;
- this.getRateDetail();
- }
- },
- methods: {
- onBack() {
- this.$nextTick(() => {
- this.$router.replace({
- path: "/site-management/dynamic-rate-configuration"
- })
- })
- },
- getCountryOptions() {
- site.getCountryList().then(res => {
- if (res.data) {
- this.options.country = res.data
- const sign = {}
- res.data.forEach(item => {
- sign[item.value] = item.currencySymbol
- })
- this.currencyData = sign;
- }
- }).catch(err => {
- this.$message({
- type: 'error',
- message: err
- })
- this.loading = false;
- })
- },
- getRepeatOptions() {
- api.getRepeatOptions().then(res => {
- if (res.data) {
- this.options.repeat = res.data
- }
- }).catch(err => {
- this.$message({
- type: 'error',
- message: err
- })
- }).finally(() => {
- this.loading = false;
- })
- },
- getRateDetail() {
- this.loading = true;
- api.getDynamicRateInfo({
- dynamicRateId: this.$route.params.id
- }).then(res => {
- if (res.data) {
- this.form = res.data;
- if (res.data.rates && res.data.rates.length) {
- this.ratesForm.chargeRates = res.data.rates;
- }
- }
- }).catch(err => {
- this.$message({
- type: 'error',
- message: err
- })
- }).finally(() => {
- this.loading = false;
- })
- },
- handleShortcut(shortcut) {
- const select = []
- if (shortcut.all) {
- this.options.repeat.forEach(item => {
- select.push(item.value)
- })
- } else {
- select.push(...shortcut.value)
- }
- this.form.repeats = select;
- },
- changeAllday(all) {
- if (all) {
- this.form.startTime = "";
- this.form.endTime = "";
- this.$refs.form.clearValidate()
- }
- },
- onClickSave() {
- this.$refs.form.validate(result => {
- if (result) {
- if (this.form.repeats.length == 0) {
- this.$message({
- message: "Please select at least one repeat day",
- type: 'error',
- duration: 3000,
- })
- return;
- }
- const rates = [];
- this.ratesForm.chargeRates.forEach(item => {
- if (item.rate) {
- rates.push(item);
- }
- })
- this.ratesForm.specialChargeRates.forEach(item => {
- if (item.rate) {
- rates.push(item);
- }
- })
- if (rates.length == 0) {
- this.$message({
- message: "Please add at least one site rate",
- type: 'error',
- duration: 3000,
- })
- return;
- }
- this.form.rates = rates;
- this.loadingSave = true;
- this.isEdit ? this.updateRateData() : this.addRateData();
- }
- });
- },
- addRateData() {
- api.addDynamicRate(this.form).then(res => {
- this.$message({
- type: 'success',
- message: "Successfully added"
- });
- this.onBack();
- }).catch(err => {
- this.$message({
- type: 'error',
- message: err
- });
- }).finally(() => {
- this.loadingSave = false;
- });
- },
- updateRateData() {
- api.updateDynamicRate(this.form).then(res => {
- this.$message({
- type: 'success',
- message: "Successfully updated"
- });
- this.onBack();
- }).catch(err => {
- this.$message({
- type: 'error',
- message: err
- });
- }).finally(() => {
- this.loadingSave = false;
- });
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- @import '../../styles/variables.scss';
- .container {
- width: 100%;
- padding: 20px 60px;
- min-height: $mainAppMinHeight;
- background-color: #F0F5FC;
- }
- .content {
- margin: 0 8px 16px;
- padding: 15px 80px;
- border-radius: 6px;
- background-color: white;
- }
-
- .section-title {
- color: #333;
- margin-top: 20px;
- margin-bottom: 30px;
- font-size: 15px;
- user-select: none;
- line-height: 24px;
- font-weight: bold;
- font-family: sans-serif;
- text-transform: uppercase;
- }
-
- .section-sub-title {
- font-size: 14px;
- padding-left: 5px;
- font-weight: normal;
- }
-
- .add-text {
- width: 100%;
- min-width: 100px;
- max-width: 300px;
- }
- .add-text ::v-deep .el-textarea__inner {
- font-family: sans-serif;
- }
- .add-input {
- width: 100%;
- min-width: 100px;
- max-width: 250px;
- margin-right: 10px;
- ::v-deep .el-input,
- ::v-deep .el-select {
- width: 100%;
- }
- }
-
- .icon-help {
- color: #999;
- font-size: 15px;
- cursor: pointer;
- }
-
- .form-photo {
- flex: 1;
- ::v-deep .el-form-item__label {
- padding: 12px;
- line-height: 16px;
- }
- .photo-uploader {
- margin-right: 10px;
- .uploader-image {
- width: 180px;
- height: 120px;
- text-align: left;
- }
- ::v-deep img {
- object-fit: cover;
- }
- .avatar-uploader-icon {
- border: 1px dashed #d9d9d9;
- border-radius: 6px;
- cursor: pointer;
- font-size: 28px;
- color: #8c939d;
- width: 120px;
- height: 120px;
- line-height: 120px;
- text-align: center;
- }
- }
- }
- .repeat-view {
- display: flex;
- font-size: 14px;
- font-weight: bold;
- align-items: center;
- padding: 0 10px 10px;
- .link-type + .link-type {
- margin-left: 5px;
- &::before {
- color: #333;
- content: "|";
- font-size: 15px;
- font-weight: normal;
- padding-right: 5px;
- }
- }
- }
- .hr {
- height: 2px;
- margin: 10px -40px;
- background-color: #F0F5FC;
- }
- .buttons {
- padding-top: 15px;
- padding-bottom: 15px;
- }
- @media screen and (max-width: 1200px) {
- .add-input {
- min-width: 80px;
- max-width: 200px;
- }
- }
- @media screen and (max-width: 500px) {
- .container {
- padding: 0px;
- }
- .content {
- padding: 15px 30px;
- }
- .add-input {
- max-width: unset;
- }
- }
- </style>
|