userAddDetails.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. <template>
  2. <div >
  3. <el-row :gutter="10" class="mb8" style="float: right; top: -30px;">
  4. <el-col :span="1.5">
  5. <el-button
  6. type="primary"
  7. plain
  8. icon="el-icon-plus"
  9. size="mini"
  10. @click="handleAdd"
  11. v-hasPermi="['his:userAddress:add']"
  12. >新增</el-button>
  13. </el-col>
  14. </el-row>
  15. <el-table v-loading="loading" border="" :data="userAddressList" @selection-change="handleSelectionChange" style="top: -30px;">
  16. <el-table-column label="收货人姓名" align="center" prop="realName" />
  17. <el-table-column label="收货人电话" align="center" prop="phone" />
  18. <el-table-column label="收货人所在省" align="center" prop="province" />
  19. <el-table-column label="收货人所在市" align="center" prop="city" />
  20. <el-table-column label="收货人所在区" align="center" prop="district" />
  21. <el-table-column label="收货人详细地址" align="center" prop="detail" />
  22. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  23. <template slot-scope="scope">
  24. <el-button
  25. size="mini"
  26. type="text"
  27. icon="el-icon-edit"
  28. @click="handleUpdate(scope.row)"
  29. v-hasPermi="['his:userAddress:edit']"
  30. >修改</el-button>
  31. <el-button
  32. size="mini"
  33. type="text"
  34. icon="el-icon-delete"
  35. @click="handleDelete(scope.row)"
  36. v-hasPermi="['his:userAddress:remove']"
  37. >删除</el-button>
  38. </template>
  39. </el-table-column>
  40. </el-table>
  41. <pagination
  42. v-show="total>0"
  43. :total="total"
  44. :page.sync="queryParams.pageNum"
  45. :limit.sync="queryParams.pageSize"
  46. @pagination="getList"
  47. />
  48. <!-- 添加或修改用户地址对话框 -->
  49. <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
  50. <el-form ref="form" :model="form" :rules="rules" label-width="100px">
  51. <el-form-item label="智能识别" prop="address">
  52. <el-input v-model="address" placeholder="输入需要识别的地址" > <el-button slot="append" icon="el-icon-search" @click="sAddress"></el-button></el-input>
  53. </el-form-item>
  54. <el-form-item label="收货人姓名" prop="realName">
  55. <el-input v-model="form.realName" placeholder="请输入收货人姓名" />
  56. </el-form-item>
  57. <el-form-item label="收货人电话" prop="phone">
  58. <el-input v-model="form.phone" placeholder="请输入收货人电话" />
  59. </el-form-item>
  60. <el-form-item label="省市区" >
  61. <el-cascader
  62. ref="citySelect"
  63. v-model="cityIds"
  64. :options="citys"
  65. @change="handleCityChange">
  66. </el-cascader>
  67. </el-form-item>
  68. <el-form-item label="详细地址" prop="detail">
  69. <el-input v-model="form.detail" placeholder="请输入收货人详细地址" />
  70. </el-form-item>
  71. <el-form-item label="是否默认地址" prop="isDefault">
  72. <el-radio-group v-model="form.isDefault">
  73. <el-radio :label="item.dictValue" v-for="item in orOptions" >{{item.dictLabel}}</el-radio>
  74. </el-radio-group>
  75. </el-form-item>
  76. </el-form>
  77. <div slot="footer" class="dialog-footer">
  78. <el-button type="primary" @click="submitForm">确 定</el-button>
  79. <el-button @click="cancel">取 消</el-button>
  80. </div>
  81. </el-dialog>
  82. </div>
  83. </template>
  84. <script>
  85. import { getAddress,listUserAddress, getUserAddress, delUserAddress, addUserAddress, updateUserAddress, exportUserAddress } from "@/api/store/userAddress";
  86. import {getCitys} from "@/api/store/city";
  87. export default {
  88. name: "UserAddress",
  89. data() {
  90. return {
  91. orOptions:[],
  92. // 遮罩层
  93. loading: true,
  94. // 导出遮罩层
  95. exportLoading: false,
  96. // 选中数组
  97. ids: [],
  98. // 非单个禁用
  99. single: true,
  100. // 非多个禁用
  101. multiple: true,
  102. // 显示搜索条件
  103. showSearch: true,
  104. // 总条数
  105. total: 0,
  106. // 用户地址表格数据
  107. userAddressList: [],
  108. // 弹出层标题
  109. title: "",
  110. // 是否显示弹出层
  111. open: false,
  112. cityIds:null,
  113. address:null,
  114. citys:[],
  115. // 查询参数
  116. queryParams: {
  117. pageNum: 1,
  118. pageSize: 10,
  119. userId: null,
  120. realName: null,
  121. phone: null,
  122. province: null,
  123. city: null,
  124. district: null,
  125. cityIds: null,
  126. detail: null,
  127. postCode: null,
  128. longitude: null,
  129. latitude: null,
  130. isDefault: null,
  131. isDel: null,
  132. },
  133. // 表单参数
  134. form: {},
  135. // 表单校验
  136. rules: {
  137. userId: [
  138. { required: true, message: "用户id不能为空", trigger: "blur" }
  139. ],
  140. realName: [
  141. { required: true, message: "收货人姓名不能为空", trigger: "blur" }
  142. ],
  143. phone: [
  144. { required: true, message: "收货人电话不能为空", trigger: "blur" },
  145. {
  146. pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
  147. message: "请输入正确的手机号码",
  148. trigger: "blur"
  149. }
  150. ],
  151. province: [
  152. { required: true, message: "收货人所在省不能为空", trigger: "blur" }
  153. ],
  154. city: [
  155. { required: true, message: "收货人所在市不能为空", trigger: "blur" }
  156. ],
  157. district: [
  158. { required: true, message: "收货人所在区不能为空", trigger: "blur" }
  159. ],
  160. detail: [
  161. { required: true, message: "收货人详细地址不能为空", trigger: "blur" }
  162. ],
  163. isDefault: [
  164. { required: true, message: "是否默认不能为空", trigger: "blur" }
  165. ],
  166. }
  167. };
  168. },
  169. created() {
  170. this.getCitys();
  171. this.getDicts("sys_company_or").then(response => {
  172. this.orOptions = response.data;
  173. });
  174. },
  175. methods: {
  176. /** 查询用户地址列表 */
  177. getList() {
  178. this.loading = true;
  179. listUserAddress(this.queryParams).then(response => {
  180. this.userAddressList = response.rows;
  181. this.total = response.total;
  182. this.loading = false;
  183. });
  184. },
  185. getAddList(id) {
  186. this.queryParams.userId=id;
  187. this.loading = true;
  188. listUserAddress(this.queryParams).then(response => {
  189. this.userAddressList = response.rows;
  190. this.total = response.total;
  191. this.loading = false;
  192. });
  193. },
  194. // 取消按钮
  195. cancel() {
  196. this.open = false;
  197. this.reset();
  198. },
  199. // 表单重置
  200. reset() {
  201. this.form = {
  202. addressId: null,
  203. userId: null,
  204. realName: null,
  205. phone: null,
  206. province: null,
  207. city: null,
  208. district: null,
  209. cityIds: null,
  210. detail: null,
  211. postCode: null,
  212. longitude: null,
  213. latitude: null,
  214. isDefault: null,
  215. isDel: null,
  216. createTime: null,
  217. updateTime: null
  218. };
  219. this.address=null;
  220. this.cityIds=[];
  221. this.resetForm("form");
  222. },
  223. getCitys(){
  224. getCitys().then(res => {
  225. this.citys=res.data;
  226. })
  227. },
  228. /** 搜索按钮操作 */
  229. handleQuery() {
  230. this.queryParams.pageNum = 1;
  231. this.getList(this.queryParams.userId);
  232. },
  233. /** 重置按钮操作 */
  234. resetQuery() {
  235. this.resetForm("queryForm");
  236. this.handleQuery();
  237. },
  238. // 多选框选中数据
  239. handleSelectionChange(selection) {
  240. this.ids = selection.map(item => item.addressId)
  241. this.single = selection.length!==1
  242. this.multiple = !selection.length
  243. },
  244. handleCityChange(value) {
  245. var nodes=this.$refs.citySelect.getCheckedNodes();
  246. this.cityIds=value.toString();
  247. this.form.province=nodes[0].pathLabels[0];
  248. this.form.city=nodes[0].pathLabels[1];
  249. this.form.district=nodes[0].pathLabels[2];
  250. },
  251. sAddress(){
  252. getAddress(this.address).then(response => {
  253. var addressJson = response.data;
  254. this.msgSuccess(addressJson.reason);
  255. this.form.province=addressJson.data.provinceName;
  256. this.form.city=addressJson.data.cityName;
  257. this.form.district=addressJson.data.expAreaName;
  258. this.form.detail=addressJson.data.streetName+addressJson.data.address;
  259. this.form.realName=addressJson.data.name;
  260. this.form.phone=addressJson.data.mobile;
  261. var province= this.citys.find(function(o) {
  262. return o.label ==addressJson.data.provinceName ;
  263. });
  264. var city= province.children.find(function(o) {
  265. return o.label == addressJson.data.cityName;
  266. });
  267. var district= city.children.find(function(o) {
  268. return o.label == addressJson.data.expAreaName;
  269. });
  270. this.cityIds=[province.value,city.value,district.value]
  271. });
  272. },
  273. /** 新增按钮操作 */
  274. handleAdd() {
  275. this.reset();
  276. this.open = true;
  277. this.title = "添加用户地址";
  278. },
  279. /** 修改按钮操作 */
  280. handleUpdate(row) {
  281. this.reset();
  282. const addressId = row.addressId || this.ids
  283. getUserAddress(addressId).then(response => {
  284. this.form = response.data;
  285. var province= this.citys.find(function(o) {
  286. return o.label ==response.data.province ;
  287. });
  288. var city= province.children.find(function(o) {
  289. return o.label == response.data.city;
  290. });
  291. var district= city.children.find(function(o) {
  292. return o.label == response.data.district;
  293. });
  294. this.cityIds=[province.value,city.value,district.value]
  295. this.open = true;
  296. this.title = "修改用户地址";
  297. });
  298. },
  299. /** 提交按钮 */
  300. submitForm() {
  301. this.$refs["form"].validate(valid => {
  302. if (valid) {
  303. if(this.form.city==null||this.form.province==null||this.form.district==null){
  304. return this.msgSuccess("省市区不能为空");
  305. }
  306. if (this.form.addressId != null) {
  307. updateUserAddress(this.form).then(response => {
  308. this.msgSuccess("修改成功");
  309. this.open = false;
  310. this.getList(this.queryParams.userId);
  311. });
  312. } else {
  313. this.form.userId=this.queryParams.userId
  314. addUserAddress(this.form).then(response => {
  315. this.msgSuccess("新增成功");
  316. this.open = false;
  317. this.getList(this.queryParams.userId);
  318. });
  319. }
  320. }
  321. });
  322. },
  323. /** 删除按钮操作 */
  324. handleDelete(row) {
  325. const addressIds = row.addressId || this.ids;
  326. this.$confirm('是否确认删除用户地址编号为"' + addressIds + '"的数据项?', "警告", {
  327. confirmButtonText: "确定",
  328. cancelButtonText: "取消",
  329. type: "warning"
  330. }).then(function() {
  331. return delUserAddress(addressIds);
  332. }).then(() => {
  333. this.getList(this.queryParams.userId);
  334. this.msgSuccess("删除成功");
  335. }).catch(() => {});
  336. },
  337. /** 导出按钮操作 */
  338. handleExport() {
  339. const queryParams = this.queryParams;
  340. this.$confirm('是否确认导出所有用户地址数据项?', "警告", {
  341. confirmButtonText: "确定",
  342. cancelButtonText: "取消",
  343. type: "warning"
  344. }).then(() => {
  345. this.exportLoading = true;
  346. return exportUserAddress(queryParams);
  347. }).then(response => {
  348. this.download(response.msg);
  349. this.exportLoading = false;
  350. }).catch(() => {});
  351. }
  352. }
  353. };
  354. </script>