index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <template>
  2. <view>
  3. <u-modal :show="showModal" ref="uModal" :asyncClose="false" showCancelButton @cancel="closeDialog"
  4. cancelColor="#909399" :confirmText="'确定'" confirmColor="#2979ff" @confirm="confirm" @close="closeDialog"
  5. :closeOnClickOverlay="false">
  6. <view class="title_wrap">
  7. <view class="title">
  8. {{ title }}
  9. </view>
  10. <view class="modal_wrap">
  11. <text @click="handleBrandClick" class="item"
  12. :class="info.dictLabel ? 'brand' : 'brand placeholder'">{{ info.dictLabel || '品牌' }}</text>
  13. <text class="divider">|</text>
  14. <u--input placeholder="型号" class="item" border="none" v-model="info.model" clearable></u--input>
  15. <text class="divider">|</text>
  16. <u--input class="code-input item" placeholder="编码" border="none" v-model="info.code"
  17. clearable></u--input>
  18. </view>
  19. </view>
  20. <view class="img_wrap">
  21. <imgs-row-scroll v-if="info.imgsUrl.length > 0" :isShowDeleteIcon="true"
  22. @deleteImgInfo="getDeleteImgInfo" imgMode="aspectFill" :totalWidth="400" :images="info.imgsUrl"
  23. :previewEnabled="true" :imageWidth="150" :imageHeight="150"></imgs-row-scroll>
  24. <u-upload @afterRead="afterRead" name="3" multiple :maxCount="10"></u-upload>
  25. </view>
  26. <u--input v-if="editOrAdd === 'edit'" type="number" class="price" placeholder="价格" border="bottom" v-model="info.price"
  27. clearable></u--input>
  28. <u--input v-if="editOrAdd === 'edit'" placeholder="备注" border="bottom" v-model="info.remark"
  29. clearable></u--input>
  30. <qiun-data-charts v-if="isShowChart" type="column" :chartData="chartData" canvasId="priceChart" :opts="opts" :ontouch="true"
  31. width="700rpx" height="600rpx" backgroundColor="#fff" />
  32. <view v-if="isShowHistory" class="history_wrap">
  33. <view class="title">
  34. 询价历史
  35. </view>
  36. <u-cell v-for="(item, index) in historyList" :key="index" :title="(index+1)+'. ¥'+item.price" :value="'备注:'+ (item.remark || '无') "></u-cell>
  37. </view>
  38. </u-modal>
  39. <brandList ref="brandListRef" @selectedBrand="handleSelectedBrand"></brandList>
  40. </view>
  41. </template>
  42. <script>
  43. import imgsRowScroll from '@/components/imgs-row-scroll/index.vue'
  44. import brandList from '@/components/brand-list/index.vue'
  45. export default {
  46. name: 'AddInquiryDialog',
  47. components: {
  48. imgsRowScroll,
  49. brandList
  50. },
  51. props: {
  52. clueId: {
  53. type: String,
  54. default: ''
  55. },
  56. show: {
  57. type: Boolean,
  58. default: false
  59. },
  60. editOrAdd: {
  61. type: String,
  62. default: ''// edit 编辑(有价格), editForm 编辑询价单(无价格), add 新增询价单, receptFormAdd 新增接收询价单 线索页面:第一次点击是新增(不需要回显),status传1,第二次点击是无价格编辑status传1;接单中心:第一次点击是新增(需要回显)status传1,第二次点击是无价格编辑status传1;只有edit是有价格编辑status传2
  63. },
  64. editInfo: {
  65. type: Object,
  66. default: () => { }
  67. },
  68. type: {
  69. type: Number,
  70. default: 1
  71. },
  72. isClue: {
  73. type: Boolean,
  74. default: false
  75. },
  76. title: {
  77. type: String,
  78. default: ''
  79. },
  80. isShowChart: {
  81. type: Boolean,
  82. default: false
  83. },
  84. isShowHistory: {
  85. type: Boolean,
  86. default: false
  87. }
  88. },
  89. emits: ['submitSuccess'],
  90. inject: {
  91. refreshData: {
  92. default: null
  93. }
  94. },
  95. data() {
  96. return {
  97. showModal: false,
  98. info: {
  99. model: '',
  100. code: '',
  101. id: '',
  102. price: '',
  103. dictLabel: '',
  104. dictValue: '',
  105. imgsUrl: [],
  106. remark: ''
  107. },
  108. historyList: [],
  109. rules: {
  110. brand: [
  111. { required: true, message: '请输入品牌', trigger: 'blur' }
  112. ]
  113. },
  114. opts: {
  115. color: [this.getRandomColor()],
  116. padding: [15, 15, 0, 5],
  117. touchMoveLimit: 24,
  118. enableScroll: true,
  119. legend: {},
  120. xAxis: {
  121. disableGrid: true,
  122. scrollShow: true,
  123. itemCount: 4
  124. },
  125. yAxis: {
  126. data: [
  127. {
  128. min: 0
  129. }
  130. ]
  131. },
  132. extra: {
  133. column: {
  134. type: "group",
  135. width: 30,
  136. activeBgColor: "#000000",
  137. activeBgOpacity: 0.08,
  138. seriesGap: 5,
  139. barBorderRadius: [6,6,6,6]
  140. }
  141. }
  142. },
  143. chartData:{}
  144. }
  145. },
  146. watch: {
  147. show: {
  148. handler(newVal) {
  149. this.showModal = newVal;
  150. },
  151. immediate: true
  152. }
  153. },
  154. methods: {
  155. getRandomColor() {
  156. var letters = '0123456789ABCDEF';
  157. var color = '#';
  158. for (var i = 0; i < 6; i++) {
  159. color += letters[Math.floor(Math.random() * 16)];
  160. }
  161. return color;
  162. },
  163. // 编辑回显
  164. initData() {
  165. this.$nextTick(() => {
  166. this.info = JSON.parse(JSON.stringify(this.editInfo))
  167. if(this.isShowChart){
  168. this.chartData = {
  169. categories: this.info.priceChart.map((item, index) => item.userName),
  170. series: [
  171. {
  172. name: "价格",
  173. data: this.info.priceChart.map(item => item.price)
  174. }
  175. ]
  176. };
  177. }
  178. if(this.isShowHistory){
  179. this.historyList = JSON.parse(this.info.myPriceHistory)
  180. }
  181. this.showModal = true;
  182. })
  183. },
  184. // 获取删除图片信息
  185. getDeleteImgInfo(info) {
  186. this.info.imgsUrl = info.newImages
  187. },
  188. handleBrandClick() {
  189. this.$refs.brandListRef.showBrandList();
  190. },
  191. handleSelectedBrand(info) {
  192. this.info.dictLabel = info.dictLabel
  193. this.info.dictValue = info.dictValue
  194. },
  195. // 上传图片
  196. afterRead(info) {
  197. info.file.forEach(item => {
  198. uni.$u.api.uploadFile(item.url).then((res) => {
  199. this.info.imgsUrl.push(res.data.url);
  200. uni.$u.toast("文件上传成功");
  201. }).catch(() => {
  202. uni.$u.toast("上传文件失败");
  203. })
  204. })
  205. },
  206. // 确认添加
  207. confirm() {
  208. if (!this.info.dictLabel || !this.info.dictValue) {
  209. uni.showToast({
  210. title: '请选择品牌',
  211. icon: 'none'
  212. })
  213. return
  214. }
  215. if (!this.info.model) {
  216. uni.showToast({
  217. title: '请输入型号',
  218. icon: 'none'
  219. })
  220. return
  221. }
  222. if (!this.info.code) {
  223. uni.showToast({
  224. title: '请输入编码',
  225. icon: 'none'
  226. })
  227. return
  228. }
  229. if (this.info.imgsUrl.length == 0) {
  230. uni.showToast({
  231. title: '请上传图片',
  232. icon: 'none'
  233. })
  234. return
  235. }
  236. if (this.editOrAdd === 'edit' && !this.info.price) {
  237. uni.showToast({
  238. title: '请输入价格',
  239. icon: 'none'
  240. })
  241. return
  242. }
  243. const data = {
  244. clueId: this.clueId,
  245. dictValue: this.info.dictValue,
  246. dictLabel: this.info.dictLabel,
  247. model: this.info.model,
  248. code: this.info.code,
  249. id: (this.editOrAdd === 'edit' || this.editOrAdd === 'editForm') ? this.info.id : '',
  250. price: this.editOrAdd === 'edit' ? this.info.price : '',
  251. imgsUrl: this.info.imgsUrl,
  252. status: this.editOrAdd === 'edit' ? '2' : '1',
  253. type: this.type,
  254. remark: this.info.remark
  255. }
  256. uni.$u.api.addInquiry(data).then(res => {
  257. uni.$u.toast('保存成功')
  258. this.closeDialog()
  259. this.$emit('submitSuccess')
  260. if (this.isClue && this.refreshData) this.refreshData.resetData(); //线索公海页面需要刷新列表
  261. }).catch((err) => {
  262. uni.$u.toast(err)
  263. })
  264. },
  265. showDialog() {
  266. if (this.editOrAdd === 'edit' || this.editOrAdd === 'editForm' || this.editOrAdd === 'receptFormAdd') {
  267. this.initData();
  268. } else if (this.editOrAdd === 'add') {
  269. this.clearForm()
  270. this.showModal = true;
  271. }
  272. },
  273. clearForm() {
  274. this.info = {
  275. dictLabel: '',
  276. dictValue: '',
  277. model: '',
  278. code: '',
  279. id: '',
  280. price: '',
  281. imgsUrl: []
  282. }
  283. },
  284. closeDialog() {
  285. this.showModal = false;
  286. },
  287. }
  288. };
  289. </script>
  290. <style lang="scss" scoped>
  291. @import './index.scss'
  292. </style>