customTemplate.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <template>
  2. <el-row :gutter="20" class="Layout">
  3. <el-col v-for="(item, index) in customs" :key="index" :span="12">
  4. <span v-if="!show && isShow(item) || show && item.bool" style="margin-bottom:20px;" class="Layout_space_between">
  5. <span class="from-name"><span v-if="item.required" style="color: red;">*</span>{{ item.fieldName }} </span>
  6. <el-input v-if="item.type === 1" v-model="item.content" size="small" :disabled="disab" style="width:100%;" placeholder="请输入" @change="getFormValue" />
  7. <el-input v-if="item.type === 2" v-model="item.content" type="textarea" size="small" :disabled="disab" :rows="1" style="width:100%;" placeholder="请输入" @change="getFormValue" />
  8. <el-select v-if="item.type === 3" v-model="item.content" clearable size="small" :disabled="disab" style="width:100%;" placeholder="请选择" @change="getFormValue(item)">
  9. <el-option v-for="i in item.options" :key="i" :label="i" :value="i" />
  10. </el-select>
  11. <el-select v-if="item.type === 4" v-model="item.contents" multiple clearable size="small" :disabled="disab" style="width:100%;" placeholder="请选择" @change="getFormValue(item)">
  12. <el-option v-for="(i, c) in item.options" :key="c" :label="i" :value="i" />
  13. </el-select>
  14. </span>
  15. </el-col>
  16. </el-row>
  17. </template>
  18. <script>
  19. export default {
  20. props: {
  21. custom: { type: Array, required: false, default: null },
  22. baseFrom: { type: Object, required: false, default: null },
  23. disab: { type: Boolean, default: false }
  24. },
  25. data() {
  26. return {
  27. customs: [],
  28. show: false
  29. }
  30. },
  31. watch: {
  32. custom: {
  33. handler(newV) {
  34. this.customs = newV.map(e => e)
  35. console.log(this.customs, '新的志')
  36. if (newV && newV[0].bool) {
  37. this.show = true
  38. this.customs.map(item => {
  39. this.baseFrom[`${item.fieldKey}_${item.content}`] = item.content
  40. if (item.contents && item.contents[0]) {
  41. item.contents.map(elm => {
  42. this.baseFrom[`${item.fieldKey}_${elm}`] = elm
  43. })
  44. }
  45. })
  46. console.log(this.customs, '新的志')
  47. return
  48. }
  49. this.show = false
  50. this.customs = newV.map(item => ({
  51. ...item,
  52. bool: item.conditions === '默认展示' || this.getBoolValue(item.conditions)
  53. }))
  54. },
  55. immediate: true
  56. }
  57. },
  58. methods: {
  59. isShow(item) {
  60. if (item.conditions === '默认展示') {
  61. return true
  62. }
  63. console.log(this.baseFrom, item.conditions, item)
  64. if (this.baseFrom[item.conditions] === item.conditions.split('_')[1]) {
  65. return true
  66. }
  67. return false
  68. },
  69. getBoolValue(conditions) {
  70. const checkList = []
  71. this.customs.forEach(item => {
  72. if (item.content && item.type < 4) {
  73. checkList.push(`${item.fieldKey}_${item.content}`)
  74. }
  75. if (item.contents && item.type === 4) {
  76. item.contents.forEach(contentItem => {
  77. checkList.push(`${item.fieldKey}_${contentItem}`)
  78. })
  79. }
  80. })
  81. console.log(checkList.indexOf(conditions) !== -1, '返回的bool')
  82. return checkList.indexOf(conditions) !== -1
  83. },
  84. getFormValue(e) {
  85. console.log(e)
  86. this.show = false
  87. const params = {}
  88. const keys = []
  89. this.customs.map(item => {
  90. if (e.type < 4) {
  91. if (item.conditions === `${e.fieldKey}_${e.content}`) {
  92. item.bool = true
  93. item.bools = true
  94. } else {
  95. if (item.conditions.split('_')[0] === e.fieldKey) {
  96. item.bool = false
  97. delete item.bools
  98. }
  99. }
  100. } else if (e.type === 4) {
  101. e.contents.map(i => {
  102. if (item.conditions === `${e.fieldKey}_${i}`) {
  103. item.bool = true
  104. item.bools = true
  105. } else {
  106. if (item.conditions.split('_')[0] === e.fieldKey) {
  107. item.bool = false
  108. delete item.bools
  109. }
  110. }
  111. // item.conditions === `${e.fieldKey}_${i}` ? item.bool = true : ''
  112. })
  113. }
  114. })
  115. // 单选
  116. if (e.type === 3) {
  117. params[`${e.fieldKey}_${e.content}`] = e.content
  118. }
  119. // 多选
  120. if (e.type === 4) {
  121. e.contents.forEach(elm => {
  122. params[`${e.fieldKey}_${elm}`] = elm
  123. })
  124. }
  125. // 删除多余字段
  126. Object.keys(this.baseFrom).forEach(key => {
  127. if (key.indexOf(e.fieldKey) > -1) {
  128. keys.push(key)
  129. }
  130. })
  131. this.$emit('formData', {
  132. customs: this.customs,
  133. keys,
  134. params
  135. })
  136. },
  137. CustomSet(e) {
  138. const key = Object.keys(e)[0]
  139. const custom = {
  140. followVersion: {
  141. key: 'followVersion',
  142. label: '是否跟版',
  143. values: 0
  144. },
  145. isCodeReview: {
  146. key: 'isCodeReview',
  147. label: '是否codereview',
  148. values: 1
  149. }
  150. }
  151. const label = custom[key].label
  152. // const value = e[key] + custom[key].values
  153. const value = e[key]
  154. // this.customs.forEach(elm => {
  155. // elm.conditions = ''
  156. // })
  157. const keys = []
  158. const params = {
  159. [`${label}_${value}`]: `${value}`
  160. }
  161. // 删除多余字段
  162. Object.keys(this.baseFrom).forEach(key => {
  163. if (key.indexOf(label) > -1) {
  164. keys.push(key)
  165. }
  166. })
  167. this.$emit('formData', {
  168. customs: this.customs.map(e => e),
  169. keys,
  170. params
  171. })
  172. // this.$emit('formData', {
  173. // customs: this.customs,
  174. // keys,
  175. // params
  176. // })
  177. // console.log(e, this.customs, this.baseFrom, 'xcdjks ncjksdjnk')
  178. }
  179. }
  180. }
  181. </script>
  182. <style lang="less" scoped>
  183. @import '@/styles/PublicStyle/index.less';
  184. .from-name {
  185. width: 150px !important;
  186. }
  187. .Layout {
  188. display: flex;
  189. flex-wrap: wrap;
  190. justify-content: space-between;
  191. }
  192. </style>