order.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. <template>
  2. <view>
  3. <view class="to_bottom" v-if="!addrList.length"> -----还没有地址啦-----</view>
  4. <view class="addr_list">
  5. <view class="addr_item" v-for="(item, index) in addrList" :key="index">
  6. <view class="contact_user">
  7. <text class="contact_name">{{ item.contact_name }}</text>
  8. <text class="contact_phone">{{ item.contact_phone }}</text>
  9. <text class="contact_shop">{{ item.contact_shop }}</text>
  10. </view>
  11. <view class="contact_addr"> {{ item.contact_area }} {{ item.contact_school }} {{ item.contact_grade }} {{ item.contact_class }} </view>
  12. <view class="contact_handler">
  13. <view class="radio_label" @click="setDefault(index)">
  14. <image class="radio_icon" :src="item.is_default ? '../../static/icon/radioed.png' : '../../static/icon/radio.png'"></image>
  15. <text :class="item.is_default ? 'radioed_text' : ''">{{ item.is_default ? "已默认" : "设为默认" }}</text>
  16. </view>
  17. <view class="addr_right_btn" @click="removeAddr(index)"> 删除 </view>
  18. <view class="addr_right_btn" @click="openForm(item)"> 编辑 </view>
  19. </view>
  20. </view>
  21. </view>
  22. <view class="create_box">
  23. <button class="create_addr" @click="openForm()">新建收货地址</button>
  24. </view>
  25. <view class="to_bottom" v-if="isLast"> -----到底啦-----</view>
  26. <uni-popup ref="addrForm" type="bottom" class="popup" background-color="#FFFFFF" @change="popupChange">
  27. <view class="contact_addr_form">
  28. <!-- 地区代表表单 -->
  29. <form class="info_form">
  30. <view class="form_group">
  31. <view class="group_title">姓名:</view>
  32. <view class="group_box">
  33. <input type="text" class="form_ctrl" placeholder="请输入学生姓名" maxlength="20" required="" v-model="addrRequest.contact_name" />
  34. </view>
  35. </view>
  36. <view class="form_group">
  37. <view class="group_title">手机号:</view>
  38. <view class="group_box">
  39. <input type="text" class="form_ctrl" placeholder="请输入家长手机号" maxlength="11" required="" v-model="addrRequest.contact_phone" />
  40. </view>
  41. </view>
  42. <view class="form_group">
  43. <view class="group_title">区域:</view>
  44. <view class="group_box">
  45. <picker class="form_ctrl" :range="cityArray" @change="cityFinish">
  46. <view class="area_text">
  47. <text v-if="addrRequest.contact_area">{{ addrRequest.contact_area }}</text>
  48. </view>
  49. </picker>
  50. </view>
  51. </view>
  52. <view class="form_group">
  53. <view class="group_title">学校</view>
  54. <view class="group_box">
  55. <view class="form_ctrl" @click="openSchoolSearch">
  56. {{ addrRequest.contact_school }}
  57. <lzcPicker ref="lzcPicker" :pickerList="schoolArray" pickerTittle="选择学校" @change="changeItem" />
  58. </view>
  59. </view>
  60. </view>
  61. <view class="form_group">
  62. <view class="group_title">年级:</view>
  63. <view class="group_box">
  64. <!-- <input type="text" class="form_ctrl" placeholder="请输入详细地址:街道/小区/门牌号" maxlength="64" required="" v-model="addrRequest.contact_addr" /> -->
  65. <picker class="form_ctrl" :range="ageArray" @change="bindAgeChange">
  66. <view class="area_text">
  67. <text>{{ addrRequest.contact_grade == "" ? "请选择年级" : addrRequest.contact_grade }}</text>
  68. </view>
  69. </picker>
  70. </view>
  71. </view>
  72. <view class="form_group">
  73. <view class="group_title">班级:</view>
  74. <view class="group_box">
  75. <picker class="form_ctrl" :range="classArray" @change="bindClassChange">
  76. <view class="area_text">
  77. <text>{{ addrRequest.contact_class == "" ? "请选择班级" : addrRequest.contact_class }}</text>
  78. </view>
  79. </picker>
  80. </view>
  81. </view>
  82. <view class="form_group">
  83. <view class="group_title">设为默认</view>
  84. <view class="group_box">
  85. <switch color="#E03519" style="transform: scale(0.6); float: right" @change="defaultSwitch" :checked="addrRequest.is_default ? true : false" />
  86. </view>
  87. </view>
  88. <button class="submit_btn" @click="saveAddr">保存地址</button>
  89. </form>
  90. </view>
  91. </uni-popup>
  92. </view>
  93. </template>
  94. <script>
  95. import lzcPicker from "@/components/lzc-picker/lzc-picker.vue";
  96. export default {
  97. components: {
  98. lzcPicker,
  99. },
  100. data() {
  101. return {
  102. // 产品列表
  103. addrList: [],
  104. // 请求参数
  105. requestParam: {
  106. page: 1,
  107. status: 0,
  108. },
  109. // 保存地址
  110. addrRequest: {
  111. id: 0,
  112. contact_name: "",
  113. contact_phone: "",
  114. contact_school: "",
  115. contact_area: "",
  116. contact_addr: "",
  117. contact_shop: "",
  118. contact_grade: "",
  119. contact_class: "",
  120. is_default: 0,
  121. },
  122. // 是否最后一页
  123. isLast: false,
  124. // 是否请求中
  125. isReqing: false,
  126. // 所在地区
  127. cityArray: [],
  128. cityValue: [],
  129. // 自动弹出
  130. autoShowForm: false,
  131. // 异步通知
  132. AddrEmit: false,
  133. ageArray: [],
  134. classArray: [],
  135. schoolArray: [],
  136. };
  137. },
  138. onLoad(param) {
  139. this.AddrEmit = param.notify == "addr" ? true : false;
  140. this.autoShowForm = param.type == "create" ? true : false;
  141. // 获取列表
  142. this.getList();
  143. //获取学院
  144. this.getSchool();
  145. },
  146. onReady() {
  147. if (this.autoShowForm) {
  148. var that = this;
  149. // 500毫秒后自动弹出
  150. setTimeout(function () {
  151. that.openForm();
  152. }, 500);
  153. }
  154. },
  155. onShow() {},
  156. methods: {
  157. changeItem(name) {
  158. this.addrRequest.contact_school = name;
  159. },
  160. openSchoolSearch() {
  161. this.$refs.lzcPicker.handleShow();
  162. },
  163. getSchoolList(name) {
  164. console.log(this.area_list);
  165. const _area_list = JSON.parse(JSON.stringify(this.area_list));
  166. const list = _area_list.find((item) => item.area_name == name).school_list;
  167. return list.map((item) => item.name);
  168. },
  169. getSchool() {
  170. // 获取学院
  171. this.$http.request("api/school/get_list").then((callback) => {
  172. // console.log(callback);
  173. if (callback.code == "success") {
  174. this.ageArray = callback.data.grade_list;
  175. this.classArray = callback.data.class_list;
  176. this.area_list = callback.data.area_list;
  177. this.cityArray = callback.data.area_list.map((item) => item.area_name);
  178. this.schoolArray = this.getSchoolList(this.cityArray[0]);
  179. // 默认地址
  180. this.addrRequest.contact_area = this.cityArray[0];
  181. this.addrRequest.contact_school = this.schoolArray[0];
  182. this.addrRequest.contact_grade = callback.data.grade_list[0];
  183. this.addrRequest.contact_class = callback.data.class_list[0];
  184. }
  185. });
  186. },
  187. // 获取列表
  188. getList() {
  189. // 登录提示
  190. if (!this.$checkAccess.alterLogin()) return;
  191. // 判断数据
  192. this.$http.request("api/student_addr/get_list").then((callback) => {
  193. // 获取成功
  194. if (callback.code == "success") {
  195. this.addrList = callback.data;
  196. // 通知地址变更
  197. if (this.AddrEmit) uni.$emit("addr_list_change", { list: this.addrList });
  198. }
  199. });
  200. },
  201. // 打开弹窗
  202. openForm(item) {
  203. if (!item) {
  204. this.addrRequest.id = 0;
  205. this.addrRequest.contact_name = "";
  206. this.addrRequest.contact_phone = "";
  207. this.addrRequest.contact_shop = "";
  208. this.addrRequest.contact_addr = "";
  209. this.addrRequest.is_default = 0;
  210. } else {
  211. const _cloneItem = JSON.parse(JSON.stringify(item));
  212. this.addrRequest = _cloneItem;
  213. }
  214. // 显示下单弹出层
  215. this.$refs.addrForm.open("bottom");
  216. },
  217. // 默认开关
  218. defaultSwitch(e) {
  219. this.addrRequest.is_default = e.detail.value ? 1 : 0;
  220. },
  221. // 弹出层
  222. popupChange(e) {
  223. // 禁止滚动穿透
  224. this.show = e.show;
  225. },
  226. // 城市修改
  227. cityChange(e) {
  228. // 替换三个选项
  229. this.cityValue.splice(e.detail.column, 1, e.detail.value);
  230. // 下一级设置为0
  231. if (e.detail.column == 0) {
  232. this.cityValue.splice(1, 1, 0);
  233. this.cityValue.splice(2, 1, 0);
  234. }
  235. if (e.detail.column == 1) {
  236. this.cityValue.splice(2, 1, 0);
  237. }
  238. // 替换对应的数据
  239. this.cityArray.splice(0, 1, this.getArea(this.area_list));
  240. this.cityArray.splice(1, 1, this.getSchoolList(this.area_list, this.cityValue[0]));
  241. },
  242. // 城市选择
  243. cityFinish(e) {
  244. this.addrRequest.contact_area = this.cityArray[e.detail.value];
  245. this.schoolArray = this.getSchoolList(this.addrRequest.contact_area);
  246. this.addrRequest.contact_school = this.schoolArray[0];
  247. },
  248. bindAgeChange(e) {
  249. this.addrRequest.contact_grade = this.ageArray[e.detail.value];
  250. },
  251. bindClassChange(e) {
  252. this.addrRequest.contact_class = this.classArray[e.detail.value];
  253. },
  254. // 保存地址
  255. saveAddr() {
  256. // 判断姓名
  257. if (!this.addrRequest.contact_name) {
  258. uni.showToast({ icon: "none", title: "请填写学生姓名" });
  259. return;
  260. }
  261. if (this.addrRequest.contact_name.length < 2) {
  262. uni.showToast({ icon: "none", title: "请填写学生完整姓名" });
  263. return;
  264. }
  265. if (!this.addrRequest.contact_phone) {
  266. uni.showToast({ icon: "none", title: "请填写收件人手机号" });
  267. return;
  268. }
  269. // 请求状态
  270. uni.showLoading({ mask: true });
  271. // 请求路径
  272. var url = this.addrRequest.id ? "api/student_addr/edit" : "api/student_addr/add";
  273. // 授权成功以后,调用绑定
  274. this.$http.request(url, this.addrRequest, "post").then((re) => {
  275. // 关闭
  276. uni.hideLoading();
  277. // 成功的话
  278. if (re.code != "success") {
  279. // 跳转
  280. uni.showToast({ title: re.msg, icon: "none" });
  281. return;
  282. }
  283. // 地址变动
  284. this.getList();
  285. // 显示下单弹出层
  286. this.$refs.addrForm.close();
  287. });
  288. },
  289. // 删除地址
  290. removeAddr(index) {
  291. // 授权成功以后,调用绑定
  292. this.$http.request("api/student_addr/del", { id: this.addrList[index].id }, "post").then((re) => {
  293. // 关闭
  294. uni.hideLoading();
  295. // 成功的话
  296. if (re.code != "success") {
  297. // 跳转
  298. uni.showToast({ title: re.msg, icon: "none" });
  299. return;
  300. }
  301. // 成功删除该项
  302. this.addrList.splice(index, 1);
  303. // 通知地址变更
  304. if (this.AddrEmit) uni.$emit("addr_list_change", { list: this.addrList });
  305. });
  306. },
  307. // 设置默认
  308. setDefault(index) {
  309. // 如果已经是默认状态
  310. if (this.addrList[index].is_default) return;
  311. // 授权成功以后,调用绑定
  312. this.$http.request("api/student_addr/set_default", { id: this.addrList[index].id }, "post").then((re) => {
  313. // 关闭
  314. uni.hideLoading();
  315. // 成功的话
  316. if (re.code != "success") {
  317. // 跳转
  318. uni.showToast({ title: re.msg, icon: "none" });
  319. return;
  320. }
  321. // 更新其他的默认项
  322. for (let i in this.addrList) {
  323. this.addrList[i].is_default = 0;
  324. }
  325. // 成功修改值
  326. this.addrList[index].is_default = 1;
  327. // 通知地址变更
  328. if (this.AddrEmit) uni.$emit("addr_list_change", { list: this.addrList });
  329. });
  330. },
  331. },
  332. };
  333. </script>
  334. <style lang="less">
  335. .addr_list {
  336. width: 730rpx;
  337. display: block;
  338. overflow: hidden;
  339. margin: 0rpx auto;
  340. .addr_item {
  341. display: block;
  342. font-size: 24rpx;
  343. overflow: hidden;
  344. line-height: 40rpx;
  345. padding: 15rpx 10rpx;
  346. border-radius: 15rpx;
  347. padding-bottom: 0rpx;
  348. margin-bottom: 10rpx;
  349. background-color: #ffffff;
  350. .contact_user {
  351. display: block;
  352. font-size: 24rpx;
  353. line-height: 50rpx;
  354. .contact_name {
  355. font-size: 26rpx;
  356. font-weight: bold;
  357. margin-right: 16rpx;
  358. }
  359. .contact_shop {
  360. float: right;
  361. }
  362. }
  363. .contact_addr {
  364. display: block;
  365. font-size: 24rpx;
  366. line-height: 30rpx;
  367. padding: 10rpx 5rpx;
  368. border-bottom: 2rpx solid #dddddd;
  369. }
  370. .contact_handler {
  371. height: 60rpx;
  372. display: block;
  373. line-height: 60rpx;
  374. font-size: 20rpx;
  375. .radio_label {
  376. float: left;
  377. height: 60rpx;
  378. line-height: 60rpx;
  379. .radio_icon {
  380. width: 40rpx;
  381. height: 40rpx;
  382. vertical-align: middle;
  383. }
  384. .radioed_text {
  385. color: #e03519;
  386. }
  387. }
  388. .addr_right_btn {
  389. float: right;
  390. height: 40rpx;
  391. display: block;
  392. line-height: 40rpx;
  393. padding: 10rpx 35rpx;
  394. }
  395. }
  396. }
  397. }
  398. .create_box {
  399. left: 0rpx;
  400. width: 750rpx;
  401. height: 140rpx;
  402. display: block;
  403. position: fixed;
  404. bottom: var(--window-bottom);
  405. .create_addr {
  406. width: 700rpx;
  407. height: 80rpx;
  408. display: block;
  409. color: #ffffff;
  410. font-size: 30rpx;
  411. overflow: hidden;
  412. line-height: 80rpx;
  413. padding: 0rpx 0rpx;
  414. text-align: center;
  415. margin: 0rpx auto;
  416. margin-top: 20rpx;
  417. border-radius: 40rpx;
  418. background-color: #e03519;
  419. }
  420. }
  421. .popup {
  422. .info_form {
  423. display: block;
  424. overflow: hidden;
  425. padding: 20rpx 0rpx;
  426. padding-top: 80rpx;
  427. background: #ffffff;
  428. .form_group {
  429. display: block;
  430. overflow: hidden;
  431. line-height: 60rpx;
  432. padding: 20rpx 35rpx;
  433. .group_title {
  434. float: left;
  435. width: 160rpx;
  436. display: block;
  437. overflow: hidden;
  438. font-size: 30rpx;
  439. margin-right: 20rpx;
  440. }
  441. .group_box {
  442. float: left;
  443. width: 480rpx;
  444. display: block;
  445. .form_ctrl {
  446. height: 56rpx;
  447. font-size: 28rpx;
  448. padding: 0rpx 20rpx;
  449. line-height: 56rpx;
  450. border: 2rpx solid #dddddd;
  451. }
  452. .area_text {
  453. width: 446rpx;
  454. font-size: 28rpx;
  455. overflow: hidden;
  456. white-space: nowrap;
  457. text-overflow: ellipsis;
  458. }
  459. .group_image {
  460. width: 200rpx;
  461. height: 200rpx;
  462. }
  463. .choose_image {
  464. display: block;
  465. width: 200rpx;
  466. height: 200rpx;
  467. font-size: 38rpx;
  468. text-align: center;
  469. line-height: 200rpx;
  470. border: 2rpx solid #dddddd;
  471. }
  472. }
  473. }
  474. .submit_btn {
  475. width: 700rpx;
  476. height: 80rpx;
  477. display: block;
  478. color: #ffffff;
  479. font-size: 30rpx;
  480. overflow: hidden;
  481. line-height: 80rpx;
  482. padding: 0rpx 0rpx;
  483. text-align: center;
  484. margin: 20rpx auto;
  485. margin-top: 40rpx;
  486. border-radius: 40rpx;
  487. background-color: #e03519;
  488. }
  489. }
  490. }
  491. </style>