chooseAddressModal.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. v-if="record.readOnlyFlag!=1"
  54. @click="handleEdit(record)"
  55. id="chooseAddressList-edit-btn"
  56. >编辑</a-button>
  57. <a-button
  58. size="small"
  59. type="primary"
  60. class="button-error"
  61. v-if="record.readOnlyFlag!=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="primary"
  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 { STable, VSelect } from '@/components'
  84. import editAddressModal from './editAddressModal'
  85. import { shippingAddressQuery, shippingAddressSet, shippingAddressDel } from '@/api/shippingAddress.js'
  86. export default {
  87. name: 'ChooseAddressModal',
  88. components: { STable, VSelect, editAddressModal },
  89. props: {
  90. openModal: { // 弹框显示状态
  91. type: Boolean,
  92. default: false
  93. }
  94. },
  95. data () {
  96. return {
  97. spinning: false,
  98. isShow: this.openModal, // 是否打开弹框
  99. queryParam: {},
  100. // 表头
  101. columns: [
  102. { title: '序号', dataIndex: 'no', width: '5%', align: 'center' },
  103. { title: '收货人', scopedSlots: { customRender: 'consignee' }, width: '24%', align: 'center', ellipsis: true },
  104. { title: '联系电话', dataIndex: 'consigneeTel', width: '12%', align: 'center', customRender: function (text) { return text || '--' } },
  105. { title: '收货地址', dataIndex: 'address', width: '25%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  106. { title: '操作', scopedSlots: { customRender: 'action' }, width: '24%', align: 'center' },
  107. { title: '选择', scopedSlots: { customRender: 'choose' }, width: '10%', align: 'center' }
  108. ],
  109. // 加载数据方法 必须为 Promise 对象
  110. loadData: parameter => {
  111. this.disabled = true
  112. this.spinning = true
  113. return shippingAddressQuery(Object.assign(parameter, this.queryParam)).then(res => {
  114. let data
  115. if (res.status == 200) {
  116. data = res.data
  117. const no = 0
  118. for (var i = 0; i < data.length; i++) {
  119. data[i].no = no + i + 1
  120. const provinceName = data[i].provinceName ? (data[i].provinceName + '-') : ''
  121. const cityName = data[i].cityName ? (data[i].cityName + '-') : ''
  122. const countyName = data[i].countyName ? (data[i].countyName + '-') : ''
  123. const addr = data[i].addr || ''
  124. data[i].address = provinceName + cityName + countyName + addr
  125. }
  126. this.disabled = false
  127. }
  128. this.spinning = false
  129. return data
  130. })
  131. },
  132. openAddrModal: false // 选择地址弹框是否显示
  133. }
  134. },
  135. methods: {
  136. // 设为默认
  137. handleDefault (row) {
  138. this.spinning = true
  139. shippingAddressSet({ 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. shippingAddressDel({
  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. this.$refs.table.clearTable()
  210. } else {
  211. const _this = this
  212. setTimeout(() => {
  213. _this.$refs.table.refresh(true)
  214. }, 300)
  215. }
  216. }
  217. }
  218. }
  219. </script>
  220. <style lang="less">
  221. .chooseAddressList-modal{
  222. .table-operator{
  223. margin-bottom: 10px;
  224. }
  225. .item-box{
  226. position: relative;
  227. display: flex;
  228. align-items: center;
  229. .ellipsis-txt{
  230. margin: 0;
  231. width: 100%;
  232. overflow: hidden;
  233. text-overflow:ellipsis;
  234. whitewhite-space: nowrap;
  235. }
  236. .badge-txt{
  237. line-height: 20px;
  238. padding: 0 7px;
  239. font-size: 12px;
  240. background-color: #fff;
  241. color: #ed1c24;
  242. border-color: #ed1c24;
  243. border-radius: 20px;
  244. box-shadow: 0 0 0 1px #d9d9d9 inset;
  245. }
  246. }
  247. }
  248. </style>