chooseSupplierModal.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <template>
  2. <a-modal
  3. centered
  4. class="chooseSupplier-modal"
  5. :footer="null"
  6. :maskClosable="false"
  7. title="选择供应商"
  8. v-model="isShow"
  9. @cancle="isShow=false"
  10. :width="900">
  11. <div class="products-con">
  12. <div>
  13. <!-- 搜索条件 -->
  14. <div class="table-page-search-wrapper">
  15. <a-form-model
  16. layout="inline"
  17. ref="ruleForm"
  18. :model="queryParam"
  19. :rules="rules"
  20. @keyup.enter.native="getSupplierList(1)"
  21. :label-col="formItemLayout.labelCol"
  22. :wrapper-col="formItemLayout.wrapperCol">
  23. <a-row :gutter="15">
  24. <a-col :md="6" :sm="24">
  25. <a-form-model-item label="供应商名称">
  26. <a-input id="chooseSupplier-supplierName" v-model.trim="queryParam.supplierName" allowClear placeholder="请输入供应商名称"/>
  27. </a-form-model-item>
  28. </a-col>
  29. <a-col :md="6" :sm="24">
  30. <a-form-model-item label="状态">
  31. <v-select code="ENABLE_FLAG" id="chooseSupplier-enabledFlag" v-model="queryParam.enabledFlag" allowClear placeholder="请选择状态"></v-select>
  32. </a-form-model-item>
  33. </a-col>
  34. <a-col :md="6" :sm="24" style="margin-bottom: 10px;">
  35. <a-button type="primary" @click="handleSearch" :disabled="disabled" id="chooseSupplier-refresh">查询</a-button>
  36. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="chooseSupplier-reset">重置</a-button>
  37. </a-col>
  38. </a-row>
  39. </a-form-model></a-form>
  40. </div>
  41. <p style="font-weight: bold;">当前已选:{{ selectedRowKeys.length }}个</p>
  42. <!-- 列表 -->
  43. <a-table
  44. class="sTable"
  45. ref="table"
  46. size="small"
  47. :rowKey="(record) => record.supplierSn"
  48. :row-selection="{
  49. selectedRowKeys: selectedRowKeys,
  50. onChange: onChange,
  51. onSelect: onSelectChange,
  52. onSelectAll: onSelectAllChange
  53. }"
  54. :data-source="loadData"
  55. :columns="columns"
  56. :pagination="false"
  57. :loading="loading"
  58. :scroll="{ y: 450 }"
  59. bordered>
  60. </a-table>
  61. <!-- 分页 -->
  62. <tablePagination
  63. ref="tablePagination"
  64. :total="paginationProps.total"
  65. :current="paginationProps.current"
  66. :pageSize="paginationProps.pageSize"
  67. @changePageSize="changePageSize"
  68. @changePage="changePage" />
  69. </div>
  70. <!-- 按钮 -->
  71. <div class="btn-con">
  72. <a-button
  73. type="primary"
  74. id="chooseSupplier-save"
  75. size="large"
  76. class="button-primary"
  77. @click="handleSave"
  78. style="padding: 0 60px;">保存</a-button>
  79. <a-button
  80. id="chooseSupplier-cancel"
  81. size="large"
  82. class="button-cancel"
  83. @click="isShow=false"
  84. style="padding: 0 60px;margin-left: 15px;">取消</a-button>
  85. </div>
  86. </div>
  87. </a-modal>
  88. </template>
  89. <script>
  90. import { STable, VSelect } from '@/components'
  91. import tablePagination from '@/views/common/tablePagination.vue'
  92. import { supplierList } from '@/api/supplier'
  93. export default {
  94. name: 'ChooseSupplierModal',
  95. components: { STable, VSelect, tablePagination },
  96. props: {
  97. openModal: { // 弹框显示状态
  98. type: Boolean,
  99. default: false
  100. },
  101. chooseData: {
  102. type: Array,
  103. default: () => {
  104. return []
  105. }
  106. },
  107. dealerSn: {
  108. type: String || Number,
  109. default: ''
  110. }
  111. },
  112. data () {
  113. return {
  114. isShow: this.openModal, // 是否打开弹框
  115. formItemLayout: {
  116. labelCol: { span: 4 },
  117. wrapperCol: { span: 20 }
  118. },
  119. queryParam: { // 查询条件
  120. supplierName: '',
  121. enabledFlag: undefined
  122. },
  123. rules: {},
  124. disabled: false, // 查询、重置按钮是否可操作
  125. loading: false, // 表格加载中
  126. columns: [
  127. { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
  128. { title: '供应商名称', dataIndex: 'supplierName', align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } },
  129. { title: '状态', dataIndex: 'enableFlagDictValue', align: 'center', customRender: function (text) { return text || '--' } }
  130. ],
  131. loadData: [],
  132. paginationProps: {
  133. total: 0, // 分页总条数
  134. current: 1,
  135. pageSize: 20
  136. },
  137. selectedRowKeys: [],
  138. selectedRows: []
  139. }
  140. },
  141. methods: {
  142. // 查询
  143. handleSearch () {
  144. const _this = this
  145. _this.$refs.ruleForm.validate(valid => {
  146. if (valid) {
  147. _this.getSupplierList(1)
  148. } else {
  149. return false
  150. }
  151. })
  152. },
  153. // 重置数据
  154. resetData () {
  155. this.queryParam.supplierName = ''
  156. this.queryParam.enabledFlag = undefined
  157. this.paginationProps.total = 0
  158. this.paginationProps.total = 0
  159. this.paginationProps.current = 1
  160. this.paginationProps.pageSize = 20
  161. },
  162. // 重置
  163. resetSearchForm () {
  164. this.resetData()
  165. this.loadData = []
  166. this.disabled = false
  167. },
  168. // 保存
  169. handleSave () {
  170. if (this.selectedRowKeys.length < 1) {
  171. this.$message.warning('请在列表勾选后再进行操作!')
  172. return
  173. }
  174. this.$emit('ok', this.selectedRows)
  175. this.isShow = false
  176. },
  177. onChange (selectedRowKeys, selectedRows) {
  178. this.selectedRowKeys = selectedRowKeys
  179. },
  180. onSelectChange (record, selected, selectedRows, nativeEvent) {
  181. const _this = this
  182. if (selected) { // 选择
  183. this.selectedRows.push(record)
  184. } else { // 取消
  185. this.selectedRows.map((item, index) => {
  186. if (item.supplierSn == record.supplierSn) {
  187. _this.selectedRows.splice(index, 1)
  188. }
  189. })
  190. }
  191. },
  192. // 本页全选/取消全选
  193. onSelectAllChange (selected, selectedRows, changeRows) {
  194. const _this = this
  195. if (selected) { // 选择
  196. this.selectedRows = [...this.selectedRows, ...changeRows]
  197. } else { // 取消
  198. this.selectedRows.map((item, index) => {
  199. this.selectedRows.map((subItem, ind) => {
  200. if (item.supplierSn == subItem.supplierSn) {
  201. _this.selectedRows.splice(index, 1)
  202. }
  203. })
  204. })
  205. }
  206. },
  207. // 供应商列表
  208. getSupplierList (pageNo) {
  209. this.paginationProps.current = pageNo || this.paginationProps.current
  210. this.disabled = true
  211. const params = {
  212. pageNo: this.paginationProps.current,
  213. pageSize: this.paginationProps.pageSize
  214. }
  215. this.loading = true
  216. supplierList(Object.assign(params, this.queryParam)).then(res => {
  217. this.loading = false
  218. if (res.status == 200) {
  219. const data = res.data
  220. this.paginationProps.total = Number(res.data.count) || 0
  221. this.paginationProps.current = data.pageNo
  222. const no = (data.pageNo - 1) * data.pageSize
  223. for (var i = 0; i < data.list.length; i++) {
  224. data.list[i].no = no + i + 1
  225. }
  226. this.loadData = data.list
  227. this.disabled = false
  228. } else {
  229. this.paginationProps.total = 0
  230. this.paginationProps.current = 1
  231. this.paginationProps.pageSize = 20
  232. this.loadData = []
  233. }
  234. })
  235. },
  236. // 已选产品 分页 一页多少条change
  237. changePageSize (current, pageSize) {
  238. this.paginationProps.current = current
  239. this.paginationProps.pageSize = pageSize
  240. this.getSupplierList()
  241. },
  242. // 已选产品 分页 页码change
  243. changePage (current) {
  244. this.paginationProps.current = current
  245. this.getSupplierList()
  246. }
  247. },
  248. watch: {
  249. // 父页面传过来的弹框状态
  250. openModal (newValue, oldValue) {
  251. this.isShow = newValue
  252. },
  253. // 重定义的弹框状态
  254. isShow (newValue, oldValue) {
  255. if (!newValue) {
  256. this.$emit('close')
  257. this.loadData = []
  258. this.disabled = false
  259. this.resetData()
  260. } else {
  261. this.getSupplierList(1)
  262. this.selectedRows = this.chooseData
  263. this.selectedRowKeys = []
  264. this.chooseData.map(item => {
  265. this.selectedRowKeys.push(item.rangeDataSn)
  266. })
  267. }
  268. }
  269. }
  270. }
  271. </script>
  272. <style lang="less" scoped>
  273. .chooseSupplier-modal{
  274. .products-con{
  275. .btn-con{
  276. text-align: center;
  277. margin: 30px 0 20px;
  278. .button-cancel{
  279. font-size: 12px;
  280. }
  281. }
  282. }
  283. }
  284. </style>