detail.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <div>
  3. <a-button type="link" @click="showDrawer">管理二级</a-button>
  4. <a-drawer
  5. v-model:visible="visible"
  6. class="custom-class"
  7. title="二级分类"
  8. placement="right"
  9. width="900"
  10. :closable="false"
  11. @close="onClose"
  12. >
  13. <a-button class="mt-10" type="primary" @click="showModal">添加分类</a-button>
  14. <normalTable rowKey="optiontypemxid" ref="list" size="small" :param="param" :columns="utils.TBLayout('optionDetailsTable')">
  15. <template #tb_cell="{data}">
  16. <template v-if="data.column.dataIndex == 'subvalues'">
  17. <a-tag v-for="item in data.record.subvalues" :key="item.optiontypeid">{{item}}</a-tag>
  18. </template>
  19. <template v-if="data.column.dataIndex == 'operation'">
  20. <a-space v-if="data.record.siteid !== ''">
  21. <a-button type="link" @click="editOption(data.record)">编辑</a-button>
  22. <a-button type="link" @click="deleteOption(data.record)">删除</a-button>
  23. </a-space>
  24. </template>
  25. </template>
  26. </normalTable>
  27. <template #extra>
  28. <a-space>
  29. <a-button @click="onClose">关闭</a-button>
  30. </a-space>
  31. </template>
  32. </a-drawer>
  33. <a-modal
  34. v-model:visible="modalVisble"
  35. class="custom-class"
  36. title="分类"
  37. placement="right"
  38. size="900"
  39. :closable="false"
  40. @close="onClose"
  41. @ok="submit">
  42. <a-form ref="formRef" :model="form" size="small" layout="vertical">
  43. <a-row :gutter="16">
  44. <a-col :span="24">
  45. <a-form-item label="分类名称" name="value" :rules="[{ required: true, message: '请输入分类名称' }]">
  46. <a-input v-model:value="form.value" placeholder="分类名称" />
  47. </a-form-item>
  48. </a-col>
  49. <a-col :span="24">
  50. <a-form-item label="分类描述" name="remarks" :rules="[{ required: true, message: '请输入分类描述' }]">
  51. <a-input v-model:value="form.remarks" placeholder="分类描述" />
  52. </a-form-item>
  53. </a-col>
  54. <a-col :span="24">
  55. <a-form-item label="二级分类">
  56. <a-tag v-for="item in form.subvalues" :key="item.index" @close="handleClose(item)" closable>{{item}}</a-tag>
  57. <a-input
  58. v-if="inputVisible"
  59. ref="inputRef"
  60. v-model:value="inputValue"
  61. type="text"
  62. size="small"
  63. :style="{ width: '78px' }"
  64. @blur="handleInputConfirm"
  65. @keyup.enter="handleInputConfirm"
  66. />
  67. <a-tag v-else style="background: #fff; border-style: dashed" @click="showInput">
  68. <plus-outlined />
  69. 添加子分类
  70. </a-tag>
  71. </a-form-item>
  72. </a-col>
  73. </a-row>
  74. </a-form>
  75. </a-modal>
  76. </div>
  77. </template>
  78. <script setup>
  79. import {ref,defineProps,nextTick} from 'vue'
  80. import Api from '@/api/api'
  81. import utils from '@/utils/utils'
  82. import normalTable from '@/template/normalTable/index.vue'
  83. import { PlusOutlined } from '@ant-design/icons-vue';
  84. const props = defineProps(['id'])
  85. const visible = ref(false)
  86. const inputVisible= ref(false)
  87. const inputValue = ref('')
  88. const modalVisble = ref(false)
  89. const param = ref({
  90. "id": 20220901092501,
  91. "content": {
  92. "pageNumber": 1,
  93. "pageSize": 20,
  94. "optiontypeid":props.id
  95. }
  96. })
  97. const list = ref()
  98. const form = ref({
  99. "optiontypeid":props.id,
  100. "optiontypemxid":0,
  101. "isused":"1",
  102. "value":"",
  103. "remarks":"",
  104. "subvalues":[],
  105. "sequence":0
  106. })
  107. const showDrawer = ()=>{
  108. visible.value = true
  109. setTimeout(() => {
  110. list.value.listData()
  111. }, 1000);
  112. }
  113. const showModal = ()=>{
  114. modalVisble.value = true
  115. }
  116. const inputRef = ref()
  117. const showInput = () => {
  118. inputVisible.value = true;
  119. nextTick(() => {
  120. inputRef.value.focus();
  121. });
  122. };
  123. const handleInputConfirm = () => {
  124. if (inputValue.value && inputValue.value !== '') {
  125. form.value.subvalues.push(inputValue.value)
  126. inputValue.value = ''
  127. }
  128. inputVisible.value = false
  129. };
  130. const handleClose = (tag)=>{
  131. form.value.subvalues = form.value.subvalues.filter(e=>{
  132. if (e !== tag) {
  133. return e
  134. }
  135. })
  136. console.log(form.value.subvalues)
  137. }
  138. const onClose = () => {
  139. visible.value = false;
  140. };
  141. const formRef = ref()
  142. const submit = async ()=>{
  143. try {
  144. const values = await formRef.value.validateFields();
  145. const res = await Api.requested({
  146. id:20220901092601,
  147. content:form.value
  148. })
  149. utils.message(res,'添加成功',()=>{
  150. list.value.listData()
  151. modalVisble.value = false
  152. formRef.value.resetFields();
  153. form.value.subvalues = []
  154. })
  155. } catch (errorInfo) {
  156. console.log('Failed:', errorInfo);
  157. }
  158. }
  159. const deleteOption = async (data)=>{
  160. const res = await Api.requested({
  161. id:20220901092701,
  162. content:{
  163. optiontypemxid:data.optiontypemxid
  164. }
  165. })
  166. utils.message(res,'删除成功',()=>{
  167. list.value.listData()
  168. })
  169. }
  170. const editOption = (data)=>{
  171. modalVisble.value = true
  172. form.value = Object.assign({},form.value,data)
  173. }
  174. </script>
  175. <style>
  176. </style>