SelectPrpductModal.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. <template>
  2. <a-modal
  3. title="选择产品(select product)"
  4. width="95%"
  5. :visible="visible"
  6. :maskClosable="false"
  7. switchFullscreen
  8. @ok = "handleOk"
  9. @cancel="handleCancel">
  10. <div>
  11. <a-card :body-style="{ padding: '10px' }" :bordered="false" style="margin: 10px;">
  12. <div class="table-page-search-wrapper">
  13. <a-form :model="queryParams" :label-col="labelCol" :wrapper-col="wrapperCol" @keyup.enter.native="searchQuery">
  14. <a-row :gutter="24">
  15. <a-col :md="6" :sm="8">
  16. <a-form-item label="分类(class)">
  17. <!-- <a-input placeholder="请输入" v-model:value="queryParams.classId"></a-input> -->
  18. <JSelectInput v-model:value="queryParams.classId" placeholder="请选择" :options="classOption" ></JSelectInput>
  19. </a-form-item>
  20. </a-col>
  21. <a-col :md="6" :sm="8">
  22. <a-form-item label="编码(code)">
  23. <a-input placeholder="请输入" v-model:value="queryParams.code"></a-input>
  24. </a-form-item>
  25. </a-col>
  26. <a-col :md="6" :sm="8">
  27. <a-form-item label="中文名(Chinese name)">
  28. <a-input placeholder="请输入" v-model:value="queryParams.chineseName"></a-input>
  29. </a-form-item>
  30. </a-col>
  31. <template v-if="toggleSearchStatus">
  32. <a-col :md="6" :sm="8">
  33. <a-form-item label="英文名(English name)">
  34. <a-input placeholder="请输入" v-model:value="queryParams.englishName"></a-input>
  35. </a-form-item>
  36. </a-col>
  37. <!-- <a-col :md="6" :sm="8">
  38. <a-form-item label="规格(specifications)">
  39. <a-input placeholder="请输入" v-model:value="queryParams.specifications"></a-input>
  40. </a-form-item>
  41. </a-col> -->
  42. <a-col :md="6" :sm="8">
  43. <a-form-item label="型号(model)">
  44. <a-input placeholder="请输入" v-model:value="queryParams.model"></a-input>
  45. </a-form-item>
  46. </a-col>
  47. <a-col :md="6" :sm="8">
  48. <a-form-item label="虚拟产品(virtual product)" :label-col="labelCol1" :wrapper-col="wrapperCol1">
  49. <JDictSelectTag v-model:value="queryParams.virtualProduct" placeholder="请选择" dictCode="yes_or_no"/>
  50. </a-form-item>
  51. </a-col>
  52. <a-col :md="6" :sm="8">
  53. <a-form-item label="有害物质(harmful substances)" :label-col="labelCol1" :wrapper-col="wrapperCol1">
  54. <JDictSelectTag v-model:value="queryParams.harmfulSubstances" placeholder="请选择" dictCode="yes_or_no"/>
  55. </a-form-item>
  56. </a-col>
  57. </template>
  58. <a-col :md="6" :sm="8">
  59. <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
  60. <a-button type="primary" @click="searchQuery" >查询(search)</a-button>
  61. <a-button type="primary" @click="searchReset" style="margin-left: 8px">重置(reset)</a-button>
  62. <a @click="handleToggleSearch" style="margin-left: 8px">
  63. {{ toggleSearchStatus ? '收起' : '展开' }}
  64. <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
  65. </a>
  66. </span>
  67. </a-col>
  68. </a-row>
  69. </a-form>
  70. </div>
  71. </a-card>
  72. <a-card :body-style="{ padding: '10px' }" :bordered="false" style="margin: 10px;">
  73. <a-alert type="info" show-icon class="alert" style="margin-bottom: 8px">
  74. <template #message>
  75. <template v-if="selectedRowKeys.length > 0">
  76. <span>已选中 {{ selectedRowKeys.length }} 条记录</span>
  77. <a-divider type="vertical" />
  78. <a @click="selectedRowKeys = []">清空</a>
  79. </template>
  80. <template v-else>
  81. <span>未选中任何数据</span>
  82. </template>
  83. </template>
  84. </a-alert>
  85. <a-table
  86. :columns="columns"
  87. :row-key="record => record.id"
  88. :data-source="dataSource"
  89. bordered
  90. size="small"
  91. @change="handleTableChange"
  92. :pagination="pagination"
  93. :scroll="{ x: 2500, y: 300 }"
  94. :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
  95. >
  96. </a-table>
  97. </a-card>
  98. </div>
  99. </a-modal>
  100. </template>
  101. <script lang="ts" setup>
  102. import {ref, reactive } from 'vue';
  103. import { defHttp } from '/@/utils/http/axios';
  104. import { message } from 'ant-design-vue';
  105. import { filterObj, getFileAccessHttpUrl } from '/@/utils/common/compUtils';
  106. import { JDictSelectTag} from '/@/components/Form';
  107. import JSelectInput from '/@/components/Form/src/jeecg/components/JSelectInput.vue';
  108. const emit = defineEmits([ 'selectProduct']); //定义emit
  109. let classOption = ref([])
  110. var visible = ref(false)
  111. const columns = [
  112. {
  113. title: '分类(class)',
  114. dataIndex: 'classId_dictText',
  115. key: 'classId_dictText',
  116. align:"center"
  117. },
  118. {
  119. title: '编码(code)',
  120. dataIndex: 'code',
  121. key: 'code',
  122. align:"center"
  123. },
  124. {
  125. title: '中文名(Chinese name)',
  126. dataIndex: 'chineseName',
  127. key: 'chineseName',
  128. align:"center",
  129. width:200
  130. },
  131. {
  132. title: '英文名(English name)',
  133. key: 'englishName',
  134. dataIndex: 'englishName',
  135. align:"center"
  136. },
  137. // {
  138. // title: '规格(specifications)',
  139. // key: 'specifications',
  140. // dataIndex: 'specifications',
  141. // align:"center"
  142. // },
  143. {
  144. title: '型号(model)',
  145. key: 'model',
  146. dataIndex: 'model',
  147. align:"center"
  148. },
  149. {
  150. title: '计量单位(measurement unit)',
  151. key: 'measurementUnit',
  152. dataIndex: 'measurementUnit',
  153. align:"center",
  154. width:250
  155. },
  156. {
  157. title: '虚拟产品(virtual product)',
  158. key: 'virtualProduct',
  159. dataIndex: 'virtualProduct',
  160. align:"center",
  161. customRender:function (t, r, index) {
  162. if(t.text==1){
  163. return '是(yes)'
  164. }else if(t.text==0){
  165. return '否(no)'
  166. }else{
  167. return ''
  168. }
  169. }
  170. },
  171. {
  172. title: '有害物质(harmful substances)',
  173. key: 'harmfulSubstances',
  174. dataIndex: 'harmfulSubstances',
  175. align:"center",
  176. width:250,
  177. customRender:function (t, r, index) {
  178. if(t.text==1){
  179. return '是(yes)'
  180. }else if(t.text==0){
  181. return '否(no)'
  182. }else{
  183. return ''
  184. }
  185. }
  186. },
  187. ];
  188. const labelCol = ref({
  189. xs: { span: 24 },
  190. sm: { span: 9 },
  191. });
  192. const wrapperCol = ref({
  193. xs: { span: 24 },
  194. sm: { span: 15 },
  195. });
  196. const labelCol1 = ref({
  197. xs: { span: 24 },
  198. sm: { span: 12 },
  199. });
  200. const wrapperCol1 = ref({
  201. xs: { span: 24 },
  202. sm: { span: 12 },
  203. });
  204. const dataSource =ref([]);
  205. let selectedRowKeys = ref([]);
  206. let selectedRows = ref([]);
  207. const toggleSearchStatus = ref(false);
  208. const queryParams = ref({
  209. classId:'',
  210. code:'',
  211. chineseName:'',
  212. englishName:'',
  213. specifications:'',
  214. model:'',
  215. chineseAlias:'',
  216. englishAlias:'',
  217. status:'',
  218. virtualProduct:'',
  219. harmfulSubstances:'',
  220. });
  221. let pagination = ref({
  222. current: 1,
  223. pageSize: 10,
  224. total: '', // 假设总共有100条数据
  225. showSizeChanger: true,
  226. showQuickJumper: true,
  227. showTotal: (total, range) => {
  228. return range[0] + "-" + range[1] + " 共" + total + "条"
  229. },
  230. size:'small'
  231. });
  232. function loadData(){
  233. let params = getQueryParams();
  234. defHttp
  235. .get({ url: '/baseCode/baseProductArchive/list',params}, { isTransformResponse: false })
  236. .then((res) => {
  237. if (res.success) {
  238. dataSource.value = res.result.records;
  239. pagination.value.total = res.result.total;
  240. pagination.value.current = res.result.current;
  241. pagination.value.pageSize = res.result.size;
  242. } else {
  243. message.error(res.message);
  244. }
  245. })
  246. .finally(() => {
  247. // loading.value = false;
  248. });
  249. }
  250. function getQueryParams(){
  251. let params = Object.assign(queryParams.value);
  252. params.pageNo = pagination.value.current;
  253. params.pageSize = pagination.value.pageSize;
  254. return filterObj(params);
  255. }
  256. function handleTableChange(paginations, filters, sorter){
  257. pagination.value.total = paginations.total;
  258. pagination.value.current = paginations.current;
  259. pagination.value.pageSize = paginations.pageSize;
  260. loadData()
  261. };
  262. function getOptiom(){
  263. defHttp
  264. .get({ url: 'baseCode/baseProductClass/list'}, { isTransformResponse: false })
  265. .then((res) => {
  266. if (res.success) {
  267. classOption.value = []
  268. res.result.records.forEach(element => {
  269. var obj = {
  270. label: element.name?element.name:'无名称请维护',
  271. value: element.id?element.id:''
  272. };
  273. classOption.value.push( obj)
  274. });
  275. }
  276. })
  277. .finally(() => {
  278. // loading.value = false;
  279. });
  280. }
  281. function searchQuery(){
  282. loadData();
  283. }
  284. function searchReset(){
  285. queryParams.value = {
  286. classId:'',
  287. code:'',
  288. chineseName:'',
  289. englishName:'',
  290. specifications:'',
  291. model:'',
  292. chineseAlias:'',
  293. englishAlias:'',
  294. status:'',
  295. virtualProduct:'',
  296. harmfulSubstances:'',
  297. }
  298. pagination.value.current =1;
  299. pagination.value.pageSize = 10;
  300. loadData();
  301. }
  302. function handleToggleSearch(){
  303. toggleSearchStatus.value = !toggleSearchStatus.value;
  304. }
  305. function onSelectChange(keys,rows){
  306. selectedRowKeys.value = keys
  307. selectedRows.value = rows
  308. }
  309. function handleOk(){
  310. if(selectedRowKeys.value.length==0){
  311. message.error('请勾选数据');
  312. }else{
  313. emit('selectProduct', selectedRows.value)
  314. handleCancel()
  315. }
  316. }
  317. function handleCancel(){
  318. visible.value = false
  319. selectedRowKeys.value = []
  320. selectedRows.value=[]
  321. }
  322. function getTable(){
  323. visible.value = true
  324. loadData()
  325. getOptiom()
  326. }
  327. defineExpose({
  328. getTable
  329. });
  330. </script>
  331. <style scoped lang="less">
  332. /deep/.ant-form-item{
  333. margin-bottom: 8px !important;
  334. }
  335. // /deep/.ant-table-wrapper .ant-table-thead > tr > th, .ant-table-wrapper .ant-table-thead > tr > td{
  336. // padding: 8px !important;
  337. // }
  338. </style>