stock-edit.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <template id="stock-edit">
  2. <el-dialog :visible.sync="edit.visible" width="30%" title="添加代理商" center>
  3. <el-form size="small" label-width="80px">
  4. <el-form-item label="等级" required>
  5. <el-select v-model="level" placeholder="请选择代理商等级">
  6. <el-option
  7. v-for="item in level_list"
  8. :label="item.name"
  9. :value="item.level">
  10. </el-option>
  11. </el-select>
  12. </el-form-item>
  13. </el-form>
  14. <el-form @submit.native.prevent size="small" label-width="80px">
  15. <el-form-item label="用户昵称" required>
  16. <el-autocomplete size="small" v-model="edit.nickname" value-key="nickname" @keyup.enter.native="keyUp"
  17. :fetch-suggestions="querySearchAsync" placeholder="请输入用户昵称/id/手机号"
  18. @select="shareClick"></el-autocomplete>
  19. </el-form-item>
  20. </el-form>
  21. <span slot="footer" class="dialog-footer">
  22. <el-button @click="editCancel" type="default" size="small">取消</el-button>
  23. <el-button type="primary" :loading="edit.btnLoading" style="margin-bottom: 10px;" size="small"
  24. @click="editSave">保存</el-button>
  25. </span>
  26. </el-dialog>
  27. </template>
  28. <script>
  29. Vue.component('stock-edit', {
  30. template: '#stock-edit',
  31. props: {
  32. value: {
  33. type: Boolean,
  34. default: false
  35. }
  36. },
  37. data() {
  38. return {
  39. edit: {
  40. visible: false,
  41. keyword: '',
  42. nickname: '',
  43. id: '',
  44. user_id:"",
  45. btnLoading: false,
  46. },
  47. level_list: [],
  48. level: '',
  49. listLoading:false,
  50. list:[],
  51. page:1,
  52. pageCount:0,
  53. radioSelection:0,
  54. keyword:'',
  55. selectUser:null
  56. }
  57. },
  58. watch: {
  59. value() {
  60. //console.log(113)
  61. this.radioSelection=0;
  62. this.keyword='';
  63. this.selectUser=null;
  64. if (this.value) {
  65. //console.log(115)
  66. this.edit.visible = true;
  67. this.getLevelList();//获取等级列表
  68. this.getUser();
  69. } else {
  70. this.edit.id = '';
  71. this.edit.nickname = '';
  72. this.edit.keyword = '';
  73. this.edit.visible = false;
  74. }
  75. }
  76. ,
  77. 'edit.visible'() {
  78. if (!this.edit.visible) {
  79. this.editCancel();
  80. }
  81. },
  82. keyword(val){//监听用户昵称的输入框 如果为空(选择后删除了用户)则重新请求用户的数据 改为实时请求
  83. /* if(val == ''){
  84. this.page = 1;
  85. this.pageCount = 0;
  86. this.getUser();
  87. } */
  88. this.page = 1;
  89. this.pageCount = 0;
  90. this.getUser();
  91. }
  92. },
  93. created() {
  94. //this.getLevelList();//获取等级列表
  95. },
  96. methods: {
  97. getUser(){//请求用户的列表
  98. //console.log('请求了getUser!page='+this.page+'----keyword='+this.keyword)
  99. this.listLoading = true;
  100. request({
  101. params: {
  102. r: 'cloud-stock-two/default/search-user',
  103. page:this.page,
  104. limit:20,
  105. keyword:this.keyword
  106. },
  107. method: 'get',
  108. }).then(response => {
  109. this.listLoading = false;
  110. //console.log('请求用户的列表结果='+JSON.stringify(response))
  111. if (response.data.code == 0) {
  112. this.list = response.data.data.list;
  113. this.pageCount = response.data.data.page_count;
  114. } else {
  115. this.$message.error(response.data.msg);
  116. }
  117. }).catch(response => {
  118. this.listLoading = false;
  119. });
  120. },
  121. pagination(currentPage) {
  122. this.page = currentPage;
  123. this.getUser();
  124. },
  125. selectionChange(e){
  126. //console.log('选中了='+JSON.stringify(e))
  127. this.selectUser = e;
  128. // this.keyword = this.selectUser.nickname;
  129. // 修改为查询ID,昵称存在空的情况
  130. this.keyword = this.selectUser.id;
  131. },
  132. querySearchAsync(queryString, cb) {
  133. this.edit.keyword = queryString;
  134. this.get_user(cb);
  135. },
  136. get_user(cb) {
  137. request({
  138. params: {
  139. r: 'cloud-stock-two/default/search-user',
  140. keyword: this.edit.keyword
  141. }
  142. }).then(res => {
  143. if (res.data.code == 0) {
  144. cb(res.data.data.list)
  145. } else {
  146. this.$message.error(res.data.msg);
  147. }
  148. });
  149. },
  150. agentClick(row) {
  151. this.edit.id = row.id
  152. },
  153. shareClick(row) {
  154. this.edit.user_id = row.id
  155. },
  156. getLevelList() {
  157. //this.edit.btnLoading = true;
  158. request({
  159. params: {
  160. r: 'cloud-stock-two/default/get-level-list' //代理商等级列
  161. },
  162. method: 'get',
  163. }).then(response => {
  164. if (response.data.code == 0) {
  165. this.level_list = response.data.data
  166. } else {
  167. this.$message.error(response.data.msg);
  168. }
  169. }).catch(response => {
  170. //this.edit.btnLoading = false;
  171. });
  172. },
  173. editCancel() {
  174. /* 重置表单中原来填入的数据 */
  175. this.level = '';
  176. this.selectUser = null;
  177. this.keyword = '';
  178. this.$emit('input', false);
  179. /* navigateTo({
  180. r: 'plugin/cloud_stock/mall/cloud-stock-two/index',
  181. }) */
  182. //this.value = false;
  183. },
  184. editSave() {
  185. if(!this.level){
  186. return this.$message.error('请选择代理商等级');
  187. }
  188. if(!this.edit.user_id){
  189. return this.$message.error('请选择下拉列表里的会员!');
  190. }
  191. this.edit.btnLoading = true;
  192. request({
  193. params: {
  194. r: 'cloud-stock-two/default/edit'//代理商添加//'plugin/stock/mall/stock/edit',
  195. },
  196. method: 'post',
  197. data: {
  198. user_id:this.edit.user_id,
  199. level:this.level
  200. }
  201. }).then(response => {
  202. this.edit.btnLoading = false;
  203. if (response.data.code == 0) {
  204. this.$message.success('添加成功');
  205. this.$emit('savesuccess')
  206. this.editCancel();
  207. } else {
  208. this.$message.error(response.data.msg);
  209. }
  210. }).catch(response => {
  211. this.edit.btnLoading = false;
  212. });
  213. },
  214. keyUp() {
  215. console.log('key up')
  216. },
  217. searchFun(){
  218. this.page = 1;
  219. this.getUser();
  220. }
  221. }
  222. });
  223. </script>