extraction-apply.vue 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. <template>
  2. <view class="page-bottom-fixed">
  3. <form @submit="form_submit" class="form-container">
  4. <view class="padding-main oh">
  5. <view class="form-gorup bg-white form-container-upload oh">
  6. <view class="form-gorup-title">logo图片<text class="form-group-tips">选传,建议300x300px</text></view>
  7. <view class="oh">
  8. <view class="form-upload-data fl">
  9. <block v-if="(extraction_data.logo || null) != null">
  10. <view class="item fl">
  11. <text class="delete-icon" @tap="upload_delete_event">x</text>
  12. <image :src="extraction_data.logo" @tap="upload_show_event" mode="aspectFill"></image>
  13. </view>
  14. </block>
  15. </view>
  16. <image class="upload-icon" :src="common_static_url+'upload-icon.png'" mode="aspectFill" @tap="file_upload_event"></image>
  17. </view>
  18. </view>
  19. <view class="form-gorup bg-white">
  20. <view class="form-gorup-title">别名</view>
  21. <input type="text" name="alias" :value="extraction_data.alias || ''" placeholder-class="cr-grey" class="cr-base" placeholder="别名格式最多 16 个字符">
  22. </view>
  23. <view class="form-gorup bg-white">
  24. <view class="form-gorup-title">联系人<text class="form-group-tips-must">*</text></view>
  25. <input type="text" name="name" :value="extraction_data.name || ''" placeholder-class="cr-grey" class="cr-base" placeholder="联系人格式 2~16 个字符之间">
  26. </view>
  27. <view class="form-gorup bg-white">
  28. <view class="form-gorup-title">联系电话<text class="form-group-tips-must">*</text></view>
  29. <input type="text" name="tel" :value="extraction_data.tel || ''" placeholder-class="cr-grey" class="cr-base" placeholder="座机 或 手机">
  30. </view>
  31. <view class="form-gorup bg-white">
  32. <view class="form-gorup-title">省市区<text class="form-group-tips-must">必选</text></view>
  33. <view class="select-address oh">
  34. <view class="section fl">
  35. <picker name="province" @change="select_province_event" :value="province_value" :range="province_list" range-key="name">
  36. <view :class="'name ' + ((province_value == null) ? 'cr-grey' : 'cr-base' )">{{((province_list[province_value] || null) == null) ? default_province : province_list[province_value]['name']}}</view>
  37. </picker>
  38. </view>
  39. <view class="section fl">
  40. <picker v-if="(province_id || null) != null" name="city" @change="select_city_event" :value="city_value" :range="city_list" range-key="name">
  41. <view :class="'name ' + ((city_value == null) ? 'cr-grey' : 'cr-base' )">{{((city_list[city_value] || null) == null) ? default_city : city_list[city_value]['name']}}</view>
  42. </picker>
  43. <text v-else class="cr-grey" @tap="region_select_error_event" data-value="请先选择省份">请先选择省份</text>
  44. </view>
  45. <view class="section fl">
  46. <picker v-if="(city_id || null) != null" name="county" @change="select_county_event" :value="county_value" :range="county_list" range-key="name">
  47. <view :class="'name ' + ((county_value == null) ? 'cr-grey' : 'cr-base' )">{{((county_list[county_value] || null) == null) ? default_county : county_list[county_value]['name']}}</view>
  48. </picker>
  49. <text v-else class="cr-grey" @tap="region_select_error_event" data-value="请先选择城市">请先选择城市</text>
  50. </view>
  51. </view>
  52. </view>
  53. <view class="form-gorup bg-white">
  54. <view class="form-gorup-title">详细地址<text class="form-group-tips-must">*</text></view>
  55. <input type="text" name="address" :value="extraction_data.address || ''" placeholder-class="cr-grey" class="cr-base" placeholder="详细地址格式 1~80 个字符之间">
  56. </view>
  57. <view class="form-gorup bg-white">
  58. <view class="form-gorup-title">地理位置<text class="form-group-tips-must">必选</text></view>
  59. <view @tap="choose_location_event" class="form-gorup-text">
  60. <view v-if="(user_location || null) == null" class="cr-gray">请选择地理位置</view>
  61. <view v-else class="cr-base">{{user_location.lng}}, {{user_location.lat}}</view>
  62. </view>
  63. </view>
  64. <view v-if="(extraction_data || null) != null && (extraction_data.status || 0) == 1" class="notice-content-blue spacing-mb">
  65. 注意:编辑信息将重新审核后方可生效
  66. </view>
  67. <view class="bottom-fixed padding-main">
  68. <button class="bg-main br-main cr-white round text-size" type="default" form-type="submit" hover-class="none" :disabled="form_submit_disabled_status">提交</button>
  69. </view>
  70. </view>
  71. </form>
  72. </view>
  73. </template>
  74. <script>
  75. const app = getApp();
  76. var common_static_url = app.globalData.get_static_url('common');
  77. export default {
  78. data() {
  79. return {
  80. common_static_url: common_static_url,
  81. params: null,
  82. data_list_loding_status: 1,
  83. data_list_loding_msg: '',
  84. extraction_data: {},
  85. province_list: [],
  86. city_list: [],
  87. county_list: [],
  88. province_id: null,
  89. city_id: null,
  90. county_id: null,
  91. editor_path_type: '',
  92. default_province: "请选择省",
  93. default_city: "请选择市",
  94. default_county: "请选择区/县",
  95. province_value: null,
  96. city_value: null,
  97. county_value: null,
  98. user_location_cache_key: app.globalData.data.cache_userlocation_key,
  99. user_location: null,
  100. form_submit_disabled_status: false
  101. };
  102. },
  103. components: {},
  104. props: {},
  105. onLoad(params) {
  106. this.setData({
  107. params: params
  108. });
  109. },
  110. onReady: function() {
  111. // 清除位置缓存信息
  112. uni.removeStorage({
  113. key: this.user_location_cache_key
  114. });
  115. this.init();
  116. },
  117. onShow() {
  118. this.user_location_init();
  119. // 分享菜单处理
  120. app.globalData.page_share_handle();
  121. },
  122. methods: {
  123. init() {
  124. var user = app.globalData.get_user_info(this, "init");
  125. if (user != false) {
  126. // 用户未绑定用户则转到登录页面
  127. if (app.globalData.user_is_need_login(user)) {
  128. uni.redirectTo({
  129. url: "/pages/login/login?event_callback=init"
  130. });
  131. this.setData({
  132. data_list_loding_status: 2,
  133. data_list_loding_msg: '请先绑定手机号码'
  134. });
  135. return false;
  136. } else {
  137. this.get_province_list();
  138. this.applyinfo_init();
  139. }
  140. } else {
  141. this.setData({
  142. data_list_loding_status: 2,
  143. data_list_loding_msg: '请先授权用户信息'
  144. });
  145. }
  146. },
  147. // 自提点信息
  148. applyinfo_init() {
  149. var self = this;
  150. uni.request({
  151. url: app.globalData.get_request_url("applyinfo", "extraction", "distribution"),
  152. method: 'POST',
  153. data: {},
  154. dataType: 'json',
  155. success: res => {
  156. if (res.data.code == 0) {
  157. var data = res.data.data;
  158. var extraction_data = data.extraction_data || null;
  159. self.setData({
  160. extraction_data: extraction_data || {},
  161. editor_path_type: data.editor_path_type || ''
  162. });
  163. // 数据设置
  164. if (extraction_data != null) {
  165. self.setData({
  166. province_id: extraction_data.province || null,
  167. city_id: extraction_data.city || null,
  168. county_id: extraction_data.county || null
  169. });
  170. // 地理位置
  171. var lng = extraction_data.lng || 0;
  172. var lat = extraction_data.lat || 0;
  173. if (lng != 0 && lat != 0) {
  174. self.setData({
  175. user_location: {
  176. lng: lng,
  177. lat: lat,
  178. address: extraction_data.address || ''
  179. }
  180. });
  181. }
  182. }
  183. // 获取城市、区县
  184. self.get_city_list();
  185. self.get_county_list();
  186. // 半秒后初始化数据
  187. setTimeout(function() {
  188. self.init_region_value();
  189. }, 500);
  190. } else {
  191. if (app.globalData.is_login_check(res.data)) {
  192. app.globalData.showToast(res.data.msg);
  193. }
  194. }
  195. },
  196. fail: () => {
  197. app.globalData.showToast("省份信息失败");
  198. }
  199. });
  200. },
  201. // 地区数据初始化
  202. init_region_value() {
  203. this.setData({
  204. province_value: this.get_region_value("province_list", "province_id"),
  205. city_value: this.get_region_value("city_list", "city_id"),
  206. county_value: this.get_region_value("county_list", "county_id")
  207. });
  208. },
  209. // 地区初始化匹配索引
  210. get_region_value(list, id) {
  211. var data = this[list];
  212. var data_id = this[id];
  213. var value = null;
  214. data.forEach((d, i) => {
  215. if (d.id == data_id) {
  216. value = i;
  217. return false;
  218. }
  219. });
  220. return value;
  221. },
  222. // 获取省份
  223. get_province_list() {
  224. var self = this;
  225. uni.request({
  226. url: app.globalData.get_request_url("index", "region"),
  227. method: 'POST',
  228. data: {},
  229. dataType: 'json',
  230. success: res => {
  231. if (res.data.code == 0) {
  232. var data = res.data.data;
  233. self.setData({
  234. province_list: data
  235. });
  236. } else {
  237. app.globalData.showToast(res.data.msg);
  238. }
  239. },
  240. fail: () => {
  241. app.globalData.showToast("省份获取失败");
  242. }
  243. });
  244. },
  245. // 获取市
  246. get_city_list() {
  247. var self = this;
  248. if (self.province_id) {
  249. uni.request({
  250. url: app.globalData.get_request_url("index", "region"),
  251. method: 'POST',
  252. data: {
  253. pid: self.province_id
  254. },
  255. dataType: 'json',
  256. success: res => {
  257. if (res.data.code == 0) {
  258. var data = res.data.data;
  259. self.setData({
  260. city_list: data
  261. });
  262. } else {
  263. app.globalData.showToast(res.data.msg);
  264. }
  265. },
  266. fail: () => {
  267. app.globalData.showToast("城市获取失败");
  268. }
  269. });
  270. }
  271. },
  272. // 获取区/县
  273. get_county_list() {
  274. var self = this;
  275. if (self.city_id) {
  276. // 加载loding
  277. uni.request({
  278. url: app.globalData.get_request_url("index", "region"),
  279. method: 'POST',
  280. data: {
  281. pid: self.city_id
  282. },
  283. dataType: 'json',
  284. success: res => {
  285. if (res.data.code == 0) {
  286. var data = res.data.data;
  287. self.setData({
  288. county_list: data
  289. });
  290. } else {
  291. app.globalData.showToast(res.data.msg);
  292. }
  293. },
  294. fail: () => {
  295. app.globalData.showToast("区/县获取失败");
  296. }
  297. });
  298. }
  299. },
  300. // 省份事件
  301. select_province_event(e) {
  302. var index = e.detail.value || 0;
  303. if (index >= 0) {
  304. var data = this.province_list[index];
  305. this.setData({
  306. province_value: index,
  307. province_id: data.id,
  308. city_value: null,
  309. county_value: null,
  310. city_id: null,
  311. county_id: null
  312. });
  313. this.get_city_list();
  314. }
  315. },
  316. // 市事件
  317. select_city_event(e) {
  318. var index = e.detail.value || 0;
  319. if (index >= 0) {
  320. var data = this.city_list[index];
  321. this.setData({
  322. city_value: index,
  323. city_id: data.id,
  324. county_value: null,
  325. county_id: null
  326. });
  327. this.get_county_list();
  328. }
  329. },
  330. // 区/县事件
  331. select_county_event(e) {
  332. var index = e.detail.value || 0;
  333. if (index >= 0) {
  334. var data = this.county_list[index];
  335. this.setData({
  336. county_value: index,
  337. county_id: data.id
  338. });
  339. }
  340. },
  341. // 省市区未按照顺序选择提示
  342. region_select_error_event(e) {
  343. var value = e.currentTarget.dataset.value || null;
  344. if (value != null) {
  345. app.globalData.showToast(value);
  346. }
  347. },
  348. // 选择地理位置
  349. choose_location_event(e) {
  350. uni.navigateTo({
  351. url: '/pages/common/open-setting-location/open-setting-location'
  352. });
  353. },
  354. // 地址信息初始化
  355. user_location_init() {
  356. var result = uni.getStorageSync(this.user_location_cache_key) || null;
  357. var data = null;
  358. if (result != null) {
  359. data = {
  360. name: result.name || null,
  361. address: result.address || null,
  362. lat: result.latitude || null,
  363. lng: result.longitude || null
  364. };
  365. }
  366. this.setData({
  367. user_location: data
  368. });
  369. },
  370. // 数据提交
  371. form_submit(e) {
  372. var self = this;
  373. // 表单数据
  374. var form_data = e.detail.value;
  375. // 数据校验
  376. var validation = [
  377. { fields: "name", msg: "请填写联系人" },
  378. { fields: "tel", msg: "请填写联系电话" },
  379. { fields: "province", msg: "请选择省份" },
  380. { fields: "city", msg: "请选择城市" },
  381. { fields: "county", msg: "请选择区县" },
  382. { fields: "address", msg: "请填写详细地址" },
  383. { fields: "lng", msg: "请选择地理位置" },
  384. { fields: "lat", msg: "请选择地理位置" }
  385. ];
  386. // logo
  387. form_data['logo'] = (this.extraction_data || null) != null ? this.extraction_data.logo || '' : '';
  388. // 地区
  389. form_data["province"] = self.province_id;
  390. form_data["city"] = self.city_id;
  391. form_data["county"] = self.county_id;
  392. // 地理位置
  393. var lng = 0;
  394. var lat = 0;
  395. if ((self.user_location || null) != null) {
  396. lng = self.user_location.lng || 0;
  397. lat = self.user_location.lat || 0;
  398. }
  399. if ((self.extraction_data || null) != null) {
  400. if ((lng || null) == null) {
  401. lng = self.extraction_data.lng || 0;
  402. }
  403. if ((lat || null) == null) {
  404. lat = self.extraction_data.lat || 0;
  405. }
  406. }
  407. form_data["lng"] = lng;
  408. form_data["lat"] = lat;
  409. // 验证提交表单
  410. if (app.globalData.fields_check(form_data, validation)) {
  411. if ((self.extraction_data || null) != null && (self.extraction_data.status || 0) == 1) {
  412. uni.showModal({
  413. title: '温馨提示',
  414. content: '数据需重新审核后方可生效',
  415. confirmText: '确认',
  416. cancelText: '暂不',
  417. success: result => {
  418. if (result.confirm) {
  419. self.request_data_save(form_data);
  420. }
  421. }
  422. });
  423. } else {
  424. self.request_data_save(form_data);
  425. }
  426. }
  427. },
  428. // 数据保存
  429. request_data_save(data) {
  430. var self = this;
  431. self.setData({
  432. form_submit_disabled_status: true
  433. });
  434. uni.showLoading({
  435. title: '处理中...'
  436. });
  437. uni.request({
  438. url: app.globalData.get_request_url("applysave", "extraction", "distribution"),
  439. method: 'POST',
  440. data: data,
  441. dataType: 'json',
  442. success: res => {
  443. uni.hideLoading();
  444. if (res.data.code == 0) {
  445. app.globalData.showToast(res.data.msg, 'success');
  446. setTimeout(function() {
  447. uni.navigateBack();
  448. }, 1000);
  449. } else {
  450. self.setData({
  451. form_submit_disabled_status: false
  452. });
  453. if (app.globalData.is_login_check(res.data)) {
  454. app.globalData.showToast(res.data.msg);
  455. } else {
  456. app.globalData.showToast('提交失败,请重试!');
  457. }
  458. }
  459. },
  460. fail: () => {
  461. self.setData({
  462. form_submit_disabled_status: false
  463. });
  464. uni.hideLoading();
  465. app.globalData.showToast('服务器请求出错');
  466. }
  467. });
  468. },
  469. // 上传图片预览
  470. upload_show_event(e) {
  471. uni.previewImage({
  472. current: this.extraction_data.logo,
  473. urls: [this.extraction_data.logo]
  474. });
  475. },
  476. // 图片删除
  477. upload_delete_event(e) {
  478. var self = this;
  479. uni.showModal({
  480. title: '温馨提示',
  481. content: '删除后不可恢复、继续吗?',
  482. success(res) {
  483. if (res.confirm) {
  484. var temp_data = self.extraction_data || {};
  485. temp_data['logo'] = '';
  486. self.setData({
  487. extraction_data: temp_data
  488. });
  489. }
  490. }
  491. });
  492. },
  493. // 文件上传
  494. file_upload_event(e) {
  495. var self = this;
  496. uni.chooseImage({
  497. count: 1,
  498. success(res) {
  499. var success = 0;
  500. var fail = 0;
  501. var length = res.tempFilePaths.length;
  502. var count = 0;
  503. self.upload_one_by_one(res.tempFilePaths, success, fail, count, length);
  504. }
  505. });
  506. },
  507. // 采用递归的方式上传多张
  508. upload_one_by_one(img_paths, success, fail, count, length) {
  509. var self = this;
  510. uni.uploadFile({
  511. url: app.globalData.get_request_url("index", "ueditor"),
  512. filePath: img_paths[count],
  513. name: 'upfile',
  514. formData: {
  515. action: 'uploadimage',
  516. path_type: self.editor_path_type
  517. },
  518. success: function(res) {
  519. success++;
  520. if (res.statusCode == 200) {
  521. var data = typeof res.data == 'object' ? res.data : JSON.parse(res.data);
  522. if (data.code == 0 && (data.data.url || null) != null) {
  523. var temp_data = self.extraction_data || {};
  524. temp_data['logo'] = data.data.url;
  525. self.setData({
  526. extraction_data: temp_data
  527. });
  528. } else {
  529. app.globalData.showToast(data.msg);
  530. }
  531. }
  532. },
  533. fail: function(e) {
  534. fail++;
  535. },
  536. complete: function(e) {
  537. count++;
  538. // 下一张
  539. if (count >= length) {
  540. // 上传完毕,作一下提示
  541. //app.showToast('上传成功' + success +'张', 'success');
  542. } else {
  543. // 递归调用,上传下一张
  544. self.upload_one_by_one(img_paths, success, fail, count, length);
  545. }
  546. }
  547. });
  548. }
  549. }
  550. };
  551. </script>
  552. <style>
  553. @import './extraction-apply.css';
  554. </style>