other-config.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <div v-loading="loading">
  3. <div class="white-box">
  4. <el-form ref="form" :model="form" label-width="250px" :label-position="labelPosition">
  5. <template v-for="item in configData">
  6. <div v-if="item.SORT==='1'" class="hr-tip"><span>{{ $t('config.memberAbout') }}</span></div>
  7. <div v-if="item.SORT==='13'" class="hr-tip"><span>{{ $t('config.homeAbout') }}</span></div>
  8. <div v-if="item.SORT==='16'" class="hr-tip"><span>{{ $t('config.withdrawalAbout') }}</span></div>
  9. <div v-if="item.SORT==='41'" class="hr-tip"><span>{{ $t('config.otherAbout') }}</span></div>
  10. <el-form-item :key="item.CONFIG_NAME" :label="item.TITLE">
  11. <template v-if="(item.INPUT_TYPE).toString()==='2'">
  12. <el-select v-model="item.VALUE" placeholder="请选择">
  13. <el-option v-for="optionItem in item.OPTIONS" :key="optionItem.label" :label="optionItem.label" :value="optionItem.value" />
  14. </el-select>
  15. </template>
  16. <template v-else-if="(item.INPUT_TYPE).toString()==='3'">
  17. <el-checkbox-group v-model="item.VALUE">
  18. <el-checkbox v-for="optionItem in item.OPTIONS" :key="optionItem.label" :label="optionItem.label" :value="optionItem.value" />
  19. </el-checkbox-group>
  20. </template>
  21. <template v-else-if="(item.INPUT_TYPE).toString()==='4'">
  22. <el-date-picker v-model="item.VALUE" type="year" placeholder="选择年" />
  23. </template>
  24. <template v-else-if="(item.INPUT_TYPE).toString()==='5'">
  25. <el-date-picker v-model="item.VALUE" type="datetime" placeholder="Select date" />
  26. </template>
  27. <template v-else-if="(item.INPUT_TYPE).toString()==='6'">
  28. <el-date-picker v-model="item.VALUE" type="date" placeholder="Select date" />
  29. </template>
  30. <template v-else-if="(item.INPUT_TYPE).toString()==='7'">
  31. <el-time-select v-model="item.VALUE" :picker-options="{start: item.OPTIONS.start, end: item.OPTIONS.end, step: item.OPTIONS.step}" placeholder="选择时间" />
  32. </template>
  33. <template v-else-if="(item.INPUT_TYPE).toString()==='8'">
  34. <el-switch v-model="item.VALUE" />
  35. </template>
  36. <template v-else-if="(item.INPUT_TYPE).toString()==='9'">
  37. <el-input
  38. v-model="item.VALUE"
  39. type="textarea"
  40. :rows="4"
  41. placeholder="请输入内容"
  42. />
  43. </template>
  44. <template v-else>
  45. <el-input v-model="item.VALUE" placeholder="请输入内容">
  46. <template v-if="!!item.UNIT" slot="append">{{ item.UNIT }}</template>
  47. </el-input>
  48. </template>
  49. </el-form-item>
  50. </template>
  51. <el-form-item>
  52. <el-button type="primary" :loading="submitButtonStat" @click="onSubmit">{{ $t('table.confirm') }}</el-button>
  53. </el-form-item>
  54. </el-form>
  55. </div>
  56. </div>
  57. </template>
  58. <script>
  59. import { getScreenWidth } from '@/utils'
  60. import { fetchOtherConfig, updateOtherConfig } from '@/api/config'
  61. export default {
  62. name: 'OtherConfig',
  63. data() {
  64. return {
  65. loading: true,
  66. submitButtonStat: false,
  67. configData: null,
  68. screenWidth: getScreenWidth() > 500 ? '500px' : getScreenWidth() + 'px',
  69. labelPosition: getScreenWidth() >= 500 ? 'right' : 'top'
  70. }
  71. },
  72. computed: {
  73. form: function() {
  74. const result = {}
  75. for (const i in this.configData) {
  76. result[i] = this.configData[i].VALUE
  77. }
  78. return result
  79. }
  80. },
  81. mounted() {
  82. this.fetchData()
  83. },
  84. methods: {
  85. fetchData() {
  86. this.loading = true
  87. fetchOtherConfig().then(response => {
  88. this.configData = response.data
  89. setTimeout(() => {
  90. this.loading = false
  91. }, 0.5 * 1000)
  92. })
  93. },
  94. onSubmit() {
  95. this.loading = true
  96. updateOtherConfig(this.form).then(response => {
  97. this.$message({
  98. message: response.data,
  99. type: 'success'
  100. })
  101. setTimeout(() => {
  102. this.loading = false
  103. }, 0.5 * 1000)
  104. this.fetchData()
  105. }).catch(error => {
  106. this.$message({
  107. message: error,
  108. type: 'warning'
  109. })
  110. this.loading = false
  111. this.fetchData()
  112. })
  113. }
  114. }
  115. }
  116. </script>
  117. <style scoped>
  118. .app-main {
  119. padding: 15px;
  120. }
  121. .app-container {
  122. padding: 0;
  123. }
  124. .white-box {
  125. padding: 15px;
  126. }
  127. .form-page {
  128. width: 100%;
  129. }
  130. .hr-tip {
  131. font-size: 12px;
  132. position: relative;
  133. text-align: center;
  134. height: 30px;
  135. line-height: 30px;
  136. color: #999;
  137. margin-bottom: 20px;
  138. }
  139. .hr-tip:before {
  140. content: '';
  141. display: block;
  142. position: absolute;
  143. left: 0;
  144. right: 0;
  145. top: 14px;
  146. border-bottom: 1px dashed #ddd;
  147. height: 1px;
  148. }
  149. .hr-tip span {
  150. display: inline-block;
  151. background: #fff;
  152. position: relative;
  153. padding: 0 10px;
  154. }
  155. </style>