chooseSupplier.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <template>
  2. <a-spin :spinning="spinning" tip="Loading...">
  3. <!-- 搜索条件 -->
  4. <div ref="tableSearch" class="table-page-search-wrapper newTableSearchName">
  5. <a-form layout="inline" id="chooseSupplier-form" @keyup.enter.native="$refs.table.refresh(true)">
  6. <a-row :gutter="15">
  7. <a-col :md="8" :sm="24">
  8. <a-form-item label="供应商名称">
  9. <a-input id="chooseSupplier-nameLike" v-model.trim="queryParam.supplier.supplierName" allowClear placeholder="请输入供应商名称"/>
  10. </a-form-item>
  11. </a-col>
  12. <a-col :md="8" :sm="24" style="margin-bottom: 10px;">
  13. <a-button type="primary" @click="searchForm(true)" :disabled="disabled" id="chooseSupplier-refresh">查询</a-button>
  14. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="chooseSupplier-reset">重置</a-button>
  15. </a-col>
  16. </a-row>
  17. </a-form>
  18. <!-- 操作按钮 -->
  19. <div style="margin-bottom: 10px">
  20. <a-button type="primary" ghost :loading="loading" id="chooseSupplier-add" @click="handleBatchAudit">批量添加</a-button>
  21. <span style="margin-left: 5px">
  22. <template v-if="selectCount"> {{ `已选 ${selectCount} 项` }} </template>
  23. </span>
  24. </div>
  25. </div>
  26. <!-- 列表 -->
  27. <s-table
  28. class="sTable"
  29. ref="table"
  30. size="small"
  31. :rowKey="(record) => record.supplierSn"
  32. rowKeyName="supplierSn"
  33. :row-selection="{ columnWidth: 40}"
  34. @rowSelection="rowSelectionFun"
  35. :columns="columns"
  36. :data="loadData"
  37. :style="{ height:tableHeight-15+'px' }"
  38. :scroll="{ y:tableHeight+80 }"
  39. :defaultLoadData="false"
  40. bordered>
  41. </s-table>
  42. </a-spin>
  43. </template>
  44. <script>
  45. import { commonMixin } from '@/utils/mixin'
  46. // 组件
  47. import { STable, VSelect } from '@/components'
  48. import AreaList from '@/views/common/areaList.js'
  49. import subarea from '@/views/common/subarea.js'
  50. // 接口
  51. import { querySupplierPage } from '@/api/bizuser'
  52. export default {
  53. name: 'ChooseSupplier',
  54. mixins: [commonMixin],
  55. components: { STable, VSelect, subarea, AreaList },
  56. data () {
  57. return {
  58. spinning: false,
  59. tableHeight: 0, // 表格高度
  60. disabled: false, // 查询、重置按钮是否可操作
  61. loading: false, // 批量添加loading
  62. // 查询条件
  63. queryParam: {
  64. supplier: {
  65. supplierName: ''// 供应商名称
  66. }
  67. },
  68. userSn: '', // 用户sn
  69. pageFlag: false, // 是否显示选择框
  70. chooseInfo: [], // 选中数据
  71. // 加载数据方法 必须为 Promise 对象
  72. loadData: parameter => {
  73. this.spinning = true
  74. this.queryParam.userSn = this.userSn
  75. // 获取列表数据 有分页
  76. return querySupplierPage(Object.assign(parameter, this.queryParam)).then(res => {
  77. let data
  78. const _this = this
  79. if (res.status == 200) {
  80. data = res.data
  81. // 计算表格序号
  82. const no = 0
  83. const chooseData = []
  84. for (var i = 0; i < data.list.length; i++) {
  85. data.list[i].no = no + i + 1
  86. data.list[i].supplierSn = data.list[i].supplier.supplierSn
  87. if (_this.chooseInfo && _this.chooseInfo.length > 0) {
  88. // 回显选中数据
  89. const flag = _this.chooseInfo.includes(data.list[i].supplier.supplierSn)
  90. if (flag) {
  91. chooseData.push(data.list[i])
  92. }
  93. }
  94. }
  95. if (!_this.pageFlag) {
  96. _this.$refs.table.setTableSelected(_this.chooseInfo, chooseData) // 设置表格选中项
  97. _this.pageFlag = true
  98. }
  99. }
  100. _this.spinning = false
  101. return data
  102. })
  103. },
  104. rowSelectionInfo: null// 列表选择数据
  105. }
  106. },
  107. computed: {
  108. columns () {
  109. const arr = [
  110. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  111. { title: '供应商名称', dataIndex: 'supplier.supplierName', width: '96%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true }
  112. // { title: '联系人', dataIndex: 'supplier.contact', align: 'left', width: '26%', customRender: function (text) { return text || '--' }, ellipsis: true },
  113. // { title: '联系电话', dataIndex: 'supplier.contactMobile', width: '20%', align: 'center', customRender: function (text) { return text || '--' } }
  114. ]
  115. return arr
  116. },
  117. // 计算列表选中数据条数
  118. selectCount () {
  119. return this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys.length
  120. }
  121. },
  122. methods: {
  123. // 表格选中项
  124. rowSelectionFun (obj) {
  125. this.rowSelectionInfo = obj || null
  126. },
  127. // 地区
  128. areaChange (val) {
  129. this.queryParam.provinceSn = val[0] ? val[0] : ''
  130. this.queryParam.citySn = val[1] ? val[1] : ''
  131. this.queryParam.districtSn = val[2] ? val[2] : ''
  132. },
  133. // 查询
  134. searchForm (flag) {
  135. this.$refs.table.refresh(flag)
  136. this.spinning = false
  137. },
  138. // 区域分区
  139. subareaChange (val) {
  140. this.queryParam.subareaSn = val[0] ? val[0] : undefined
  141. this.queryParam.subareaAreaSn = val[1] ? val[1] : undefined
  142. },
  143. // 重置
  144. resetSearchForm () {
  145. this.queryParam = {
  146. supplier: {
  147. supplierName: ''
  148. }
  149. }
  150. this.$refs.table.clearSelected()
  151. this.$refs.table.refresh(true)
  152. this.pageFlag = false
  153. },
  154. // 清除表格内容
  155. clearTable () {
  156. this.rowSelectionInfo = null
  157. this.$refs.table.clearTable()
  158. },
  159. // 批量添加
  160. handleBatchAudit () {
  161. const _this = this
  162. if (!_this.rowSelectionInfo || (_this.rowSelectionInfo && _this.rowSelectionInfo.selectedRowKeys.length < 1)) {
  163. _this.$message.warning('请在列表勾选后再进行批量操作!')
  164. return
  165. }
  166. const supplierSnList = _this.rowSelectionInfo.selectedRowKeys
  167. this.spinning = false
  168. this.$emit('plAdd', supplierSnList)
  169. },
  170. // 添加
  171. handleAdd (row) {
  172. if (row.subareaArea) {
  173. const _this = this
  174. this.$confirm({
  175. title: '提示',
  176. content: '当前经销商已被其他区域分区绑定,确定要更新绑定关系吗?',
  177. centered: true,
  178. onOk () {
  179. _this.spinning = true
  180. _this.$emit('add', row)
  181. }
  182. })
  183. } else {
  184. this.spinning = true
  185. this.$emit('add', row)
  186. }
  187. },
  188. // 初始化
  189. pageInit (data) {
  190. const _this = this
  191. this.$nextTick(() => { // 页面渲染完成后的回调
  192. _this.setTableH()
  193. })
  194. this.chooseInfo = data.list ? data.list : []
  195. this.userSn = data.sn
  196. this.resetSearchForm()
  197. this.pageFlag = false
  198. },
  199. // 计算表格高度
  200. setTableH () {
  201. const tableSearchH = this.$refs.tableSearch.offsetHeight
  202. this.tableHeight = window.innerHeight - tableSearchH - 300
  203. }
  204. },
  205. watch: {
  206. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  207. this.setTableH()
  208. }
  209. }
  210. }
  211. </script>