<template>
  <div class="page">
    <topBar
      v-if="topList.length > 0"
      :top-list="topList"
      :moren="moren"
    />
    <div class="thetopbox">
      <el-form label-width="100px">
        <el-row>
          <el-col :span="4">
            <el-form-item :label="'订单编号'">
              <el-input v-model="queryParams.orderCode" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'会员编号'">
              <el-input v-model="queryParams.memberCode" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'会员姓名'">
              <el-input v-model="queryParams.memberName" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'收货人'">
              <el-input v-model="queryParams.recName" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'联系方式'">
              <el-input v-model="queryParams.recPhone" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'订单类型'">
              <el-select
                v-model="queryParams.orderType"
                clearable
                placeholder=""
              >
                <el-option
                  v-for="item in orderTypeList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'订单状态'">
              <el-select
                v-model="queryParams.orderStatus"
                clearable
                placeholder=""
              >
                <el-option
                  v-for="item in orderStatusList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item class="dizhi" :label="'详细地址'" prop="">
              <el-cascader
                v-model="queryParams.shoppingAddress"
                style="width: 100%"
                clearable
                :options="areaData"
                :props="regionParams"
                @change="handleChange1"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="" label-width="40px">
              <el-input v-model="queryParams.recAddress" clearable />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item :label="'申请日期'">
              <el-date-picker
                v-model="thetimes"
                type="daterange"
                range-separator="——"
                :start-placeholder="'开始日期'"
                :end-placeholder="'结束日期'"
                value-format="yyyy-MM-dd"
                @change="checkTime"
              />
            </el-form-item>
          </el-col>

          <el-col :span="4">
            <div class="searchbox">
              <el-button class="my_search" @click="getSearch"> {{ '搜索' }}</el-button>
              <el-button class="my_reset" @click="reChongzhi"> {{ '重置' }}</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="main">
      <div class="maintable">
        <el-table
          ref="multipleTable"
          v-loading="loading"
          :data="tableData"
          height="640px"
          style="width: 100%"
          :header-cell-style="{ background: '#EEEEEE' }"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55" />
          <el-table-column
            align="center"
            prop="orderCode"
            :label="'订单编号'"
            width="190"
          />
          <el-table-column align="center" prop="orderTypeVal" :label="'订单类型'" />
          <el-table-column
            align="center"
            prop="orderStatusVal"
            :label="'订单状态'"
          />
          <el-table-column
            align="center"
            width="200"
            prop="memberCode"
            :label="'会员编号'"
          />
          <el-table-column align="center" prop="memberName" :label="'会员姓名'" />
          <el-table-column min-width="120px" align="center" prop="recName" :label="'变更前收货人'" />
          <el-table-column width="180px" align="center" prop="recPhone" :label="'变更前联系方式'" />
          <el-table-column align="center" prop="recProvinceVal" :label="'变更前省'" />
          <el-table-column align="center" prop="recCityVal" :label="'变更前市'" />
          <el-table-column min-width="120px" align="center" prop="recCountyVal" :label="'变更前区/县'" />
          <el-table-column
            align="center"
            min-width="150px"
            prop="recAddress"
            :label="'变更前详细地址'"
          />
          <el-table-column min-width="120px" align="center" prop="newRecName" :label="'变更后收货人'" />
          <el-table-column width="180px" align="center" prop="newRecPhone" :label="'变更后联系方式'" />
          <el-table-column align="center" prop="newRecProvinceVal" :label="'变更后省'" />
          <el-table-column align="center" prop="newRecCityVal" :label="'变更后市'" />
          <el-table-column min-width="120px" align="center" prop="newRecCountyVal" :label="'变更后区/县'" />
          <el-table-column
            align="center"
            min-width="150px"
            prop="newRecAddress"
            :label="'变更后详细地址'"
          />
          <el-table-column align="center" prop="" :label="'备注'" />
          <el-table-column
            align="center"
            width="200"
            prop="creationTime"
            :label="'申请日期'"
          />
        </el-table>
      </div>
    </div>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getSearch"
    />

  </div>
</template>

<script>
import topBar from '@/components/topBar'
import * as api from '@/api/site.js'
import * as log from '@/api/logistics'
import * as del from '@/api/delivery'
import ImageUpload from '@/components/ImageUpload'
import Editor from '@/components/Editor/index.vue'

export default {
  name: 'UpdateAdress',
  components: {
    topBar,
    ImageUpload,
    Editor
  },
  data() {
    return {
      isShow: false,
      relContent: '',
      rejectData: '',
      moren: 'updateAdress',
      topList: [
        {
          name: '修改地址',
          path: 'updateAdress'
        }
      ],
      uploadImgUrl: process.env.VUE_APP_BASE_API + '/system/upload',
      tableData: [],
      loading: false,
      queryParams: {
        pageNum: 1,
        pageSize: 50,
        shoppingAddress: ['', '', '']
      },
      total: 0,
      multipleSelection: [],
      areaData: [],
      regionParams: {
        label: 'name',
        value: 'id',
        children: 'children',
        expandTrigger: 'hover'
      },
      dialogVisible: false,
      rules: {
        storeName: [
          { required: true, message: '请输入店铺名称', trigger: 'blur' }
        ],
        memberCode: [
          { required: true, message: '请输入店长编号', trigger: 'blur' }
        ],
        pkStoreLevel: [
          { required: true, message: '请选择店铺等级', trigger: 'change' }
        ],

        shoppingAddress: [
          { required: true, message: '请选择收货地址', trigger: 'change' }
        ],
        picture: [
          {
            required: true,
            message: '请上传图片',
            trigger: 'change'
          }
        ]
      },
      form: {
        storeCode: '',
        storeName: '',
        province: '',
        city: '',
        county: '',
        address: '',
        memberCode: '',
        shopowner: '',
        pkStoreLevel: '',
        picture: '',
        shoppingAddress: ['', '', '']
      },
      orderTypeList: [],
      orderStatusList: [],
      thetimes: []
    }
  },
  created() {
    this.getSearch()
    this.getData()
  },
  methods: {
    handleClose1() {
      this.isShow = false
      this.relContent = ''
    },
    getDetails(obj, index) {
      log.queryPass(obj).then((res) => {
        this.$router.push({
          path: 'addressZxqc',
          query: {
            data: JSON.stringify(res.data),
            approvalBusiness: 131,
            businessNoList: JSON.stringify(obj.businessNoList)
          }
        })
      })
    },
    // 驳回申请
    confirmSubmit() {
      if (this.relContent.length == 0) {
        this.$message({
          message: '请输入驳回信息',
          type: 'warning'
        })
        return false
      }
      log.rejectAddress(Object.assign({ rejectMsg: this.relContent }, this.rejectData)).then((res) => {
        if (res.code == 200) {
          this.$message({
            message: res.msg,
            type: 'success'
          })
          this.isShow = false
          this.relContent = ''
          this.getSearch()
        }
      })
    },
    rejectAddress(obj) {
      this.isShow = true
      this.rejectData = obj
    },

    handleClose() {
      this.dialogVisible = false
      this.$refs['form'].clearValidate()
      this.$refs['form'].resetFields()
    },
    checkTime(val) {
      this.queryParams.startDate = val[0]
      this.queryParams.endDate = val[1]
    },
    handleChange1(val) {
      this.queryParams.recProvince = val[0]
      this.queryParams.recCity = val[1]
      this.queryParams.recCounty = val[2] || ''
    },
    getData() {
      // 获取订单类型
      log.getOrderType().then((res) => {
        this.orderTypeList = res.data
      })
      api.areaList().then((res) => {
        this.areaData = res.data
      })
      del.getOrderStatus().then((res) => {
        this.orderStatusList = res.data
      })
    },

    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    reChongzhi() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 50,
        shoppingAddress: ['', '', '']
      }
      this.getSearch()
      this.thetimes = []
    },
    getSearch() {
      this.loading = true
      log.getModifyAddress(this.queryParams).then((res) => {
        this.loading = false
        this.tableData = res.rows
        this.total = res.total
        const regex = new RegExp('<img', 'gi')
        this.tableData.forEach(item => {
          if (item.rejectMsg) {
            item.rejectMsg = item.rejectMsg.replace(regex, `<img style="max-width: 200px;"`)
          }
        })
      })
    }
  }
}
</script>

    <style lang="scss" scoped>
::v-deep .el-range-editor.el-input__inner {
  width: 100%;
}
::v-deep .el-table thead {
  color: #000000;
}
::v-deep .el-table .warning-row {
  background: #f9f9f9;
}
.page {
  padding: 10px 20px;
  background: #f9f9f9;
  font-size: 14px;
  .thetopbox {
    padding: 15px 20px 15px 0;
    background: #ffffff;
    border-radius: 8px;
    .searchbox {
      display: flex;
      align-items: center;
      margin-left: 40px;
    }
    .searchtitle {
      margin-right: 10px;
    }
    .searchbtn {
      background: #08143f;
      color: #ffffff;
    }
  }
  .main {
    //margin-top: 20px;
    background: #f9f9f9;
    //border-radius: 8px;
    //box-shadow: 0px 2px 20px 0px rgba(238, 238, 238, 0.5);

    .maintop {
      display: flex;
      // padding: 10px 0;
      justify-content: space-between;
      align-items: center;
      .mainbtn {
        .thebtn1 {
          color: #ffffff;
          background: #48b2fd;
        }
        .thebtn2 {
          color: #ffffff;
          background: #ffad41;
        }
      }
    }
  }
}
.button-s{
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  margin-top: 20px;
  .submit{
    width: 209px;
    height: 48px;
    background: #CCCCCC;
    border-radius: 5px 5px 5px 5px;
    line-height: 48px;
    text-align: center;
    color: #fff;
    font-size: 18px;
  }
  .colors{
    margin-left: 40px;
    background-color: #48B2FD;
  }
}
</style>
