123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- <template>
- <a-modal
- centered
- class="chooseAddressList-modal"
- :footer="null"
- :maskClosable="false"
- title="收货地址"
- v-model="isShow"
- @cancel="isShow=false"
- :width="960">
- <a-spin :spinning="spinning" tip="Loading...">
- <!-- 操作按钮 -->
- <div class="table-operator">
- <a-button id="chooseAddressList-add" type="primary" class="button-error" @click="handleEdit()">新增</a-button>
- </div>
- <!-- 列表 -->
- <s-table
- class="sTable"
- ref="table"
- size="small"
- :rowKey="(record) => record.id"
- :columns="columns"
- :data="loadData"
- :showPagination="false"
- :defaultLoadData="false"
- bordered>
- <!-- 收货人 -->
- <template slot="consignee" slot-scope="text, record">
- <div class="item-box">
- <a-tooltip placement="top">
- <template slot="title">
- <span>{{ record.consigneeName }}</span>
- </template>
- <p class="ellipsis-txt">{{ record.consigneeName }}</p>
- </a-tooltip>
- <span v-if="record.defaultFlag==1" class="badge-txt">默认</span>
- </div>
- </template>
- <!-- 操作 -->
- <template slot="action" slot-scope="text, record">
- <a-button
- size="small"
- type="primary"
- class="button-success"
- v-if="record.defaultFlag!=1"
- @click="handleDefault(record)"
- id="chooseAddressList-default-btn">设为默认</a-button>
- <a-button
- size="small"
- type="primary"
- class="button-info"
- @click="handleEdit(record)"
- id="chooseAddressList-edit-btn"
- >编辑</a-button>
- <a-button
- size="small"
- type="primary"
- class="button-error"
- @click="handleDel(record)"
- id="chooseAddressList-del-btn"
- >删除</a-button>
- </template>
- <!-- 选择 -->
- <template slot="choose" slot-scope="text, record">
- <a-button
- size="small"
- type="primary"
- class="button-primary"
- @click="handleChoose(record)"
- id="chooseAddressList-choose-btn">选择</a-button>
- </template>
- </s-table>
- </a-spin>
- <!-- 新增/编辑地址 -->
- <edit-address-modal ref="addrModal" :openModal="openAddrModal" :paramsData="paramsData" @ok="handleOk" @close="openAddrModal=false" />
- </a-modal>
- </template>
- <script>
- import { STable, VSelect } from '@/components'
- import editAddressModal from './editAddressModal'
- import { dealerRecevieAddrQuery, dealerRecevieAddrSet, dealerRecevieAddrDel } from '@/api/dealerRecevieAddr'
- export default {
- name: 'ChooseAddressModal',
- components: { STable, VSelect, editAddressModal },
- props: {
- openModal: { // 弹框显示状态
- type: Boolean,
- default: false
- },
- paramsData: {
- type: String || Number,
- default: ''
- }
- },
- data () {
- return {
- spinning: false,
- isShow: this.openModal, // 是否打开弹框
- // 表头
- columns: [
- { title: '序号', dataIndex: 'no', width: 50, align: 'center' },
- { title: '收货人', scopedSlots: { customRender: 'consignee' }, align: 'center', ellipsis: true },
- { title: '手机号码', dataIndex: 'consigneeTel', width: 230, align: 'center', customRender: function (text) { return text || '--' } },
- { title: '收货地址', dataIndex: 'address', width: 400, align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
- // { title: '操作', scopedSlots: { customRender: 'action' }, width: 200, align: 'center', fixed: 'right' },
- { title: '选择', scopedSlots: { customRender: 'choose' }, width: 80, align: 'center', fixed: 'right' }
- ],
- // 加载数据方法 必须为 Promise 对象
- loadData: parameter => {
- this.disabled = true
- return dealerRecevieAddrQuery({ dealerSn: this.paramsData }).then(res => {
- const data = res.data
- const no = 0
- for (var i = 0; i < data.length; i++) {
- data[i].no = no + i + 1
- const provinceName = data[i].provinceName ? (data[i].provinceName + '-') : ''
- const cityName = data[i].cityName ? (data[i].cityName + '-') : ''
- const countyName = data[i].countyName ? (data[i].countyName + '-') : ''
- const addr = data[i].addr || ''
- data[i].address = provinceName + cityName + countyName + addr
- }
- this.disabled = false
- return data
- })
- },
- openAddrModal: false // 选择地址弹框是否显示
- }
- },
- methods: {
- // 设为默认
- handleDefault (row) {
- this.spinning = true
- dealerRecevieAddrSet({ id: row.id }).then(res => {
- if (res.status == 200) {
- this.$message.success(res.message)
- this.$refs.table.refresh(true)
- this.spinning = false
- } else {
- this.spinning = false
- }
- })
- },
- // 新增/编辑收货地址
- handleEdit (row) {
- if (row) {
- this.$refs.addrModal.setData({
- id: row.id,
- consigneeName: row.consigneeName,
- consigneeTel: row.consigneeTel,
- provinceSn: row.provinceSn,
- provinceName: row.provinceName,
- citySn: row.citySn,
- cityName: row.cityName,
- countySn: row.countySn,
- countyName: row.countyName,
- addr: row.addr
- })
- }
- this.openAddrModal = true
- },
- // 选择
- handleChoose (row) {
- this.$emit('ok', row)
- },
- // 删除
- handleDel (row) {
- const _this = this
- this.$confirm({
- title: '提示',
- content: '删除后不可恢复,确定要进行删除吗?',
- centered: true,
- onOk () {
- _this.spinning = true
- dealerRecevieAddrDel({
- id: row.id
- }).then(res => {
- if (res.status == 200) {
- _this.$message.success(res.message)
- _this.$emit('verify', row.id)
- _this.$refs.table.refresh(true)
- _this.spinning = false
- } else {
- _this.spinning = false
- }
- })
- }
- })
- },
- // 地址保存成功
- handleOk (data) {
- this.$refs.table.refresh(true)
- }
- },
- watch: {
- // 父页面传过来的弹框状态
- openModal (newValue, oldValue) {
- this.isShow = newValue
- },
- // 重定义的弹框状态
- isShow (newValue, oldValue) {
- if (!newValue) {
- this.$emit('close')
- } else {
- const _this = this
- setTimeout(() => {
- _this.$refs.table.refresh(true)
- }, 300)
- }
- }
- }
- }
- </script>
- <style lang="less">
- .chooseAddressList-modal{
- .table-operator{
- margin-bottom: 10px;
- }
- .item-box{
- position: relative;
- display: flex;
- align-items: center;
- .ellipsis-txt{
- margin: 0;
- width: 100%;
- overflow: hidden;
- text-overflow:ellipsis;
- whitewhite-space: nowrap;
- }
- .badge-txt{
- line-height: 20px;
- padding: 0 7px;
- font-size: 12px;
- background-color: #fff;
- color: #ed1c24;
- border-color: #ed1c24;
- border-radius: 20px;
- box-shadow: 0 0 0 1px #d9d9d9 inset;
- }
- }
- }
- </style>
|