chooseAddressModal.vue 7.5 KB

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