PubSelect.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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" :disabled="disableBtn" @change="handlePlaceholder(0)">文字输入框占位符</el-checkbox-button>
  7. </el-checkbox-group>
  8. <el-checkbox-group size="small">
  9. <el-checkbox-button :label="0" :disabled="disableBtn" @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. disableBtn:false, //占位符是否禁用
  149. }
  150. },
  151. mounted(){
  152. const {options} = this.$props;
  153. if(options){
  154. const arr = options.filter((it)=>{
  155. return it.name;
  156. });
  157. this.rows = arr.length==0?utils.getInitRow(initRow,4):arr;
  158. this.$emit('pushValues',arr);
  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. const placeReg = /(\$\{number_\S*?\})|(\$\{input_\S*?\})/g;
  195. if(placeReg.test(this.rows[index][name])){
  196. this.disableBtn = true;
  197. return;
  198. }
  199. this.disableBtn = false;
  200. },
  201. handlePlaceholder(type){ //占位符类型,type=0文本输入框,type=1数字输入框
  202. const i = this.focusOn;
  203. if(i==-1){
  204. this.$message({
  205. message: '请先选中要操作的行',
  206. type: 'warning',
  207. showClose: true,
  208. });
  209. return ;
  210. }
  211. const maps = {0:'${input_输入}',1:'${number_输入}'};
  212. const key = this.focusName;
  213. this.rows[i][key] = this.rows[i][key]+maps[type];
  214. this.disableBtn = true;
  215. //this.rows[i].description = this.rows[i].description+maps[type];
  216. },
  217. handleExclu(){
  218. const i = this.focusOn;
  219. if(i==-1){
  220. this.$message({
  221. message: '请先选中要操作的行',
  222. type: 'warning',
  223. showClose: true,
  224. });
  225. return ;
  226. }
  227. this.rows.map((it,x)=>{
  228. if(x===i){
  229. it.exclusion = 1;
  230. }else{
  231. it.exclusion = 0;
  232. }
  233. });
  234. },
  235. emitValues(i,type,flag){
  236. if(typeof i =='number'&&this.focusOn == -1){
  237. this.$message({
  238. message: '请先选择要操作的行',
  239. type: 'warning',
  240. showClose: true,
  241. });
  242. return;
  243. }
  244. const items = this.rows;
  245. this.$emit('pushValues',items);
  246. },
  247. HandleInputName(i, name, isName) {
  248. const pureName=name.replace(/(\$\{number_\S*?\})|(\$\{input_\S*?\})/g,'');
  249. const hasPlace = /(\$\{number_\S*?\})|(\$\{input_\S*?\})/g.test(name);
  250. if(hasPlace&&this.disableBtn==false){
  251. this.disableBtn = true;
  252. }else if(!hasPlace&&this.disableBtn==true){
  253. this.disableBtn = false;
  254. }
  255. if(pureName.length > 30) {
  256. this.$message({
  257. message: '最多输入30个字',
  258. type: 'warning',
  259. showClose: true,
  260. });
  261. return;
  262. }
  263. },
  264. delRow(){
  265. if(this.focusOn==-1){
  266. this.$message({
  267. message: '请先选择要删除的行',
  268. type: 'warning',
  269. showClose: true,
  270. });
  271. return;
  272. }
  273. this.$alert('确定要删除该行吗?', '提示', {
  274. confirmButtonText: '确定',
  275. type: 'warning'
  276. }).then(() => {
  277. this.rows.splice(this.focusOn,1);
  278. this.focusOn = -1;
  279. this.emitValues();
  280. }).catch(() => {});
  281. }
  282. }
  283. }
  284. </script>