chooseAddressModal.vue 7.1 KB

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