SpareStoreSelectModalYY3.vue 10 KB

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