formInput.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. <!--
  2. A1 手工填写-单个-数字-无单位
  3. A2 手工填写-单个-数字-有单位
  4. A3 手工填写-多个-数字-无单位
  5. A4 手工填写-多个-数字-有单位
  6. A5 手工填写-单个-数字范围-无单位
  7. A6 手工填写-单个-数字范围-有单位
  8. A7 手工填写-多个-数字范围-无单位
  9. A8 手工填写-多个-数字范围-有单位
  10. B1 手工填写-单个-文本
  11. B2 手工填写-多个-文本
  12. C1 手工填写-单个-日期时间值
  13. C2 手工填写-单个-日期时间段
  14. C3 手工填写-多个-日期时间值
  15. C4 手工填写-多个-日期时间段
  16. C5 手工填写-单个-日期值
  17. C6 手工填写-单个-日期段
  18. C7 手工填写-多个-日期值
  19. C8 手工填写-多个-日期段
  20. C9 手工填写-单个-时间值
  21. C10 手工填写-单个-时间段
  22. C11 手工填写-多个-时间值
  23. C12 手工填写-多个-时间段
  24. D1 字典选择-单个-单选
  25. D1L 字典选择-单个-单选(级联)
  26. D2 字典选择-单个-多选
  27. D3 字典选择-多个-单选
  28. D4 字典选择-多个-多选
  29. E1 字典布尔选择-单个
  30. E2 字典布尔选择-多个
  31. F1 上传-单个文件 -->
  32. <template>
  33. <el-form :label-position="'right'" :labelWidth="width + 'px'" :model="formLabelAlign" ref="form" @submit.native.prevent>
  34. <el-form-item :label="label" :rules="isRule ? { required: true, message: '不能为空'} : {}">
  35. <!-- 普通输入类型 -->
  36. <el-input v-if="!isShow && (type == 'default' || type == 'B1')" v-model="formLabelAlign.name" style="width: 9rem;" @change="onSubmit" @keyup.enter.native="onSubmit">
  37. <template slot="append" v-if="unit">{{unit}}</template>
  38. </el-input>
  39. <el-input type="number" v-if="!isShow && (type == 'A1' || type == 'A2')" v-model="formLabelAlign.name" style="width: 9rem;" @change="onSubmit" @keyup.enter.native="onSubmit">
  40. <template slot="append" v-if="unit">{{unit}}</template>
  41. </el-input>
  42. <!-- date类型 -->
  43. <el-date-picker
  44. v-if="!isShow && (type == 'year' || type == 'C5')"
  45. v-model="formLabelAlign.name"
  46. type="date"
  47. value-format="yyyy-MM-dd"
  48. @change="onSubmit"
  49. :clearable="false"
  50. placeholder="选择日期">
  51. </el-date-picker>
  52. <!-- 级联选择 -->
  53. <el-cascader
  54. v-if="!isShow && (type == 'cascader' || type == 'D1' || type == 'D1L')"
  55. :options="typeArr"
  56. :show-all-levels="false"
  57. v-model="formLabelAlign.name"
  58. @change="onSubmit"
  59. :props="props"
  60. ></el-cascader>
  61. <!-- 日期到分 -->
  62. <el-date-picker
  63. v-if="!isShow && type == 'C1'"
  64. v-model="formLabelAlign.name"
  65. type="datetime"
  66. value-format="yyyy-MM-dd HH:MM"
  67. @change="onSubmit"
  68. :clearable="false"
  69. placeholder="选择日期">
  70. </el-date-picker>
  71. <!-- 输入文本框 -->
  72. <el-input
  73. v-if="!isShow && type == 'B2'"
  74. type="textarea"
  75. :rows="2"
  76. @change="onSubmit"
  77. @keyup.enter.native="onSubmit"
  78. placeholder="请输入内容"
  79. v-model="formLabelAlign.name">
  80. </el-input>
  81. <!-- 日期 -->
  82. <el-date-picker
  83. v-if="!isShow && type == 'C6'"
  84. v-model="formLabelAlign.name"
  85. type="daterange"
  86. range-separator="至"
  87. start-placeholder="开始日期"
  88. end-placeholder="结束日期"
  89. value-format="yyyy-MM-dd"
  90. @change="onSubmit"
  91. :clearable="false"
  92. placeholder="选择日期">
  93. </el-date-picker>
  94. <!-- 点击确定 -->
  95. <i v-if="!isShow && (type == 'default' || type == 'B1')" class="el-input__icon el-icon-check hover" @click="onSubmit"></i>
  96. <!-- 显示基本内容 -->
  97. <span v-if="isShow" @click="changeItem" class="hover">{{ filterArr(formLabelAlign.name) }} {{unit}}<i class="el-icon-edit" v-if="editShow(type)"></i></span>
  98. <slot name="mess"></slot>
  99. </el-form-item>
  100. </el-form>
  101. </template>
  102. <script>
  103. export default {
  104. name: "ownerInput",
  105. props: {
  106. type: {
  107. type: String,
  108. default: "default"
  109. }, //类型
  110. value: [String, Array, Number], //value值
  111. label: String, //label值,从父级传入
  112. isRule: Boolean, //是否需要规则
  113. keys: String, //
  114. myArr: [Array, String], //当其为级联或者下拉时传入
  115. unit: {
  116. //单位
  117. type: String,
  118. default: ""
  119. },
  120. width: {
  121. type: Number,
  122. default: 150
  123. }
  124. },
  125. data() {
  126. return {
  127. formLabelAlign: {
  128. name: ""
  129. },
  130. key: "",
  131. isShow: true,
  132. props: {
  133. label: "name",
  134. value: "code",
  135. children: "content"
  136. }, //修改默认数据格式
  137. typeArr: []
  138. };
  139. },
  140. methods: {
  141. //点击确定或者url
  142. onSubmit() {
  143. if (this.formLabelAlign.name == "" || this.formLabelAlign.name == []) {
  144. this.$message.error("请确定值不为空");
  145. } else {
  146. this.isShow = true;
  147. if (this.type == "cascader" || this.type == "D1" || this.type == "D1L") {
  148. let data = this.formLabelAlign.name;
  149. this.$emit("change", data[data.length - 1], this.keys);
  150. } else {
  151. this.$emit("change", this.formLabelAlign.name, this.keys);
  152. }
  153. }
  154. },
  155. //点击文案出现输入
  156. changeItem() {
  157. if (
  158. this.type == "X" ||
  159. this.type == "L" ||
  160. this.type == "N2" ||
  161. this.type == "F2" ||
  162. this.type == 'M'
  163. ) {
  164. this.$message("该信息点不支持编辑");
  165. return;
  166. } else {
  167. this.isShow = false;
  168. }
  169. },
  170. //对数组中的空数组去除
  171. toMyNeed(arr) {
  172. return arr.map(res => {
  173. let param = {};
  174. if (res.content && res.content.length != 0) {
  175. param.content = this.toMyNeed(res.content);
  176. }
  177. param.name = res.name;
  178. param.code = res.code;
  179. return param;
  180. });
  181. },
  182. //获取级联选中的值
  183. getCascaderObj(val, opt) {
  184. let data = this.getMyVal(val, opt, "name");
  185. data.length > 1 ? (data = data.join("/")) : (data = data.join(""));
  186. return data;
  187. },
  188. getMyVal(val, content, code) {
  189. let data = [];
  190. if (content && content.length) {
  191. for (let i = 0; i < content.length; i++) {
  192. if (content[i].code == val) {
  193. data.push(content[i][code]);
  194. break;
  195. } else {
  196. if (content[i].content && content.length) {
  197. for (let j = 0; j < content[i].content.length; j++) {
  198. if (content[i].content[j].code == val) {
  199. data.push(content[i][code]);
  200. data.push(content[i].content[j][code]);
  201. break;
  202. } else {
  203. if (
  204. content[i].content[j].content &&
  205. content[i].content[j].content.length
  206. ) {
  207. for (
  208. let k = 0;
  209. k < content[i].content[j].content.length;
  210. k++
  211. ) {
  212. if (content[i].content[j].content[k].code == val) {
  213. data.push(content[i][code]);
  214. data.push(content[i].content[j][code]);
  215. data.push(content[i].content[j].content[k][code]);
  216. break;
  217. } else {
  218. }
  219. }
  220. }
  221. }
  222. }
  223. }
  224. }
  225. }
  226. }
  227. if (!data.length) {
  228. data = null;
  229. }
  230. return data;
  231. },
  232. getMap(val, opt) {
  233. return opt.map(function(value, index, array) {
  234. for (var itm of opt) {
  235. if (itm.code == value.code) {
  236. opt = itm.content;
  237. return itm;
  238. }
  239. }
  240. return null;
  241. });
  242. },
  243. //数组过滤
  244. filterArr(val) {
  245. let value = ""; //最后输出的文案
  246. let isNeedType = this.type == "cascader" || this.type == "D1" || this.type == "D1L";
  247. if (this.type == "C6") {
  248. if (val instanceof Array) {
  249. value = val[0] + "至" + val[1];
  250. } else {
  251. value = "--";
  252. }
  253. } else if (this.type == "cascader" || this.type == "D1" || this.type == "D1L") {
  254. if (val && val.length) {
  255. value =
  256. this.getCascaderObj(val[val.length - 1], this.typeArr, "name") ||
  257. "--";
  258. }
  259. } else {
  260. value = val || "--";
  261. }
  262. return value;
  263. },
  264. changeArray(arr) {
  265. return arr.map(item => {
  266. if (!!item.Content && item.Content.length) {
  267. return {
  268. code: item.Code,
  269. name: item.Name,
  270. content: this.changeArray(item.Content)
  271. };
  272. } else {
  273. return {
  274. code: item.Code,
  275. name: item.Name,
  276. content: null
  277. };
  278. }
  279. });
  280. },
  281. editShow(type) {
  282. if (type == "X" || type == "L" || type == "N2" || type == "F2" || type == 'M' ) {
  283. return false;
  284. } else {
  285. return true;
  286. }
  287. },
  288. formatDataSource(data) {
  289. let options
  290. let arr = []
  291. try {
  292. options = JSON.parse(data)
  293. if (options) {
  294. if (options instanceof Array) {
  295. this.typeArr = this.changeArray(options);
  296. }
  297. if (typeof this.typeArr == Object) {
  298. this.typeArr = this.toMyNeed(this.typeArr);
  299. }
  300. } else {
  301. this.typeArr = arr
  302. }
  303. } catch (err) {
  304. this.typeArr = arr
  305. }
  306. }
  307. },
  308. created() {
  309. console.log(this.type)
  310. // if (this.myArr instanceof Array) {
  311. // this.typeArr = this.changeArray(this.myArr);
  312. // }
  313. // if (typeof this.typeArr == Object) {
  314. // this.typeArr = this.toMyNeed(this.typeArr);
  315. // }
  316. this.formatDataSource(this.myArr)
  317. if (this.type == "cascader" || this.type == "D1" || this.type == "D1L") {
  318. if (this.value == "" || this.value == undefined) {
  319. this.formLabelAlign.name = [];
  320. } else {
  321. this.formLabelAlign.name = this.getMyVal(
  322. this.value,
  323. this.typeArr,
  324. "code"
  325. );
  326. }
  327. } else {
  328. this.formLabelAlign.name = this.value;
  329. }
  330. this.key = this.label;
  331. },
  332. watch: {
  333. label() {}
  334. }
  335. };
  336. </script>
  337. <style lang="less">
  338. .hover:hover {
  339. cursor: pointer;
  340. color: #409eff;
  341. }
  342. input::-webkit-outer-spin-button,
  343. input::-webkit-inner-spin-button {
  344. -webkit-appearance: none;
  345. }
  346. input[type="number"] {
  347. -moz-appearance: textfield;
  348. }
  349. </style>