PubSelect.vue 7.4 KB

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