item.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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" 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. if(this.pageStu == 'edit' || this.pageStu == 'see'){
  84. if(!this.latestTemplate){
  85. await this.fetchTargetItem(this.form.id);
  86. }
  87. }
  88. },
  89. methods: {
  90. //增行
  91. useAdd(){
  92. this.items.push(this.itemTemplate);
  93. console.log('this.itemTemplate',this.itemTemplate);
  94. console.log('this.items',this.items);
  95. },
  96. //删行
  97. useDel(index){
  98. this.items[index].delFlag = '2';
  99. if(this.items[index].id){
  100. let delList = this.items.filter(item => {
  101. return item.delFlag == '2'
  102. })
  103. this.delItems.push(...delList);
  104. }
  105. this.items.splice(index, 1);
  106. },
  107. //表头数据处理
  108. processHeadersData(unfold,columns){
  109. const array = [];
  110. if("cycle/unfold" == unfold){
  111. for(let i in columns){
  112. if(columns[i].type == 'D'){
  113. columns[i].prop = columns[i].model
  114. array.push(columns[i]);
  115. }else{
  116. const arr = array.filter(element => element.model == columns[i].superiors);
  117. if(arr.length > 0){
  118. columns[i].prop = array[array.length - 1].model + '-' + columns[i].model;
  119. array[array.length - 1].children.push(columns[i]);
  120. }else{
  121. columns[i].prop = columns[i].superiors + '-' + columns[i].model;
  122. let c = {
  123. type:'C',
  124. model:columns[i].superiors,
  125. modelName:columns[i].superiorsName,
  126. children:[columns[i]]
  127. }
  128. array.push(c);
  129. }
  130. }
  131. }
  132. this.headers = array;
  133. }else if("cycle" == unfold){
  134. for(let i in columns){
  135. columns[i].prop = columns[i].model
  136. if(columns[i].model == 'MK_TARGET_CYCLE_PARAM' || columns[i].model == 'MK_TARGET_INDEX_PARAM'){
  137. columns[i].templateId = this.template.id
  138. }
  139. array.push(columns[i]);
  140. }
  141. this.headers = array;
  142. }else if("unfold" == unfold){
  143. for(let i in columns){
  144. columns[i].prop = columns[i].model
  145. if(columns[i].model == 'MK_TARGET_CYCLE_PARAM' || columns[i].model == 'MK_TARGET_INDEX_PARAM'){
  146. columns[i].templateId = this.template.id
  147. }
  148. array.push(columns[i]);
  149. }
  150. this.headers = array;
  151. }else if("" == unfold){
  152. for(let i in columns){
  153. columns[i].prop = columns[i].model
  154. if(columns[i].model == 'MK_TARGET_CYCLE_PARAM' || columns[i].model == 'MK_TARGET_INDEX_PARAM'){
  155. columns[i].templateId = this.template.id
  156. }
  157. array.push(columns[i]);
  158. }
  159. this.headers = array;
  160. }
  161. console.log('this.headers',this.headers);
  162. },
  163. //获取明细数据
  164. async fetchTargetItem(id){
  165. await getTargetItem(id).then(res => {
  166. if (res.code === 200) {
  167. this.items = res.rows
  168. }
  169. })
  170. },
  171. //格式化数据
  172. formatItem(item){
  173. let obj = {};
  174. for(let i in item){
  175. obj[item[i].prop] = item[i];
  176. }
  177. return obj;
  178. },
  179. //合并已存在和删除的数据
  180. merge(){
  181. this.items.push(...this.delItems);
  182. return this.items;
  183. },
  184. //附加查询条件
  185. additionalCondition(prop){
  186. console.log("prop",prop);
  187. return {
  188. parame:{
  189. templateId: prop.templateId
  190. }
  191. }
  192. }
  193. }
  194. }
  195. </script>
  196. <style lang="scss" scoped>
  197. .btn_add{
  198. margin-bottom: 10px;
  199. display: flex;
  200. justify-content: flex-end;
  201. }
  202. .btn_group {
  203. width: 100%;
  204. margin: 20px 0;
  205. display: flex;
  206. justify-content: center;
  207. }
  208. </style>