sub.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. <template>
  2. <div>
  3. <el-col v-if='item.type ==="input" ' class='full-width'>
  4. <div class='flex item full-width'>
  5. <el-form-item class='full-width '>
  6. <template v-slot:label>
  7. <div class='label full-width padding-left text-left bold' >
  8. {{ item.label }}
  9. </div>
  10. </template>
  11. <div class='full-width text-left flex full-width'>
  12. <input v-model='editData[item.prop]' :disabled='disable' :placeholder='`请输入` + item.label'
  13. @change='change($event,item)'
  14. class='full-width'/>
  15. <el-icon v-if='!disable' class="padding-right">
  16. <edit/>
  17. </el-icon>
  18. </div>
  19. </el-form-item>
  20. </div>
  21. </el-col>
  22. <!--textarea-->
  23. <el-col v-if='item.type ==="textarea" ' :style='`height:` + item.rows * 35 + `px`' class='full-width'>
  24. <div class='flex item full-width'>
  25. <el-form-item class='full-width '>
  26. <template v-slot:label>
  27. <div :style='`height:` + item.rows * 35 + `px`'
  28. class='label white-bg full-width text-left padding-left bold'>
  29. {{ item.label }}
  30. </div>
  31. </template>
  32. <div class='full-width flex flex-align-start full-height text-left full-width'
  33. style='white-space: pre-wrap;text-overflow: ellipsis;'>
  34. <textarea v-model='editData[item.prop]' :disabled='disable'
  35. :placeholder='`请输入` + item.label'
  36. :style='`height:` + item.rows * 35 + `px`'
  37. class='full-width padding-right full-height padding-top'
  38. @change='change($event,item)'
  39. style='line-height:20px;resize:none '/>
  40. <el-icon v-if='!disable' class="padding-right padding-top">
  41. <edit/>
  42. </el-icon>
  43. </div>
  44. </el-form-item>
  45. </div>
  46. </el-col>
  47. <!-- autoinput-->
  48. <el-col v-if='item.type ==="autoInput" ' :style='`height:` + item.rows * 35 + `px`' class='full-width'>
  49. <div class='flex item full-width'>
  50. <el-form-item class='full-width '>
  51. <template v-slot:label>
  52. <div :style='`height:` + item.rows * 35 + `px`'
  53. class='label white-bg full-width text-left padding-left bold'>
  54. {{ item.label }}
  55. </div>
  56. </template>
  57. <div class='full-width flex flex-align-start full-height text-left full-width'
  58. style='white-space: pre-wrap;text-overflow: ellipsis;'>
  59. <el-select v-model="editData[item.prop]" class="m-2" :placeholder="`请选择${item.label}`"
  60. @change='change($event,item)'>
  61. <el-option
  62. v-for="item in item.dict"
  63. :key="item.value"
  64. :label="item.label"
  65. :value="item.value"
  66. />
  67. </el-select>
  68. <el-icon v-if='!disable' class="padding-right padding-top">
  69. <edit/>
  70. </el-icon>
  71. </div>
  72. </el-form-item>
  73. </div>
  74. </el-col>
  75. <el-col v-if='item.type ==="select" ' :style='`height:` + item.rows * 35 + `px`' class='full-width'>
  76. <div class='flex item full-width'>
  77. <el-form-item class='full-width '>
  78. <template v-slot:label>
  79. <div :style='`height:` + item.rows * 35 + `px`'
  80. class='label white-bg full-width text-left padding-left bold'>
  81. {{ item.label }}
  82. </div>
  83. </template>
  84. <div class='full-width flex flex-align-start full-height text-left full-width'
  85. style='white-space: pre-wrap;text-overflow: ellipsis;'>
  86. <el-select v-if='!disable' class="m-2" v-model="editData[item.prop]" :placeholder="`请选择${item.label}`" @change='change($event,item)'>
  87. <el-option
  88. v-for="item in item.dict"
  89. :key="item.value"
  90. :label="item.label"
  91. :value="item.value"
  92. />
  93. </el-select>
  94. <input v-else disabled v-model='editData[item.prop]' />
  95. <el-icon v-if='!disable' class="padding-right padding-top">
  96. <edit/>
  97. </el-icon>
  98. </div>
  99. </el-form-item>
  100. </div>
  101. </el-col>
  102. <el-col v-if='item.type ==="area" ' :style='`height:` + item.rows * 35 + `px`' class='full-width'>
  103. <div class='flex item full-width'>
  104. <el-form-item class='full-width '>
  105. <template v-slot:label>
  106. <div :style='`height:` + item.rows * 35 + `px`'
  107. class='label white-bg full-width text-left padding-left bold'>
  108. {{ item.label }}
  109. </div>
  110. </template>
  111. <div class='full-width flex flex-align-start full-height text-left full-width'
  112. style='white-space: pre-wrap;text-overflow: ellipsis;'>
  113. <el-cascader v-if='!disable' ref='area' :options="item.dict" v-model="editData[item.prop]" :disabled='disable' class="m-2"
  114. :placeholder="`请选择${item.label}`" @change='change($event,item)'>
  115. </el-cascader>
  116. <input v-else disabled v-model='editData[item.prop]' />
  117. <el-icon v-if='!disable' class="padding-right padding-top">
  118. <edit/>
  119. </el-icon>
  120. </div>
  121. </el-form-item>
  122. </div>
  123. </el-col>
  124. <!-- daterange -->
  125. <el-col v-if='item.type ==="daterange" ' :style='`height:` + item.rows * 35 + `px`' class='full-width'>
  126. <div class='flex item full-width'>
  127. <el-form-item class='full-width '>
  128. <template v-slot:label>
  129. <div :style='`height:` + item.rows * 35 + `px`'
  130. class='label white-bg full-width text-left padding-left bold'>
  131. {{ item.label }}
  132. </div>
  133. </template>
  134. <div class='full-width flex flex-align-start full-height text-left full-width'
  135. style='white-space: pre-wrap;text-overflow: ellipsis;'>
  136. <el-date-picker
  137. v-if='!disable'
  138. v-model="editData[item.prop]"
  139. :disabled='disable'
  140. type="daterange"
  141. @change='change($event,item)'
  142. range-separator="至"
  143. start-placeholder="开始日期"
  144. end-placeholder='结束日期'
  145. value-format='YYYY-MM-DD'
  146. format='YYYY-MM-DD'
  147. />
  148. <input v-else disabled v-model='editData[item.prop]' />
  149. <el-icon v-if='!disable' class="padding-right padding-top">
  150. <edit/>
  151. </el-icon>
  152. </div>
  153. </el-form-item>
  154. </div>
  155. </el-col>
  156. <!--number-->
  157. <el-col v-if='item.type ==="number" ' :style='`height:` + item.rows * 35 + `px`' class='full-width'>
  158. <div class='flex item full-width'>
  159. <el-form-item class='full-width '>
  160. <template v-slot:label>
  161. <div :style='`height:` + item.rows * 35 + `px`'
  162. class='label white-bg full-width text-left padding-left bold'>
  163. {{ item.label }}
  164. </div>
  165. </template>
  166. <div class='full-width flex flex-align-center full-height text-left full-width'
  167. style='white-space: pre-wrap;text-overflow: ellipsis;'>
  168. <input v-model='editData[item.prop]' :disabled='disable' type='number' class='full-width'
  169. :placeholder='`请输入` + item.label' step='2'
  170. @change='change($event,item)'/>
  171. <el-icon v-if='!disable' class="padding-right padding-top">
  172. <edit/>
  173. </el-icon>
  174. </div>
  175. </el-form-item>
  176. </div>
  177. </el-col>
  178. </div>
  179. </template>
  180. <script>
  181. export default {
  182. name: 'sub',
  183. props: {
  184. form: {
  185. type: Object,
  186. default: null
  187. },
  188. item: {
  189. type: Object,
  190. default: null
  191. },
  192. disable: {
  193. type: Boolean,
  194. default: false
  195. }
  196. },
  197. watch: {
  198. item: {
  199. handler (val) {
  200. if (val.type === 'autoInput') {
  201. this.getDic(val).then(res => {
  202. val.dict = res
  203. })
  204. console.log(val.dict)
  205. } else if (val.type === 'area') {
  206. const tmp = {
  207. dict: '/blade-system/region/lazy-list',
  208. props: {
  209. label: 'name',
  210. value: 'id'
  211. }
  212. }
  213. val.expand = JSON.stringify(tmp, null, 4)
  214. val.expand = JSON.parse(val.expand)
  215. this.getDic(val).then(res => {
  216. val.dict = res
  217. })
  218. } else if (val.type === 'select') {
  219. this.getDic(val).then(res => {
  220. val.dict = res
  221. })
  222. }
  223. },
  224. immediate: true
  225. },
  226. form: {
  227. handler (val) {
  228. this.editData = val
  229. },
  230. immediate: true
  231. },
  232. editData: {
  233. deep: true,
  234. immediate: false
  235. }
  236. },
  237. data () {
  238. return {
  239. data: {},
  240. dic: [],
  241. editData: null
  242. }
  243. },
  244. methods: {
  245. async getDic (item) {
  246. let result = []
  247. if (item.type === 'area') {
  248. const local = localStorage.getItem('lazy-list')
  249. if (local) {
  250. return JSON.parse(local)
  251. }
  252. const tmp = await this.$api.common.basicFormRequest(item.expand.dict)
  253. result = tmp.data.map(sub => this.mapTree(sub, item.expand))
  254. localStorage.setItem('lazy-list', JSON.stringify(result))
  255. } else {
  256. const tmp = await this.$api.common.basicFormRequest(item.expand.dict)
  257. result = tmp.data.map(sub => this.mapTree(sub, item.expand))
  258. }
  259. return result
  260. },
  261. mapTree (item, expand) {
  262. const haveChildren = Array.isArray(item.children) && item.children.length > 0
  263. return {
  264. key: item.label,
  265. value: item[expand.props.value],
  266. label: item[expand.props.label],
  267. children: haveChildren ? item.children.map(i => this.mapTree(i, expand)) : []
  268. }
  269. },
  270. change (res, item) {
  271. if (item.type === 'area') {
  272. this.editData[item.prop] = res[0]
  273. const tmp = this.$refs.area.getCheckedNodes()[0].pathLabels
  274. const keys = Object.keys(res)
  275. if (keys.length === 3) {
  276. this.editData.provinceCode = res[0]
  277. this.editData.province = tmp[0]
  278. this.editData.cityCode = res[1]
  279. this.editData.city = tmp[1]
  280. this.editData.districtCode = res[2]
  281. this.editData.district = tmp[2]
  282. } else if (keys.length === 2) {
  283. this.editData.provinceCode = res[0]
  284. this.editData.province = tmp[0]
  285. this.editData.cityCode = res[1]
  286. this.editData.city = res[1]
  287. } else {
  288. this.editData.provinceCode = res[0]
  289. this.editData.province = res[0]
  290. }
  291. }
  292. this.$emit('change', this.editData)
  293. }
  294. }
  295. }
  296. </script>
  297. <style lang='scss' scoped>
  298. .form {
  299. border-right: #CCCFCE solid 1px;
  300. border-left: #CCCFCE solid 1px;
  301. border-bottom: #CCCFCE solid 1px;
  302. .item {
  303. :deep(.el-form-item--default) {
  304. margin-bottom: 0;
  305. padding: 0;
  306. }
  307. }
  308. .label {
  309. padding-right: 10px;
  310. border-right: #CCCFCE solid 1px;
  311. }
  312. .sub-item {
  313. border-left: #CCCFCE solid 1px;
  314. }
  315. .sub-item:first-child {
  316. border-left: none;
  317. }
  318. }
  319. .form:first-child {
  320. padding: 0;
  321. border: #CCCFCE solid 1px;
  322. }
  323. </style>