add.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <template>
  2. <div class="inline-16">
  3. <el-button type="primary" size="small" @click="dialogTableVisible=true" v-if="type == 'add'">新增产品组</el-button>
  4. <el-button type="text" size="small" @click="editBtn" v-else>编辑</el-button>
  5. <el-dialog title="新增产品" :visible.sync="dialogTableVisible" width="30%">
  6. <el-row :gutter="20">
  7. <el-form label-position="right" ref="form" :rules="rules" inline label-width="100px" :model="form" size="small">
  8. <el-col :span="24">
  9. <el-form-item label="产品组名称" prop="groupname">
  10. <el-input v-model="form.groupname" placeholder="请输入商品组名称"></el-input>
  11. </el-form-item>
  12. </el-col>
  13. <el-col :span="24">
  14. <el-form-item label="品牌" prop="sa_brandid">
  15. <el-select v-model="form.sa_brandid" placeholder="请选择品牌">
  16. <el-option
  17. v-for="item in brandData"
  18. :key="item.sa_brandid"
  19. :label="item.brandname"
  20. :value="item.sa_brandid"
  21. size="small">
  22. </el-option>
  23. </el-select>
  24. </el-form-item>
  25. </el-col>
  26. <el-col :span="24">
  27. <el-form-item label="商品" prop="itemno">
  28. <el-select v-model="form.itemno" placeholder="请选择商品">
  29. <el-option
  30. v-for="item in productData"
  31. :key="item.itemno"
  32. :label="item.itemname"
  33. :value="item.itemno"
  34. size="small">
  35. </el-option>
  36. </el-select>
  37. </el-form-item>
  38. </el-col>
  39. <el-col :span="24">
  40. <el-form-item label="自定义标签" prop="tag" style="margin-bottom:0px; !important">
  41. <el-tag
  42. :key="tag"
  43. v-for="tag in form.tag"
  44. closable
  45. :disable-transitions="false"
  46. @close="handleClose(tag)">
  47. {{tag}}
  48. </el-tag>
  49. <el-input
  50. class="input-new-tag"
  51. v-if="inputVisible"
  52. v-model="inputValue"
  53. ref="saveTagInput"
  54. size="small"
  55. @keyup.enter.native="handleInputConfirm"
  56. @blur="handleInputConfirm"
  57. >
  58. </el-input>
  59. <el-button v-else class="button-new-tag" size="small" @click="showInput">+ New 标签</el-button>
  60. </el-form-item>
  61. </el-col>
  62. </el-form>
  63. </el-row>
  64. <span slot="footer" class="dialog-footer">
  65. <div>
  66. <el-button @click="dialogTableVisible = false" size="small">取 消</el-button>
  67. <el-button type="primary" @click="submit" size="small">确 定</el-button>
  68. </div>
  69. </span>
  70. </el-dialog>
  71. </div>
  72. </template>
  73. <script>
  74. export default {
  75. data () {
  76. return {
  77. dialogTableVisible:false,
  78. /* 当前选择的组 */
  79. seleteGroup:'',
  80. inputVisible: false,
  81. inputValue: '',
  82. form:{
  83. sa_brandid:'',
  84. groupname:'',
  85. itemno:'',
  86. tag:[]
  87. },
  88. rules:{
  89. sa_brandid: [
  90. { required: true, message: '请选择品牌', trigger: 'blur' },
  91. ],
  92. groupname: [
  93. { required: true, message: '请输入商品组名称', trigger: 'blur' },
  94. ],
  95. itemno: [
  96. { required: true, message: '请选择商品', trigger: 'blur' },
  97. ]
  98. }
  99. }
  100. },
  101. props:['type','brandData','productData','groupData'],
  102. watch: {
  103. },
  104. created() {
  105. },
  106. methods: {
  107. submit() {
  108. this.$refs.form.validate(async val => {
  109. if(val) {
  110. let res = await this.$api.requested({
  111. "id": "20220922164303",
  112. "version":1,
  113. "content": {
  114. "sa_itemgroupid":this.type == 'add' ? 0 : this.groupData.sa_itemgroupid,
  115. "sa_brandid":this.form.sa_brandid,
  116. "groupname":this.form.groupname,
  117. "itemno":this.form.itemno,
  118. "tag": this.form.tag
  119. }
  120. })
  121. this.tool.showMessage(res,() => {
  122. this.$emit('addSuccess')
  123. this.dialogTableVisible = false
  124. })
  125. }
  126. })
  127. },
  128. editBtn() {
  129. this.dialogTableVisible = true
  130. this.seleteGroup = this.groupData
  131. let temp = JSON.parse(JSON.stringify(this.seleteGroup))
  132. this.form = {
  133. sa_brandid:temp.sa_brandid,
  134. groupname:temp.groupname,
  135. itemno:temp.itemno,
  136. tag:temp.tag1
  137. }
  138. },
  139. handleClose(tag) {
  140. this.form.tag.splice(this.form.tag.indexOf(tag), 1);
  141. },
  142. showInput() {
  143. this.inputVisible = true;
  144. this.$nextTick(_ => {
  145. this.$refs.saveTagInput.$refs.input.focus();
  146. });
  147. },
  148. handleInputConfirm() {
  149. let inputValue = this.inputValue;
  150. if (inputValue) {
  151. this.form.tag.push(inputValue);
  152. }
  153. this.inputVisible = false;
  154. this.inputValue = '';
  155. }
  156. }
  157. }
  158. </script>
  159. <style scoped>
  160. /deep/.el-dialog__body {
  161. padding-top: 10px !important;
  162. padding-bottom: 0 !important;
  163. }
  164. /deep/.dialog-footer {
  165. margin-top: 10px !important;
  166. }
  167. /deep/.el-form-item__content {
  168. width: calc(100% - 100px) !important;
  169. }
  170. /deep/.el-select {
  171. width: 100% !important;
  172. }
  173. /deep/.el-form-item {
  174. width: 100% !important;
  175. }
  176. .el-tag + .el-tag {
  177. margin-left: 10px;
  178. margin-bottom: 10px;
  179. }
  180. .button-new-tag {
  181. margin-left: 10px;
  182. height: 32px;
  183. line-height: 30px;
  184. padding-top: 0;
  185. padding-bottom: 0;
  186. }
  187. .input-new-tag {
  188. width: 90px;
  189. margin-left: 10px;
  190. }
  191. </style>