SelectProductModal.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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-table
  74. :columns="columns"
  75. :row-key="record => record.id"
  76. :data-source="dataSource"
  77. bordered
  78. size="small"
  79. @change="handleTableChange"
  80. :pagination="pagination"
  81. :scroll="{ x: 1800, y: 300 }"
  82. :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
  83. >
  84. </a-table>
  85. </a-card>
  86. </div>
  87. </a-modal>
  88. </template>
  89. <script lang="ts" setup>
  90. import { defHttp } from '/@/utils/http/axios';
  91. import { message } from 'ant-design-vue';
  92. import { JDictSelectTag} from '/@/components/Form';
  93. import JSelectInput from '/@/components/Form/src/jeecg/components/JSelectInput.vue';
  94. import { ref, reactive, toRaw, toRefs, watch, nextTick, onMounted, getCurrentInstance } from 'vue';
  95. import { filterObj, getFileAccessHttpUrl } from '/@/utils/common/compUtils';
  96. const emit = defineEmits([ 'success']); //定义emit
  97. var visible = ref(false)
  98. let classOption = ref([])
  99. const columns = [
  100. {
  101. title: '分类(class)',
  102. dataIndex: 'classId_dictText',
  103. key: 'classId',
  104. align:"center"
  105. },
  106. {
  107. title: '编码(code)',
  108. dataIndex: 'code',
  109. key: 'code',
  110. align:"center"
  111. },
  112. {
  113. title: '中文名(Chinese name)',
  114. dataIndex: 'chineseName',
  115. key: 'chineseName',
  116. align:"center",
  117. width:200
  118. },
  119. {
  120. title: '英文名(English name)',
  121. key: 'englishName',
  122. dataIndex: 'englishName',
  123. align:"center"
  124. },
  125. {
  126. title: '规格(specifications)',
  127. key: 'specifications',
  128. dataIndex: 'specifications',
  129. align:"center"
  130. },
  131. {
  132. title: '型号(model)',
  133. key: 'model',
  134. dataIndex: 'model',
  135. align:"center"
  136. },
  137. {
  138. title: '计量单位(measurement unit)',
  139. key: 'measurementUnit',
  140. dataIndex: 'measurementUnit',
  141. align:"center",
  142. width:250
  143. },
  144. {
  145. title: '虚拟产品(virtual product)',
  146. key: 'virtualProduct',
  147. dataIndex: 'virtualProduct',
  148. align:"center",
  149. customRender:function (t, r, index) {
  150. if(t.text==1){
  151. return '是(yes)'
  152. }else if(t.text==0){
  153. return '否(no)'
  154. }else{
  155. return ''
  156. }
  157. }
  158. },
  159. {
  160. title: '有害物质(harmful substances)',
  161. key: 'harmfulSubstances',
  162. dataIndex: 'harmfulSubstances',
  163. align:"center",
  164. width:250,
  165. customRender:function (t, r, index) {
  166. if(t.text==1){
  167. return '是(yes)'
  168. }else if(t.text==0){
  169. return '否(no)'
  170. }else{
  171. return ''
  172. }
  173. }
  174. },
  175. ];
  176. const labelCol = ref({
  177. xs: { span: 24 },
  178. sm: { span: 9 },
  179. });
  180. const wrapperCol = ref({
  181. xs: { span: 24 },
  182. sm: { span: 15 },
  183. });
  184. const labelCol1 = ref({
  185. xs: { span: 24 },
  186. sm: { span: 12 },
  187. });
  188. const wrapperCol1 = ref({
  189. xs: { span: 24 },
  190. sm: { span: 12 },
  191. });
  192. const dataSource =ref([]);
  193. let selectedRowKeys = ref([]);
  194. let selectedRows = ref([]);
  195. const toggleSearchStatus = ref(false);
  196. const queryParams = ref({
  197. classId:'',
  198. code:'',
  199. chineseName:'',
  200. englishName:'',
  201. specifications:'',
  202. model:'',
  203. chineseAlias:'',
  204. englishAlias:'',
  205. status:'',
  206. virtualProduct:'',
  207. harmfulSubstances:'',
  208. });
  209. let pagination = ref({
  210. current: 1,
  211. pageSize: 10,
  212. total: '', // 假设总共有100条数据
  213. showSizeChanger: true,
  214. showQuickJumper: true,
  215. showTotal: (total, range) => {
  216. return range[0] + "-" + range[1] + " 共" + total + "条"
  217. },
  218. size:'small'
  219. });
  220. function handleOk() {
  221. emit('success',selectedRows);
  222. visible.value = false
  223. selectedRowKeys.value = []
  224. selectedRows.value = []
  225. dataSource.value = []
  226. }
  227. function handleCancel() {
  228. visible.value = false
  229. selectedRowKeys.value = []
  230. selectedRows.value = []
  231. dataSource.value = []
  232. }
  233. function getTable(record){
  234. visible.value = true
  235. loadData()
  236. getOptiom()
  237. }
  238. function loadData(){
  239. let params = getQueryParams();
  240. params.status = 1
  241. defHttp
  242. .get({ url: '/baseCode/baseProductArchive/list',params}, { isTransformResponse: false })
  243. .then((res) => {
  244. if (res.success) {
  245. dataSource.value = res.result.records;
  246. pagination.value.total = res.result.total;
  247. pagination.value.current = res.result.current;
  248. pagination.value.pageSize = res.result.size;
  249. } else {
  250. message.error(res.message);
  251. }
  252. })
  253. .finally(() => {
  254. // loading.value = false;
  255. });
  256. }
  257. function getOptiom(){
  258. defHttp
  259. .get({ url: 'baseCode/baseProductClass/list'}, { isTransformResponse: false })
  260. .then((res) => {
  261. if (res.success) {
  262. classOption.value = []
  263. res.result.records.forEach(element => {
  264. var obj = {
  265. label: element.name?element.name:'无名称请维护',
  266. value: element.id?element.id:''
  267. };
  268. classOption.value.push(obj)
  269. });
  270. }
  271. })
  272. .finally(() => {
  273. // loading.value = false;
  274. });
  275. }
  276. function getQueryParams(){
  277. let params = Object.assign(queryParams.value);
  278. params.pageNo = pagination.value.current;
  279. params.pageSize = pagination.value.pageSize;
  280. return filterObj(params);
  281. }
  282. function handleTableChange(paginations, filters, sorter){
  283. pagination.value.total = paginations.total;
  284. pagination.value.current = paginations.current;
  285. pagination.value.pageSize = paginations.pageSize;
  286. loadData()
  287. };
  288. function searchQuery(){
  289. loadData();
  290. }
  291. function searchReset(){
  292. queryParams.value = {
  293. classId:'',
  294. code:'',
  295. chineseName:'',
  296. englishName:'',
  297. specifications:'',
  298. model:'',
  299. chineseAlias:'',
  300. englishAlias:'',
  301. status:'',
  302. virtualProduct:'',
  303. harmfulSubstances:'',
  304. }
  305. pagination.value.current =1;
  306. pagination.value.pageSize = 10;
  307. loadData();
  308. }
  309. function handleToggleSearch(){
  310. toggleSearchStatus.value = !toggleSearchStatus.value;
  311. }
  312. function onSelectChange(keys,rows){
  313. selectedRowKeys.value = keys
  314. selectedRows.value = rows
  315. }
  316. defineExpose({
  317. getTable
  318. });
  319. </script>
  320. <style lang="less" scoped>
  321. /deep/.ant-spin-container{
  322. padding: 8px;
  323. }
  324. /deep/.ant-form-item{
  325. margin-bottom: 8px !important;
  326. }
  327. </style>