accumulatePointsApplyEdit.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <template>
  2. <m-dialog ref="dialog" title="积分申报" @sure="onSure">
  3. <m-card shadow="never" v-loading="loading" style="min-height: 500px">
  4. <template v-if="finished">
  5. <el-descriptions
  6. :column="1"
  7. :labelStyle="{
  8. width: '200px',
  9. 'justify-content': 'flex-end',
  10. 'padding-top': '5px'
  11. }"
  12. >
  13. <el-descriptions-item label="提交月份">
  14. <el-date-picker
  15. v-model="month"
  16. size="small"
  17. type="month"
  18. value-format="yyyy-MM"
  19. placeholder="选择月份">
  20. </el-date-picker>
  21. </el-descriptions-item>
  22. </el-descriptions>
  23. <el-descriptions
  24. v-for="item in items"
  25. :key="item.ruleCategory"
  26. :title="item.ruleCategory"
  27. :column="1"
  28. :labelStyle="{
  29. width: '200px',
  30. 'justify-content': 'flex-end',
  31. 'padding-top': '5px'
  32. }"
  33. >
  34. <el-descriptions-item
  35. v-for="_item in item.item"
  36. :key="_item.employeeScoreRuleItemId"
  37. :label="_item.title"
  38. >
  39. <!-- <div style="width: 100%;"> -->
  40. <template v-if="_item.inputType === 0">
  41. <el-input-number
  42. size="small"
  43. :min="0"
  44. v-model="formValues[_item.employeeScoreRuleItemId].value"
  45. ></el-input-number>
  46. <UploadBtn v-model="formValues[_item.employeeScoreRuleItemId].image"></UploadBtn>
  47. </template>
  48. <template v-if="_item.inputType === 2">
  49. <m-card shadow="never" class="fullWidth">
  50. <div class="d-flex mb-3">
  51. <div style="width: 50px;">
  52. 积分
  53. </div>
  54. <el-input-number
  55. size="small"
  56. :min="0"
  57. placeholder="请输入积分"
  58. v-model="formValues[_item.employeeScoreRuleItemId].value"
  59. ></el-input-number>
  60. <UploadBtn v-model="formValues[_item.employeeScoreRuleItemId].image"></UploadBtn>
  61. </div>
  62. <div class="d-flex">
  63. <div style="width: 50px;">
  64. 描述
  65. </div>
  66. <el-input
  67. type="textarea"
  68. :rows="1"
  69. placeholder="请输入类目描述"
  70. v-model="formValues[_item.employeeScoreRuleItemId].desc"
  71. ></el-input>
  72. </div>
  73. </m-card>
  74. </template>
  75. <template v-if="_item.inputType === 3">
  76. <el-radio-group v-model="formValues[_item.employeeScoreRuleItemId].value" class="mt-2">
  77. <el-radio
  78. v-for="radio in _item.child"
  79. :key="radio.employeeScoreRuleItemId"
  80. :label="radio.employeeScoreRuleItemId">
  81. {{ radio.title }}
  82. </el-radio>
  83. </el-radio-group>
  84. <UploadBtn v-model="formValues[_item.employeeScoreRuleItemId].image"></UploadBtn>
  85. </template>
  86. <!-- </div> -->
  87. <!-- <el-upload>
  88. <m-button size="small" type="primary">附件上传</m-button>
  89. </el-upload> -->
  90. </el-descriptions-item>
  91. </el-descriptions>
  92. </template>
  93. </m-card>
  94. </m-dialog>
  95. </template>
  96. <script>
  97. import {
  98. getAccumulatePointRule,
  99. saveAccumulatePoint
  100. } from '@/api/accumulatePoint'
  101. import UploadBtn from './accumulatePointsApplyEditUpload.vue'
  102. export default {
  103. name: 'accumulatePointsApplyEdit',
  104. components: {
  105. UploadBtn
  106. },
  107. data () {
  108. return {
  109. month: null,
  110. loading: false,
  111. finished: false,
  112. items: [],
  113. formValues: {}
  114. }
  115. },
  116. created () {
  117. const date = new Date()
  118. this.month = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}`
  119. },
  120. methods: {
  121. async open () {
  122. this.loading = true
  123. this.$refs.dialog.open()
  124. try {
  125. const { data } = await getAccumulatePointRule()
  126. this.items = data
  127. this.formValues = this.items.reduce((acc, cur) => {
  128. cur.item.forEach(item => {
  129. acc[item.employeeScoreRuleItemId] = {
  130. value: item.inputType === 3 ? null : 0,
  131. desc: null,
  132. maxScore: item.maxScore ? Number(item.maxScore) : item.maxScore,
  133. image: null
  134. }
  135. })
  136. return acc
  137. }, {})
  138. this.finished = true
  139. } catch (error) {
  140. this.$message.error(error)
  141. } finally {
  142. this.loading = false
  143. }
  144. },
  145. async onSure () {
  146. const values = Object.values(this.formValues)
  147. if (values.some(item => item.value === null)) {
  148. this.$message.error('请填写完整再提交')
  149. return
  150. }
  151. const param = Object.keys(this.formValues).map(key => {
  152. return {
  153. images: this.formValues[key].image,
  154. inputValue: this.formValues[key].value,
  155. desc: this.formValues[key].desc,
  156. employeeScoreRuleItemId: key
  157. }
  158. })
  159. try {
  160. await saveAccumulatePoint({
  161. month: this.month,
  162. item: param
  163. })
  164. this.$refs.dialog.close()
  165. this.$emit('success')
  166. } catch (error) {
  167. this.$message.error(error)
  168. }
  169. }
  170. }
  171. }
  172. </script>
  173. <style lang="scss" scoped>
  174. .fullWidth {
  175. width: 100%;
  176. }
  177. .el-radio {
  178. display: block;
  179. margin-bottom: 5px;
  180. }
  181. </style>