price-increase.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <div class="app-content">
  3. <div class="module-com flex-center-between switch-blo">
  4. <div class="app-size-32">开启涨价</div>
  5. <div>
  6. <switch :checked="form.riseSwitch == '0' ? false : true" @change="switchChangeFn" />
  7. </div>
  8. </div>
  9. <block v-if="form.riseSwitch != 0">
  10. <!-- 选项设置 -->
  11. <div class="input-line-wrap new-wrap">
  12. <tui-list-cell class="line-cell" :hover="false">
  13. <div class="tui-title">涨价节日</div>
  14. <div class="tui-input button-wrap">
  15. <block v-for="(item, index) in festData" :key="index">
  16. <button class="admin-button-com" :class="[form.festIdList.includes(item.id) ? '' : 'default']" @click="selFestFn(item)">{{ item.name || '暂无' }}</button>
  17. </block>
  18. </div>
  19. </tui-list-cell>
  20. <tui-list-cell class="line-cell" :hover="false">
  21. <div class="tui-title">涨价方式</div>
  22. <radio-group class="tui-input flex-center-between" @change="radioChange">
  23. <label class="list" for="customLink">
  24. <radio id="customLink" value="0" :checked="form.riseType == 0" />
  25. <span class="checkbox-text">按百分比</span>
  26. </label>
  27. <label class="list" for="goodsLink">
  28. <radio id="goodsLink" value="1" :checked="form.riseType == 1" />
  29. <span class="checkbox-text">按金额</span>
  30. </label>
  31. </radio-group>
  32. </tui-list-cell>
  33. <block v-if="form.riseType == 0">
  34. <tui-list-cell class="line-cell" :hover="false">
  35. <div class="tui-title">比例</div>
  36. <input v-model="form.riseAmount" placeholder-class="phcolor" class="tui-input" name="phone" placeholder="涨价10%,请输入10" maxlength="50" type="number" />
  37. </tui-list-cell>
  38. </block>
  39. <block v-else>
  40. <tui-list-cell class="line-cell" :hover="false">
  41. <div class="tui-title">金额</div>
  42. <input v-model="form.riseAmount" placeholder-class="phcolor" class="tui-input" name="phone" placeholder="涨价80元请输入80" maxlength="50" type="number" />
  43. </tui-list-cell>
  44. </block>
  45. </div>
  46. <div class="prompt-text">节日当天和前一天,设置涨价的商品将统一按上面规则涨价。</div>
  47. </block>
  48. <button class="admin-button-com blue big confirm-btn" @click="setPrice">确定</button>
  49. </div>
  50. </template>
  51. <script>
  52. import { mapGetters } from 'vuex'
  53. import TuiListCell from '@/components/plugin/list-cell'
  54. // api
  55. import { getFest } from '@/utils/config'
  56. import { getRise, updateRise } from '@/api/goods'
  57. export default {
  58. name: 'setting-price-increase',
  59. components: {
  60. TuiListCell
  61. },
  62. data() {
  63. return {
  64. // radioVal: '0',
  65. form: {
  66. riseSwitch: '0',
  67. riseType: '0',
  68. festIdList: [],
  69. riseAmount: ''
  70. }
  71. }
  72. },
  73. computed: {
  74. ...mapGetters({ festData: 'getFest' })
  75. },
  76. onLoad() {
  77. // this.init()
  78. },
  79. methods: {
  80. init() {
  81. getFest().then(() => {
  82. this._getDet()
  83. })
  84. },
  85. _getDet() {
  86. return getRise().then(res => {
  87. if (this.$util.isEmpty(res.data)) return
  88. res.data.festIdList = res.data.festIdList.map(e => e + '')
  89. Object.keys(this.form).forEach((i, index) => {
  90. this.form[i] = res.data[i]
  91. })
  92. })
  93. },
  94. setPrice() {
  95. if (this.form.festIdList.length == 0) {
  96. this.$msg('请先选择节日!')
  97. return false
  98. }
  99. if (!this.form.riseAmount) {
  100. this.$msg('请先输入比例或者金额!')
  101. return false
  102. }
  103. updateRise(this.form).then(res => {
  104. this.$msg('更新成功!')
  105. })
  106. },
  107. selFestFn(item) {
  108. let index = this.form.festIdList.findIndex(e => e == item.id)
  109. if (index == -1) {
  110. this.form.festIdList.push(item.id)
  111. } else {
  112. this.form.festIdList.splice(index, 1)
  113. }
  114. },
  115. switchChangeFn(e) {
  116. this.form.riseSwitch = e.detail.value ? '1' : '0'
  117. },
  118. radioChange(e) {
  119. this.form.riseAmount = ''
  120. this.form.riseType = e.detail.value
  121. }
  122. }
  123. }
  124. </script>
  125. <style lang="scss" scoped>
  126. .prompt-text {
  127. color: $fontColor3;
  128. padding-bottom: 20px;
  129. padding-left: 30px;
  130. }
  131. .module-com {
  132. margin-bottom: 20px;
  133. padding: 30px;
  134. background-color: #fff;
  135. color: $fontColor2;
  136. .module-tit {
  137. font-size: 28px;
  138. }
  139. }
  140. .confirm-btn {
  141. width: calc(100% - 60px);
  142. margin: 60px 30px 0;
  143. }
  144. .switch-blo {
  145. padding: 15px 30px;
  146. }
  147. .new-wrap {
  148. margin-bottom: 20px;
  149. .checkbox-text {
  150. color: $fontColor2;
  151. }
  152. .button-wrap {
  153. justify-content: flex-start;
  154. flex-wrap: wrap;
  155. .admin-button-com {
  156. padding-top: 12px;
  157. padding-bottom: 12px;
  158. margin-right: 20px;
  159. border-radius: 4px;
  160. // &:first-child {
  161. // margin-left: 0;
  162. // }
  163. }
  164. }
  165. }
  166. </style>