item.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <div>
  3. <el-row>
  4. <div class="btn_add">
  5. <el-button type="primary" size="mini" @click="useAdd" v-if="this.pageStu != 'see'">增行</el-button>
  6. </div>
  7. </el-row>
  8. <!-- 渲染表头 -->
  9. <el-table :data="items" style="width: 100%" height="500px">
  10. <el-table-column label="序号" type="index" width="50" align="center" fixed>
  11. </el-table-column>
  12. <el-table-column show-overflow-tooltip v-for="head in headers" :prop="head.prop" :label="head.modelName" width="200" align="center">
  13. <template slot-scope="scope">
  14. <div v-if="pageStu == 'add' || pageStu == 'edit'">
  15. <div v-if="scope.row[head.prop].type == 'D'">
  16. <dr-popover-select
  17. size="mini"
  18. v-if="scope.row[head.prop].model == 'MK_TARGET_CYCLE_PARAM' || scope.row[head.prop].model == 'MK_TARGET_INDEX_PARAM'"
  19. v-model="scope.row[head.prop].valueName"
  20. title="参照选择"
  21. :type="scope.row[head.prop].model"
  22. :dataMapping="{
  23. value: 'id',
  24. valueName: 'name',
  25. }"
  26. :source.sync="scope.row[head.prop]"
  27. :queryParams="additionalCondition"
  28. />
  29. <dr-popover-select size="mini" v-else v-model="scope.row[head.prop].valueName" title="参照选择" :type="scope.row[head.prop].model" :dataMapping="{
  30. value: 'id',
  31. valueName: 'name',
  32. }" :source.sync="scope.row[head.prop]"></dr-popover-select>
  33. </div>
  34. <div v-if="scope.row[head.prop].type == 'C' || scope.row[head.prop].type == 'I'">
  35. <el-input size="mini" v-model="scope.row[head.prop].value"></el-input>
  36. </div>
  37. </div>
  38. <div v-else-if="pageStu == 'see'">
  39. <div v-if="scope.row[head.prop].type == 'D'">
  40. {{scope.row[head.prop].valueName}}
  41. </div>
  42. <div v-else>
  43. {{scope.row[head.prop].value}}
  44. </div>
  45. </div>
  46. </template>
  47. <el-table-column show-overflow-tooltip v-if="head.children" v-for="headChi in head.children" :prop="headChi.prop" :label="headChi.modelName" width="150" align="center">
  48. <template slot-scope="scope">
  49. <div v-if="pageStu == 'add' || pageStu == 'edit'">
  50. <el-input size="mini" v-model="scope.row[headChi.prop].value"></el-input>
  51. </div>
  52. <div v-else-if="pageStu == 'see'">
  53. {{scope.row[headChi.prop].value}}
  54. </div>
  55. </template>
  56. </el-table-column>
  57. </el-table-column>
  58. <el-table-column fixed="right" label="操作" align="center" width="100" v-if="this.pageStu != 'see'">
  59. <template slot-scope="scope">
  60. <el-button type="text" size="mini" @click="useDel(scope.$index, scope.row)">删除</el-button>
  61. </template>
  62. </el-table-column>
  63. </el-table>
  64. </div>
  65. </template>
  66. <script>
  67. import { getTargetItem } from "@/api/business/spd/starget/target";
  68. export default {
  69. name: 'item',
  70. props: ['pageStu','template','form','columns','latestTemplate'],
  71. dicts: ['sys_yes_no','mk_periodic_unit','mk_dimensionality','mk_index_type','mk_expansion_mode'],
  72. data() {
  73. return {
  74. items:[],
  75. delItems:[],
  76. headers:[],
  77. itemTemplate:{},
  78. }
  79. },
  80. async created() {
  81. this.processHeadersData(this.template.unfold,this.columns);
  82. this.itemTemplate = this.formatItem(this.columns);
  83. console.log('this.itemTemplate',this.itemTemplate);
  84. if(this.pageStu == 'edit' || this.pageStu == 'see'){
  85. if(!this.latestTemplate){
  86. await this.fetchTargetItem(this.form.id);
  87. }
  88. }
  89. },
  90. methods: {
  91. //增行
  92. useAdd(){
  93. this.items.push(this.itemTemplate);
  94. },
  95. //删行
  96. useDel(index){
  97. this.items[index].delFlag = '2';
  98. if(this.items[index].id){
  99. let delList = this.items.filter(item => {
  100. return item.delFlag == '2'
  101. })
  102. this.delItems.push(...delList);
  103. }
  104. this.items.splice(index, 1);
  105. },
  106. //表头数据处理
  107. processHeadersData(unfold,columns){
  108. const array = [];
  109. if("cycle/unfold" == unfold){
  110. for(let i in columns){
  111. if(columns[i].type == 'D'){
  112. columns[i].prop = columns[i].model
  113. array.push(columns[i]);
  114. }else{
  115. const arr = array.filter(element => element.model == columns[i].superiors);
  116. if(arr.length > 0){
  117. columns[i].prop = array[array.length - 1].model + '-' + columns[i].model;
  118. array[array.length - 1].children.push(columns[i]);
  119. }else{
  120. columns[i].prop = columns[i].superiors + '-' + columns[i].model;
  121. let c = {
  122. type:'C',
  123. model:columns[i].superiors,
  124. modelName:columns[i].superiorsName,
  125. children:[columns[i]]
  126. }
  127. array.push(c);
  128. }
  129. }
  130. }
  131. this.headers = array;
  132. }else if("cycle" == unfold){
  133. for(let i in columns){
  134. columns[i].prop = columns[i].model
  135. if(columns[i].model == 'MK_TARGET_CYCLE_PARAM' || columns[i].model == 'MK_TARGET_INDEX_PARAM'){
  136. columns[i].templateId = this.template.id
  137. }
  138. array.push(columns[i]);
  139. }
  140. this.headers = array;
  141. }else if("unfold" == unfold){
  142. for(let i in columns){
  143. columns[i].prop = columns[i].model
  144. if(columns[i].model == 'MK_TARGET_CYCLE_PARAM' || columns[i].model == 'MK_TARGET_INDEX_PARAM'){
  145. columns[i].templateId = this.template.id
  146. }
  147. array.push(columns[i]);
  148. }
  149. this.headers = array;
  150. }else if("" == unfold){
  151. for(let i in columns){
  152. columns[i].prop = columns[i].model
  153. if(columns[i].model == 'MK_TARGET_CYCLE_PARAM' || columns[i].model == 'MK_TARGET_INDEX_PARAM'){
  154. columns[i].templateId = this.template.id
  155. }
  156. array.push(columns[i]);
  157. }
  158. this.headers = array;
  159. }
  160. console.log('this.headers',this.headers);
  161. },
  162. //获取明细数据
  163. async fetchTargetItem(id){
  164. await getTargetItem(id).then(res => {
  165. if (res.code === 200) {
  166. this.items = res.rows
  167. }
  168. })
  169. },
  170. //格式化数据
  171. formatItem(item){
  172. let obj = {};
  173. for(let i in item){
  174. obj[item[i].prop] = item[i];
  175. }
  176. return obj;
  177. },
  178. //合并已存在和删除的数据
  179. merge(){
  180. this.items.push(...this.delItems);
  181. return this.items;
  182. },
  183. //附加查询条件
  184. additionalCondition(prop){
  185. console.log("prop",prop);
  186. return {
  187. parame:{
  188. templateId: prop.templateId
  189. }
  190. }
  191. }
  192. }
  193. }
  194. </script>
  195. <style lang="scss" scoped>
  196. .btn_add{
  197. margin-bottom: 10px;
  198. display: flex;
  199. justify-content: flex-end;
  200. }
  201. .btn_group {
  202. width: 100%;
  203. margin: 20px 0;
  204. display: flex;
  205. justify-content: center;
  206. }
  207. </style>