chooseAddressModal.vue 6.4 KB

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