chooseAddressModal.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <template>
  2. <a-modal
  3. centered
  4. class="chooseAddressList-modal"
  5. :footer="null"
  6. :maskClosable="false"
  7. title="收货地址"
  8. v-model="isShow"
  9. @cancel="isShow=false"
  10. :width="960">
  11. <a-spin :spinning="spinning" tip="Loading...">
  12. <!-- 操作按钮 -->
  13. <div class="table-operator">
  14. <a-button id="chooseAddressList-add" type="primary" class="button-error" @click="handleEdit()">新增</a-button>
  15. </div>
  16. <!-- 列表 -->
  17. <s-table
  18. class="sTable"
  19. ref="table"
  20. size="small"
  21. :rowKey="(record) => record.id"
  22. :columns="columns"
  23. :data="loadData"
  24. :showPagination="false"
  25. :defaultLoadData="false"
  26. bordered>
  27. <!-- 收货人 -->
  28. <template slot="consignee" slot-scope="text, record">
  29. <div class="item-box">
  30. <a-tooltip placement="top">
  31. <template slot="title">
  32. <span>{{ record.consigneeName }}</span>
  33. </template>
  34. <p class="ellipsis-txt">{{ record.consigneeName }}</p>
  35. </a-tooltip>
  36. <span v-if="record.defaultFlag==1" class="badge-txt">默认</span>
  37. </div>
  38. </template>
  39. <!-- 操作 -->
  40. <template slot="action" slot-scope="text, record">
  41. <a-button
  42. size="small"
  43. type="primary"
  44. class="button-success"
  45. v-if="record.defaultFlag!=1"
  46. @click="handleDefault(record)"
  47. id="chooseAddressList-default-btn">设为默认</a-button>
  48. <a-button
  49. size="small"
  50. type="primary"
  51. class="button-info"
  52. @click="handleEdit(record)"
  53. id="chooseAddressList-edit-btn"
  54. >编辑</a-button>
  55. <a-button
  56. size="small"
  57. type="primary"
  58. class="button-error"
  59. @click="handleDel(record)"
  60. id="chooseAddressList-del-btn"
  61. >删除</a-button>
  62. </template>
  63. <!-- 选择 -->
  64. <template slot="choose" slot-scope="text, record">
  65. <a-button
  66. size="small"
  67. type="primary"
  68. class="button-primary"
  69. @click="handleChoose(record)"
  70. id="chooseAddressList-choose-btn">选择</a-button>
  71. </template>
  72. </s-table>
  73. </a-spin>
  74. <!-- 新增/编辑地址 -->
  75. <edit-address-modal ref="addrModal" :openModal="openAddrModal" :paramsData="paramsData" @ok="handleOk" @close="openAddrModal=false" />
  76. </a-modal>
  77. </template>
  78. <script>
  79. import { STable, VSelect } from '@/components'
  80. import editAddressModal from './editAddressModal'
  81. import { dealerRecevieAddrQuery, dealerRecevieAddrSet, dealerRecevieAddrDel } from '@/api/dealerRecevieAddr'
  82. export default {
  83. name: 'ChooseAddressModal',
  84. components: { STable, VSelect, editAddressModal },
  85. props: {
  86. openModal: { // 弹框显示状态
  87. type: Boolean,
  88. default: false
  89. },
  90. paramsData: {
  91. type: String || Number,
  92. default: ''
  93. }
  94. },
  95. data () {
  96. return {
  97. spinning: false,
  98. isShow: this.openModal, // 是否打开弹框
  99. // 表头
  100. columns: [
  101. { title: '序号', dataIndex: 'no', width: 50, align: 'center' },
  102. { title: '收货人', scopedSlots: { customRender: 'consignee' }, align: 'center', ellipsis: true },
  103. { title: '手机号码', dataIndex: 'consigneeTel', width: 230, align: 'center', customRender: function (text) { return text || '--' } },
  104. { title: '收货地址', dataIndex: 'address', width: 400, align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  105. // { title: '操作', scopedSlots: { customRender: 'action' }, width: 200, align: 'center', fixed: 'right' },
  106. { title: '选择', scopedSlots: { customRender: 'choose' }, width: 80, align: 'center', fixed: 'right' }
  107. ],
  108. // 加载数据方法 必须为 Promise 对象
  109. loadData: parameter => {
  110. this.disabled = true
  111. return dealerRecevieAddrQuery({ dealerSn: this.paramsData }).then(res => {
  112. const data = res.data
  113. const no = 0
  114. for (var i = 0; i < data.length; i++) {
  115. data[i].no = no + i + 1
  116. const provinceName = data[i].provinceName ? (data[i].provinceName + '-') : ''
  117. const cityName = data[i].cityName ? (data[i].cityName + '-') : ''
  118. const countyName = data[i].countyName ? (data[i].countyName + '-') : ''
  119. const addr = data[i].addr || ''
  120. data[i].address = provinceName + cityName + countyName + addr
  121. }
  122. this.disabled = false
  123. return data
  124. })
  125. },
  126. openAddrModal: false // 选择地址弹框是否显示
  127. }
  128. },
  129. methods: {
  130. // 设为默认
  131. handleDefault (row) {
  132. this.spinning = true
  133. dealerRecevieAddrSet({ id: row.id }).then(res => {
  134. if (res.status == 200) {
  135. this.$message.success(res.message)
  136. this.$refs.table.refresh(true)
  137. this.spinning = false
  138. } else {
  139. this.spinning = false
  140. }
  141. })
  142. },
  143. // 新增/编辑收货地址
  144. handleEdit (row) {
  145. if (row) {
  146. this.$refs.addrModal.setData({
  147. id: row.id,
  148. consigneeName: row.consigneeName,
  149. consigneeTel: row.consigneeTel,
  150. provinceSn: row.provinceSn,
  151. provinceName: row.provinceName,
  152. citySn: row.citySn,
  153. cityName: row.cityName,
  154. countySn: row.countySn,
  155. countyName: row.countyName,
  156. addr: row.addr
  157. })
  158. }
  159. this.openAddrModal = true
  160. },
  161. // 选择
  162. handleChoose (row) {
  163. this.$emit('ok', row)
  164. },
  165. // 删除
  166. handleDel (row) {
  167. const _this = this
  168. this.$confirm({
  169. title: '提示',
  170. content: '删除后不可恢复,确定要进行删除吗?',
  171. centered: true,
  172. onOk () {
  173. _this.spinning = true
  174. dealerRecevieAddrDel({
  175. id: row.id
  176. }).then(res => {
  177. if (res.status == 200) {
  178. _this.$message.success(res.message)
  179. _this.$emit('verify', row.id)
  180. _this.$refs.table.refresh(true)
  181. _this.spinning = false
  182. } else {
  183. _this.spinning = false
  184. }
  185. })
  186. }
  187. })
  188. },
  189. // 地址保存成功
  190. handleOk (data) {
  191. this.$refs.table.refresh(true)
  192. }
  193. },
  194. watch: {
  195. // 父页面传过来的弹框状态
  196. openModal (newValue, oldValue) {
  197. this.isShow = newValue
  198. },
  199. // 重定义的弹框状态
  200. isShow (newValue, oldValue) {
  201. if (!newValue) {
  202. this.$emit('close')
  203. } else {
  204. const _this = this
  205. setTimeout(() => {
  206. _this.$refs.table.refresh(true)
  207. }, 300)
  208. }
  209. }
  210. }
  211. }
  212. </script>
  213. <style lang="less">
  214. .chooseAddressList-modal{
  215. .table-operator{
  216. margin-bottom: 10px;
  217. }
  218. .item-box{
  219. position: relative;
  220. display: flex;
  221. align-items: center;
  222. .ellipsis-txt{
  223. margin: 0;
  224. width: 100%;
  225. overflow: hidden;
  226. text-overflow:ellipsis;
  227. whitewhite-space: nowrap;
  228. }
  229. .badge-txt{
  230. line-height: 20px;
  231. padding: 0 7px;
  232. font-size: 12px;
  233. background-color: #fff;
  234. color: #ed1c24;
  235. border-color: #ed1c24;
  236. border-radius: 20px;
  237. box-shadow: 0 0 0 1px #d9d9d9 inset;
  238. }
  239. }
  240. }
  241. </style>