config.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. <template>
  2. <base-page>
  3. <view class="common-wrap common-form fixd">
  4. <view class="common-title">门店设置</view>
  5. <view class="common-form-item">
  6. <label class="form-label">门店名称</label>
  7. <view class="form-input-inline"><input type="text" v-model="storeData.store_name" class="form-input" /></view>
  8. <text class="form-word-aux-line">门店的名称(招牌)</text>
  9. </view>
  10. <view class="common-form-item store-img">
  11. <label class="form-label">门店图片</label>
  12. <view class="form-input-inline upload-box" @click="addImg">
  13. <view class="upload" v-if="storeData.store_image">
  14. <image :src="$util.img(storeData.store_image)" @error="$util.img(defaultImg.store)" mode="heightFix"></image>
  15. </view>
  16. <view class="upload" v-else>
  17. <text class="iconfont iconyunshangchuan"></text>
  18. <view>点击上传</view>
  19. </view>
  20. </view>
  21. <text class="form-word-aux-line">门店图片在PC及移动端对应页面及列表作为门店标志出现。建议图片尺寸:100 * 100像素,图片格式:jpg、png、jpeg。</text>
  22. </view>
  23. <view class="common-form-item">
  24. <label class="form-label">门店类型</label>
  25. <view class="form-inline">
  26. <radio-group @change="storeTypeChange" class="form-radio-group">
  27. <label class="radio form-radio-item">
  28. <radio value="directsale" :checked="storeData.store_type == 'directsale'" />
  29. 直营店
  30. </label>
  31. <label class="radio form-radio-item">
  32. <radio value="franchise" :checked="storeData.store_type == 'franchise'" />
  33. 加盟店
  34. </label>
  35. </radio-group>
  36. </view>
  37. </view>
  38. <view class="common-form-item" v-if="category.status">
  39. <label class="form-label">门店分类</label>
  40. <view class="form-input-inline"><uni-data-select v-model="storeData.category_id" :localdata="category.list"></uni-data-select></view>
  41. </view>
  42. <view class="common-form-item" v-if="label.length">
  43. <label class="form-label">门店标签</label>
  44. <view class="form-block">
  45. <checkbox-group class="form-checkbox-group" @change="labelChange">
  46. <label class="form-checkbox-item" v-for="(item, index) in label">
  47. <checkbox :value="item.label_id.toString()" :checked="labelChecked(item)" />
  48. {{ item.label_name }}
  49. </label>
  50. </checkbox-group>
  51. </view>
  52. </view>
  53. <view class="common-form-item">
  54. <label class="form-label">门店电话</label>
  55. <view class="form-input-inline"><input type="number" v-model="storeData.telphone" class="form-input" /></view>
  56. </view>
  57. <view class="common-form-item">
  58. <label class="form-label">门店地址</label>
  59. <view class="form-inline">
  60. <pick-regions ref="selectArea" :default-regions="defaultRegions" @getRegions="handleGetRegions">
  61. <view class="form-input-inline long">
  62. <view class="form-input">{{ storeData.full_address }}</view>
  63. </view>
  64. </pick-regions>
  65. </view>
  66. </view>
  67. <view class="common-form-item">
  68. <label class="form-label"></label>
  69. <view class="form-inline">
  70. <view class="form-input-inline long"><input type="text" v-model="storeData.address" class="form-input" /></view>
  71. <view class="form-input-inline short btn" @click="getlatlng()">查找</view>
  72. </view>
  73. </view>
  74. <view class="common-form-item store-img">
  75. <label class="form-label">地图定位</label>
  76. <view class="form-inline">
  77. <view class="map-box">
  78. <image src="../../static/location.png" class="map-icon"></image>
  79. <map
  80. style="width: 100%; height: 100%;"
  81. :latitude="storeData.latitude"
  82. :longitude="storeData.longitude"
  83. :markers="covers"
  84. @markertap="markertap"
  85. @regionchange="tap"
  86. ></map>
  87. </view>
  88. </view>
  89. </view>
  90. <view class="common-btn-wrap">
  91. <button type="default" class="screen-btn" @click="saveFn">保存</button>
  92. <button type="default" @click="$util.redirectTo('/pages/store/index')">返回</button>
  93. </view>
  94. <nc-loading :layer-background="{ background: 'rgba(255,255,255,.8)' }" ref="loading"></nc-loading>
  95. </view>
  96. </base-page>
  97. </template>
  98. <script>
  99. export default {
  100. data() {
  101. return {
  102. storeData: {},
  103. covers: [
  104. {
  105. latitude: 39.909,
  106. longitude: 116.39742,
  107. iconPath: '/static/location.png'
  108. }
  109. ],
  110. defaultRegions: [],
  111. category: {
  112. status: 0,
  113. list: []
  114. },
  115. label: [],
  116. labelData: {}
  117. };
  118. },
  119. onLoad() {
  120. this.getLabel();
  121. this.getCategory();
  122. this.getData();
  123. },
  124. methods: {
  125. getData() {
  126. this.$api.sendRequest({
  127. url: '/store/storeapi/store/info',
  128. success: res => {
  129. if (res.code >= 0) {
  130. this.storeData = res.data;
  131. this.storeData.start_time = this.timeFormat(this.storeData.start_time);
  132. this.storeData.end_time = this.timeFormat(this.storeData.end_time);
  133. this.defaultRegions = [this.storeData.province_id, this.storeData.city_id, this.storeData.district_id];
  134. this.$refs.selectArea.handleDefaultRegions();
  135. this.$refs.loading.hide();
  136. } else {
  137. this.$util.showToast({
  138. title: res.message
  139. });
  140. }
  141. }
  142. });
  143. },
  144. getLabel() {
  145. this.$api.sendRequest({
  146. url: '/store/storeapi/store/label',
  147. success: res => {
  148. if (res.code == 0) {
  149. this.label = res.data;
  150. let labelData = {};
  151. res.data.forEach(item => {
  152. labelData[item.label_id] = item.label_name;
  153. });
  154. this.labelData = labelData;
  155. }
  156. }
  157. });
  158. },
  159. getCategory() {
  160. this.$api.sendRequest({
  161. url: '/store/storeapi/store/category',
  162. success: res => {
  163. if (res.code == 0) {
  164. this.category.status = res.data.status;
  165. this.category.list = res.data.list.map(item => {
  166. return { value: item.category_id, text: item.category_name };
  167. });
  168. }
  169. }
  170. });
  171. },
  172. addImg() {
  173. this.$util.upload(
  174. 1,
  175. {
  176. path: 'image'
  177. },
  178. res => {
  179. if (res.length > 0) {
  180. this.storeData.store_image = res[0];
  181. this.$forceUpdate();
  182. }
  183. }
  184. );
  185. },
  186. tap(e) {
  187. if (e.detail && e.detail.centerLocation) {
  188. this.storeData.latitude = e.detail.centerLocation.latitude;
  189. this.storeData.longitude = e.detail.centerLocation.longitude;
  190. this.covers = [
  191. {
  192. latitude: this.storeData.latitude,
  193. longitude: this.storeData.longitude,
  194. iconPath: '/static/location.png'
  195. }
  196. ];
  197. this.getAddress();
  198. this.$forceUpdate();
  199. }
  200. },
  201. handleGetRegions(regions) {
  202. this.storeData.full_address = '';
  203. this.storeData.full_address += regions[0] != undefined ? regions[0].label : '';
  204. this.storeData.full_address += regions[1] != undefined ? '-' + regions[1].label : '';
  205. this.storeData.full_address += regions[2] != undefined ? '-' + regions[2].label : '';
  206. // this.storeData.address = '';
  207. this.storeData.province_id = regions[0] != undefined ? regions[0].value : '';
  208. this.storeData.city_id = regions[1] != undefined ? regions[1].value : '';
  209. this.storeData.district_id = regions[2] != undefined ? regions[2].value : '';
  210. this.defaultRegions = [this.storeData.province_id, this.storeData.city_id, this.storeData.district_id];
  211. this.$forceUpdate();
  212. this.getlatlng();
  213. },
  214. //获取详细地址
  215. getAddress() {
  216. let value = this.storeData.latitude + ',' + this.storeData.longitude;
  217. this.$api.sendRequest({
  218. url: '/cashier/storeapi/address/tranaddressinfo',
  219. data: {
  220. latlng: value
  221. },
  222. success: res => {
  223. if (res.code == 0) {
  224. this.storeData.full_address = '';
  225. this.storeData.full_address += res.data.province != undefined ? res.data.province : '';
  226. this.storeData.full_address += res.data.city != undefined ? '-' + res.data.city : '';
  227. this.storeData.full_address += res.data.district != undefined ? '-' + res.data.district : '';
  228. this.storeData.address = res.data.address != undefined ? res.data.address : '';
  229. this.storeData.province_id = res.data.province_id != undefined ? res.data.province_id : '';
  230. this.storeData.city_id = res.data.city_id != undefined ? res.data.city_id : '';
  231. this.storeData.district_id = res.data.district_id != undefined ? res.data.district_id : '';
  232. this.defaultRegions = [this.storeData.province_id, this.storeData.city_id, this.storeData.district_id];
  233. this.$forceUpdate();
  234. }
  235. }
  236. });
  237. },
  238. //获取详细地址
  239. getlatlng() {
  240. let value = this.storeData.full_address + this.storeData.address;
  241. this.$api.sendRequest({
  242. url: '/cashier/storeapi/address/getaddressbyname',
  243. data: {
  244. address: value
  245. },
  246. success: res => {
  247. if (res.code == 0) {
  248. this.storeData.latitude = res.data.latitude;
  249. this.storeData.longitude = res.data.longitude;
  250. // if(this.storeData.address == '') this.getAddress();
  251. }
  252. }
  253. });
  254. },
  255. storeTypeChange(e) {
  256. this.storeData.store_type = e.detail.value;
  257. },
  258. getSaveData() {
  259. let data = Object.assign({}, this.storeData);
  260. data.start_time = this.timeTurnTimeStamp(data.start_time);
  261. data.end_time = this.timeTurnTimeStamp(data.end_time);
  262. data.time_week = this.storeData.time_week.toString();
  263. return data;
  264. },
  265. checkData(data) {
  266. if (data.store_name == '') {
  267. this.$util.showToast({
  268. title: '请输入门店名称'
  269. });
  270. return false;
  271. }
  272. if (!data.district_id || data.address == '') {
  273. this.$util.showToast({
  274. title: '请选择门店地址'
  275. });
  276. return false;
  277. }
  278. return true;
  279. },
  280. saveFn() {
  281. let data = this.getSaveData();
  282. if (this.checkData(data)) {
  283. if (this.flag) return false;
  284. this.flag = true;
  285. this.$api.sendRequest({
  286. url: '/store/storeapi/store/edit',
  287. data: data,
  288. success: res => {
  289. this.flag = false;
  290. this.$util.showToast({
  291. title: res.message
  292. });
  293. if (res.code >= 0) {
  294. this.$refs.loading.show();
  295. this.getData();
  296. }
  297. }
  298. });
  299. }
  300. },
  301. timeTurnTimeStamp(_time) {
  302. let data = _time.split(':');
  303. return data[0] * 3600 + data[1] * 60;
  304. },
  305. timeFormat(time) {
  306. let h = time / 3600;
  307. let i = (time % 3600) / 60;
  308. h = h < 10 ? '0' + h : h;
  309. i = i < 10 ? '0' + i : i;
  310. return h + ':' + i;
  311. },
  312. labelChange(e) {
  313. if (e.detail.value.length) {
  314. this.storeData.label_id = ',' + e.detail.value.toString() + ',';
  315. let labelName = [];
  316. e.detail.value.forEach(item => {
  317. labelName.push(this.labelData[item]);
  318. });
  319. this.storeData.label_name = ',' + labelName.toString() + ',';
  320. } else {
  321. this.storeData.label_id = '';
  322. this.storeData.label_name = '';
  323. }
  324. },
  325. labelChecked(item) {
  326. let labelIdArr = [];
  327. if (!this.storeData.label_id) return false;
  328. if (typeof this.storeData.label_id == 'string') labelIdArr = this.storeData.label_id.split(',');
  329. return labelIdArr.includes(item.label_id.toString());
  330. }
  331. }
  332. };
  333. </script>
  334. <style lang="scss">
  335. .common-wrap {
  336. padding: 30rpx;
  337. background-color: #fff;
  338. @extend %body-overhide;
  339. .form-label {
  340. width: 1.5rem !important;
  341. }
  342. .form-input-inline /deep/ .uni-select {
  343. border: none;
  344. }
  345. .common-btn-wrap {
  346. z-index: 999;
  347. margin-left: 1.5rem !important;
  348. }
  349. .form-word-aux-line {
  350. margin-left: 1.5rem !important;
  351. }
  352. }
  353. .upload-box {
  354. border: 0.01rem dashed #e6e6e6 !important;
  355. width: 2.5rem !important;
  356. height: 1.2rem !important;
  357. display: flex;
  358. align-items: center;
  359. justify-content: center;
  360. .upload {
  361. text-align: center;
  362. color: #5a5a5a;
  363. .iconfont {
  364. font-size: 0.3rem;
  365. }
  366. image {
  367. max-width: 100%;
  368. height: 1.2rem !important;
  369. }
  370. }
  371. }
  372. .store-img {
  373. align-items: flex-start !important;
  374. }
  375. .map-box {
  376. width: 6.5rem;
  377. height: 5rem;
  378. position: relative;
  379. .map-icon {
  380. position: absolute;
  381. top: calc(50% - 0.36rem);
  382. left: calc(50% - 0.18rem);
  383. width: 0.36rem;
  384. height: 0.36rem;
  385. z-index: 100;
  386. }
  387. }
  388. .form-input {
  389. font-size: 0.16rem;
  390. }
  391. .form-input-inline.btn {
  392. height: 0.37rem;
  393. line-height: 0.35rem;
  394. box-sizing: border-box;
  395. border: 0.01rem solid #e6e6e6;
  396. text-align: center;
  397. cursor: pointer;
  398. }
  399. .common-title {
  400. font-size: 0.18rem;
  401. margin-bottom: 0.2rem;
  402. }
  403. </style>