manager.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <template>
  2. <view class="page">
  3. <view class="flex-row justify-between outView" :style="{marginTop:'24rpx'}" v-if="roleList.length>0"
  4. @click="selectRole">
  5. <view class="roleName">
  6. <text>角色</text>
  7. </view>
  8. <view class="flex-row">
  9. <text class="roleName">{{roleList[confirmRoleIndex].name}}</text>
  10. <u-icon name="arrow-right" color="#666" size="18"></u-icon>
  11. </view>
  12. </view>
  13. <view class="dataNullView flex-col" v-if="roleBindRuleList.length===0">
  14. <view class="flex-row justify-center">
  15. <image class="dataNullImage" src="/static/zhanwu.png"></image>
  16. </view>
  17. <text v-if="roleList[confirmRoleIndex]" class="roleName1">{{roleList[confirmRoleIndex].name}}<text
  18. class="roleHint">角色没有拓客规则,点击下方“添加规则”按钮可添加拓客规则</text></text>
  19. </view>
  20. <view v-else class="scroll-Y">
  21. <view class="flex-col outView" v-for="(item,index) in roleBindRuleList" :key="index">
  22. <view class="flex-row justify-between">
  23. <text class="title">{{item.title}}</text>
  24. <u-icon name="trash" color="#666" size="24" @click="deleteRule(item)"></u-icon>
  25. </view>
  26. <view class="flex-row justify-between awardView">
  27. <text>直推:</text>
  28. <view>
  29. <view class="flex-row award justify-between">
  30. <text class="awardItem">注册现金:{{item.awardAmount}}元</text>
  31. </view>
  32. <view class="flex-row award justify-between">
  33. <text class="awardItem">消费现金:{{item.consumeAmount}}元</text>
  34. <text class="awardItem">消费比例:{{item.consumeRatio * 100}}%</text>
  35. </view>
  36. </view>
  37. </view>
  38. <view class="flex-row justify-between awardView">
  39. <text>间推:</text>
  40. <view class="flex-row award justify-between">
  41. <text class="awardItem">间推现金:{{item.indirectAmount}}元</text>
  42. <text class="awardItem">间推比例:{{item.indirectRatio * 100}}%</text>
  43. </view>
  44. </view>
  45. <view class="flex-row justify-between awardView">
  46. <text>优惠券:</text>
  47. <view class="flex-col">
  48. <view class="flex-col discount award" v-for="(item1,index1) in item.strategyList" :key="index1">
  49. <text>{{item1.name}} * {{item1.degree}}张</text>
  50. <text>有效期:{{item1.startTime.substring(0,10)}} 至 {{item1.endTime.substring(0,10)}}</text>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. <view class="addButton" @click="addRule">
  57. <text>+添加规则</text>
  58. </view>
  59. <view class="confirmButton" @click="createQrCode">
  60. <text>生成二维码</text>
  61. </view>
  62. <!--邀请好友福利码-->
  63. <uni-popup ref="createQrCodePopup" type="center" @change="createQrCodePopupChange">
  64. <view class="createQrCodePopup">
  65. <view class="flex-row justify-center">
  66. <text class="popupTitle">邀请好友福利码</text>
  67. </view>
  68. <view class="xoIcon" @click="closePopup">
  69. <u-icon name="close-circle" color="#666" size="24"></u-icon>
  70. </view>
  71. <view class="flex-row justify-center">
  72. <uv-qrcode ref="qrcode" size="540rpx" :value="qrcodeUrl" :options="options"></uv-qrcode>
  73. </view>
  74. <view class="flex-row justify-center qrCreateTime">
  75. <text>生成时间:{{qrCreateTime}}</text>
  76. </view>
  77. </view>
  78. </uni-popup>
  79. <!--选择规则-->
  80. <uni-popup ref="rulePopup" type="bottom" @change="popupChange">
  81. <view class="rulePopup">
  82. <view class="flex-row justify-between">
  83. <text class="popupTitle">选择规则</text>
  84. <u-icon name="close-circle" color="#666" size="24" @click="closePopup"></u-icon>
  85. </view>
  86. <scroll-view scroll-y class="scroll-Y1">
  87. <view class="dataNullView flex-col" v-if="roleNoBindRuleList.length===0">
  88. <view class="flex-row justify-center">
  89. <image class="dataNullImage" src="/static/dataNull.png"></image>
  90. </view>
  91. <text class="roleHint">暂无可添加的拓客规则</text>
  92. </view>
  93. <view v-else>
  94. <view class="flex-col outView " :class="{selectRoleName1: item.select }"
  95. v-for="(item,index) in roleNoBindRuleList" :style="{marginTop: '24rpx'}"
  96. @click="selectRule(item,index)" :key="index">
  97. <view class="flex-row justify-between">
  98. <text class="title">{{item.title}}</text>
  99. </view>
  100. <view class="flex-row justify-between awardView">
  101. <text>直推:</text>
  102. <view>
  103. <view class="flex-row award justify-between">
  104. <text class="awardItem">注册现金:{{item.awardAmount}}元</text>
  105. </view>
  106. <view class="flex-row award justify-between">
  107. <text class="awardItem">消费现金:{{item.consumeAmount}}元</text>
  108. <text class="awardItem">消费比例:{{item.consumeRatio * 100}}%</text>
  109. </view>
  110. </view>
  111. </view>
  112. <view class="flex-row justify-between awardView">
  113. <text>间推:</text>
  114. <view class="flex-row award justify-between">
  115. <text class="awardItem">间推现金:{{item.indirectAmount}}元</text>
  116. <text class="awardItem">间推比例:{{item.indirectRatio * 100}}%</text>
  117. </view>
  118. </view>
  119. <view class="flex-row justify-between awardView">
  120. <text>优惠券:</text>
  121. <view class="flex-col">
  122. <view class="flex-col discount award" v-for="(item1,index1) in item.strategyList"
  123. :key="index1">
  124. <text>{{item1.name}} * {{item1.degree}}张</text>
  125. <text>有效期:{{item1.startTime.substring(0,10)}} 至
  126. {{item1.endTime.substring(0,10)}}</text>
  127. </view>
  128. </view>
  129. </view>
  130. </view>
  131. </view>
  132. </scroll-view>
  133. <view class="confirmButton" @click="confirmAddRule">
  134. <text>确定</text>
  135. </view>
  136. </view>
  137. </uni-popup>
  138. <!--选择角色-->
  139. <uni-popup ref="rolePopup" type="bottom" @change="popupChange">
  140. <view class="rolePopup">
  141. <view class="flex-row justify-between">
  142. <text class="popupTitle">选择角色</text>
  143. <u-icon name="close-circle" color="#666" size="24" @click="closePopup"></u-icon>
  144. </view>
  145. <scroll-view scroll-y class="scroll-Y2">
  146. <view class="roleName1" :class="{selectRoleName1: selectRoleIndex === index }"
  147. v-for="(item,index) in roleList" :key="index" @click="selectRoleIndex = index">
  148. <text>{{item.name}}</text>
  149. <!-- <text class="tag" v-if="item.tag == '0'">拓客专员</text>-->
  150. <!-- <text class="tag" v-if="item.tag == '1'">合作伙伴</text>-->
  151. <!-- <text class="tag" v-if="item.tag == '2'">推广人员</text>-->
  152. </view>
  153. </scroll-view>
  154. <view class="confirmButton" @click="confirmRole">
  155. <text>确定</text>
  156. </view>
  157. </view>
  158. </uni-popup>
  159. </view>
  160. </template>
  161. <script>
  162. import commonUtils from "../../../common/js/utils/commonUtils";
  163. export default {
  164. props: {
  165. height: {
  166. type: String,
  167. default () {
  168. return ''
  169. }
  170. },
  171. },
  172. data() {
  173. return {
  174. qrCreateTime: '',
  175. selectRoleIndex: 0, //正在选择的角色下标
  176. confirmRoleIndex: 0, //当前选中的角色下标
  177. roleList: [],
  178. roleBindRuleList: [], //角色已经绑定的规则
  179. roleNoBindRuleList: [], //角色没有绑定的规则
  180. roleBindRuleParam: {},
  181. value: 1,
  182. qrcodeUrl: this.$tkUrl + '?roleId={roleId}&parentId={parentId}&timestamp={timestamp}&type=2&expand1=2',
  183. options: {
  184. // 指定二维码前景,一般可在中间放logo
  185. foregroundImagePadding: 2,
  186. foregroundImageBorderRadius: 5,
  187. foregroundImageSrc: '/static/logo.png'
  188. },
  189. }
  190. },
  191. created() {
  192. console.log('接收到的高度', this.height)
  193. this.userInfo = uni.getStorageSync('spreadUserInfo')
  194. this.getRoleList()
  195. },
  196. methods: {
  197. formatDate() {
  198. this.qrCreateTime = commonUtils.formatDate(new Date())
  199. },
  200. deleteRule(item) {
  201. let that = this
  202. uni.showModal({
  203. title: '温馨提示',
  204. content: '是否确认删除该规则!',
  205. success: function(res) {
  206. if (res.confirm) {
  207. console.log('用户点击确定');
  208. that.$api.service.cancelRoleBindRule({
  209. roleId: that.roleList[that.confirmRoleIndex].id,
  210. ruleIds: [item.id]
  211. }).then(res => {
  212. that.getRuleByRoleId(that.roleList[that.confirmRoleIndex].id)
  213. that.getNewRules(that.roleList[that.confirmRoleIndex].id)
  214. })
  215. } else if (res.cancel) {
  216. console.log('用户点击取消');
  217. }
  218. }
  219. });
  220. },
  221. selectRule(item, index) {
  222. console.log(item)
  223. item.select = !item.select
  224. this.$set(this.roleNoBindRuleList, index, item)
  225. },
  226. confirmAddRule() {
  227. let ruleIds = []
  228. for (const rule of this.roleNoBindRuleList) {
  229. if (rule.select) {
  230. ruleIds.push(rule.id)
  231. }
  232. }
  233. if (ruleIds.length === 0) {
  234. this.closePopup()
  235. return
  236. }
  237. this.$api.service.roleBindRule({
  238. roleId: this.roleList[this.confirmRoleIndex].id,
  239. ruleIds: ruleIds
  240. }).then(res => {
  241. this.getRuleByRoleId(this.roleList[this.confirmRoleIndex].id)
  242. this.getNewRules(this.roleList[this.confirmRoleIndex].id)
  243. })
  244. this.closePopup()
  245. },
  246. confirmRole() {
  247. this.confirmRoleIndex = this.selectRoleIndex
  248. this.getRuleByRoleId(this.roleList[this.confirmRoleIndex].id)
  249. this.getNewRules(this.roleList[this.confirmRoleIndex].id)
  250. this.closePopup()
  251. },
  252. popupChange(e) {
  253. if (e.show) {
  254. uni.hideTabBar()
  255. }
  256. if (!e.show) {
  257. uni.showTabBar()
  258. }
  259. },
  260. closePopup() {
  261. this.$refs.rolePopup.close()
  262. this.$refs.createQrCodePopup.close()
  263. this.$refs.rulePopup.close()
  264. },
  265. selectRole() {
  266. this.$refs.rolePopup.open()
  267. },
  268. createQrCode() {
  269. if (!this.roleBindRuleList || this.roleBindRuleList.length === 0) {
  270. uni.showToast({
  271. icon: 'error',
  272. duration: 3000,
  273. title: '请先添加规则!'
  274. });
  275. return
  276. }
  277. let data = {
  278. roleId: this.roleList[this.confirmRoleIndex].id,
  279. parentId: this.userInfo.id,
  280. timestamp: new Date().getTime() + (60 * 1000 * 60 * 24 * 365 * 10)
  281. };
  282. for (let key in data) {
  283. let regexp = new RegExp("{" + key + "}"); // 构造正则表达式
  284. this.qrcodeUrl = this.qrcodeUrl.replace(regexp, data[key]); // 执行替换操作
  285. }
  286. console.log('++++qrcodeUrl+++++', this.qrcodeUrl)
  287. this.formatDate()
  288. this.$refs.createQrCodePopup.open()
  289. },
  290. createQrCodePopupChange(e) {
  291. console.log(e)
  292. if (!e.show) {
  293. this.qrcodeUrl = this.$tkUrl + '?roleId={roleId}&parentId={parentId}&timestamp={timestamp}&type=2&expand1=2'
  294. }
  295. },
  296. addRule() {
  297. this.$refs.rulePopup.open()
  298. },
  299. change(e) {
  300. console.log("e:", e);
  301. },
  302. //查询规则
  303. getRuleList() {
  304. this.$api.service.getRuleList().then(res => {
  305. console.log(res)
  306. this.ruleList = res.data.data
  307. })
  308. },
  309. //查询角色
  310. getRoleList() {
  311. this.$api.service.getRoleList().then(res => {
  312. console.log(res)
  313. this.roleList = res.data.data
  314. this.getRuleByRoleId(this.roleList[this.confirmRoleIndex].id)
  315. this.getNewRules(this.roleList[this.confirmRoleIndex].id)
  316. })
  317. },
  318. //查询角色已经绑定的规则
  319. getRuleByRoleId(roleId) {
  320. this.$api.service.getRuleByRoleId({
  321. roleId: roleId
  322. }).then(res => {
  323. this.roleBindRuleList = res.data.data
  324. })
  325. },
  326. //查询角色没有绑定的规则
  327. getNewRules(roleId) {
  328. this.$api.service.getNewRules({
  329. roleId: roleId
  330. }).then(res => {
  331. this.roleNoBindRuleList = res.data.data
  332. })
  333. },
  334. }
  335. }
  336. </script>
  337. <style scoped lang="scss">
  338. @import './index.rpx.css';
  339. </style>