shopAdd.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. <!--
  2. * @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
  3. * @Date: 2023-05-26 16:37:34
  4. * @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
  5. * @LastEditTime: 2024-02-22 16:21:34
  6. * @FilePath: \admin-manage\src\views\operationManage\shopManage\shopAdd.vue
  7. * @Description:
  8. *
  9. * Copyright (c) 2023 by ${git_name_email}, All Rights Reserved.
  10. -->
  11. <template>
  12. <div class="shopAdd app-container" v-loading="loading">
  13. <el-form
  14. :model="setQuery"
  15. ref="setQuery"
  16. :rules="rules"
  17. v-loading="pageLoading"
  18. :disabled="disabled"
  19. label-width="130px"
  20. >
  21. <el-form-item label="主体名称:" prop="shopMainId">
  22. <el-select v-model="setQuery.shopMainId" size="small" filterable class="item-width-300" placeholder="请搜索选择店铺主体">
  23. <el-option
  24. v-for="item in shopMainOptions"
  25. :key="item.value"
  26. :label="item.label"
  27. :value="item.value">
  28. </el-option>
  29. </el-select>
  30. </el-form-item>
  31. <el-form-item label="店铺名称:" prop="shopName">
  32. <el-input
  33. v-model.number="setQuery.shopName"
  34. size="small"
  35. :maxlength="18"
  36. class="item-width-300"
  37. ></el-input>
  38. </el-form-item>
  39. <el-form-item label="店铺地址:" prop="address">
  40. <el-input
  41. disabled
  42. v-model="setQuery.address"
  43. class="item-width-500"
  44. size="small"
  45. placeholder="请点击右侧定位图标选择店铺地址"
  46. ></el-input>
  47. <i class="el-icon-location ml10 position red" @click="chooseAddress"></i>
  48. </el-form-item>
  49. <el-form-item label="店铺类型:" prop="shopType">
  50. <el-select v-model="setQuery.shopType" size="small" class="item-width-300" placeholder="请选择店铺经营类型">
  51. <el-option
  52. v-for="item in options1"
  53. :key="item.value"
  54. :label="item.label"
  55. :value="item.value">
  56. </el-option>
  57. </el-select>
  58. </el-form-item>
  59. <el-form-item label="店铺经营类型:" prop="shopMenuId">
  60. <el-select v-model="setQuery.shopMenuId" size="small" class="item-width-300" placeholder="请选择店铺经营类型">
  61. <el-option
  62. v-for="item in options"
  63. :key="item.value"
  64. :label="item.label"
  65. :value="item.value">
  66. </el-option>
  67. </el-select>
  68. </el-form-item>
  69. <el-form-item label="店铺头像:" prop="logoPath">
  70. <Upload
  71. type="logoPath"
  72. id="logoPath"
  73. width="250px"
  74. height="150px"
  75. :disabled="mode == 'detail'"
  76. uploadType="SHOP_INFO"
  77. :imgUrl="setQuery.logoPath"
  78. @uploadEnd="uploadEnd"
  79. ></Upload>
  80. </el-form-item>
  81. <el-form-item label="店铺门头图片:" prop="doorImg">
  82. <Upload
  83. type="doorImg"
  84. id="doorImg"
  85. width="250px"
  86. height="150px"
  87. :disabled="mode == 'detail'"
  88. uploadType="SHOP_INFO"
  89. :imgUrl="setQuery.doorImg"
  90. @uploadEnd="uploadEnd"
  91. ></Upload>
  92. </el-form-item>
  93. <el-form-item label="店铺简介:">
  94. <el-input
  95. type="textarea"
  96. placeholder="请输入店铺简介"
  97. v-model="setQuery.detailContent"
  98. maxlength="400"
  99. class="item-width-500"
  100. show-word-limit
  101. >
  102. </el-input>
  103. </el-form-item>
  104. </el-form>
  105. <el-dialog title="选择地址" close="chose-model" :close-on-press-escape="false" :show-close="false" :close-on-click-modal="false" width="60vw" :visible.sync="showMap">
  106. <div id="container"></div>
  107. <div class="address-input-box">
  108. <el-input
  109. v-model="setQuery.address"
  110. size="small"
  111. class="address-input"
  112. placeholder="请先点击地图定位,再修改详细地址"
  113. ></el-input>
  114. <el-button type="primary" size="small" class="address-btn" @click="saveAddress">提 交</el-button>
  115. </div>
  116. </el-dialog>
  117. <!-- 新增和编辑模式 -->
  118. <div class="btn-group" v-if="mode == 'add'|| mode == 'edit'">
  119. <el-button>取 消</el-button>
  120. <el-button type="primary" :loading="loading" @click="save"
  121. >提交</el-button >
  122. </div>
  123. <!-- 详情时的按钮 -->
  124. <div class="btn-group" v-else>
  125. <el-button>取 消</el-button>
  126. <el-button type="primary" :loading="loading" @click="edit"
  127. >编辑</el-button >
  128. </div>
  129. </div>
  130. </template>
  131. <script>
  132. import Upload from "@/components/Upload";
  133. import { add, detail, update,getMainName } from "@/api/shop";
  134. import {getMenuName} from '@/api/appConfig';
  135. import {getRuleList} from '@/api/commission'
  136. import { debounce } from "@/utils/index";
  137. export default {
  138. components: {
  139. Upload,
  140. },
  141. data() {
  142. return {
  143. map:null,
  144. mode:'detail',//编辑模式
  145. showMap:false,
  146. setQuery: {
  147. address: "",
  148. businessImg: "",
  149. city: "",
  150. detailImg: "",
  151. district: "",
  152. doorImg: "",
  153. handlerImg: "",
  154. idCardBack: "",
  155. idCardFront: "",
  156. idCardNo: "",
  157. logoPath: "",
  158. mapLat: "",
  159. mapLon: "",
  160. province: "",
  161. serviceName: "",
  162. serviceTel: "",
  163. shopLabel: "",
  164. shopMainId: "",
  165. shopName: "",
  166. shopType: '',
  167. source:'2',
  168. shareChannelId:''
  169. },
  170. ruleOptions:[],
  171. options:[],
  172. options1:[
  173. {
  174. value: 1,
  175. label: "小微商户",
  176. },
  177. {
  178. value: 2,
  179. label: "个体工商户",
  180. },
  181. {
  182. value: 3,
  183. label: "企业",
  184. },
  185. {
  186. value: 4,
  187. label: "机关事业单位或社会团体",
  188. },
  189. ],
  190. shopMainOptions:[],//主体选择
  191. disabled: false,
  192. pageLoading: false, //页面loading
  193. loading: false,
  194. rules: {
  195. shopMainId: [
  196. { required: true, message: "请选择商铺主体", trigger: "change" },
  197. ],
  198. shopMenuId: [
  199. { required: true, message: "请选择商铺经营类型", trigger: "change" },
  200. ],
  201. shopType: [
  202. { required: true, message: "请选择商铺类型", trigger: "change" },
  203. ],
  204. shopName: [
  205. { required: true, message: "请输入商铺名称", trigger: "blur" },
  206. ],
  207. address: [
  208. { required: true, message: "请输入商铺地址", trigger: "blur" },
  209. ],
  210. shareChannelId: [
  211. { required: true, message: "请选择商家佣金", trigger: "change" },
  212. ],
  213. logoPath: [
  214. { required: true, message: "请上传店铺头像", trigger: "change" },
  215. ],
  216. doorImg: [
  217. { required: true, message: "请上传门头照", trigger: "change" },
  218. ],
  219. detailImg: [
  220. { required: true, message: "请上传店铺详情图", trigger: "change" },
  221. ],
  222. businessImg: [
  223. { required: true, message: "请上传营业执照", trigger: "change" },
  224. ],
  225. serviceName: [
  226. { required: true, message: "请输入联系人", trigger: "blur" },
  227. ],
  228. serviceTel: [
  229. { required: true, message: "请输入客服电话", trigger: "blur" },
  230. ],
  231. idCardBack: [
  232. {
  233. required: true,
  234. message: "请上传法人身份证反面照",
  235. trigger: "change",
  236. },
  237. ],
  238. idCardFront: [
  239. {
  240. required: true,
  241. message: "请上传法人身份证正面照",
  242. trigger: "change",
  243. },
  244. ],
  245. handlerImg: [
  246. {
  247. required: true,
  248. message: "请上传法人手持身份证照",
  249. trigger: "change",
  250. },
  251. ],
  252. },
  253. };
  254. },
  255. watch: {
  256. 'setQuery.address':debounce(function(val){
  257. if(this.map){
  258. let that = this
  259. //创建地址解析器实例
  260. var myGeo = new BMapGL.Geocoder();
  261. that.marker? that.map.removeOverlay(that.marker):''
  262. // 将地址解析结果显示在地图上,并调整地图视野
  263. myGeo.getPoint(val, function(point){
  264. if(point ){
  265. console.log(point);
  266. that.setQuery.mapLat = point.lat
  267. that.setQuery.mapLon = point.lng
  268. that.marker = new BMapGL.Marker(point, {title: val})
  269. if(that.map){
  270. that.map.centerAndZoom(point, 16);
  271. that.map.addOverlay(that.marker)
  272. }
  273. }
  274. }, that.setQuery.city)
  275. }
  276. })
  277. },
  278. methods: {
  279. edit(){
  280. this.$router.push({
  281. path: "/operationManage/shopManage/shopAdd",
  282. query: {
  283. title: "店铺编辑",
  284. id:this.$route.query.id,
  285. },
  286. });
  287. },
  288. save() {
  289. this.$refs.setQuery.validate((v) => {
  290. if (v) {
  291. if(this.loading) return
  292. if (this.setQuery.shopId) {
  293. this.update();
  294. } else {
  295. this.add();
  296. }
  297. }
  298. });
  299. },
  300. add() {
  301. this.loading = true;
  302. add(this.setQuery).then((res) => {
  303. this.loading = false;
  304. if (res.state == "Success") {
  305. this.$notify({
  306. title: "成功",
  307. message: "操作成功",
  308. type: "success",
  309. });
  310. this.$router.push("/operationManage/shopManage/index");
  311. }
  312. });
  313. },
  314. update() {
  315. this.loading = true;
  316. update(this.setQuery).then((res) => {
  317. this.loading = false;
  318. if (res.state == "Success") {
  319. this.$notify({
  320. title: "成功",
  321. message: "操作成功",
  322. type: "success",
  323. });
  324. this.$router.push("/operationManage/shopManage/index");
  325. }
  326. });
  327. },
  328. // 图片统一上传
  329. uploadEnd(val) {
  330. this.setQuery[val.type] = val.url;
  331. },
  332. detail() {
  333. this.pageLoading = true;
  334. detail({ shopId: this.$route.query.id }).then((res) => {
  335. this.pageLoading = false;
  336. if (res.state == "Success") {
  337. this.setQuery = res.content;
  338. }
  339. });
  340. },
  341. // 获取经营类型
  342. getMenuName(){
  343. getMenuName().then(res=>{
  344. if(res.state == 'Success'){
  345. for (const key in res.content) {
  346. if (res.content.hasOwnProperty.call(res.content, key)) {
  347. this.options.push({
  348. label:res.content[key],
  349. value:Number(key)
  350. })
  351. }
  352. }
  353. }
  354. })
  355. },
  356. // 获取主体类型
  357. getMainName(){
  358. getMainName().then(res=>{
  359. if(res.state == 'Success'){
  360. for (const key in res.content) {
  361. if (Object.hasOwnProperty.call(res.content, key)) {
  362. this.shopMainOptions.push({
  363. label:res.content[key],
  364. value:key
  365. })
  366. }
  367. }
  368. }
  369. })
  370. },
  371. // 选择经营地址
  372. chooseAddress() {
  373. if(this.mode == 'detail') return
  374. this.showMap = true;
  375. let that = this
  376. this.$nextTick(() => {
  377. this.map = new BMapGL.Map("container");
  378. var geoc = new BMapGL.Geocoder();
  379. that.map.enableScrollWheelZoom(); // 启用滚轮放大缩小
  380. var myCity = new BMapGL.LocalCity();
  381. myCity.get((result)=> {
  382. console.log(result);
  383. var cityName = result.name;
  384. that.map.setCenter(cityName);
  385. var point = new BMapGL.Point(result.center.lat, result.center.lng);
  386. that.map.centerAndZoom(point, 15);
  387. let cache = this.setQuery.address
  388. this.setQuery.address = '切换地址触发标记点'
  389. setTimeout(() => {
  390. this.setQuery.address = cache
  391. }, 100);
  392. });
  393. that.map.addEventListener("click", function (e) {
  394. console.log(1111111,e.latlng);
  395. var pt = e.latlng;
  396. that.map.removeOverlay(that.marker); //移除点标记
  397. geoc.getLocation(pt, function (rs) {
  398. var addComp = rs.addressComponents;
  399. let point1 = new BMapGL.Point(rs.point.lng, rs.point.lat);
  400. that.marker = new BMapGL.Marker(point1); // 创建标注
  401. that.map.addOverlay(that.marker); // 将标注添加到地图中
  402. that.setQuery.address = rs.address +rs.content.poi_desc
  403. // 选择营业地址时保存省市区
  404. that.setQuery.province = addComp.province
  405. that.setQuery.city = addComp.city
  406. that.setQuery.district = addComp.district
  407. that.setQuery.mapLat = rs.point.lat
  408. that.setQuery.mapLon = rs.point.lng
  409. console.log(rs);
  410. });
  411. });
  412. });
  413. },
  414. // 保存地址
  415. saveAddress(){
  416. this.$confirm('请确认地址信息准确无误,并精确到门牌号?', '提示', {
  417. confirmButtonText: '确定',
  418. cancelButtonText: '取消',
  419. type: 'warning'
  420. }).then(() => {
  421. this.showMap = false
  422. })
  423. },
  424. getRuleList(){
  425. getRuleList().then(res=>{
  426. if(res.state == 'Success'){
  427. console.log(res.content.records);
  428. this.ruleOptions = res.content.records.filter(item=>item.shareType == 2)
  429. // for (const key in res.content) {
  430. // if (Object.hasOwnProperty.call(res.content, key)) {
  431. // this.shopMainOptions.push({
  432. // label:res.content[key],
  433. // value:key
  434. // })
  435. // }
  436. // }
  437. }
  438. })
  439. }
  440. },
  441. created() {
  442. this.getRuleList()
  443. this.getMenuName()
  444. this.getMainName()
  445. if (this.$route.query.title == "店铺编辑") {
  446. this.disabled = false;
  447. this.mode = 'edit'
  448. this.detail();
  449. } else if (this.$route.query.title == "店铺详情") {
  450. this.disabled = true;
  451. this.mode = 'detail'
  452. this.detail();
  453. } else {
  454. this.disabled = false;
  455. this.mode = 'add'
  456. }
  457. },
  458. };
  459. </script>
  460. <style lang="scss" scoped>
  461. .shopAdd {
  462. padding-bottom: 40px;
  463. .position{
  464. cursor: pointer;
  465. font-size: 20px;
  466. }
  467. .btn-group {
  468. display: flex;
  469. align-items: center;
  470. justify-content: center;
  471. }
  472. #container {
  473. width: 100%;
  474. height: 600px;
  475. }
  476. }
  477. </style>