customNameComponents.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template>
  2. <div>
  3. <el-button
  4. type="primary"
  5. size="mini"
  6. icon="el-icon-plus"
  7. plain
  8. @click="handleAddClick"
  9. >新增</el-button
  10. >
  11. <el-table :data="formData" style="width: 100%">
  12. <el-table-column prop="country" label="国家" align="center"></el-table-column>
  13. <el-table-column prop="name" label="别名" align="center"></el-table-column>
  14. <el-table-column label="操作" align="center" min-width="100">
  15. <template slot-scope="scope">
  16. <span
  17. class="editor"
  18. @click="handleEditorClick(scope.$index, scope.row)"
  19. >
  20. 编辑
  21. </span>
  22. <el-divider direction="vertical"></el-divider>
  23. <span
  24. class="editor"
  25. @click="handleDeleteClick(scope.$index, scope.row)"
  26. >
  27. 删除
  28. </span>
  29. </template>
  30. </el-table-column>
  31. </el-table>
  32. <el-dialog
  33. title="新增"
  34. :visible.sync="dialogVisible"
  35. width="30%"
  36. :before-close="handleClose"
  37. >
  38. <el-form>
  39. <el-form-item label="国家">
  40. <el-select
  41. v-model="country"
  42. style="width: 200px"
  43. placeholder="请选择国家"
  44. size="mini"
  45. >
  46. <el-option v-for="(item,index) in Object.values(nameMap)" :key="index" :value="item">{{ item }}</el-option>
  47. </el-select>
  48. </el-form-item>
  49. <el-form-item label="别名">
  50. <el-input
  51. v-model="name"
  52. style="width: 200px"
  53. placeholder="请输入别名"
  54. size="mini"
  55. >
  56. </el-input>
  57. </el-form-item>
  58. </el-form>
  59. <span slot="footer" class="dialog-footer">
  60. <el-button size="mini" @click="dialogVisible = false">取 消</el-button>
  61. <el-button size="mini" type="primary" @click="handleSaveClick"
  62. >确 定</el-button
  63. >
  64. </span>
  65. </el-dialog>
  66. </div>
  67. </template>
  68. <script>
  69. import { nameMap } from "@/utils/word";
  70. export default {
  71. name: "customNameComponents",
  72. model: {
  73. prop: "formData",
  74. event: "input"
  75. },
  76. props: {
  77. formData: Array
  78. },
  79. data() {
  80. return {
  81. nameMap,
  82. predefineColors: [
  83. "#ff4500",
  84. "#ff8c00",
  85. "#ffd700",
  86. "#90ee90",
  87. "#00ced1",
  88. "#1e90ff",
  89. "#c71585"
  90. ],
  91. country: "",
  92. name:'',
  93. dialogVisible: false,
  94. flag: true, // true 新增, false 编辑
  95. indexEditor: -1 // 编辑第几个数据
  96. };
  97. },
  98. mounted() {},
  99. methods: {
  100. // 弹出框关闭
  101. handleClose() {
  102. this.dialogVisible = false;
  103. this.country = "";
  104. this.name=''
  105. },
  106. // 新增
  107. handleAddClick() {
  108. this.country = "";
  109. this.name=''
  110. this.flag = true;
  111. this.dialogVisible = true;
  112. },
  113. // 确定
  114. handleSaveClick() {
  115. if (this.flag) {
  116. // 新增
  117. const obj = {
  118. country: this.country,
  119. name:this.name
  120. };
  121. this.formData.push(obj);
  122. this.dialogVisible = false;
  123. } else {
  124. // 编辑
  125. this.formData[this.indexEditor].country = this.country;
  126. this.formData[this.indexEditor].name = this.name;
  127. this.dialogVisible = false;
  128. }
  129. this.$emit("input", this.formData);
  130. this.$emit("change", this.formData);
  131. },
  132. // 编辑
  133. handleEditorClick(index, row) {
  134. this.flag = false;
  135. this.country = row.country;
  136. this.name = row.name;
  137. this.dialogVisible = true;
  138. this.indexEditor = index;
  139. },
  140. // 删除
  141. handleDeleteClick(index) {
  142. this.formData.splice(index, 1);
  143. this.$emit("input", this.formData);
  144. this.$emit("change", this.formData);
  145. }
  146. }
  147. };
  148. </script>
  149. <style lang="scss" scoped>
  150. .color-box {
  151. .title {
  152. display: flex;
  153. flex-direction: row;
  154. }
  155. }
  156. /deep/.el-table,
  157. /deep/.el-table__expanded-cell,
  158. /deep/.el-table th,
  159. /deep/.el-table tr {
  160. background-color: transparent !important;
  161. color: #859094 !important;
  162. }
  163. /deep/.el-table td,
  164. /deep/.el-table th.is-leaf {
  165. border-bottom: none;
  166. line-height: 26px;
  167. }
  168. /deep/.el-table tbody tr:hover > td {
  169. background-color: #263445 !important;
  170. }
  171. /deep/.el-table::before {
  172. height: 0;
  173. }
  174. /deep/.el-color-picker--mini,
  175. /deep/.el-color-picker--mini .el-color-picker__trigger {
  176. width: 23px;
  177. height: 23px;
  178. }
  179. /deep/.el-dialog {
  180. background: #1b1e25;
  181. .el-dialog__title {
  182. color: #fff;
  183. }
  184. }
  185. .color-box {
  186. display: inline-block;
  187. width: 20px;
  188. height: 20px;
  189. border-radius: 5px;
  190. }
  191. .editor {
  192. color: #409eff;
  193. cursor: pointer;
  194. }
  195. </style>