SpareStoreSelectModalYY3.vue 10 KB

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