SelectPrpductModal.vue 13 KB

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