chooseAddressModal.vue 7.5 KB

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