SpareStoreSelectModalYY3.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. <template>
  2. <a-modal
  3. :title="modalTitle"
  4. :width="1300"
  5. :visible="visible"
  6. :confirmLoading="confirmLoading"
  7. class="ant-modal2"
  8. @cancel="handleCancel"
  9. >
  10. <a-card :bordered="false">
  11. <a-row :gutter="8">
  12. <!-- <a-col :span="5">
  13. <a-tree
  14. @expand="onExpand"
  15. :expandedKeys="expandedKeys"
  16. :autoExpandParent="true"
  17. @select="onSelect"
  18. :selectedKeys="selectedKeys"
  19. :treeData="spareTypeTreeData"
  20. />
  21. </a-col>-->
  22. <a-col :span="24">
  23. <div class="table-page-search-wrapper">
  24. <a-form layout="inline">
  25. <a-row :gutter="48">
  26. <a-col :md="6" :sm="24">
  27. <a-form-item label="仓库编码">
  28. <a-input v-model.trim="queryParam.storeNo" placeholder="仓库编码"/>
  29. </a-form-item>
  30. </a-col>
  31. <a-col :md="6" :sm="24">
  32. <a-form-item label="仓库名称">
  33. <a-input v-model.trim="queryParam.storeName" placeholder="仓库名称"/>
  34. <a-input type="hidden" v-model="queryParam.purchaseFlag"/>
  35. </a-form-item>
  36. </a-col>
  37. <a-col :md="6" :sm="24">
  38. <a-form-item label="存货编码">
  39. <a-input v-model.trim="queryParam.spareNo" placeholder="存货名称"/>
  40. </a-form-item>
  41. </a-col>
  42. <a-col :md="6" :sm="24">
  43. <a-form-item label="存货名称">
  44. <a-input v-model.trim="queryParam.spareName" placeholder="存货名称"/>
  45. </a-form-item>
  46. </a-col>
  47. <a-col :md="6" :sm="24">
  48. <a-form-item label="规格型号">
  49. <a-input v-model.trim="queryParam.ggxh" placeholder="规格型号"/>
  50. </a-form-item>
  51. </a-col>
  52. <a-col :md="6" :sm="24">
  53. <a-form-item label="查询方式">
  54. <a-switch un-checked-children="存量" checked-children="存货" v-model="searchType" default-checked @change="$refs.table.refresh(true)"/>
  55. </a-form-item>
  56. </a-col>
  57. <a-col :md="8 || 24" :sm="24">
  58. <span class="table-page-search-submitButtons">
  59. <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
  60. <a-button style="margin-left: 8px" @click="resetSearchForm">重置</a-button>
  61. <a-button style="margin-left: 8px" @click="handleAdd">新增</a-button>
  62. </span>
  63. </a-col>
  64. </a-row>
  65. </a-form>
  66. </div>
  67. <div class="table-operator" style="margin-bottom: 8px;">
  68. </div>
  69. <s-table
  70. ref="table"
  71. size="default"
  72. rowKey="autoId"
  73. :columns="columns"
  74. :data="loadData"
  75. :alert="options.alert"
  76. :customRow="options.customRow"
  77. :rowSelection="options.rowSelection"
  78. showPagination="auto"
  79. >
  80. </s-table>
  81. </a-col>
  82. </a-row>
  83. <detail ref="detailModal"/>
  84. </a-card>
  85. <template slot="footer">
  86. <a-button :loading="confirmLoading" type="primary" @click="handleCancel()">取消</a-button>
  87. <a-button :loading="confirmLoading" type="primary" @click="handleSelect()">选择</a-button>
  88. </template>
  89. <AddSpareForm ref="addSpareForm" @ok="handleOk" />
  90. </a-modal>
  91. </template>
  92. <script>
  93. import { STable, Ellipsis } from '@/components'
  94. import AddSpareForm from './AddSpareForm'
  95. import Detail from './Detail'
  96. import { fetchSpareTypeTree } from '@/api/sqarepartmanage/sparetype'
  97. import { fetchStoreTree } from '@/api/store/store'
  98. import { getSpareStorePageYY3, getInventoryPage } from '@/api/yongyou/yongyou'
  99. export default {
  100. name: 'SpareStoreSelectModalYY',
  101. components: {
  102. STable,
  103. Ellipsis,
  104. Detail,
  105. AddSpareForm
  106. },
  107. props: {
  108. type: {
  109. type: String,
  110. default: 'checkbox'
  111. },
  112. selectedRowKey: {
  113. type: Array,
  114. default: () => {
  115. return []
  116. }
  117. },
  118. selectedRow: {
  119. type: Array,
  120. default: () => {
  121. return []
  122. }
  123. }
  124. },
  125. data () {
  126. return {
  127. confirmLoading: false,
  128. mdl: {},
  129. storeTreeDate: [],
  130. modalTitle: null,
  131. visible: false,
  132. record: null,
  133. spareTypeTreeData: [],
  134. expandedKeys: [],
  135. selectedKeys: [],
  136. isSpecial: null,
  137. // 查询参数
  138. queryParam: {
  139. storeNo: '09'
  140. },
  141. // 表头
  142. columns: [
  143. {
  144. title: '序号',
  145. dataIndex: 'index',
  146. customRender: (text, record, index) => {
  147. return `${(this.$refs.table.localPagination.current - 1) * this.$refs.table.localPagination.pageSize + index + 1}`
  148. }
  149. },
  150. {
  151. title: '存货编号',
  152. dataIndex: 'no'
  153. },
  154. {
  155. title: '存货名称',
  156. dataIndex: 'spareName'
  157. },
  158. {
  159. title: '规格型号',
  160. dataIndex: 'ggxh'
  161. },
  162. {
  163. title: '仓库名称',
  164. dataIndex: 'storeName'
  165. },
  166. {
  167. title: '货架号',
  168. dataIndex: 'storePosition'
  169. },
  170. {
  171. title: '批号',
  172. dataIndex: 'cbatch'
  173. },
  174. {
  175. title: '库存数量',
  176. dataIndex: 'num'
  177. },
  178. {
  179. title: '单位',
  180. dataIndex: 'unit'
  181. }
  182. ],
  183. // 下拉框map
  184. tokenType: 1,
  185. searchType: 0,
  186. delFlagMap: {},
  187. // 加载数据方法 必须为 Promise 对象
  188. loadData: parameter => {
  189. parameter = {
  190. ...parameter,
  191. ...this.queryParam,
  192. tokenType: this.tokenType,
  193. purchaseFlag: 1,
  194. dataScope: {
  195. sortBy: 'desc',
  196. sortName: 'update_time'
  197. }
  198. }
  199. if (!this.searchType) {
  200. return getSpareStorePageYY3(Object.assign(parameter, this.queryParam)).then(res => {
  201. if (res.data.rows === null) {
  202. const data = { total: 0, rows: [], pageNum: 1, pageSize: 10, pages: 1 }
  203. return data
  204. } else {
  205. return res.data
  206. }
  207. })
  208. } else {
  209. return getInventoryPage(Object.assign(parameter, this.queryParam)).then(res => {
  210. if (res.data.rows === null) {
  211. const data = { total: 0, rows: [], pageNum: 1, pageSize: 10, pages: 1 }
  212. return data
  213. } else {
  214. return res.data
  215. }
  216. })
  217. }
  218. },
  219. selectedRowKeys: [],
  220. selectedRows: [],
  221. options: {
  222. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  223. rowSelection: {
  224. selectedRowKeys: this.selectedRowKeys,
  225. onChange: this.onSelectChange
  226. }
  227. },
  228. optionAlertShow: false,
  229. isCreated: false
  230. }
  231. },
  232. created () {
  233. // 下拉框map
  234. this.delFlagMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.DELFLAG)
  235. // this.tableOption()
  236. fetchSpareTypeTree({}).then(res => {
  237. this.spareTypeTreeData = res.data
  238. })
  239. fetchStoreTree({}).then(res => {
  240. this.storeTreeDate = res.data
  241. })
  242. },
  243. methods: {
  244. tableOption () {
  245. if (!this.optionAlertShow) {
  246. this.options = {
  247. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  248. rowSelection: {
  249. selectedRowKeys: this.selectedRowKeys,
  250. onChange: this.onSelectChange,
  251. type: this.type,
  252. getCheckboxProps: record => ({
  253. props: {
  254. disabled: false,
  255. name: record.id
  256. }
  257. })
  258. }
  259. // customRow: (record) => {
  260. // return {
  261. // on: { // 事件
  262. // click: (event) => { // 点击行
  263. // // 选择对象
  264. // this.mySelect([record.id], [record])
  265. // },
  266. // dblclick: (event) => {
  267. // this.mySelect([record.id], [record])
  268. // this.handleSelect()
  269. // }
  270. // }
  271. // }
  272. // }
  273. }
  274. this.optionAlertShow = true
  275. } else {
  276. this.options = {
  277. alert: false,
  278. rowSelection: null
  279. }
  280. this.optionAlertShow = false
  281. }
  282. },
  283. handleOk () {
  284. this.$refs.table.refresh()
  285. },
  286. onSelectChange (selectedRowKeys, selectedRows) {
  287. this.selectedRows = [...new Set([...this.selectedRows, ...selectedRows])]
  288. this.selectedRowKeys = selectedRowKeys
  289. },
  290. resetSearchForm () {
  291. this.queryParam = {
  292. storeNo: '09'
  293. }
  294. this.$refs.table.refresh(true)
  295. },
  296. base (record, queryParam = { storeNo: '09' }) {
  297. this.visible = true
  298. this.modalTitle = '选择信息'
  299. this.tokenType = record.tokenType
  300. this.queryParam = queryParam
  301. if (queryParam.isSpecial !== undefined) {
  302. this.isSpecial = queryParam.isSpecial
  303. this.record = record
  304. }
  305. if (this.isCreated) {
  306. this.$refs.table.clearSelected()
  307. // this.options.rowSelection.type = this.type
  308. this.handleOk()
  309. } else {
  310. this.tableOption()
  311. this.isCreated = true
  312. }
  313. },
  314. handleCancel () {
  315. this.visible = false
  316. this.confirmLoading = false
  317. },
  318. handleSelect () {
  319. if (this.selectedRowKeys.length === 0) {
  320. this.$message.warn('请至少选择一项信息')
  321. } else {
  322. /* console.log(this.selectedRows[0].num)
  323. if (this.selectedRows[0].num == 0) {
  324. this.$message.error('不能选择库存为0的物品,请重新选择')
  325. return
  326. } */
  327. this.confirmLoading = true
  328. if (this.record !== null) {
  329. this.record.isSpecial = this.isSpecial
  330. }
  331. this.selectedRows = this.selectedRows.filter(item => this.selectedRowKeys.includes(+item.id))
  332. this.$emit('selected', this.record, this.selectedRowKeys, this.selectedRows)
  333. this.confirmLoading = false
  334. this.visible = false
  335. }
  336. },
  337. // mySelect (selectedRowKeys, selectedRows) {
  338. // this.selectedRowKeys = selectedRowKeys
  339. // this.selectedRows = selectedRows
  340. // console.log(this.selectedRowKeys, this.selectedRows)
  341. // this.$refs.table.updateSelect(this.selectedRowKeys, this.selectedRows)
  342. // this.$refs.table.rowSelection.onChange(this.selectedRowKeys, this.selectedRows)
  343. // },
  344. onSelect: function (selectedKeys, info) {
  345. this.selectedKeys = selectedKeys
  346. this.queryParam.typeId = selectedKeys.length > 0 ? selectedKeys[0] : ''
  347. this.$refs.table.refresh(true)
  348. },
  349. onExpand (expandedKeys) {
  350. this.expandedKeys = expandedKeys
  351. this.autoExpandParent = false
  352. },
  353. handleAdd () {
  354. this.$refs.addSpareForm.base()
  355. }
  356. }
  357. }
  358. </script>