index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. <template>
  2. <div class="app-container personal-info">
  3. <div class="title">公司信息</div>
  4. <el-divider />
  5. <el-row>
  6. <el-col :span="5">公司名称:</el-col>
  7. <el-col :span="19">{{ supplierInfo.shopName }}</el-col>
  8. </el-row>
  9. <el-divider />
  10. <el-row>
  11. <el-col :span="5">所属类型:</el-col>
  12. <el-col :span="8">{{ supplierInfo.shopType === 1 ? '品牌方' : '代理商' }}</el-col>
  13. </el-row>
  14. <el-divider />
  15. <el-row>
  16. <el-col :span="5">手机号:</el-col>
  17. <el-col :span="8">{{ supplierInfo.mobile }}</el-col>
  18. <el-col :span="8">
  19. <router-link class="link" to="/personal/mobile"><i class="el-icon-edit" /><span>修改手机号</span></router-link>
  20. </el-col>
  21. </el-row>
  22. <el-divider />
  23. <el-row>
  24. <el-col :span="5">联系人:</el-col>
  25. <el-col :span="8">{{ supplierInfo.linkMan }}</el-col>
  26. <el-col :span="8">
  27. <el-link icon="el-icon-edit" type="primary" @click="onEditContactName">修改联系人</el-link>
  28. </el-col>
  29. </el-row>
  30. <el-divider />
  31. <el-row>
  32. <el-col :span="5">公司logo:</el-col>
  33. <el-col :span="8">
  34. <preview-image :src="supplierInfo.logo" />
  35. <div style="margin-top: 12px">
  36. <el-link icon="el-icon-upload" type="primary" @click="onEditLogo">修改</el-link>
  37. </div>
  38. </el-col>
  39. </el-row>
  40. <el-divider />
  41. <el-row>
  42. <el-col :span="5">登录账号:</el-col>
  43. <el-col :span="8">{{ supplierInfo.loginAccount ? supplierInfo.loginAccount : '暂未绑定' }}</el-col>
  44. <el-col v-if="!supplierInfo.loginAccount" :span="8">
  45. <router-link class="link" to="/personal/account"><i class="el-icon-link" /><span>去绑定</span></router-link>
  46. </el-col>
  47. </el-row>
  48. <el-divider />
  49. <template v-if="supplierInfo.shopType === 2">
  50. <el-row>
  51. <el-col :span="5">旗下品牌:</el-col>
  52. <el-col :span="19">
  53. <div class="tag-list">
  54. <template v-for="(item, index) in brandList">
  55. <el-tag
  56. :key="index"
  57. closable
  58. effect="dark"
  59. size="small"
  60. type="success"
  61. @close="onRemoveBrand(item, index)"
  62. @click="onEditBrand('edit', item, index)"
  63. >
  64. <span>{{ item.brandName }}</span>
  65. </el-tag>
  66. </template>
  67. <el-tag
  68. effect="dark"
  69. type="primary"
  70. size="small"
  71. @click="onEditBrand('add')"
  72. >添加品牌<span
  73. class="el-icon-plus"
  74. /></el-tag>
  75. </div>
  76. </el-col>
  77. </el-row>
  78. <el-divider />
  79. </template>
  80. <el-row>
  81. <el-col :span="5">会员状态:</el-col>
  82. <el-col :span="8">
  83. <span v-if="supplierInfo.vipStatus === 1">会员</span>
  84. <span v-if="supplierInfo.vipStatus === 3">非会员</span>
  85. </el-col>
  86. <el-col :span="8">
  87. <router-link v-if="supplierInfo.vipStatus === 3" class="link" to="/vip/vip-open">
  88. <i class="el-icon-thumb" /><span>开通会员</span>
  89. </router-link>
  90. <router-link v-if="supplierInfo.vipStatus === 1" class="link" to="/vip/vip-open">
  91. <i class="el-icon-thumb" /><span>续费会员</span>
  92. </router-link>
  93. </el-col>
  94. </el-row>
  95. <!-- 品牌编辑dialog -->
  96. <el-dialog
  97. :title="eidtText"
  98. width="36%"
  99. :visible.sync="editVisible"
  100. :close-on-click-modal="false"
  101. :close-on-press-escape="false"
  102. :show-close="false"
  103. >
  104. <template v-if="editType < 2">
  105. <brand-edit-form v-if="editVisible" ref="brandEditForm" :model="brandModel" @change="onBrandFormChange" />
  106. </template>
  107. <template v-else>
  108. <el-form v-if="editVisible" ref="submitForm" label-width="80px" :model="formData" :rules="rules">
  109. <el-form-item v-if="editType === 2" label="logo:" prop="logo">
  110. <el-input v-show="false" v-model="formData.logo" />
  111. <upload-image
  112. tip="建议尺寸:200px * 200px"
  113. :image-list="logoImageList"
  114. @success="onUploadLogoSuccess"
  115. @remove="onRemoveLogoImage"
  116. />
  117. </el-form-item>
  118. <el-form-item v-if="editType === 3" label="联系人:" prop="linkMan">
  119. <el-input v-model="formData.linkMan" placeholder="请输入联系人" />
  120. </el-form-item>
  121. </el-form>
  122. </template>
  123. <span slot="footer" class="dialog-footer">
  124. <el-button @click="onCancel">取 消</el-button>
  125. <el-button type="primary" @click="onSubmit">确 定</el-button>
  126. </span>
  127. </el-dialog>
  128. </div>
  129. </template>
  130. <script>
  131. import {
  132. getSupplierById,
  133. updateSupplierLinkMan,
  134. updateSupplierLogo,
  135. saveSupplierShopInfo,
  136. deleteSupplierShopInfo
  137. } from '@/api/supplier'
  138. import UploadImage from '@/components/UploadImage'
  139. import { BrandEditForm } from '@/views/components'
  140. import { deepClone } from '@/utils'
  141. const generateBrandInfo = () => ({
  142. infoId: '',
  143. brandName: '',
  144. brandLogo: '',
  145. producePlace: '',
  146. manufacturer: ''
  147. })
  148. export default {
  149. components: {
  150. UploadImage,
  151. BrandEditForm
  152. },
  153. data() {
  154. return {
  155. editType: 0,
  156. editVisible: false,
  157. brandEditType: 'add',
  158. brandEditIndex: 0,
  159. supplierInfo: {},
  160. brandList: [],
  161. brandModel: generateBrandInfo(),
  162. formData: {
  163. logo: '',
  164. linkMan: ''
  165. },
  166. rules: {
  167. logo: [{ required: true, message: '请上传logo', trigger: 'change' }],
  168. linkMan: [{ required: true, message: '请输入联系人', trigger: 'blur' }]
  169. },
  170. logoImageList: []
  171. }
  172. },
  173. computed: {
  174. eidtText() {
  175. const eidtText = ['添加品牌', '修改品牌', '修改logo', '修改联系人']
  176. return eidtText[this.editType]
  177. }
  178. },
  179. created() {
  180. this.fetchSupplierInfo()
  181. },
  182. methods: {
  183. // 获取供应商信息
  184. fetchSupplierInfo() {
  185. getSupplierById({ authUserId: this.$store.getters.authUserId }).then((res) => {
  186. console.log(res)
  187. this.supplierInfo = res.data
  188. this.brandList = res.data.shopInfo
  189. })
  190. },
  191. // 品牌信息变化
  192. onBrandFormChange(data) {
  193. this.brandModel = data
  194. },
  195. // 编辑品牌事件
  196. onEditBrand(type, row, index) {
  197. this.editType = type === 'add' ? 0 : 1
  198. this.brandEditType = type
  199. this.brandEditIndex = index
  200. this.brandModel = type === 'add' ? generateBrandInfo() : row
  201. this.editVisible = true
  202. },
  203. // 删除品牌操作
  204. async onRemoveBrand(item, index) {
  205. // 判断品牌是否可删除
  206. let existInfoIds = this.formData.existProductInfoIds
  207. existInfoIds = existInfoIds ? existInfoIds.split(',') : []
  208. const exist = existInfoIds.indexOf(item.infoId.toString()) > -1
  209. if (exist) {
  210. this.$alert('对不起,该品牌已绑定设备认证,暂时无法删除!', '提示', {
  211. confirmButtonText: '确定',
  212. type: 'warning'
  213. }).then(() => {})
  214. return
  215. }
  216. try {
  217. await this.$confirm('确认删除该品牌信息?', '提示', {
  218. confirmButtonText: '确定',
  219. cancelButtonText: '取消',
  220. type: 'warning'
  221. })
  222. await this.removeBrand(item, index)
  223. } catch (error) {
  224. console.log(error)
  225. this.$message.info('已取消操作')
  226. }
  227. },
  228. async removeBrand(item, index) {
  229. try {
  230. await deleteSupplierShopInfo({ infoId: item.infoId })
  231. this.$message.success('成功删除品牌')
  232. this.brandList.splice(index, 1)
  233. } catch (error) {
  234. console.log(error)
  235. }
  236. },
  237. // 品牌信息确认提交
  238. async onBrandSubmit() {
  239. try {
  240. await this.$refs.brandEditForm.validate()
  241. await this.onBrandSave()
  242. } catch (error) {
  243. console.log(error)
  244. }
  245. },
  246. async onBrandSave() {
  247. try {
  248. await saveSupplierShopInfo(deepClone(this.brandModel))
  249. this.$message.success('品牌信息已保存')
  250. } catch (error) {
  251. console.log(error)
  252. }
  253. },
  254. // 编辑取消
  255. onCancel() {
  256. this.editVisible = false
  257. },
  258. // 编辑提交
  259. async onSubmit() {
  260. const action = {
  261. 0: this.onBrandSubmit,
  262. 1: this.onBrandSubmit,
  263. 2: this.onLogoSubmit,
  264. 3: this.onContactSubmit
  265. }
  266. try {
  267. await this.$refs.submitForm?.validate()
  268. await action[this.editType]()
  269. } catch (error) {
  270. console.log(error)
  271. } finally {
  272. this.fetchSupplierInfo()
  273. this.editVisible = false
  274. }
  275. },
  276. // logo编辑
  277. onEditLogo() {
  278. this.editType = 2
  279. this.editVisible = true
  280. },
  281. // logo编辑提交
  282. async onLogoSubmit() {
  283. try {
  284. await updateSupplierLogo({ logo: this.formData.logo })
  285. this.$message.success('修改logo成功')
  286. } catch (error) {
  287. console.log(error)
  288. } finally {
  289. this.logoImageList = []
  290. }
  291. },
  292. // 编辑联系人
  293. onEditContactName() {
  294. this.editType = 3
  295. this.editVisible = true
  296. },
  297. // 联系人编辑提交
  298. async onContactSubmit() {
  299. try {
  300. await updateSupplierLinkMan({ linkMan: this.formData.linkMan })
  301. this.$message.success('修改联系人成功')
  302. } catch (error) {
  303. console.log(error)
  304. }
  305. },
  306. // 供应商logo上传成功
  307. onUploadLogoSuccess({ response, file, fileList }) {
  308. this.logoImageList = fileList
  309. this.formData.logo = response.data
  310. },
  311. // 移除供应商logo
  312. onRemoveLogoImage() {
  313. this.logoImageList = []
  314. this.formData.logo = ''
  315. }
  316. }
  317. }
  318. </script>
  319. <style scoped lang="scss">
  320. .personal-info {
  321. width: 600px;
  322. margin: 0 auto;
  323. margin-top: 60px;
  324. color: #101010;
  325. .link {
  326. color: #409eff;
  327. font-size: 14px;
  328. &:hover {
  329. text-decoration: underline;
  330. }
  331. }
  332. .el-row {
  333. .el-col:nth-child(2) {
  334. color: #404040;
  335. }
  336. }
  337. }
  338. .title {
  339. font-size: 24px;
  340. font-weight: bold;
  341. }
  342. .tag-list {
  343. margin-top: -10px;
  344. .el-tag {
  345. cursor: pointer;
  346. margin-right: 8px;
  347. margin-top: 8px;
  348. }
  349. }
  350. .el-divider {
  351. margin: 16px 0;
  352. }
  353. </style>