SupplyCatalogModal.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <template>
  2. <a-modal
  3. title="供货目录(supply catalog)"
  4. width="95%"
  5. :visible="visible"
  6. :maskClosable="false"
  7. switchFullscreen
  8. @ok = "handleOk"
  9. @cancel="handleCancel">
  10. <a-spin :spinning="loading" >
  11. <a-button type="primary" v-auth="'cuspCode:cusp_supplier_profile:add'" @click="selectProducts" preIcon="ant-design:plus-outlined">选择产品(select product)</a-button>
  12. <a-table
  13. :columns="columns"
  14. :row-key="record => record.id"
  15. :data-source="dataSource"
  16. bordered
  17. size="small"
  18. height="500"
  19. :pagination="false"
  20. :scroll="{ x: 1800, y: 500 }"
  21. >
  22. <template #valid="{ text, record }">
  23. <!-- <a-select v-model:value="record.valid" v-bind="attrs">
  24. <a-select-option value="1">是(yes)</a-select-option>
  25. <a-select-option value="1">否(no)</a-select-option>
  26. </a-select> -->
  27. <JDictSelectTag v-model:value="record.valid" placeholder="请选择" dictCode="yes_or_no" stringToNumber/>
  28. </template>
  29. <template #action="{ text, record,index }">
  30. <a @click="deleteRow(index)">删除(delete)</a>
  31. </template>
  32. </a-table>
  33. </a-spin>
  34. <SelectProductModal ref="SelectProductModalRef" @success="addRow"></SelectProductModal>
  35. </a-modal>
  36. </template>
  37. <script lang="ts" setup>
  38. import { defHttp } from '/@/utils/http/axios';
  39. import { message } from 'ant-design-vue';
  40. import { JDictSelectTag} from '/@/components/Form';
  41. import SelectProductModal from './SelectProductModal.vue';
  42. import { ref, reactive, toRaw, toRefs, watch, nextTick, onMounted, getCurrentInstance,readonly } from 'vue';
  43. const emit = defineEmits([ 'success']); //定义emit
  44. var visible = ref(false)
  45. let loading = ref(false)
  46. var dataSource = ref([]);
  47. var SelectProductModalRef = ref()
  48. var headId = ref('')
  49. var columns = reactive([
  50. {
  51. title: '分类(class)',
  52. dataIndex: 'classId',
  53. key: 'classId',
  54. align:"center",
  55. ellipsis: true,
  56. },
  57. {
  58. title: '编码(code)',
  59. dataIndex: 'code',
  60. key: 'code',
  61. align:"center"
  62. },
  63. {
  64. title: '中文名(Chinese name)',
  65. dataIndex: 'chineseName',
  66. key: 'chineseName',
  67. align:"center",
  68. width:200
  69. },
  70. {
  71. title: '英文名(English name)',
  72. key: 'englishName',
  73. dataIndex: 'englishName',
  74. align:"center",
  75. width:200
  76. },
  77. // {
  78. // title: '规格(specifications)',
  79. // key: 'specifications',
  80. // dataIndex: 'specifications',
  81. // align:"center",
  82. // width:150
  83. // },
  84. {
  85. title: '型号(model)',
  86. key: 'model',
  87. dataIndex: 'model',
  88. align:"center"
  89. },
  90. {
  91. title: '计量单位(measurement unit)',
  92. key: 'measurementUnit',
  93. dataIndex: 'measurementUnit',
  94. align:"center",
  95. width:250
  96. },
  97. {
  98. title: '有害物质(harmful substances)',
  99. key: 'harmfulSubstances',
  100. dataIndex: 'harmfulSubstances',
  101. align:"center",
  102. width:250,
  103. customRender:function (t, r, index) {
  104. if(t.text==1){
  105. return '是(yes)'
  106. }else if(t.text==0){
  107. return '否(no)'
  108. }else{
  109. return ''
  110. }
  111. }
  112. },
  113. {
  114. title: '是否有效(valid)',
  115. key: 'valid',
  116. dataIndex: 'valid',
  117. align:"center",
  118. slots: { customRender: 'valid' },
  119. },
  120. {
  121. title: '操作(operation)',
  122. key: 'operation',
  123. dataIndex: 'operation',
  124. align:"center",
  125. fixed: 'right',
  126. slots: { customRender: 'action' },
  127. },
  128. ]);
  129. function handleOk() {
  130. if(dataSource.value.length==0){
  131. message.warn('请选择产品');
  132. }else{
  133. dataSource.value.map(item=>{
  134. item.headId = headId.value
  135. item.productId =item.productId&&item.productId!==''?item.productId:item.id
  136. })
  137. defHttp.post({ url: '/cuspCode/cuspSupplierProfileCatalog/add', params: {cuspSupplierProfileCatalog:dataSource.value} }, { isTransformResponse: false }).then((res)=>{
  138. if(res.success){
  139. emit('success');
  140. visible.value = false
  141. }else{
  142. message.warning(res.message);
  143. }
  144. });
  145. }
  146. }
  147. function handleCancel() {
  148. visible.value = false
  149. emit('success');
  150. dataSource.value = []
  151. }
  152. function getTable(record){
  153. visible.value = true
  154. headId.value = record
  155. let params = {id:record}
  156. defHttp.get({url:"/cuspCode/cuspSupplierProfileCatalog/querySupplierProfileCatalogByMainId",params}).then(res=>{
  157. if(res){
  158. dataSource.value = res
  159. }
  160. })
  161. }
  162. function selectProducts(){
  163. SelectProductModalRef.value.getTable()
  164. }
  165. function deleteRow(index){
  166. dataSource.value.splice(index, 1);
  167. }
  168. function addRow(selectedRows){
  169. var arr =[...selectedRows.value, ...dataSource.value]
  170. dataSource.value = arr
  171. }
  172. defineExpose({
  173. getTable
  174. });
  175. </script>
  176. <style lang="less" scoped>
  177. /deep/.ant-spin-container{
  178. padding: 8px;
  179. }
  180. /deep/.ant-select-dropdown{
  181. position: fixed !important;
  182. // margin-top: 15%;
  183. // margin-left: 82%;
  184. }
  185. </style>