chooseCustomerModal.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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="districtSn" style="margin: 0;">
  40. <a-select v-model="queryParam.districtSn" 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. :defaultLoadData="false"
  66. bordered>
  67. </s-table>
  68. <!-- 按钮 -->
  69. <div class="btn-con">
  70. <a-button
  71. type="primary"
  72. id="chooseCustomer-submit"
  73. size="large"
  74. class="button-primary"
  75. style="padding: 0 60px;"
  76. @click="handleSubmit">确定</a-button>
  77. <a-button
  78. id="chooseCustomer-cancel"
  79. size="large"
  80. class="button-cancel"
  81. @click="isShow=false"
  82. style="padding: 0 60px;margin-left: 15px;">取消</a-button>
  83. </div>
  84. </div>
  85. </a-modal>
  86. </template>
  87. <script>
  88. import { STable } from '@/components'
  89. import { getArea } from '@/api/data'
  90. import { dealerQueryList } from '@/api/dealer'
  91. export default {
  92. name: 'ChooseCustomerModal',
  93. components: { STable },
  94. props: {
  95. openModal: { // 弹框显示状态
  96. type: Boolean,
  97. default: false
  98. },
  99. chooseCust: {
  100. type: Array,
  101. default: () => {
  102. return []
  103. }
  104. }
  105. },
  106. data () {
  107. return {
  108. isShow: this.openModal, // 是否打开弹框
  109. disabled: false, // 查询、重置按钮是否可操作
  110. queryParam: {
  111. dealerName: '',
  112. provinceSn: undefined,
  113. citySn: undefined,
  114. districtSn: undefined
  115. },
  116. columns: [
  117. { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
  118. { title: '客户名称', dataIndex: 'dealerName', align: 'center', customRender: function (text) { return text || '--' } }
  119. ],
  120. // 加载数据方法 必须为 Promise 对象
  121. loadData: parameter => {
  122. this.disabled = true
  123. return dealerQueryList(Object.assign(parameter, this.queryParam)).then(res => {
  124. const data = res.data
  125. const no = (data.pageNo - 1) * data.pageSize
  126. for (var i = 0; i < data.list.length; i++) {
  127. data.list[i].no = no + i + 1
  128. }
  129. this.disabled = false
  130. return data
  131. })
  132. },
  133. selectedRowKeys: [],
  134. addrProvinceList: [], // 省下拉
  135. addrCityList: [], // 市下拉
  136. addrDistrictList: [] // 区下拉
  137. }
  138. },
  139. methods: {
  140. // 重置
  141. resetSearchForm () {
  142. this.resetData()
  143. this.$refs.table.refresh(true)
  144. },
  145. resetData () {
  146. console.log('重置艾迪康')
  147. this.queryParam.dealerName = ''
  148. this.queryParam.provinceSn = undefined
  149. this.queryParam.citySn = undefined
  150. this.queryParam.districtSn = undefined
  151. this.addrCityList = []
  152. this.addrDistrictList = []
  153. },
  154. // 确定
  155. handleSubmit () {
  156. if (this.selectedRowKeys.length < 1) {
  157. this.$message.warning('请在列表勾选后再进行操作!')
  158. return
  159. }
  160. this.$emit('ok', this.selectedRowKeys)
  161. this.isShow = false
  162. },
  163. onSelectChange (selectedRowKeys, selectedRows) {
  164. console.log('selectedRowKeys changed: ', selectedRowKeys, selectedRows)
  165. this.selectedRowKeys = selectedRowKeys
  166. },
  167. // 获取城市列表
  168. getCityList (val) {
  169. this.addrCityList = []
  170. this.addrDistrictList = []
  171. this.queryParam.citySn = undefined
  172. this.queryParam.districtSn = undefined
  173. this.getArea('city', val)
  174. },
  175. // 获取区县列表
  176. getAreaList (val) {
  177. this.addrDistrictList = []
  178. this.queryParam.districtSn = undefined
  179. this.getArea('district', val)
  180. },
  181. // 省/市/区
  182. getArea (leve, sn) {
  183. let params
  184. if (leve == 'province') {
  185. params = { type: '2' }
  186. } else {
  187. params = { parentId: sn, type: leve == 'city' ? '3' : '4' }
  188. }
  189. getArea(params).then(res => {
  190. if (res.status == 200) {
  191. if (leve == 'province') {
  192. this.addrProvinceList = res.data || []
  193. } else if (leve == 'city') {
  194. this.addrCityList = res.data || []
  195. } else if (leve == 'district') {
  196. this.addrDistrictList = res.data || []
  197. }
  198. } else {
  199. if (leve == 'province') {
  200. this.addrProvinceList = []
  201. } else if (leve == 'city') {
  202. this.addrCityList = []
  203. } else if (leve == 'district') {
  204. this.addrDistrictList = []
  205. }
  206. }
  207. })
  208. }
  209. },
  210. watch: {
  211. // 父页面传过来的弹框状态
  212. openModal (newValue, oldValue) {
  213. this.isShow = newValue
  214. },
  215. // 重定义的弹框状态
  216. isShow (newValue, oldValue) {
  217. if (!newValue) {
  218. this.$emit('close')
  219. this.resetData()
  220. } else {
  221. this.selectedRowKeys = this.chooseCust
  222. if (this.addrProvinceList.length == 0) {
  223. this.getArea('province')
  224. }
  225. const _this = this
  226. setTimeout(() => {
  227. _this.$refs.table.refresh(true)
  228. }, 200)
  229. }
  230. }
  231. }
  232. }
  233. </script>
  234. <style lang="less" scoped>
  235. .chooseCustomer-modal{
  236. .chooseCustomer-con{
  237. .btn-con{
  238. text-align: center;
  239. margin: 30px 0 20px;
  240. .button-cancel{
  241. font-size: 12px;
  242. }
  243. }
  244. }
  245. }
  246. </style>