chooseCustomerModal.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <a-modal
  3. centered
  4. class="chooseCustomer-modal"
  5. :footer="null"
  6. :maskClosable="false"
  7. title="选择客户"
  8. v-model="isShow"
  9. @cancle="isShow=false"
  10. :width="900">
  11. <div class="chooseCustomer-con">
  12. <!-- 搜索条件 -->
  13. <div class="table-page-search-wrapper">
  14. <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
  15. <a-row :gutter="15">
  16. <a-col :md="6" :sm="24">
  17. <a-form-item label="客户名称">
  18. <a-input id="chooseCustomer-dealerName" v-model.trim="queryParam.dealerName" allowClear placeholder="请输入客户名称"/>
  19. </a-form-item>
  20. </a-col>
  21. <a-col :md="12" :sm="24">
  22. <a-row>
  23. <a-form-item label="地区">
  24. <a-col span="7">
  25. <a-form-item prop="provinceSn" style="margin: 0;">
  26. <a-select v-model="queryParam.provinceSn" @change="getCityList" placeholder="请选择省">
  27. <a-select-option v-for="item in addrProvinceList" :value="item.id" :key="item.id + 'a'">{{ item.name }}</a-select-option>
  28. </a-select>
  29. </a-form-item>
  30. </a-col>
  31. <a-col span="7" offset="1">
  32. <a-form-item prop="citySn" style="margin: 0;">
  33. <a-select v-model="queryParam.citySn" @change="getAreaList" placeholder="请选择市">
  34. <a-select-option v-for="item in addrCityList" :value="item.id" :key="item.id + 'b'">{{ item.name }}</a-select-option>
  35. </a-select>
  36. </a-form-item>
  37. </a-col>
  38. <a-col span="7" offset="1">
  39. <a-form-item prop="countySn" style="margin: 0;">
  40. <a-select v-model="queryParam.countySn" placeholder="请选择区/县">
  41. <a-select-option v-for="item in addrDistrictList" :value="item.id" :key="item.id + 'c'">{{ item.name }}</a-select-option>
  42. </a-select>
  43. </a-form-item>
  44. </a-col>
  45. </a-form-item>
  46. </a-row>
  47. </a-col>
  48. <a-col :md="6" :sm="24">
  49. <a-button style="margin-bottom: 18px;" type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="promotionRulesList-refresh">查询</a-button>
  50. <a-button style="margin: 0 0 18px 8px" @click="resetSearchForm" :disabled="disabled" id="promotionRulesList-reset">重置</a-button>
  51. </a-col>
  52. </a-row>
  53. </a-form>
  54. </div>
  55. <p style="font-weight: bold;">当前已选:{{ selectedRowKeys.length }}个</p>
  56. <!-- 列表 -->
  57. <s-table
  58. class="sTable"
  59. ref="table"
  60. size="small"
  61. :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
  62. :rowKey="(record) => record.id"
  63. :columns="columns"
  64. :data="loadData"
  65. bordered>
  66. </s-table>
  67. <!-- 按钮 -->
  68. <div class="btn-con">
  69. <a-button
  70. type="primary"
  71. id="chooseCustomer-submit"
  72. size="large"
  73. class="button-primary"
  74. style="padding: 0 60px;"
  75. @click="handleSubmit">确定</a-button>
  76. <a-button
  77. id="chooseCustomer-cancel"
  78. size="large"
  79. class="button-cancel"
  80. @click="isShow=false"
  81. style="padding: 0 60px;margin-left: 15px;">取消</a-button>
  82. </div>
  83. </div>
  84. </a-modal>
  85. </template>
  86. <script>
  87. import { STable } from '@/components'
  88. import { getArea } from '@/api/data'
  89. import { dealerQueryList } from '@/api/dealer'
  90. export default {
  91. name: 'ChooseCustomerModal',
  92. components: { STable },
  93. props: {
  94. openModal: { // 弹框显示状态
  95. type: Boolean,
  96. default: false
  97. },
  98. chooseCust: {
  99. type: Array,
  100. default: () => {
  101. return []
  102. }
  103. }
  104. },
  105. data () {
  106. return {
  107. isShow: this.openModal, // 是否打开弹框
  108. disabled: false, // 查询、重置按钮是否可操作
  109. queryParam: {
  110. dealerName: '',
  111. provinceSn: undefined,
  112. citySn: undefined,
  113. districtSn: undefined
  114. },
  115. columns: [
  116. { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
  117. { title: '客户名称', dataIndex: 'dealerName', align: 'center', customRender: function (text) { return text || '--' } }
  118. ],
  119. // 加载数据方法 必须为 Promise 对象
  120. loadData: parameter => {
  121. this.disabled = true
  122. return dealerQueryList(Object.assign(parameter, this.queryParam)).then(res => {
  123. const data = res.data
  124. const no = (data.pageNo - 1) * data.pageSize
  125. for (var i = 0; i < data.list.length; i++) {
  126. data.list[i].no = no + i + 1
  127. }
  128. this.disabled = false
  129. return data
  130. })
  131. },
  132. selectedRowKeys: [],
  133. addrProvinceList: [], // 省下拉
  134. addrCityList: [], // 市下拉
  135. addrDistrictList: [] // 区下拉
  136. }
  137. },
  138. methods: {
  139. // 重置
  140. resetSearchForm () {
  141. this.queryParam.dealerName = ''
  142. this.queryParam.provinceSn = undefined
  143. this.queryParam.citySn = undefined
  144. this.queryParam.districtSn = undefined
  145. this.$refs.table.refresh(true)
  146. },
  147. // 确定
  148. handleSubmit () {
  149. if (this.selectedRowKeys.length < 1) {
  150. this.$message.warning('请在列表勾选后再进行操作!')
  151. return
  152. }
  153. this.$emit('ok', this.selectedRowKeys)
  154. this.isShow = false
  155. },
  156. onSelectChange (selectedRowKeys, selectedRows) {
  157. console.log('selectedRowKeys changed: ', selectedRowKeys, selectedRows)
  158. this.selectedRowKeys = selectedRowKeys
  159. },
  160. // 获取城市列表
  161. getCityList (val) {
  162. this.addrCityList = []
  163. this.addrDistrictList = []
  164. this.queryParam.citySn = undefined
  165. this.queryParam.districtSn = undefined
  166. this.getArea('city', val)
  167. },
  168. // 获取区县列表
  169. getAreaList (val) {
  170. this.addrDistrictList = []
  171. this.queryParam.districtSn = undefined
  172. this.getArea('district', val)
  173. },
  174. // 省/市/区
  175. getArea (type, sn) {
  176. let params
  177. if (type == 'province') {
  178. params = { level: '1' }
  179. } else {
  180. params = { psn: sn }
  181. }
  182. getArea(params).then(res => {
  183. if (res.status == 200) {
  184. if (type == 'province') {
  185. this.addrProvinceList = res.data || []
  186. } else if (type == 'city') {
  187. this.addrCityList = res.data || []
  188. } else if (type == 'district') {
  189. this.addrDistrictList = res.data || []
  190. }
  191. } else {
  192. if (type == 'province') {
  193. this.addrProvinceList = []
  194. } else if (type == 'city') {
  195. this.addrCityList = []
  196. } else if (type == 'district') {
  197. this.addrDistrictList = []
  198. }
  199. }
  200. })
  201. }
  202. },
  203. watch: {
  204. // 父页面传过来的弹框状态
  205. openModal (newValue, oldValue) {
  206. this.isShow = newValue
  207. },
  208. // 重定义的弹框状态
  209. isShow (newValue, oldValue) {
  210. if (!newValue) {
  211. this.$emit('close')
  212. } else {
  213. this.selectedRowKeys = this.chooseCust
  214. if (this.addrProvinceList.length == 0) {
  215. this.getArea('province')
  216. }
  217. }
  218. }
  219. }
  220. }
  221. </script>
  222. <style lang="less" scoped>
  223. .chooseCustomer-modal{
  224. .chooseCustomer-con{
  225. .btn-con{
  226. text-align: center;
  227. margin: 30px 0 20px;
  228. .button-cancel{
  229. font-size: 12px;
  230. }
  231. }
  232. }
  233. }
  234. </style>