add.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. <template>
  2. <view class="app-content">
  3. <form @submit="formSubmit" @reset="formReset">
  4. <view class="module-com input-line-wrap">
  5. <tui-list-cell class="line-cell" :hover="false">
  6. <view class="tui-title required">门店名称</view>
  7. <input v-model="form.shopName" placeholder-class="phcolor" class="tui-input" name="shopName" placeholder="请输入名称,如同安店" maxlength="50" type="text" />
  8. </tui-list-cell>
  9. <tui-list-cell class="line-cell" :hover="false">
  10. <view class="tui-title">营业状态</view>
  11. <view><switch style="transform:scale(0.7,0.7)" :checked="form.open == 0 ? false : true" @change="openChange" /></view>
  12. </tui-list-cell>
  13. <template v-if="visible">
  14. <tui-list-cell class="line-cell" :hover="false">
  15. <view class="tui-title">营业时间</view>
  16. <radio-group class="tui-input" @change="radioChange">
  17. <label class="list" for="hourLink">
  18. <radio id="hourLink" value="0" :checked="form.openType == 0" />
  19. <span class="checkbox-text">24小时</span>
  20. </label>
  21. <label class="list" for="setTimeLink">
  22. <radio id="setTimeLink" value="1" :checked="form.openType == 1" />
  23. <span class="checkbox-text">指定时段</span>
  24. </label>
  25. <input v-model="form.openType" name="openType" hidden />
  26. </radio-group>
  27. </tui-list-cell>
  28. <template v-if="openTimeVisible">
  29. <tui-list-cell class="line-cell" :hover="false">
  30. <view class="tui-title">开店时间</view>
  31. <picker mode="time" :value="start_time" start="00:00" end="24:00" @change="startTimeChange">
  32. <view class="uni-input">{{start_time}}</view>
  33. </picker>
  34. <input v-model="form.openStartTime" name="openStartTime" hidden />
  35. </tui-list-cell>
  36. <tui-list-cell class="line-cell" :hover="false">
  37. <view class="tui-title">关店时间</view>
  38. <picker mode="time" :value="end_time" start="00:00" end="24:00" @change="endTimeChange">
  39. <view class="uni-input">{{end_time}}</view>
  40. </picker>
  41. <input v-model="form.openEndTime" name="openEndTime" hidden />
  42. </tui-list-cell>
  43. </template>
  44. </template>
  45. <tui-list-cell class="line-cell" :hover="false">
  46. <view class="tui-title">门店类型</view>
  47. <radio-group class="tui-input" @change="joinChange">
  48. <label class="list" for="chainLink">
  49. <radio id="chainLink" value="0" :checked="form.join == 0" />
  50. <span class="checkbox-text">直营店</span>
  51. </label>
  52. <label class="list" for="joinLink">
  53. <radio id="joinLink" value="1" :checked="form.join == 1" />
  54. <span class="checkbox-text">加盟店</span>
  55. </label>
  56. </radio-group>
  57. </tui-list-cell>
  58. <tui-list-cell class="line-cell" :hover="false">
  59. <view class="tui-title required">手机号</view>
  60. <input v-model="form.mobile" placeholder-class="phcolor" class="tui-input" name="mobile" placeholder="请输入手机号" maxlength="50" type="number" />
  61. </tui-list-cell>
  62. <tui-list-cell class="line-cell" :hover="false" :arrow="true" @click="openAddres">
  63. <view class="tui-title required">所在城市</view>
  64. <view class="tui-input" v-if="form.province || form.city">{{ form.province + '-' + form.city }}</view>
  65. <view class="tui-placeholder" v-else>请选择</view>
  66. <input v-model="form.province" name="province" hidden />
  67. </tui-list-cell>
  68. <tui-list-cell class="line-cell" :hover="false" :arrow="true" @click="selectRegion">
  69. <view class="tui-title required">地址</view>
  70. <view class="tui-input" v-if="form.address">{{ form.address }}</view>
  71. <view class="tui-placeholder" v-else>请填写详细地址</view>
  72. <input v-model="form.address" name="address" hidden />
  73. </tui-list-cell>
  74. <tui-list-cell class="line-cell" :hover="false">
  75. <view class="tui-title ">门牌号</view>
  76. <input v-model="form.floor" placeholder-class="phcolor" class="tui-input" name="floor" placeholder="楼号门牌号(选填)" />
  77. </tui-list-cell>
  78. <tui-list-cell class="line-cell remark-wrap" :hover="false">
  79. <view class="tui-title">简介</view>
  80. <view class="tui-input">
  81. <textarea v-model="form.introduction" class="tui-textarea remark" placeholder-class="phcolor" placeholder="请输入简介" />
  82. </view>
  83. </tui-list-cell>
  84. </view>
  85. <!-- 提交 -->
  86. <view class="confirm-btn">
  87. <button class="admin-button-com big blue" formType="submit">提交</button>
  88. </view>
  89. </form>
  90. <!-- 省市联动 -->
  91. <simple-address ref="simpleAddress" :pickerValueDefault="cityPickerValueDefault" @onConfirm="onCityConfirm"></simple-address>
  92. <!-- 选择地区 -->
  93. <app-area-sel :show.sync="showRegion" :city="form.city" @change="changeAreaFn" />
  94. </view>
  95. </template>
  96. <script>
  97. import TuiListCell from '@/components/plugin/list-cell'
  98. import AppAvatarModule from '@/components/module/app-avatar'
  99. import AppUploader from "@/components/app-uploader";
  100. import SimpleAddress from '@/components/plugin/simple-address'
  101. import AppAreaSel from '@/components/app-area-sel'
  102. const form = require('@/utils/formValidation.js')
  103. import {mapActions} from "vuex";
  104. import { updateShop as update, addShop as add } from '@/api/shop'
  105. export default {
  106. name: 'staff-add',
  107. components: {
  108. TuiListCell,
  109. AppAvatarModule,
  110. SimpleAddress,
  111. AppAreaSel,
  112. AppUploader
  113. },
  114. data() {
  115. return {
  116. visible: true,
  117. openTimeVisible: false,
  118. start_time: '00:00',
  119. end_time: '00:00',
  120. form: {
  121. join:0,
  122. shopName: '',
  123. province: '',
  124. city: '',
  125. address: '',
  126. floor: '',
  127. open: 1,
  128. openType: 0, // openType: 0. 表示 24小时营业 1. 表示 xx ~ xx
  129. openStartTime: '',
  130. openEndTime: '',
  131. introduction: '',
  132. mobile: '',
  133. img: []
  134. },
  135. showRegion: false,
  136. region: {
  137. lat: 0,
  138. long: 0
  139. },
  140. regionData: [],
  141. cityPickerValueDefault: [0, 0],
  142. img: []
  143. }
  144. },
  145. onLoad() {
  146. },
  147. onShow() {
  148. if (this.option.id) {
  149. uni.setNavigationBarTitle({
  150. title: `修改门店`
  151. })
  152. } else {
  153. uni.setNavigationBarTitle({
  154. title: `添加门店`
  155. })
  156. }
  157. },
  158. methods: {
  159. ...mapActions(['setUserShopAll']),
  160. init() {
  161. this._getDet()
  162. },
  163. _getDet() {
  164. let data = uni.getStorageSync('modifyShopB')
  165. if (this.$util.isEmpty(data)){
  166. return
  167. }
  168. Object.keys(this.form).forEach((i, index) => {
  169. this.form[i] = data[i]
  170. })
  171. this.region.lat = data.lat
  172. this.region.long = data.long
  173. // 营业时间初始化
  174. this.visible = this.form.open == 1 ? true : false
  175. this.openTimeVisible = true
  176. this.form.openType = 1
  177. this.start_time = this.form.openStartTime
  178. this.end_time = this.form.openEndTime
  179. if (data.openStartTime == '') {
  180. this.openTimeVisible = false
  181. this.form.openType = 0
  182. this.start_time = '09:00'
  183. this.form.openStartTime = this.start_time
  184. }
  185. if (data.openEndTime == '') {
  186. this.end_time = '18:00'
  187. this.form.openEndTime = this.end_time
  188. }
  189. },
  190. openChange(e) {
  191. this.visible = e.target.value ? true : false
  192. this.form.open = e.target.value ? 1 : 0
  193. },
  194. startTimeChange: function(e) {
  195. this.start_time = e.detail.value
  196. this.form.openStartTime = e.detail.value
  197. },
  198. joinChange(e){
  199. this.form.join = e.detail.value
  200. },
  201. endTimeChange: function(e) {
  202. this.end_time = e.detail.value
  203. this.form.openEndTime = e.detail.value
  204. },
  205. radioChange(e) {
  206. this.openTimeVisible = e.detail.value == 0 ? false : true;
  207. this.form.openType = e.detail.value == 0 ? 0 : 1; // openType: 0. 24小时 1. xx ~ xx
  208. if (this.openTimeVisible) {
  209. this.start_time = '09:00'
  210. this.end_time = '18:00'
  211. }
  212. },
  213. selectRegion() {
  214. if (!this.form.city) {
  215. this.$msg('请先选择城市!')
  216. return false
  217. }
  218. this.showRegion = true
  219. },
  220. _resultData(val) {
  221. console.log(val)
  222. this.form.img = val;
  223. },
  224. changeAreaFn(e) {
  225. console.log('changeAreaFn', e)
  226. this.form.address = e.title
  227. this.region.lat = e.location.lat
  228. this.region.long = e.location.lng
  229. },
  230. // 省市联动
  231. openAddres() {
  232. this.$refs.simpleAddress.open()
  233. },
  234. onCityConfirm(e) {
  235. this.form.province = e.provinceName
  236. this.form.city = e.cityName
  237. this.form.address = ''
  238. this.region.lat = 0
  239. this.region.long = 0
  240. },
  241. confirmFn() {
  242. let hostFn = this.option.id ? update : add
  243. if (this.option.id) {
  244. this.form.id = this.option.id
  245. }
  246. this.form = {...this.form,...this.region}
  247. uni.showLoading({mask:true})
  248. hostFn(this.form).then(res => {
  249. uni.hideLoading()
  250. this.setUserShopAll();
  251. let promptText = this.option.id ? '修改成功!' : '添加成功!'
  252. this.$msg(promptText)
  253. uni.removeStorageSync('modifyShopB')
  254. setTimeout(() => {
  255. this.$util.pageTo(1)
  256. }, 1000)
  257. })
  258. },
  259. // 表单验证
  260. formSubmit(e) {
  261. // 表单规则
  262. let rules = [
  263. {
  264. name: 'shopName',
  265. rule: ['required'],
  266. msg: ['请输入名称']
  267. },
  268. {
  269. name: 'mobile',
  270. rule: ['required'],
  271. msg: ['请输入手机号']
  272. },
  273. {
  274. name: 'province',
  275. rule: ['required'],
  276. msg: ['请选择地址']
  277. },
  278. {
  279. name: 'address',
  280. rule: ['required'],
  281. msg: ['请填写详细地址']
  282. }
  283. ]
  284. // 进行表单检查
  285. let formData = e.detail.value
  286. let checkRes = form.validation(formData, rules)
  287. // 验证通过!
  288. if (!checkRes) {
  289. this.confirmFn()
  290. } else {
  291. this.$msg(checkRes)
  292. }
  293. }
  294. }
  295. }
  296. </script>
  297. <style lang="scss" scoped>
  298. .app-content {
  299. min-height: calc(100vh - 20upx);
  300. padding-top: 20upx;
  301. }
  302. .prompt-text {
  303. color: $fontColor3;
  304. padding-left: 30upx;
  305. margin-bottom: 30upx;
  306. }
  307. .module-com {
  308. margin-bottom: 20upx;
  309. .member-wrap {
  310. .member-det {
  311. font-size: 24upx;
  312. margin-left: 20upx;
  313. }
  314. }
  315. .remark-wrap {
  316. align-items: flex-start;
  317. .remark {
  318. height: 240upx;
  319. }
  320. }
  321. }
  322. // 按钮
  323. .confirm-btn {
  324. width: calc(100% - 60upx);
  325. margin: 60upx 30upx 20upx;
  326. .admin-button-com {
  327. width: 100%;
  328. }
  329. }
  330. </style>