chooseCustomerModal.vue 5.9 KB

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