SingleSelect.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <div class="single-container">
  3. <el-form :model="form">
  4. <div class="operation-row">
  5. <el-checkbox-group size="small" v-model="form.defaultCheckeds" @change="emitValues">
  6. <el-checkbox-button v-for="(it,i) in rows" v-if="focusOn==i||(focusOn==-1&&i==0)" :label="i">默认选中</el-checkbox-button>
  7. </el-checkbox-group>
  8. <el-checkbox-group size="small" v-model="form.sameToNones" @change="emitValues">
  9. <el-checkbox-button v-for="(it,i) in rows" v-if="focusOn==i||(focusOn==-1&&i==0)" :label="i">同“无”类型</el-checkbox-button>
  10. </el-checkbox-group>
  11. <el-checkbox-group size="small" v-model="form.sameToBans" @change="emitValues">
  12. <el-checkbox-button v-for="(it,i) in rows" v-if="focusOn==i||(focusOn==-1&&i==0)" :label="i">同“伴”类型</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">
  17. <el-input v-for="(it,i) in rows"
  18. v-model="form.options[i]"
  19. v-bind:class="{select:focusOn==i}"
  20. @focus="selectRow(i)"
  21. @blur="emitValues"></el-input>
  22. <el-button @click="addRow">+</el-button>
  23. </div>
  24. </el-form>
  25. </div>
  26. </template>
  27. <style lang="less">
  28. @import "../../less/common.less";
  29. .el-checkbox-button--small .el-checkbox-button__inner{
  30. font-size: 14px;
  31. }
  32. .el-checkbox-button:last-child .el-checkbox-button__inner{
  33. border-radius: 3px;
  34. border-color: @adminBase;
  35. color: @adminBase;
  36. margin-right: 15px;
  37. }
  38. .el-checkbox-button.is-checked:first-child .el-checkbox-button__inner{
  39. background-color:@adminBase;
  40. border-left-color:@adminBase;
  41. color:#fff;
  42. }
  43. .el-checkbox-group{
  44. display: inline-block;
  45. }
  46. .operation-row{
  47. margin-left:150px;
  48. .del{
  49. margin-left: 150px;
  50. }
  51. }
  52. .main-area{
  53. width: 200px;
  54. margin:20px 150px;
  55. .el-input {
  56. width: 200px;
  57. display: block;
  58. &.select{
  59. input{
  60. border-color: @adminBase;
  61. }
  62. }
  63. }
  64. .el-button{
  65. width: 200px;
  66. }
  67. }
  68. </style>
  69. <script>
  70. import utils from '@api/utils';
  71. export default {
  72. props:['type'],
  73. data(){
  74. return {
  75. form:{
  76. options:[],
  77. defaultCheckeds:[],
  78. sameToNones:[],
  79. sameToBans:[]
  80. },
  81. rows:[{},{},{},{}],
  82. focusOn:-1
  83. }
  84. },
  85. /*watch:{
  86. defaultChecked:function(next){
  87. if(this.focusOn==-1){
  88. this.defaultChecked = false;
  89. this.$message({
  90. message: '请先选择要操作的行',
  91. type: 'warning'
  92. });
  93. return;
  94. }
  95. this.form.defaultChecked=next?this.focusOn:-1;console.log(this.form)
  96. this.emitValues();
  97. },
  98. sameToNone:function(next){
  99. if(this.focusOn==-1){
  100. this.sameToNone = false;
  101. this.$message({
  102. message: '请先选择要操作的行',
  103. type: 'warning'
  104. });
  105. return;
  106. }
  107. this.form.sameToNone=next?this.focusOn:-1;
  108. this.emitValues();
  109. },
  110. sameToBan:function(next){
  111. if(this.focusOn==-1){
  112. this.sameToBan = false;
  113. this.$message({
  114. message: '请先选择要操作的行',
  115. type: 'warning'
  116. });
  117. return;
  118. }
  119. this.form.sameToBan=next?this.focusOn:-1;
  120. this.emitValues();
  121. }
  122. },*/
  123. methods:{
  124. setValues(name){
  125. if(this.focusOn==-1){
  126. this[name] = false;
  127. this.$message({
  128. message: '请先选择要操作的行',
  129. type: 'warning'
  130. });
  131. return;
  132. }
  133. this.form[name]=this[name]?this.focusOn:-1;
  134. this.emitValues();
  135. },
  136. addRow(){
  137. this.rows.push({});
  138. },
  139. selectRow(index){
  140. this.focusOn = index;
  141. },
  142. emitValues(){
  143. //console.log(this.form)
  144. const items = utils.simpleOptionData(this.form);
  145. //this.$emit('pushValues',items);
  146. },
  147. delRow(){
  148. if(this.focusOn==-1){
  149. this.$message({
  150. message: '请先选择要删除的行',
  151. type: 'warning'
  152. });
  153. return;
  154. }
  155. this.$alert('确定要删除该行吗?', '提示', {
  156. confirmButtonText: '确定',
  157. type: 'warning'
  158. }).then(() => {
  159. this.form.options.splice(this.focusOn,1);
  160. this.rows.splice(this.focusOn,1);
  161. this.focusOn = -1;
  162. this.emitValues();
  163. }).catch(() => {});
  164. }
  165. }
  166. }
  167. </script>