PubSelect.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <template>
  2. <div class="single-container">
  3. <el-form>
  4. <div class="operation-row">
  5. <el-checkbox-group size="small">
  6. <el-checkbox-button :label="0" @change="handlePlaceholder(0)">文字输入框占位符</el-checkbox-button>
  7. </el-checkbox-group>
  8. <el-checkbox-group size="small">
  9. <el-checkbox-button :label="0" @change="handlePlaceholder(1)">数字输入框占位符</el-checkbox-button>
  10. </el-checkbox-group>
  11. <el-checkbox-group size="small" v-if="type==2">
  12. <el-checkbox-button :label="0" @change="handleExclu">互斥项</el-checkbox-button>
  13. </el-checkbox-group>
  14. <el-button type="danger" size="small" class="del" @click="delRow">删除</el-button>
  15. </div>
  16. <div class="main-area" v-if="type!=3">
  17. <el-col class="col-title">
  18. <span><i>*</i>填写单医生界面展示标准内容</span>
  19. <span>填写单患者界面展示通俗内容</span>
  20. </el-col>
  21. <el-col v-for="(it,i) in rows" :key="i">
  22. <div class="inps">
  23. <el-input v-model="rows[i].name"
  24. v-bind:class="{select:focusOn==i}"
  25. @focus="selectRow(i,'name')"
  26. ref = "inputName"
  27. @input="HandleInputName(i, rows[i].name,true)"
  28. @blur="emitValues"></el-input>
  29. <el-input v-model="rows[i].description"
  30. v-bind:class="{select:focusOn==i}"
  31. @focus="selectRow(i,'description')"
  32. ref = "inputDesc"
  33. @input="HandleInputName(i, rows[i].description)"
  34. @blur="emitValues"></el-input>
  35. </div>
  36. <el-tag v-if="it.exclusion" type="info" size="mini">互斥项</el-tag>
  37. </el-col>
  38. <el-button @click="addRow">+</el-button>
  39. </div>
  40. <div class="main-area" v-if="type==3">
  41. <el-col v-for="(it,i) in rows" :key="i">
  42. <div class="inps">
  43. <el-input v-model="rows[i].name"
  44. v-bind:class="{select:focusOn==i}"
  45. @focus="selectRow(i,'name')"
  46. ref = "inputName"
  47. @input="HandleInputName(i, rows[i].name,true)"
  48. @blur="emitValues"></el-input>
  49. </div>
  50. <el-tag v-if="it.exclusion" type="info" size="mini">互斥项</el-tag>
  51. </el-col>
  52. <el-button @click="addRow" class="little">+</el-button>
  53. </div>
  54. </el-form>
  55. </div>
  56. </template>
  57. <style lang="less">
  58. @import "../../less/common.less";
  59. .el-checkbox-button--small .el-checkbox-button__inner{
  60. font-size: 14px;
  61. }
  62. .el-checkbox-button.is-disabled:first-child .el-checkbox-button__inner{
  63. border-color: @disableColor;
  64. border-left-color: @disableColor;
  65. color: @disableColor;
  66. }
  67. .el-checkbox-button:last-child .el-checkbox-button__inner{
  68. border-radius: 3px;
  69. border-color: @adminBase;
  70. color: @adminBase;
  71. margin-right: 15px;
  72. }
  73. .el-checkbox-button.is-checked:first-child .el-checkbox-button__inner{
  74. background-color:@adminBase;
  75. border-left-color:@adminBase;
  76. color:#fff;
  77. }
  78. .el-checkbox-group{
  79. display: inline-block;
  80. }
  81. .operation-row{
  82. margin-left:150px;
  83. /*text-align: right;*/
  84. .del{
  85. margin-left: 150px;
  86. }
  87. .tip {
  88. color: #22ccc8;
  89. }
  90. }
  91. .main-area{
  92. width: 80%;
  93. min-width: 400px;
  94. margin:20px 150px;
  95. .inps{
  96. display: inline-block;
  97. width: calc(100% - 60px);
  98. }
  99. .el-tag{
  100. margin-left: 10px;
  101. }
  102. .col-title{
  103. margin-bottom:10px;
  104. span{
  105. display: inline-block;
  106. width: calc(50% - 30px);
  107. font-size:12px;
  108. i{
  109. color: #f56c6c;
  110. margin-right: 3px;
  111. }
  112. }
  113. }
  114. .el-col .el-input {
  115. width: 50%;
  116. display: inline-block;
  117. .el-input__inner{
  118. border-radius: 0;
  119. }
  120. &.select{
  121. input{
  122. border-color: @adminBase;
  123. }
  124. }
  125. }
  126. .el-button{
  127. width: calc(100% - 60px);
  128. border-radius: 0;
  129. &.little{
  130. width: calc(50% - 30px);
  131. }
  132. }
  133. }
  134. </style>
  135. <script>
  136. import utils from '@api/utils.js';
  137. import Vue from 'vue';
  138. //单行数据
  139. const initRow = {orderNo:0,name:'',description:'',exclusion:0};
  140. const initRows = utils.getInitRow(initRow,4);
  141. export default {
  142. props:['type','options','ascription','sexType'],
  143. data(){
  144. return {
  145. rows:[...initRows],
  146. focusOn:-1, //聚焦的行index
  147. focusName:'name', //是否聚焦医生界面输入框
  148. }
  149. },
  150. mounted(){
  151. const {options} = this.$props;
  152. if(options){
  153. const arr = options.filter((it)=>{
  154. return it.name;
  155. });
  156. this.rows = arr;
  157. const items = utils.simpleOptionData(this.rows);
  158. this.$emit('pushValues',items);
  159. }else{
  160. this.initData();
  161. }
  162. },
  163. computed:{
  164. showTag:function(){
  165. return function(it){
  166. let name = Object.keys(this.maps).find((item)=>{
  167. return it[item];
  168. });
  169. return this.maps[name];
  170. }
  171. },
  172. },
  173. watch: {
  174. /*ascription(newVal, preVal) { //永远检测不到,因为归属修改时类型被清空,本组件被销毁
  175. this.rows = [...utils.getInitRow(initRow,4)];
  176. },*/
  177. type() {
  178. this.initData();
  179. },
  180. sexType() {
  181. this.initData();
  182. },
  183. },
  184. methods:{
  185. initData(){
  186. this.rows = [...utils.getInitRow(initRow,4)];
  187. },
  188. addRow(){
  189. this.rows.push(Object.assign({},initRow,{orderNo:this.rows.length}));
  190. },
  191. selectRow(index,name){
  192. this.focusOn = index;
  193. this.focusName = name;
  194. },
  195. handlePlaceholder(type){ //占位符类型,type=0文本输入框,type=1数字输入框
  196. const i = this.focusOn;
  197. if(i==-1){
  198. this.$message({
  199. message: '请先选中要操作的行',
  200. type: 'warning',
  201. showClose: true,
  202. });
  203. return ;
  204. }
  205. const maps = {0:'${input_输入}',1:'${number_输入}'};
  206. const key = this.focusName;
  207. this.rows[i][key] = this.rows[i][key]+maps[type];
  208. //this.rows[i].description = this.rows[i].description+maps[type];
  209. },
  210. handleExclu(){
  211. const i = this.focusOn;
  212. if(i==-1){
  213. this.$message({
  214. message: '请先选中要操作的行',
  215. type: 'warning',
  216. showClose: true,
  217. });
  218. return ;
  219. }
  220. this.rows.map((it,x)=>{
  221. if(x===i){
  222. it.exclusion = 1;
  223. }else{
  224. it.exclusion = 0;
  225. }
  226. });
  227. },
  228. emitValues(i,type,flag){
  229. if(typeof i =='number'&&this.focusOn == -1){
  230. this.$message({
  231. message: '请先选择要操作的行',
  232. type: 'warning',
  233. showClose: true,
  234. });
  235. return;
  236. }
  237. const items = this.rows;
  238. this.$emit('pushValues',items);
  239. },
  240. HandleInputName(i, name, isName) {
  241. const pureName=name.replace(/(\$\{number_\S*?\})|(\$\{input_\S*?\})/g,'');
  242. //console.log(pureName);
  243. if(pureName.length > 30) {
  244. if(isName){
  245. Vue.set(this.rows[i], 'name', this.rows[i].name.slice(0, 30));
  246. this.$refs.inputName[i].currentValue = this.rows[i].name;
  247. }else{
  248. Vue.set(this.rows[i], 'description', this.rows[i].description.slice(0, 30));
  249. this.$refs.inputDesc[i].currentValue = this.rows[i].description;
  250. }
  251. this.$message({
  252. message: '最多输入30个字',
  253. type: 'warning',
  254. showClose: true,
  255. });
  256. return;
  257. }
  258. },
  259. delRow(){
  260. if(this.focusOn==-1){
  261. this.$message({
  262. message: '请先选择要删除的行',
  263. type: 'warning',
  264. showClose: true,
  265. });
  266. return;
  267. }
  268. this.$alert('确定要删除该行吗?', '提示', {
  269. confirmButtonText: '确定',
  270. type: 'warning'
  271. }).then(() => {
  272. this.rows.splice(this.focusOn,1);
  273. this.focusOn = -1;
  274. this.emitValues();
  275. }).catch(() => {});
  276. }
  277. }
  278. }
  279. </script>