addEbdDialog.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <script setup>
  2. import { ref, reactive, nextTick, watch } from 'vue'
  3. import { apiIndicatorImport } from '@/api/indicator'
  4. import { ElMessage } from 'element-plus'
  5. const ruleFormRef = ref();
  6. const show = defineModel('show', { type: Boolean, default: false });
  7. const formData = reactive({
  8. IndexCode:'',
  9. IndexName:'',
  10. Frequency:'',
  11. Unit:'',
  12. StartDate:'',
  13. EndDate:'',
  14. });
  15. const tableData = ref([]);
  16. const dataList = ref([]);
  17. const showData = ref(false);
  18. const dataLoading = ref(false);
  19. const saveLoading = ref(false);
  20. const emits = defineEmits(["success"]);
  21. watch(show,(val)=>{
  22. if(val) closeDialog();
  23. })
  24. const frequencyOptions = [
  25. { label:'日度',val: '日度' },
  26. { label:'周度',val: '周度' },
  27. { label:'旬度',val: '旬度' },
  28. { label:'月度',val: '月度' },
  29. { label:'季度',val: '季度' },
  30. { label:'半年度',val: '半年度' },
  31. { label:'年度',val: '年度' },
  32. ];
  33. const tableColums = [
  34. {
  35. label: '指标ID',
  36. key: 'IndexCode',
  37. },
  38. {
  39. label: '起始时间',
  40. key: 'StartDate',
  41. },
  42. {
  43. label: '结束时间',
  44. key: 'EndDate',
  45. },
  46. ];
  47. const rules = reactive({
  48. IndexCode: [{required: true,message: '请输入指标ID',trigger: 'change'}],
  49. // IndexName: [{required: true,message: '请输入指标名称',trigger: 'change'}],
  50. // Frequency: [{required: true,message: '请选择频度',trigger: 'change'}],
  51. // Unit: [{required: true,message: '请输入单位',trigger: 'change'}],
  52. });
  53. function closeDialog(){
  54. ruleFormRef.value?.resetFields();
  55. formData.IndexCode = '';
  56. formData.IndexName = '';
  57. formData.Frequency = '';
  58. formData.Unit = '';
  59. formData.StartDate = '';
  60. formData.EndDate = '';
  61. tableData.value = [];
  62. dataList.value = [];
  63. showData.value = false;
  64. dataLoading.value = false;
  65. saveLoading.value = false;
  66. };
  67. async function getIndexDetail(){
  68. if(!formData.IndexCode) return;
  69. dataLoading.value = true;
  70. let res = await apiIndicatorImport.getIndexInfo({
  71. IndexCode:formData.IndexCode
  72. });
  73. dataLoading.value = false;
  74. if(res.Ret != 200) return;
  75. const { Data } = res;
  76. formData.IndexName = Data.IndexName;
  77. formData.Frequency = Data.Frequency;
  78. formData.Unit = Data.Unit;
  79. formData.StartDate = Data.StartDate;
  80. formData.EndDate = Data.EndDate;
  81. dataList.value = Data.DataList || [];
  82. tableData.value = [{
  83. StartDate:formData.StartDate,
  84. EndDate:formData.EndDate,
  85. IndexCode:formData.IndexCode
  86. }]
  87. showData.value = true;
  88. }
  89. async function confirm(){
  90. await ruleFormRef.value?.validate();
  91. // if(!showData.value) return ElMessage.warning('请在数据搜索之后再进行添加操作');
  92. saveLoading.value = true;
  93. let res = await apiIndicatorImport.dataPush({ IndexCode:formData.IndexCode });
  94. saveLoading.value = false;
  95. if(res.Ret != 200) return;
  96. ElMessage.success('添加成功')
  97. emits('success');
  98. show.value = false;
  99. }
  100. </script>
  101. <template>
  102. <el-dialog
  103. v-model="show"
  104. :close-on-click-modal="false"
  105. :modal-append-to-body="false"
  106. width="75%"
  107. draggable
  108. title="添加指标"
  109. @close="closeDialog"
  110. style="min-width: 900px;overflow: auto;"
  111. >
  112. <el-form ref="ruleFormRef" :model="formData" size="large" @submit.prevent class="form-wrap" :rules="rules">
  113. <el-form-item label="指标ID" :style="showData?`flex:1`:`width:300px;`" prop="IndexCode">
  114. <el-input v-model="formData.IndexCode" placeholder="请输入指标ID" @change="getIndexDetail" clearable/>
  115. </el-form-item>
  116. <el-form-item label="指标名称" style="flex: 1;" v-if="showData" prop="IndexName">
  117. <el-input v-model="formData.IndexName" placeholder="请输入指标名称" clearable :disabled="true"/>
  118. </el-form-item>
  119. <el-form-item label="频度" style="flex: 1;" v-if="showData" prop="Frequency">
  120. <el-select
  121. v-model="formData.Frequency"
  122. placeholder="请选择频度"
  123. clearable
  124. :disabled="true"
  125. >
  126. <el-option v-for="item in frequencyOptions" :key="item.val" :label="item.label" :value="item.val"/>
  127. </el-select>
  128. </el-form-item>
  129. <el-form-item label="单位" style="flex: 1;" v-if="showData" prop="Unit">
  130. <el-input v-model="formData.Unit" placeholder="请输入单位" clearable :disabled="true"/>
  131. </el-form-item>
  132. </el-form>
  133. <div class="main" v-loading="dataLoading">
  134. <el-table
  135. :data="tableData"
  136. border
  137. >
  138. <el-table-column
  139. v-for="item in tableColums"
  140. :key="item.label"
  141. :label="item.label"
  142. :width="item.widthsty"
  143. :min-width="item.minwidthsty"
  144. align="center"
  145. >
  146. <template #default="scope">
  147. <span>{{ scope.row[item.key] }}</span>
  148. </template>
  149. </el-table-column>
  150. <template #empty>
  151. <el-empty description="暂无数据" />
  152. </template>
  153. </el-table>
  154. <div v-if="dataList && dataList.length" class="value-ul" ref="valueUl">
  155. <div v-for="(item,index) in dataList" :key="index + 1" class="ul-content">
  156. <div>{{ item.Date }}</div>
  157. <div>{{ item.Value }}</div>
  158. </div>
  159. </div>
  160. </div>
  161. <div class="footer">
  162. <el-button @click="show = false" size="large" style="width: 100px;">取 消</el-button>
  163. <el-button type="primary" size="large" style="width: 100px;margin-left: 20px;" @click="confirm" :loading="saveLoading">确定</el-button>
  164. </div>
  165. </el-dialog>
  166. </template>
  167. <style lang="scss" scoped>
  168. .form-wrap{
  169. display: flex;
  170. justify-content: space-between;
  171. align-items: center;
  172. gap: 37px;
  173. }
  174. .main {
  175. .value-ul{
  176. height: 300px;
  177. margin-top: 0;
  178. border-bottom: 1px solid #EBEFF6;
  179. border-left: 1px solid #EBEFF6;
  180. border-right: 1px solid #EBEFF6;
  181. overflow-y: auto;
  182. .ul-content{
  183. display: flex;
  184. align-items: center;
  185. justify-content: space-around;
  186. line-height: 40px;
  187. color: #666;
  188. }
  189. }
  190. }
  191. .footer{
  192. margin: 80px 0 40px;
  193. display: flex;
  194. align-items: center;
  195. justify-content: center;
  196. }
  197. </style>