chooseSupplierModal.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. <a-spin :spinning="spinning" tip="Loading...">
  12. <div class="products-con">
  13. <div>
  14. <!-- 搜索条件 -->
  15. <div class="table-page-search-wrapper">
  16. <a-form-model
  17. ref="ruleForm"
  18. class="form-model-con"
  19. layout="inline"
  20. :model="queryParam"
  21. :rules="rules"
  22. @keyup.enter.native="$refs.table.refresh(true)"
  23. :label-col="formItemLayout.labelCol"
  24. :wrapper-col="formItemLayout.wrapperCol">
  25. <a-row :gutter="15">
  26. <a-col :md="6" :sm="24">
  27. <a-form-model-item label="供应商名称">
  28. <a-input id="chooseSupplier-supplierName" v-model.trim="queryParam.supplierName" allowClear placeholder="请输入供应商名称"/>
  29. </a-form-model-item>
  30. </a-col>
  31. <a-col :md="6" :sm="24">
  32. <a-form-model-item label="状态">
  33. <v-select code="ENABLE_FLAG" id="chooseSupplier-enabledFlag" v-model="queryParam.enabledFlag" allowClear placeholder="请选择状态"></v-select>
  34. </a-form-model-item>
  35. </a-col>
  36. <a-col :md="6" :sm="24" style="margin-bottom: 10px;">
  37. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="chooseSupplier-refresh">查询</a-button>
  38. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="chooseSupplier-reset">重置</a-button>
  39. </a-col>
  40. </a-row>
  41. </a-form-model>
  42. </div>
  43. <p style="font-weight: bold;">当前已选:{{ rowSelectionInfo&&rowSelectionInfo.selectedRowKeys.length }}个</p>
  44. <!-- 列表 -->
  45. <s-table
  46. class="sTable"
  47. ref="table"
  48. size="small"
  49. :rowKey="(record) => record.supplierSn"
  50. rowKeyName="supplierSn"
  51. :row-selection="{ columnWidth: 40 }"
  52. @rowSelection="rowSelectionFun"
  53. :columns="columns"
  54. :data="loadData"
  55. :scroll="{ y: 450 }"
  56. :defaultLoadData="false"
  57. bordered>
  58. </s-table>
  59. </div>
  60. <!-- 按钮 -->
  61. <div class="btn-con">
  62. <a-button
  63. type="primary"
  64. id="chooseSupplier-save"
  65. size="large"
  66. class="button-primary"
  67. @click="handleSave"
  68. style="padding: 0 60px;">保存</a-button>
  69. <a-button
  70. id="chooseSupplier-cancel"
  71. size="large"
  72. class="button-cancel"
  73. @click="isShow=false"
  74. style="padding: 0 60px;margin-left: 15px;">取消</a-button>
  75. </div>
  76. </div>
  77. </a-spin>
  78. </a-modal>
  79. </template>
  80. <script>
  81. import { STable, VSelect } from '@/components'
  82. import { supplierList } from '@/api/supplier'
  83. export default {
  84. name: 'ChooseSupplierModal',
  85. components: { STable, VSelect },
  86. props: {
  87. openModal: { // 弹框显示状态
  88. type: Boolean,
  89. default: false
  90. },
  91. chooseData: {
  92. type: Array,
  93. default: () => {
  94. return []
  95. }
  96. },
  97. dealerSn: {
  98. type: String || Number,
  99. default: ''
  100. }
  101. },
  102. data () {
  103. return {
  104. spinning: false,
  105. isShow: this.openModal, // 是否打开弹框
  106. formItemLayout: {
  107. labelCol: { span: 4 },
  108. wrapperCol: { span: 20 }
  109. },
  110. queryParam: { // 查询条件
  111. supplierName: '',
  112. enabledFlag: undefined
  113. },
  114. rules: {},
  115. disabled: false, // 查询、重置按钮是否可操作
  116. columns: [
  117. { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
  118. { title: '供应商名称', dataIndex: 'supplierName', align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } },
  119. { title: '状态', dataIndex: 'enableFlagDictValue', align: 'center', customRender: function (text) { return text || '--' } }
  120. ],
  121. // 加载数据方法 必须为 Promise 对象
  122. loadData: parameter => {
  123. this.disabled = true
  124. this.spinning = true
  125. return supplierList(Object.assign(parameter, this.queryParam)).then(res => {
  126. let data
  127. if (res.status == 200) {
  128. data = res.data
  129. const no = (data.pageNo - 1) * data.pageSize
  130. for (var i = 0; i < data.list.length; i++) {
  131. data.list[i].no = no + i + 1
  132. }
  133. this.disabled = false
  134. }
  135. this.spinning = false
  136. return data
  137. })
  138. },
  139. rowSelectionInfo: null
  140. }
  141. },
  142. methods: {
  143. // 表格选中项
  144. rowSelectionFun (obj) {
  145. this.rowSelectionInfo = obj || null
  146. },
  147. // 重置
  148. resetSearchForm () {
  149. this.queryParam.supplierName = ''
  150. this.queryParam.enabledFlag = undefined
  151. this.$refs.table.refresh(true)
  152. },
  153. // 保存
  154. handleSave () {
  155. if (!this.rowSelectionInfo || (this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys.length < 1)) {
  156. this.$message.warning('请在列表勾选后再进行操作!')
  157. return
  158. }
  159. this.$emit('ok', this.rowSelectionInfo && this.rowSelectionInfo.selectedRows)
  160. this.isShow = false
  161. }
  162. },
  163. watch: {
  164. // 父页面传过来的弹框状态
  165. openModal (newValue, oldValue) {
  166. this.isShow = newValue
  167. },
  168. // 重定义的弹框状态
  169. isShow (newValue, oldValue) {
  170. if (!newValue) {
  171. this.$emit('close')
  172. this.resetSearchForm()
  173. } else {
  174. const _this = this
  175. const selectedRowKeys = []
  176. this.chooseData.map(item => {
  177. selectedRowKeys.push(item.rangeDataSn)
  178. })
  179. this.$nextTick(() => { // 页面渲染完成后的回调
  180. _this.$refs.table.refresh(true)
  181. _this.$refs.table.setTableSelected(selectedRowKeys, _this.chooseData) // 设置表格选中项
  182. })
  183. }
  184. }
  185. }
  186. }
  187. </script>
  188. <style lang="less" scoped>
  189. .chooseSupplier-modal{
  190. .products-con{
  191. .btn-con{
  192. text-align: center;
  193. margin: 30px 0 20px;
  194. .button-cancel{
  195. font-size: 12px;
  196. }
  197. }
  198. }
  199. }
  200. </style>