chooseAddressModal.vue 7.7 KB

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