JPattributeEditor.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. <template>
  2. <div class="JPattributeEditor">
  3. <van-nav-bar class="navBar" title="金牌店档案编辑" left-arrow @click-left="onClickLeft" />
  4. <div class="content" v-if="detail">
  5. <van-form ref="tabstoreVal">
  6. <van-field
  7. class="sendCode"
  8. v-model="detail.ownerMobile"
  9. label="主经营者电话"
  10. placeholder="请输入主经营者电话"
  11. @blur="sendCodeTelFn(detail.ownerMobile)"
  12. type="tel">
  13. <template #button v-if="!verifyMobile">
  14. <van-button
  15. size="small"
  16. style="color: white; background: rgb(0, 87, 186); border-radius: 6px"
  17. @click="sendCode(detail.ownerMobile)"
  18. :disabled="telConfirm">
  19. <span v-if="telConfirm">已确认</span>
  20. <span v-else>确认真实</span>
  21. </van-button>
  22. </template>
  23. </van-field>
  24. <span style="color: #ee0a24;font-size: 12px;">为了不打扰金牌店老板,不再发送短信验证码,请务必确认手机号正确无误!</span>
  25. <!-- <van-field
  26. v-model="verificationVal"
  27. label="主经营者收到的验证码"
  28. placeholder="请输入验证码"
  29. type="number"
  30. @blur="verification(verificationVal)"
  31. v-if="!verifyMobile" /> -->
  32. <van-field v-model="detail.ownerName" :error-message="ownerNameMsg" label="主经营者姓名" />
  33. <!-- <van-field
  34. v-model="detail.ownerBirthday"
  35. label="主经营者出生日期"
  36. placeholder="请输入主经营者出生日期"
  37. @click="getNyr('ownerBirthday', detail.ownerBirthday)" /> -->
  38. <van-field autosize type="textarea" label="主营/擅长经营品类">
  39. <template #input>
  40. <van-checkbox-group v-model="detail.mainProductCategorys" direction="horizontal">
  41. <van-checkbox
  42. v-for="(item, index) in mainProductCategorys"
  43. :name="item.dictValue"
  44. shape="square"
  45. :key="index">
  46. {{ item.dictValue }}
  47. </van-checkbox>
  48. </van-checkbox-group>
  49. </template>
  50. </van-field>
  51. <van-field
  52. v-model="detail.totalSalesAmount"
  53. type="number"
  54. :error-message="totalSalesAmountMsg"
  55. label="门店24年总进货额(含所有品牌品类,单位:万元)" />
  56. <van-field
  57. v-model="detail.performanceRatio"
  58. type="number"
  59. :error-message="performanceRatioMsg"
  60. label="门店立邦业绩占比(单位:%)" />
  61. <van-field
  62. v-model="detail.mainBrand"
  63. autosize
  64. type="textarea"
  65. :error-message="mainBrandMsg"
  66. label="门店主营TOP3品牌" />
  67. <van-field label="是否有工地资源(支持工地配送,承接工地双包等)">
  68. <template #input>
  69. <van-radio-group
  70. v-model="detail.constructionResource"
  71. direction="horizontal"
  72. @change="changeResource">
  73. <van-radio name="是">是</van-radio>
  74. <van-radio name="否">否</van-radio>
  75. </van-radio-group>
  76. </template>
  77. </van-field>
  78. <van-field
  79. v-if="detail.constructionResource == '是'"
  80. v-model="detail.constructionYearNum"
  81. type="number"
  82. :error-message="constructionYearNumMsg"
  83. label="年工地数量" />
  84. <van-field label="是否有双包能力">
  85. <template #input>
  86. <van-radio-group v-model="detail.doubleContracting" direction="horizontal">
  87. <van-radio name="是">是</van-radio>
  88. <van-radio name="否">否</van-radio>
  89. </van-radio-group>
  90. </template>
  91. </van-field>
  92. <van-field label="紧急联系人身份">
  93. <template #input>
  94. <van-radio-group v-model="detail.emergencyContactRelation" direction="horizontal">
  95. <van-radio
  96. v-for="(item, index) in emergencyContactRelation"
  97. :name="item.dictValue"
  98. :key="index">
  99. {{ item.dictValue }}
  100. </van-radio>
  101. </van-radio-group>
  102. </template>
  103. </van-field>
  104. <van-field v-model="detail.emergencyContact" label="紧急联系人姓名" />
  105. <!-- <van-field
  106. v-model="detail.emergencyContactBirthday"
  107. label="紧急联系人出生日期"
  108. @click="getNyr('emergencyContactBirthday', detail.emergencyContactBirthday)" /> -->
  109. <van-field
  110. v-model="detail.emergencyContactMobile"
  111. type="number"
  112. @blur="emergencyContactBlur(detail.emergencyContactMobile)"
  113. label="紧急联系人电话" />
  114. </van-form>
  115. </div>
  116. <div class="footer-btn">
  117. <van-button
  118. style="color: white; background: rgb(0, 87, 186); border-radius: 6px; width: 90%"
  119. @click="confirmShare">
  120. 保 存
  121. </van-button>
  122. </div>
  123. <!-- 时间选择 -->
  124. <van-popup v-model="datetimeShowPicker" position="bottom">
  125. <van-datetime-picker
  126. v-model="currentDate"
  127. type="date"
  128. title="选择年月日"
  129. :min-date="minDate"
  130. :max-date="maxDate"
  131. @confirm="datetimeOnConfirm"
  132. @cancel="datetimeShowPicker = false" />
  133. </van-popup>
  134. </div>
  135. </template>
  136. <script>
  137. import { sendAndCheckVerCode, getDictOption } from '@/api/index';
  138. import { getStoreArchives, updateArchives } from '@/api/storeManagement';
  139. export default {
  140. name: 'JPattributeEditor',
  141. data() {
  142. return {
  143. ownerNameMsg: '',
  144. totalSalesAmountMsg: '',
  145. performanceRatioMsg: '',
  146. mainBrandMsg: '',
  147. constructionYearNumMsg: '',
  148. detail: null,
  149. time: null, //计时
  150. timeNum: 60,
  151. verificationVal: '',
  152. datetimeShowPicker: false,
  153. activatNyrItem: '',
  154. checkboxGroup: [],
  155. mainProductCategorys: [],
  156. emergencyContactRelation: [],
  157. verificationPassedPhoneNum: '', //验证通过手机号
  158. minDate: new Date(1945, 0, 1),
  159. maxDate: new Date(),
  160. currentDate: new Date(1945, 0, 1),
  161. mobileStatus: '0',
  162. verifyMobile: false, //手机号是否验证透通过
  163. telConfirm: false,
  164. };
  165. },
  166. activated() {
  167. this.telConfirm = false;
  168. this.ownerNameMsg = '';
  169. this.totalSalesAmountMsg = '';
  170. this.performanceRatioMsg = '';
  171. this.mainBrandMsg = '';
  172. this.constructionYearNumMsg = '';
  173. this.detail = null;
  174. this.verificationVal = '';
  175. if (this.time) clearInterval(this.time);
  176. this.time = null; //计时
  177. this.timeNum = 60;
  178. this.toastLoading(0, '加载中...', true);
  179. getDictOption({}, 'archives_main_product_categorys').then((res) => {
  180. let mainProductCategorys = [];
  181. let emergencyContactRelation = [];
  182. res.data.forEach((val) => {
  183. if (val.remark == 'mainProductCategorys') {
  184. mainProductCategorys.push(val);
  185. } else {
  186. emergencyContactRelation.push(val);
  187. }
  188. });
  189. this.mainProductCategorys = mainProductCategorys;
  190. this.emergencyContactRelation = emergencyContactRelation;
  191. this.getDetaild();
  192. });
  193. },
  194. methods: {
  195. getDetaild() {
  196. getStoreArchives({ storeCode: this.$route.query.storeCode }).then((res) => {
  197. this.toastLoading().clear();
  198. if (res.code == 200) {
  199. // let copyData = JSON.parse(JSON.stringify(res.data));
  200. res.data.mainProductCategorys = res.data.mainProductCategorys
  201. ? res.data.mainProductCategorys.split(',')
  202. : [];
  203. this.detail = res.data;
  204. this.mobileStatus = res.data.mobileStatus;
  205. // mobileStatus 是否验证通过 1,2是
  206. if (res.data.mobileStatus == '1' || res.data.mobileStatus == '2') {
  207. this.verificationPassedPhoneNum = this.detail.ownerMobile;
  208. }
  209. // 验证码和发送按钮是否显示
  210. this.verifyMobile = this.mobileStatus == '0' ? false : true;
  211. }
  212. });
  213. },
  214. sendCodeTelFn(tel) {
  215. if (!/^1[123456789]\d{9}$/.test(tel) || tel == '') {
  216. this.$toast('格式错误');
  217. return;
  218. }
  219. if (tel != this.verificationPassedPhoneNum) {
  220. this.telConfirm = false;
  221. this.verifyMobile = false;
  222. } else {
  223. this.telConfirm = false;
  224. this.verifyMobile = true;
  225. }
  226. },
  227. // 发送验证码
  228. sendCode(val) {
  229. if (!/^1[123456789]\d{9}$/.test(val) || val == '') {
  230. this.$toast('格式错误');
  231. return;
  232. }
  233. this.telConfirm = true;
  234. this.verificationPassedPhoneNum = val;
  235. this.$toast('验证成功');
  236. // if (this.time) return;
  237. // clearInterval(this.time);
  238. // this.timeNum = 60;
  239. // this.sendCodeFun(
  240. // {
  241. // type: '1', //String 调用类型:1:发送验证码 2:校验验证码
  242. // phone: val, //String 手机号
  243. // verification: '', //String 手机号验证码
  244. // },
  245. // () => {
  246. // this.time = setInterval(() => {
  247. // this.timeNum--;
  248. // if (this.timeNum <= 0) {
  249. // clearInterval(this.time);
  250. // this.time = null;
  251. // }
  252. // }, 1000);
  253. // this.$toast('发送成功');
  254. // }
  255. // );
  256. },
  257. sendCodeFun(params, callback) {
  258. sendAndCheckVerCode(params).then((res) => {
  259. if (res.code == 200) {
  260. callback && callback(res);
  261. }
  262. });
  263. },
  264. verification(val) {
  265. // 验证码
  266. if (val == '') {
  267. return;
  268. }
  269. // 手机号
  270. if (this.detail.ownerMobile == '') {
  271. return;
  272. }
  273. this.sendCodeFun(
  274. {
  275. type: '2', //String 调用类型:1:发送验证码 2:校验验证码
  276. phone: this.detail.ownerMobile, //String 手机号
  277. verification: val, //String 手机号验证码
  278. },
  279. (res) => {
  280. if (res.data) this.verificationPassedPhoneNum = this.detail.ownerMobile;
  281. this.$toast(res.data ? '验证成功' : '验证码错误');
  282. }
  283. );
  284. },
  285. getNyr(val, date) {
  286. this.activatNyrItem = val;
  287. if (date && date != '') {
  288. let time = date.split('-');
  289. this.currentDate = new Date(time[0], Number(time[1]) - 1, time[2]);
  290. } else {
  291. this.currentDate = new Date(1945, 0, 1);
  292. }
  293. this.datetimeShowPicker = true;
  294. },
  295. datetimeOnConfirm(time) {
  296. this.$set(this.detail, this.activatNyrItem, this.parseTime(time, '{y}-{m}-{d}'));
  297. // this.detail.ownerBirthday = this.parseTime(time, '{y}-{m}-{d}');
  298. this.datetimeShowPicker = false;
  299. },
  300. isValidOwnerName() {
  301. this.ownerNameMsg = '';
  302. let ownerName = this.detail.ownerName;
  303. if (ownerName.length < 2) {
  304. this.ownerNameMsg = '最短字数2';
  305. return true;
  306. }
  307. if (ownerName.length > 20) {
  308. this.ownerNameMsg = '最长字数20';
  309. return true;
  310. }
  311. const chineseChars = ownerName.match(/[\u4e00-\u9fa5]/g) || [];
  312. if (chineseChars.length < 1) {
  313. this.ownerNameMsg = '至少一个汉字';
  314. return true;
  315. }
  316. if (!/^[\u4e00-\u9fa5]+(·[\u4e00-\u9fa5]*)*·?$/.test(ownerName)) {
  317. this.ownerNameMsg = '只能输入中文';
  318. return true;
  319. }
  320. // if (!/^[\u4e00-\u9fa5a-zA-Z0-9·]+$/.test(ownerName)) {
  321. // this.ownerNameMsg = '不可输入特殊符号';
  322. // return true;
  323. // }
  324. return false;
  325. },
  326. isValidTotalSalesAmount() {
  327. this.totalSalesAmountMsg = '';
  328. let totalSalesAmount = this.detail.totalSalesAmount;
  329. const value = parseFloat(totalSalesAmount);
  330. if (isNaN(value)) {
  331. this.totalSalesAmountMsg = '请输入数字';
  332. return true;
  333. }
  334. if (value < 1) {
  335. this.totalSalesAmountMsg = '最小值1';
  336. return true;
  337. }
  338. if (value > 1000) {
  339. this.totalSalesAmountMsg = '最大值1000';
  340. return true;
  341. }
  342. return false;
  343. },
  344. isConstructionYearNum() {
  345. this.constructionYearNumMsg = '';
  346. let constructionYearNum = this.detail.constructionYearNum;
  347. const value = parseFloat(constructionYearNum);
  348. if (isNaN(value)) {
  349. this.constructionYearNumMsg = '请输入数字';
  350. return true;
  351. }
  352. if (value < 1) {
  353. this.constructionYearNumMsg = '最小值1';
  354. return true;
  355. }
  356. if (value > 10000) {
  357. this.constructionYearNumMsg = '最大值10000';
  358. return true;
  359. }
  360. return false;
  361. },
  362. isPerformanceRatio() {
  363. this.performanceRatioMsg = '';
  364. let performanceRatio = this.detail.performanceRatio;
  365. const value = parseFloat(performanceRatio);
  366. if (isNaN(value)) {
  367. this.performanceRatioMsg = '请输入数字';
  368. return true;
  369. }
  370. if (value < 1) {
  371. this.performanceRatioMsg = '最小值1';
  372. return true;
  373. }
  374. if (value > 100) {
  375. this.performanceRatioMsg = '最大值100';
  376. return true;
  377. }
  378. return false;
  379. },
  380. isValidMainBrand() {
  381. this.mainBrandMsg = '';
  382. let mainBrand = this.detail.mainBrand;
  383. const chineseChars = mainBrand.match(/[\u4e00-\u9fa5]/g) || [];
  384. if (chineseChars.length < 1) {
  385. this.mainBrandMsg = '至少一个汉字';
  386. return true;
  387. }
  388. return false;
  389. },
  390. // 保存
  391. confirmShare() {
  392. if (
  393. this.verificationPassedPhoneNum == '' ||
  394. this.detail.ownerMobile != this.verificationPassedPhoneNum
  395. ) {
  396. this.$toast('请验证手机号');
  397. return;
  398. }
  399. this.isValidOwnerName();
  400. this.isValidTotalSalesAmount();
  401. this.isPerformanceRatio();
  402. this.isValidMainBrand();
  403. if (this.detail.constructionResource == '是') {
  404. this.isConstructionYearNum();
  405. }
  406. if (this.isValidOwnerName()) return;
  407. if (this.isValidTotalSalesAmount()) return;
  408. if (this.isPerformanceRatio()) return;
  409. if (this.isValidMainBrand()) return;
  410. if (this.detail.constructionResource == '是') {
  411. if (this.isConstructionYearNum()) return;
  412. }
  413. if (this.detail.emergencyContactMobile != '') {
  414. if (!/^1[123456789]\d{9}$/.test(this.detail.emergencyContactMobile)) {
  415. this.$toast('紧急联系人电话格式错误');
  416. return;
  417. }
  418. }
  419. this.toastLoading(0, '加载中...', true);
  420. let params = JSON.parse(JSON.stringify(this.detail));
  421. params.mainProductCategorys = params.mainProductCategorys.join(',');
  422. params.storeCode = this.$route.query.storeCode;
  423. updateArchives(params).then((res) => {
  424. this.toastLoading().clear();
  425. if (res.code == 200) {
  426. this.$toast(res.msg);
  427. this.$router.go(-1);
  428. } else {
  429. this.$toast(res.msg);
  430. }
  431. });
  432. },
  433. emergencyContactBlur(val) {
  434. if (!/^1[123456789]\d{9}$/.test(val)) {
  435. this.$toast('紧急联系人电话格式错误');
  436. }
  437. },
  438. changeResource(val) {
  439. if (val == '否') {
  440. this.detail.constructionYearNum = '';
  441. }
  442. },
  443. onClickLeft() {
  444. this.$router.go(-1);
  445. },
  446. },
  447. };
  448. </script>
  449. <style lang="scss">
  450. .JPattributeEditor {
  451. width: 100%;
  452. height: 100%;
  453. display: flex;
  454. flex-direction: column;
  455. justify-content: space-between;
  456. overflow: hidden;
  457. .content {
  458. flex: 1;
  459. overflow-y: auto;
  460. background: #fff;
  461. padding: 10px 15px;
  462. margin-top: 10px;
  463. background: #fff;
  464. .van-cell {
  465. padding: 10px 0;
  466. border-bottom: 1px solid #ccc;
  467. }
  468. .van-field__label {
  469. width: 9em;
  470. }
  471. .sendCode {
  472. border: none !important;
  473. input {
  474. border: 1px solid #f1f1f1;
  475. height: 35px;
  476. }
  477. }
  478. .van-checkbox--horizontal {
  479. margin-bottom: 10px;
  480. width: 100%;
  481. }
  482. .van-radio--horizontal {
  483. margin-bottom: 10px;
  484. }
  485. }
  486. .footer-btn {
  487. display: flex;
  488. justify-content: space-around;
  489. padding: 10px 0;
  490. }
  491. }
  492. </style>