chooseAddressModal.vue 7.8 KB

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