ChainForm.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <template><page-meta :root-font-size="fontSize+'px'"></page-meta>
  2. <seller-base :show="false">
  3. <view class="div container">
  4. <view class="div common-header-wrap">
  5. <view :style="'height:'+navHeight+'px'"></view>
  6. <view class="common-header-holder"></view>
  7. <view class="common-header-fixed">
  8. <title-header />
  9. <uni-nav-bar :title="getTitle" class="common-header" left-icon="back" @clickLeft="goBack()">
  10. <view slot="right" class="div common-btn btn" @click="onDelete" v-if="!isAddMode">删除</view>
  11. </uni-nav-bar>
  12. </view>
  13. </view>
  14. <view class="div main-content">
  15. <view class="div" v-if="!isAddMode">
  16. <flex-line :show-border="true"><text class="span line-name">门店账号</text><text class="span" slot="right">{{chain.chain_name}}</text></flex-line>
  17. </view>
  18. <flex-line v-else :show-border="true" class="field-line"><text class="span field-name">门店账号</text><view class="div field-line-right" slot="right"><input class="field-input" v-model="chain.chain_name" /></view></flex-line>
  19. <flex-line class="field-line" :show-border="true"><text class="span field-name">门店密码</text><view class="div field-line-right" slot="right"><input class="field-input" type="password" v-model="chain.chain_passwd" /></view></flex-line>
  20. <flex-line class="field-line" :show-border="true"><text class="span field-name">门店名称</text><view class="div field-line-right" slot="right"><input class="field-input" v-model="chain.chain_addressname" /></view></flex-line>
  21. <flex-line class="field-line" :show-border="true"><text class="span field-name">联系人姓名</text><view class="div field-line-right" slot="right"><input class="field-input" type="phone" v-model="chain.chain_truename" /></view></flex-line>
  22. <flex-line class="field-line" :show-border="true"><text class="span field-name">联系人手机</text><view class="div field-line-right" slot="right"><input class="field-input" type="phone" v-model="chain.chain_mobile" /></view></flex-line>
  23. <flex-line class="field-line" :show-border="true"><text class="span field-name">座机</text><view class="div field-line-right" slot="right"><input class="field-input" type="email" v-model="chain.chain_telephony" /></view></flex-line>
  24. <view class="div" @click="onRegion">
  25. <flex-line :is-link="true" :show-border="true"><text class="span line-name">地区</text><text class="span" slot="right">{{chain.chain_area_info}}</text></flex-line>
  26. </view>
  27. <flex-line class="field-line" :show-border="true">
  28. <text class="span field-name">地址</text>
  29. <view class="address-line div field-line-right" slot="right"><input class="text field-input" type="text" v-model="chain.chain_address"><text class="i iconfont" @click="getPosition()">&#xe6d3;</text></view>
  30. </flex-line>
  31. <flex-line :show-border="true"><text class="span line-name">门店状态</text><view class="div" slot="right"><switch @change="switchChange(1,$event)" :checked="!!chain.chain_state"></switch></view></flex-line>
  32. <flex-line :show-border="true"><text class="span line-name">开启自提</text><view class="div" slot="right"><switch @change="switchChange(2,$event)" :checked="!!chain.chain_if_pickup"></switch></view></flex-line>
  33. <flex-line :show-border="true"><text class="span line-name">开启代收</text><view class="div" slot="right"><switch @change="switchChange(3,$event)" :checked="!!chain.chain_if_collect"></switch></view></flex-line>
  34. <view class="div pt-10 pb-10"><view class="div common-btn ds-button-large" @click="submit">提交</view></view>
  35. </view>
  36. <region-picker ref="picker" v-on:onConfirm="onPickerConfirm"></region-picker>
  37. <uni-popup background-color="#fff" ref="popMap" type="right" >
  38. <view :style="'width:'+screenWidth+'px'" class="common-popup-wrapper">
  39. <view class="div common-header-wrap">
  40. <view :style="'height:'+navHeight+'px'"></view>
  41. <view class="common-header-holder"></view>
  42. <view class="common-header-fixed">
  43. <title-header />
  44. <uni-nav-bar title="定位" class="common-header" left-icon="back" @clickLeft="hidePopup('popMap')">
  45. </uni-nav-bar>
  46. </view>
  47. </view>
  48. <view class="div common-popup-content">
  49. <map-select ref="map_select" :longitude="chain.chain_longitude" :latitude="chain.chain_latitude" @setPosition="setPosition"></map-select>
  50. </view>
  51. </view>
  52. </uni-popup>
  53. </view>
  54. <uni-popup background-color="#fff" ref="confirm" type="dialog">
  55. <uni-popup-dialog :mode="dialog.mode" :title="dialog.title" :content="dialog.content" :placeholder="dialog.content" @confirm="confirmDialog" @close="closeDialog"></uni-popup-dialog>
  56. </uni-popup>
  57. </seller-base>
  58. </template>
  59. <script>
  60. import {getFontSize} from '@/util/common'
  61. import TitleHeader from '../../TitleHeader'
  62. import SellerBase from '../SellerBase'
  63. import { getPointByAddress } from '../../../util/bmap'
  64. import { getChainInfo, delChain, addChain, editChain } from '../../../api/sellerChain'
  65. import RegionPicker from '../../RegionPicker'
  66. import MapSelect from '../../MapSelect'
  67. import flexLine from '../../flexLine'
  68. export default {
  69. name: 'ChainForm',
  70. components:{
  71. TitleHeader,
  72. SellerBase,
  73. flexLine,
  74. RegionPicker,
  75. MapSelect
  76. },
  77. data(){
  78. return {
  79. navHeight: 0,
  80. dialog:{},
  81. screenWidth:0,
  82. chain_id: 0,
  83. action:'',
  84. chain: {
  85. chain_state: true,
  86. chain_if_pickup: true,
  87. chain_if_collect: true
  88. }
  89. }
  90. },
  91. onLoad: function (option) {
  92. this.action = option.action
  93. if (this.action!='add') {
  94. this.chain_id = option.chain_id
  95. getChainInfo({ chain_id: this.chain_id }).then(res => {
  96. let chain = res.result.chain_info
  97. chain.chain_passwd = ''
  98. chain.chain_state = !!chain.chain_state
  99. chain.chain_if_pickup = !!chain.chain_if_pickup
  100. chain.chain_if_collect = !!chain.chain_if_collect
  101. this.chain = chain
  102. }).catch(function (error) {
  103. uni.showToast({icon:'none',title: error.message})
  104. })
  105. }
  106. },
  107. computed:{
  108. fontSize(){
  109. return getFontSize()
  110. },
  111. isAddMode () {
  112. let mode = this.action
  113. // add: 添加门店,edit: 编辑门店
  114. if (mode === 'add') {
  115. return true
  116. } else {
  117. return false
  118. }
  119. },
  120. getTitle () {
  121. if (this.isAddMode) {
  122. return '新增门店'
  123. } else {
  124. return '修改门店'
  125. }
  126. }
  127. },
  128. mounted(){
  129. // #ifdef MP-WEIXIN
  130. this.navHeight = uni.getMenuButtonBoundingClientRect().height
  131. // #endif
  132. this.screenWidth=uni.getSystemInfoSync().screenWidth
  133. },
  134. methods:{
  135. switchChange(i,e){
  136. switch(i){
  137. case 1:
  138. this.chain.chain_state=e.detail.value
  139. break
  140. case 2:
  141. this.chain.chain_if_pickup=e.detail.value
  142. break
  143. case 3:
  144. this.chain.chain_if_collect=e.detail.value
  145. break
  146. }
  147. },
  148. closeDialog(){
  149. },
  150. confirmDialog(value){
  151. delChain({chain_id:this.chain_id}).then(
  152. (response) => {
  153. uni.navigateTo({url:'/pages/seller/chain/ChainList'})
  154. }, (error) => {
  155. uni.showToast({icon:'none',title: error.message})
  156. })
  157. },
  158. showPopup(id){
  159. this.$refs[id].open()
  160. },
  161. hidePopup(id){
  162. this.$refs[id].close()
  163. },
  164. goBack(){uni.navigateBack({delta:1})},
  165. getPosition () {
  166. getPointByAddress(this.chain.chain_area_info + (this.chain.chain_address?this.chain.chain_address:'')).then(res => {
  167. if (res.result.location) {
  168. this.chain.chain_longitude = res.result.location.lng
  169. this.chain.chain_latitude = res.result.location.lat
  170. }
  171. this.$forceUpdate()
  172. this.showPopup('popMap')
  173. }).catch(function (error) {
  174. uni.showToast({icon:'none',title: error.message})
  175. })
  176. },
  177. setPosition (lat, lng, name) {
  178. this.hidePopup('popMap')
  179. this.chain.chain_address = name
  180. this.chain.chain_longitude = lng
  181. this.chain.chain_latitude = lat
  182. this.$forceUpdate()
  183. },
  184. onRegion (picker, values) {
  185. this.$refs.picker.show()
  186. },
  187. onPickerConfirm (values) {
  188. this.chain.chain_area_info = this.getRegionStr(values)
  189. this.chain.chain_area_3 = values[2].area_id
  190. this.chain.chain_area_2 = values[1].area_id
  191. this.$forceUpdate()
  192. },
  193. getRegionStr (values) {
  194. let title = ''
  195. for (let i = 0; i < values.length; i++) {
  196. const element = values[i]
  197. if (i !== 0) {
  198. title = title + ' ' + element.area_name
  199. } else {
  200. title = title + element.area_name
  201. }
  202. }
  203. return title
  204. },
  205. onDelete () {
  206. this.dialog={content:'确定要删除该门店吗?'}
  207. this.$refs.confirm.open()
  208. },
  209. submit () {
  210. if (this.isAddMode) {
  211. uni.showLoading({ title: '加载中' })
  212. addChain(this.chain).then(
  213. (response) => {
  214. uni.hideLoading()
  215. uni.showToast({icon:'none',title: response.message})
  216. uni.navigateTo({url:'/pages/seller/chain/ChainList'})
  217. }, (error) => {
  218. uni.hideLoading()
  219. uni.showToast({icon:'none',title: error.message})
  220. })
  221. } else {
  222. uni.showLoading({ title: '加载中' })
  223. editChain(this.chain).then(
  224. (response) => {
  225. uni.hideLoading()
  226. uni.showToast({icon:'none',title: response.message})
  227. }, (error) => {
  228. uni.hideLoading()
  229. uni.showToast({icon:'none',title: error.message})
  230. })
  231. }
  232. }
  233. }
  234. }
  235. </script>
  236. <style scoped lang="scss">
  237. .common-header{
  238. .btn{background: #000;color: #fff;box-shadow: 0px 2px 4px #d2d2d2;}
  239. }
  240. .main-content{background: #fff;padding:0 $pageSpace}
  241. .text{text-align: right;border: 0}
  242. .address-line{display: flex;flex-direction: row;}
  243. </style>