index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. <template>
  2. <el-card class="box-card">
  3. <h3>新建门店</h3>
  4. <div class="wrapper">
  5. <el-form
  6. :model="ruleForm"
  7. :rules="rules"
  8. ref="ruleForm"
  9. label-width="110px"
  10. class="demo-ruleForm"
  11. :inline="true"
  12. size="medium"
  13. >
  14. <el-row>
  15. <el-col :span="9">
  16. <el-form-item label="门店名称" prop="name">
  17. <el-input
  18. v-model="ruleForm.name"
  19. placeholder="Nowwa挪瓦咖啡(测试店)"
  20. ></el-input>
  21. <span class="tip">严格按照此命名,替换测试二字</span>
  22. </el-form-item>
  23. </el-col>
  24. <el-col :span="8">
  25. <el-form-item label="门店类别" prop="category">
  26. <el-select v-model="ruleForm.category" placeholder="门店类别">
  27. <el-option
  28. v-for="item in categoryArr"
  29. :label="item.label"
  30. :value="item.value"
  31. :key="item.value"
  32. ></el-option>
  33. </el-select>
  34. </el-form-item>
  35. </el-col>
  36. </el-row>
  37. <el-row>
  38. <el-col :span="9">
  39. <el-form-item label="营业时间" prop="businesshour">
  40. <el-time-picker
  41. is-range
  42. value-format="HH:mm"
  43. format="HH:mm"
  44. v-model="ruleForm.businesshour"
  45. range-separator="至"
  46. start-placeholder="开始时间"
  47. end-placeholder="结束时间"
  48. placeholder="选择时间范围"
  49. >
  50. </el-time-picker>
  51. </el-form-item>
  52. </el-col>
  53. <el-col :span="10">
  54. <el-form-item label="banner">
  55. <el-input
  56. v-model="ruleForm.banner"
  57. placeholder="门店banner"
  58. ></el-input>
  59. <span class="tip">请先用上传工具上传,也可以在上传后再改</span>
  60. </el-form-item>
  61. </el-col>
  62. </el-row>
  63. <el-row>
  64. <el-col :span="8"
  65. ><el-form-item label="城市(地级市)" prop="city">
  66. <el-input v-model="ruleForm.city" placeholder="成都市"></el-input>
  67. <!-- <span class="tip">城市(地级市)</span> -->
  68. </el-form-item>
  69. </el-col>
  70. <el-col :span="7">
  71. <el-form-item label="区县、县级市" prop="district">
  72. <el-input
  73. v-model="ruleForm.district"
  74. placeholder="青羊区"
  75. ></el-input>
  76. <!-- <span class="tip">区县、县级市</span> -->
  77. </el-form-item>
  78. </el-col>
  79. <el-col :span="9">
  80. <el-form-item label="详细地址" prop="address">
  81. <el-input
  82. v-model="ruleForm.address"
  83. placeholder="青羊区春熙路1号"
  84. @keyup.enter.native="gettxLng"
  85. ></el-input>
  86. <!-- <span class="tip">以区县开头什么路多少号</span> -->
  87. </el-form-item>
  88. </el-col>
  89. </el-row>
  90. <el-row>
  91. <el-col :span="8">
  92. <el-form-item label="腾讯地图纬度" prop="txlat">
  93. <el-input
  94. v-model="ruleForm.txlat"
  95. type="number"
  96. placeholder="腾讯地图纬度"
  97. ></el-input>
  98. </el-form-item>
  99. </el-col>
  100. <el-col :span="8">
  101. <el-form-item label="腾讯地图经度" prop="txlng">
  102. <el-input
  103. type="number"
  104. v-model="ruleForm.txlng"
  105. placeholder="腾讯地图经度"
  106. ></el-input>
  107. </el-form-item>
  108. </el-col>
  109. <el-col :span="8"> </el-col>
  110. </el-row>
  111. <el-row>
  112. <el-col :span="8">
  113. <el-form-item label="高德地图纬度" prop="gdlat">
  114. <el-input
  115. type="number"
  116. v-model="ruleForm.gdlat"
  117. placeholder="高德地图纬度"
  118. ></el-input>
  119. </el-form-item>
  120. </el-col>
  121. <el-col :span="8">
  122. <el-form-item label="高德地图经度" prop="gdlng">
  123. <el-input
  124. type="number"
  125. v-model="ruleForm.gdlng"
  126. placeholder="高德地图经度"
  127. ></el-input>
  128. </el-form-item>
  129. </el-col>
  130. <el-col :span="8"></el-col>
  131. </el-row>
  132. <el-row>
  133. <el-col :span="8">
  134. <el-form-item label="老板姓名" prop="contactname">
  135. <el-input
  136. v-model="ruleForm.contactname"
  137. placeholder="老板姓名"
  138. ></el-input>
  139. </el-form-item>
  140. </el-col>
  141. <el-col :span="7">
  142. <el-form-item label="老板手机" prop="takeawayphone">
  143. <el-input
  144. type="number"
  145. v-model="ruleForm.takeawayphone"
  146. placeholder="老板手机,仅作记录"
  147. ></el-input>
  148. </el-form-item>
  149. </el-col>
  150. <el-col :span="9">
  151. <el-form-item label="运营手机号" prop="contactphone">
  152. <el-input
  153. type="tel"
  154. v-model="ruleForm.contactphone"
  155. placeholder="运营手机号"
  156. ></el-input>
  157. <span class="tip">用来登录商家端小程序</span>
  158. </el-form-item>
  159. </el-col>
  160. </el-row>
  161. <el-row> </el-row>
  162. <el-row>
  163. <el-col>
  164. <el-form-item label="k4或k6机器码">
  165. <el-tag
  166. :key="tag"
  167. v-for="tag in dynamicTags"
  168. closable
  169. :disable-transitions="false"
  170. @close="handleClose(tag, 'k4')"
  171. >
  172. {{ tag }}
  173. </el-tag>
  174. <el-input
  175. class="input-new-tag"
  176. v-if="inputVisible"
  177. v-model="inputValue"
  178. ref="saveTagInput"
  179. size="small"
  180. @keyup.enter.native="handleInputConfirm('k4')"
  181. @blur="handleInputConfirm('k4')"
  182. >
  183. </el-input>
  184. <el-button
  185. v-else
  186. class="button-new-tag"
  187. size="small"
  188. @click="showInput('k4')"
  189. >+</el-button
  190. >
  191. </el-form-item>
  192. </el-col>
  193. </el-row>
  194. <el-row>
  195. <el-col>
  196. <el-form-item label="k5">
  197. <el-tag
  198. :key="tag"
  199. v-for="tag in k5_dynamicTags"
  200. closable
  201. :disable-transitions="false"
  202. @close="handleClose(tag, 'k5')"
  203. >
  204. {{ tag }}
  205. </el-tag>
  206. <el-input
  207. class="input-new-tag"
  208. v-if="k5_inputVisible"
  209. v-model="k5_inputValue"
  210. ref="k5_saveTagInput"
  211. size="small"
  212. @keyup.enter.native="handleInputConfirm('k5')"
  213. @blur="handleInputConfirm('k5')"
  214. >
  215. </el-input>
  216. <el-button
  217. v-else
  218. class="button-new-tag"
  219. size="small"
  220. @click="showInput('k5')"
  221. >+</el-button
  222. >
  223. </el-form-item>
  224. </el-col>
  225. </el-row>
  226. <!-- ------------------------------ -->
  227. <div class="upload-box">
  228. <el-form-item>
  229. <el-button type="primary" @click="submitForm('ruleForm')"
  230. >立即创建</el-button
  231. >
  232. <el-button @click="resetForm('ruleForm')">重置</el-button>
  233. </el-form-item>
  234. </div>
  235. </el-form>
  236. <div class="upload-tip">
  237. <div>温馨提示:</div>
  238. <div class="pd-20">
  239. <div>
  240. <el-link
  241. type="primary"
  242. target="_blank"
  243. href="https://lbs.qq.com/getPoint/"
  244. >腾讯地图地址</el-link
  245. >
  246. </div>
  247. <div>
  248. <el-link
  249. type="primary"
  250. target="_blank"
  251. href="https://lbs.amap.com/tools/picker"
  252. >高德地图地址</el-link
  253. >
  254. </div>
  255. <div>
  256. 如需上传banner,请上传至 nowwa/shop_banner/ 目录<el-link
  257. href="https://help.aliyun.com/document_detail/195868.html?spm=a2c4g.11186623.6.620.74d062e7wbqjEy"
  258. target="_blank"
  259. type="success"
  260. >图片上传工具下载</el-link
  261. >
  262. </div>
  263. </div>
  264. </div>
  265. </div>
  266. </el-card>
  267. </template>
  268. <script>
  269. import { createShop } from "@/api/shop.js";
  270. const categoryArr = [
  271. {
  272. label: "支持外送和自提",
  273. value: 1
  274. },
  275. {
  276. label: "仅外卖",
  277. value: 2
  278. },
  279. {
  280. label: "仅自提",
  281. value: 3
  282. },
  283. {
  284. label: "2.0/3.0门店",
  285. value: 9
  286. }
  287. ];
  288. export default {
  289. data() {
  290. var checkPhone = (rule, value, callback) => {
  291. if (!value) {
  292. return callback(new Error("手机号不能为空"));
  293. } else {
  294. const reg = /^1[3|4|5|7|8][0-9]\d{8}$/;
  295. console.log(reg.test(value));
  296. if (reg.test(value)) {
  297. callback();
  298. } else {
  299. return callback(new Error("请输入正确的手机号"));
  300. }
  301. }
  302. };
  303. return {
  304. // k46
  305. dynamicTags: [],
  306. inputVisible: false,
  307. inputValue: "",
  308. // k5
  309. k5_dynamicTags: [],
  310. k5_inputVisible: false,
  311. k5_inputValue: "",
  312. categoryArr,
  313. ruleForm: {
  314. name: "",
  315. city: "",
  316. district: "",
  317. address: "",
  318. txlat: null,
  319. txlng: null,
  320. gdlat: null,
  321. gdlng: null,
  322. category: null,
  323. contactname: "",
  324. contactphone: "",
  325. takeawayphone: "",
  326. businesshour: "",
  327. k46: "",
  328. k5: "",
  329. banner: ""
  330. },
  331. rules: {
  332. name: [{ required: true, message: " ", trigger: "blur" }],
  333. city: [{ required: true, message: " ", trigger: "blur" }],
  334. district: [{ required: true, message: " ", trigger: "blur" }],
  335. address: [{ required: true, message: " ", trigger: "blur" }],
  336. // banner: [{ required: true, message: " ", trigger: "blur" }],
  337. txlat: [{ required: true, message: " ", trigger: "blur" }],
  338. txlng: [{ required: true, message: " ", trigger: "blur" }],
  339. gdlat: [{ required: true, message: " ", trigger: "blur" }],
  340. gdlng: [{ required: true, message: " ", trigger: "blur" }],
  341. category: [{ required: true, message: " ", trigger: "change" }],
  342. contactname: [{ required: true, message: " ", trigger: "blur" }],
  343. contactphone: [
  344. {
  345. required: true,
  346. validator: checkPhone,
  347. message: " ",
  348. trigger: "blur"
  349. }
  350. ],
  351. takeawayphone: [
  352. {
  353. required: true,
  354. validator: checkPhone,
  355. message: " ",
  356. trigger: "blur"
  357. }
  358. ],
  359. businesshour: [{ required: true, message: " ", trigger: "change" }]
  360. }
  361. };
  362. },
  363. methods: {
  364. submitForm(formName) {
  365. console.log(this.ruleForm);
  366. this.$refs[formName].validate(valid => {
  367. if (valid) {
  368. console.log("ddd");
  369. console.log(this.dynamicTags);
  370. console.log(this.k5_dynamicTags);
  371. if (!this.dynamicTags.length || !this.k5_dynamicTags.length) {
  372. return this.$message({
  373. message: "请添加对应的机器码!",
  374. type: "error"
  375. });
  376. }
  377. createShop({
  378. ...this.ruleForm,
  379. businesshour: this.ruleForm.businesshour.join("-"),
  380. banner: "nowwa/shop_banner/" + this.ruleForm.banner,
  381. k46: this.dynamicTags.join(";"),
  382. k5: this.k5_dynamicTags.join(";")
  383. })
  384. .then(res => {
  385. console.log(res);
  386. if (res === "OK") {
  387. this.$message({
  388. message: "创建成功!",
  389. type: "success"
  390. });
  391. this.resetForm("ruleForm");
  392. }
  393. })
  394. .catch(err => {
  395. console.log(err);
  396. this.$message({
  397. message: "提交的数据有误!",
  398. type: "error"
  399. });
  400. });
  401. } else {
  402. console.log("error submit!!");
  403. return false;
  404. }
  405. });
  406. },
  407. resetForm(formName) {
  408. this.$refs[formName].resetFields();
  409. console.log(this.dynamicTags);
  410. this.dynamicTags = [];
  411. this.k5_dynamicTags = [];
  412. console.log(this.k5_dynamicTags);
  413. },
  414. // 获取腾讯经纬度
  415. gettxLng() {
  416. // console.log(this.ruleForm);
  417. // let { city, district, address } = this.ruleForm;
  418. // if (!city || !district || !address) {
  419. // return;
  420. // }
  421. // this.$axios({
  422. // method: "get",
  423. // url: `https://apis.map.qq.com/ws/geocoder/v1/?address=${city}${district}${address}&key=36IBZ-VI53O-FJHW2-SV2NP-USSAE-GFBUS`,
  424. // dataType: "JSONP"
  425. // })
  426. // .then(res => {
  427. // console.log(res);
  428. // })
  429. // .catch(err => {
  430. // console.log("catch", err);
  431. // });
  432. },
  433. handleClose(tag, name) {
  434. if (name == "k4") {
  435. this.dynamicTags.splice(this.dynamicTags.indexOf(tag), 1);
  436. }
  437. if (name === "k5") {
  438. this.k5_dynamicTags.splice(this.dynamicTags.indexOf(tag), 1);
  439. }
  440. },
  441. showInput(name) {
  442. if (name === "k4") {
  443. this.inputVisible = true;
  444. this.$nextTick(_ => {
  445. this.$refs.saveTagInput.$refs.input.focus();
  446. });
  447. }
  448. if (name === "k5") {
  449. this.k5_inputVisible = true;
  450. this.$nextTick(_ => {
  451. this.$refs.k5_saveTagInput.$refs.input.focus();
  452. });
  453. }
  454. },
  455. handleInputConfirm(name) {
  456. if (name === "k4") {
  457. let inputValue = this.inputValue;
  458. if (inputValue) {
  459. this.dynamicTags.push(inputValue);
  460. }
  461. this.inputVisible = false;
  462. this.inputValue = "";
  463. }
  464. if (name === "k5") {
  465. let inputValue = this.k5_inputValue;
  466. if (inputValue) {
  467. this.k5_dynamicTags.push(inputValue);
  468. }
  469. this.k5_inputVisible = false;
  470. this.k5_inputValue = "";
  471. }
  472. }
  473. },
  474. computed: {}
  475. };
  476. </script>
  477. <style scoped>
  478. .box-card {
  479. margin: 20px;
  480. }
  481. .wrapper {
  482. /* width: 800px; */
  483. padding: 20px;
  484. }
  485. .tip {
  486. color: #999;
  487. }
  488. input {
  489. width: 220px !important;
  490. }
  491. .el-tag + .el-tag {
  492. margin-left: 10px;
  493. }
  494. .button-new-tag {
  495. margin-left: 10px;
  496. height: 32px;
  497. line-height: 30px;
  498. padding-top: 0;
  499. padding-bottom: 0;
  500. }
  501. .input-new-tag {
  502. width: 90px;
  503. margin-left: 10px;
  504. vertical-align: bottom;
  505. }
  506. .upload-box {
  507. padding: 40px 0;
  508. }
  509. .pd-20 {
  510. padding: 20px;
  511. }
  512. </style>