addEdit.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <template>
  2. <el-dialog
  3. v-loading="loading"
  4. :title="'修改表格需求'"
  5. :center="true"
  6. align="left"
  7. top="25vh"
  8. width="600px"
  9. :close-on-click-modal="false"
  10. :visible.sync="showModelThis"
  11. element-loading-text="拼命加载中"
  12. element-loading-spinner="el-icon-loading"
  13. element-loading-background="rgba(0, 0, 0, 0.8)"
  14. @close="closeModel"
  15. >
  16. <el-card style="margin: -20px 0 0 0">
  17. <el-row :gutter="10">
  18. <el-col :span="24">
  19. <el-form
  20. ref="ruleForm"
  21. :model="ruleForm"
  22. status-icon
  23. :rules="rulesThis"
  24. label-width="90px"
  25. class="demo-ruleForm"
  26. >
  27. <el-form-item label="业务表" prop="id">
  28. <el-select v-model="ruleForm.id" style="width: 100%" disabled placeholder="请选择业务表">
  29. <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
  30. </el-select>
  31. </el-form-item>
  32. <el-form-item label="数据时间" prop="start">
  33. <period-date-picker
  34. :start="ruleForm.start"
  35. :end="ruleForm.end"
  36. :type="type"
  37. :width="'199px'"
  38. :size="searchSize"
  39. @timeReturned="timeReturned($event)"
  40. />
  41. </el-form-item>
  42. </el-form>
  43. </el-col>
  44. <el-col :span="12" style="text-align: right">
  45. <el-alert
  46. style="width: 230px"
  47. :closable="false"
  48. :title="
  49. type === '2'
  50. ? '报表会在提交后开始执行!'
  51. : '报表会在明天01:00开始生成'
  52. "
  53. type="warning"
  54. />
  55. </el-col>
  56. <el-col :span="12" style="text-align: right">
  57. <el-button v-if="!isDetail" type="primary" @click="submitForm">保 存
  58. </el-button>
  59. <el-button @click="showModelThis = false">{{
  60. isDetail ? "关 闭" : "取 消"
  61. }}</el-button>
  62. </el-col>
  63. </el-row>
  64. </el-card>
  65. </el-dialog>
  66. </template>
  67. <script>
  68. import asyncRequest from '@/apis/service/reportQuery/financeReport/index.js'
  69. import resToken from '@/mixins/resToken'
  70. import PeriodDatePicker from './components/PeriodDatePicker'
  71. export default {
  72. name: 'FinanceReport',
  73. components: {
  74. PeriodDatePicker
  75. },
  76. mixins: [resToken],
  77. props: ['showModel', 'sitem', 'type'],
  78. data() {
  79. const validateTime = (rule, value, callback) => {
  80. if (value === '') {
  81. callback(new Error('数据开始时间不能为空!'))
  82. } else {
  83. if (this.ruleForm.end === '') {
  84. callback(new Error('数据结束时间不能为空!'))
  85. } else {
  86. callback()
  87. }
  88. }
  89. }
  90. return {
  91. options: [],
  92. loading: false,
  93. title: '添加账号',
  94. showModelThis: this.showModel,
  95. ruleForm: {
  96. start: '',
  97. end: '',
  98. id: ''
  99. },
  100. rulesThis: this.rules,
  101. rules: {
  102. start: [
  103. {
  104. required: true,
  105. validator: validateTime,
  106. trigger: 'change'
  107. }
  108. ],
  109. id: [
  110. {
  111. required: true,
  112. message: '请选择业务表!',
  113. trigger: 'change'
  114. }
  115. ]
  116. }
  117. }
  118. },
  119. watch: {
  120. showModel: function(val) {
  121. this.showModelThis = val
  122. if (val) {
  123. this.initForm()
  124. }
  125. },
  126. showModelThis(val) {
  127. if (!val) {
  128. this.$emit('cancel')
  129. }
  130. }
  131. },
  132. methods: {
  133. closeModel() {
  134. console.log('closeModel!!')
  135. },
  136. async initForm() {
  137. this.loading = true
  138. this.options = []
  139. this.rulesThis = this.rules
  140. await this.resetForm()
  141. this.loading = false
  142. },
  143. async timeReturned(e) {
  144. if (e.startTime !== '') {
  145. this.ruleForm.start = e.startTime
  146. } else {
  147. this.ruleForm.start = ''
  148. }
  149. if (e.endTime !== '') {
  150. this.ruleForm.end = e.endTime
  151. } else {
  152. this.ruleForm.end = ''
  153. }
  154. },
  155. async resetForm() {
  156. // 重置
  157. await this.$nextTick(() => {
  158. if (this.$refs.ruleForm) {
  159. this.$refs.ruleForm.resetFields()
  160. this.$refs.ruleForm.clearValidate()
  161. const { start, end, id, name } = this.sitem
  162. // console.log(this.sitem);
  163. this.options = [
  164. {
  165. value: id,
  166. label: name
  167. }
  168. ]
  169. this.ruleForm = {
  170. start: '',
  171. end: '',
  172. id: id || ''
  173. }
  174. console.log(this.ruleForm)
  175. }
  176. })
  177. },
  178. getDiffDay(date_1, date_2) {
  179. // 计算两个日期之间的差值
  180. let totalDays, diffDate
  181. const myDate_1 = Date.parse(date_1)
  182. const myDate_2 = Date.parse(date_2)
  183. // 将两个日期都转换为毫秒格式,然后做差
  184. diffDate = Math.abs(myDate_1 - myDate_2) // 取相差毫秒数的绝对值
  185. totalDays = Math.floor(diffDate / (1000 * 3600 * 24)) // 向下取整
  186. return totalDays // 相差的天数
  187. },
  188. async submitForm() {
  189. await this.$refs.ruleForm.validate(async(valid) => {
  190. if (valid) {
  191. if (this.loading) {
  192. return
  193. }
  194. const model = JSON.parse(JSON.stringify(this.ruleForm))
  195. const diffDays = this.getDiffDay(model.start, model.end)
  196. if (diffDays > 30) return this.$message.warning('数据时间间隔不能超过30天')
  197. this.loading = true
  198. const res = await asyncRequest.add(model)
  199. this.loading = false
  200. if (res && res.code === 0) {
  201. this.$notify.success({
  202. title: '需求创建成功!',
  203. message: ''
  204. })
  205. this.showModelThis = false
  206. // 刷新
  207. this.$emit('refresh')
  208. } else if (res && res.code >= 100 && res.code <= 104) {
  209. await this.logout()
  210. } else {
  211. this.$message.warning(res.message)
  212. }
  213. } else {
  214. console.log('error submit!!')
  215. return false
  216. }
  217. })
  218. }
  219. }
  220. }
  221. </script>
  222. <style lang="scss" scoped>
  223. .account {}
  224. </style>